From e2bcb0bbbbc192dd121189257c5eeeabaac4dda5 Mon Sep 17 00:00:00 2001 From: Sri Sham Haran Date: Sat, 12 Nov 2022 23:57:12 +0800 Subject: [PATCH] play pause stop bound to F5 F6 F7 --- .../EditorWindow/MenuBar/SHEditorMenuBar.cpp | 25 +-------- SHADE_Engine/src/Editor/SHEditor.cpp | 56 ++++++++++++++++++- SHADE_Engine/src/Editor/SHEditor.h | 4 ++ 3 files changed, 62 insertions(+), 23 deletions(-) diff --git a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp index fdde55e1..ce3ca8b5 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/MenuBar/SHEditorMenuBar.cpp @@ -223,39 +223,20 @@ namespace SHADE { if(editor->SaveScene()) { - const SHEditorStateChangeEvent STATE_CHANGE_EVENT - { - .previousState = editor->editorState - }; - editor->editorState = SHEditor::State::PLAY; - SHCommandManager::SwapStacks(); - SHEventManager::BroadcastEvent(STATE_CHANGE_EVENT, SH_EDITOR_ON_PLAY_EVENT); + editor->Play(); } } ImGui::EndDisabled(); ImGui::BeginDisabled(editor->editorState == SHEditor::State::PAUSE); if(ImGui::SmallButton(ICON_MD_PAUSE)) { - const SHEditorStateChangeEvent STATE_CHANGE_EVENT - { - .previousState = editor->editorState - }; - editor->editorState = SHEditor::State::PAUSE; - - SHEventManager::BroadcastEvent(STATE_CHANGE_EVENT, SH_EDITOR_ON_PAUSE_EVENT); + editor->Pause(); } ImGui::EndDisabled(); ImGui::BeginDisabled(editor->editorState == SHEditor::State::STOP); if(ImGui::SmallButton(ICON_MD_STOP)) { - const SHEditorStateChangeEvent STATE_CHANGE_EVENT - { - .previousState = editor->editorState - }; - editor->editorState = SHEditor::State::STOP; - SHCommandManager::SwapStacks(); - SHEventManager::BroadcastEvent(STATE_CHANGE_EVENT, SH_EDITOR_ON_STOP_EVENT); - editor->LoadScene(SHSceneManager::GetCurrentSceneAssetID()); + editor->Stop(); } ImGui::EndDisabled(); ImGui::EndMenuBar(); diff --git a/SHADE_Engine/src/Editor/SHEditor.cpp b/SHADE_Engine/src/Editor/SHEditor.cpp index c4ad3459..90655a62 100644 --- a/SHADE_Engine/src/Editor/SHEditor.cpp +++ b/SHADE_Engine/src/Editor/SHEditor.cpp @@ -168,7 +168,19 @@ namespace SHADE { SHCommandManager::UndoCommand(); } - + if(ImGui::IsKeyReleased(ImGuiKey_F5)) + { + Play(); + } + else if (ImGui::IsKeyReleased(ImGuiKey_F6)) + { + Pause(); + } + else if (ImGui::IsKeyReleased(ImGuiKey_F7)) + { + Stop(); + } + Render(); } @@ -597,6 +609,48 @@ namespace SHADE } } + void SHEditor::Play() + { + if(editorState == State::PLAY) + return; + if (SaveScene()) + { + const SHEditorStateChangeEvent STATE_CHANGE_EVENT + { + .previousState = editorState + }; + editorState = State::PLAY; + SHCommandManager::SwapStacks(); + SHEventManager::BroadcastEvent(STATE_CHANGE_EVENT, SH_EDITOR_ON_PLAY_EVENT); + } + } + + void SHEditor::Pause() + { + if (editorState == State::PAUSE) + return; + const SHEditorStateChangeEvent STATE_CHANGE_EVENT + { + .previousState = editorState + }; + editorState = State::PAUSE; + SHEventManager::BroadcastEvent(STATE_CHANGE_EVENT, SH_EDITOR_ON_PAUSE_EVENT); + } + + void SHEditor::Stop() + { + if (editorState == State::STOP) + return; + const SHEditorStateChangeEvent STATE_CHANGE_EVENT + { + .previousState = editorState + }; + editorState = SHEditor::State::STOP; + SHCommandManager::SwapStacks(); + SHEventManager::BroadcastEvent(STATE_CHANGE_EVENT, SH_EDITOR_ON_STOP_EVENT); + LoadScene(SHSceneManager::GetCurrentSceneAssetID()); + } + void SHEditor::NewFrame() { SDL_Event event; diff --git a/SHADE_Engine/src/Editor/SHEditor.h b/SHADE_Engine/src/Editor/SHEditor.h index 0f5a3aaa..0de7796a 100644 --- a/SHADE_Engine/src/Editor/SHEditor.h +++ b/SHADE_Engine/src/Editor/SHEditor.h @@ -184,6 +184,10 @@ namespace SHADE void LoadScene(AssetID const& assetID) noexcept; + void Play(); + void Pause(); + void Stop(); + // List of selected entities std::vector selectedEntities;