From c7c44705e143052be41f9df88dc65ec69ea96a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Mon, 3 Jul 2023 20:54:54 +0200 Subject: [PATCH 1/3] Refactor rendering of editor mentions and modebar --- src/game/editor/editor.cpp | 82 +++++++++++++++----------------------- src/game/editor/editor.h | 1 + 2 files changed, 33 insertions(+), 50 deletions(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 137e998f1..b49ef855f 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -5270,44 +5270,49 @@ void CEditor::ShowFileDialogError(const char *pFormat, ...) void CEditor::RenderModebar(CUIRect View) { - CUIRect Button; + CUIRect Mentions, ModeButton; + View.HSplitTop(30.0f, &Mentions, &ModeButton); + ModeButton.VSplitLeft(65.0f, &ModeButton, nullptr); - // mode buttons + // mentions + if(m_Mentions) { - View.VSplitLeft(65.0f, &Button, &View); - Button.HSplitTop(30.0f, nullptr, &Button); - static int s_Button = 0; - const char *pButName = ""; + char aBuf[64]; + if(m_Mentions == 1) + str_copy(aBuf, Localize("1 new mention")); + else if(m_Mentions <= 9) + str_format(aBuf, sizeof(aBuf), Localize("%d new mentions"), m_Mentions); + else + str_copy(aBuf, Localize("9+ new mentions")); + TextRender()->TextColor(ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f)); + UI()->DoLabel(&Mentions, aBuf, 10.0f, TEXTALIGN_MC); + TextRender()->TextColor(TextRender()->DefaultTextColor()); + } + + // mode button + { + const char *pModeLabel = ""; if(m_Mode == MODE_LAYERS) - pButName = "Layers"; + pModeLabel = "Layers"; else if(m_Mode == MODE_IMAGES) - pButName = "Images"; + pModeLabel = "Images"; else if(m_Mode == MODE_SOUNDS) - pButName = "Sounds"; + pModeLabel = "Sounds"; + else + dbg_assert(false, "m_Mode invalid"); - int MouseButton = DoButton_Tab(&s_Button, pButName, 0, &Button, 0, "Switch between images, sounds and layers management."); + static int s_ModeButton = 0; + const int MouseButton = DoButton_Tab(&s_ModeButton, pModeLabel, 0, &ModeButton, 0, "Switch between images, sounds and layers management."); if(MouseButton == 2 || (Input()->KeyPress(KEY_LEFT) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) { - if(m_Mode == MODE_LAYERS) - m_Mode = MODE_SOUNDS; - else if(m_Mode == MODE_IMAGES) - m_Mode = MODE_LAYERS; - else - m_Mode = MODE_IMAGES; + m_Mode = (m_Mode + NUM_MODES - 1) % NUM_MODES; } else if(MouseButton == 1 || (Input()->KeyPress(KEY_RIGHT) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) { - if(m_Mode == MODE_LAYERS) - m_Mode = MODE_IMAGES; - else if(m_Mode == MODE_IMAGES) - m_Mode = MODE_SOUNDS; - else - m_Mode = MODE_LAYERS; + m_Mode = (m_Mode + 1) % NUM_MODES; } } - - View.VSplitLeft(5.0f, nullptr, &View); } void CEditor::RenderStatusbar(CUIRect View) @@ -6229,7 +6234,7 @@ void CEditor::Render() // render checker RenderBackground(View, m_CheckerTexture, 32.0f, 1.0f); - CUIRect MenuBar, CModeBar, ToolBar, StatusBar, ExtraEditor, ToolBox; + CUIRect MenuBar, ModeBar, ToolBar, StatusBar, ExtraEditor, ToolBox; m_ShowPicker = Input()->KeyIsPressed(KEY_SPACE) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0 && UI()->LastActiveItem() != &m_SettingsCommandInput && m_vSelectedLayers.size() == 1; if(m_GuiActive) @@ -6326,34 +6331,12 @@ void CEditor::Render() RenderBackground(ToolBar, m_BackgroundTexture, 128.0f, Brightness); ToolBar.Margin(2.0f, &ToolBar); - ToolBar.VSplitLeft(100.0f, &CModeBar, &ToolBar); + ToolBar.VSplitLeft(100.0f, &ModeBar, &ToolBar); RenderBackground(StatusBar, m_BackgroundTexture, 128.0f, Brightness); StatusBar.Margin(2.0f, &StatusBar); } - // show mentions - if(m_GuiActive && m_Mentions) - { - char aBuf[64]; - if(m_Mentions == 1) - { - str_copy(aBuf, Localize("1 new mention")); - } - else if(m_Mentions <= 9) - { - str_format(aBuf, sizeof(aBuf), Localize("%d new mentions"), m_Mentions); - } - else - { - str_copy(aBuf, Localize("9+ new mentions")); - } - - TextRender()->TextColor(1.0f, 0.0f, 0.0f, 1.0f); - TextRender()->Text(5.0f, 27.0f, 10.0f, aBuf, -1.0f); - TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f); - } - // do the toolbar if(m_Mode == MODE_LAYERS) DoToolbarLayers(ToolBar); @@ -6471,8 +6454,7 @@ void CEditor::Render() if(m_GuiActive) { RenderMenubar(MenuBar); - - RenderModebar(CModeBar); + RenderModebar(ModeBar); if(!m_ShowPicker) { if(m_ShowEnvelopeEditor) diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 4d03c92bd..1c70f6c81 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -36,6 +36,7 @@ enum MODE_LAYERS = 0, MODE_IMAGES, MODE_SOUNDS, + NUM_MODES, DIALOG_NONE = 0, DIALOG_FILE, From 3a5228bb8fb4b0c4aadf979db96145ed037998a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Tue, 11 Jul 2023 17:59:39 +0200 Subject: [PATCH 2/3] Use `DoButton_Ex` instead of `DoButton_Tab` Reduce duplicate code. --- src/game/editor/editor.cpp | 9 +-------- src/game/editor/editor.h | 1 - 2 files changed, 1 insertion(+), 9 deletions(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index b49ef855f..b23f487ab 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -458,13 +458,6 @@ int CEditor::DoButton_MenuItem(const void *pID, const char *pText, int Checked, return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); } -int CEditor::DoButton_Tab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) -{ - pRect->Draw(GetButtonColor(pID, Checked), IGraphics::CORNER_T, 5.0f); - UI()->DoLabel(pRect, pText, 10.0f, TEXTALIGN_MC); - return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); -} - int CEditor::DoButton_Ex(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int Corners, float FontSize) { pRect->Draw(GetButtonColor(pID, Checked), Corners, 3.0f); @@ -5303,7 +5296,7 @@ void CEditor::RenderModebar(CUIRect View) dbg_assert(false, "m_Mode invalid"); static int s_ModeButton = 0; - const int MouseButton = DoButton_Tab(&s_ModeButton, pModeLabel, 0, &ModeButton, 0, "Switch between images, sounds and layers management."); + const int MouseButton = DoButton_Ex(&s_ModeButton, pModeLabel, 0, &ModeButton, 0, "Switch between images, sounds and layers management.", IGraphics::CORNER_T, 10.0f); if(MouseButton == 2 || (Input()->KeyPress(KEY_LEFT) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) { m_Mode = (m_Mode + NUM_MODES - 1) % NUM_MODES; diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 1c70f6c81..010829510 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -1176,7 +1176,6 @@ public: int DoButton_Editor(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip); int DoButton_Env(const void *pID, const char *pText, int Checked, const CUIRect *pRect, const char *pToolTip, ColorRGBA Color, int Corners); - int DoButton_Tab(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip); int DoButton_Ex(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int Corners, float FontSize = 10.0f); int DoButton_FontIcon(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int Corners, float FontSize = 10.0f); int DoButton_ButtonDec(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip); From 43109bec3c3efea558c583cb85197e9c2dd8a486 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20M=C3=BCller?= Date: Sat, 8 Jul 2023 12:45:38 +0200 Subject: [PATCH 3/3] Show message in editor when player is moved ingame Show a short message below the existing chat mentions message that is shown in the top left area of the editor above the layers/images/sounds button when the player character is moved ingame while the editor is open. The messages are cleared when the editor is activated and when the client is disconnected. Closes #1993. --- src/engine/client/client.cpp | 2 +- src/engine/editor.h | 3 +++ src/game/client/gameclient.cpp | 10 ++++++++++ src/game/editor/editor.cpp | 20 ++++++++++++++++++-- src/game/editor/editor.h | 8 +++++--- 5 files changed, 37 insertions(+), 6 deletions(-) diff --git a/src/engine/client/client.cpp b/src/engine/client/client.cpp index 6832cebe4..9a706537f 100644 --- a/src/engine/client/client.cpp +++ b/src/engine/client/client.cpp @@ -3200,7 +3200,7 @@ void CClient::Run() { Input()->MouseModeRelative(); GameClient()->OnActivateEditor(); - m_pEditor->ResetMentions(); + m_pEditor->OnActivate(); m_EditorActive = true; } } diff --git a/src/engine/editor.h b/src/engine/editor.h index 01000428d..2967c6c89 100644 --- a/src/engine/editor.h +++ b/src/engine/editor.h @@ -12,11 +12,14 @@ public: virtual void Init() = 0; virtual void OnUpdate() = 0; virtual void OnRender() = 0; + virtual void OnActivate() = 0; virtual bool HasUnsavedData() const = 0; virtual bool Load(const char *pFilename, int StorageType) = 0; virtual bool Save(const char *pFilename) = 0; virtual void UpdateMentions() = 0; virtual void ResetMentions() = 0; + virtual void OnIngameMoved() = 0; + virtual void ResetIngameMoved() = 0; }; extern IEditor *CreateEditor(); diff --git a/src/game/client/gameclient.cpp b/src/game/client/gameclient.cpp index 114895685..7c0833fbd 100644 --- a/src/game/client/gameclient.cpp +++ b/src/game/client/gameclient.cpp @@ -567,6 +567,9 @@ void CGameClient::OnReset() m_LastDummyConnected = false; m_ReceivedDDNetPlayer = false; + + Editor()->ResetMentions(); + Editor()->ResetIngameMoved(); } void CGameClient::UpdatePositions() @@ -1754,6 +1757,13 @@ void CGameClient::OnNewSnapshot() for(auto &pComponent : m_vpAll) pComponent->OnNewSnapshot(); + // notify editor when local character moved + if(m_Snap.m_pLocalCharacter && m_Snap.m_pLocalPrevCharacter && + (m_Snap.m_pLocalCharacter->m_X != m_Snap.m_pLocalPrevCharacter->m_X || m_Snap.m_pLocalCharacter->m_Y != m_Snap.m_pLocalPrevCharacter->m_Y)) + { + Editor()->OnIngameMoved(); + } + // detect air jump for other players for(int i = 0; i < MAX_CLIENTS; i++) if(m_Snap.m_aCharacters[i].m_Active && (m_Snap.m_aCharacters[i].m_Cur.m_Jumped & 2) && !(m_Snap.m_aCharacters[i].m_Prev.m_Jumped & 2)) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index b23f487ab..969cdf436 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -5263,8 +5263,10 @@ void CEditor::ShowFileDialogError(const char *pFormat, ...) void CEditor::RenderModebar(CUIRect View) { - CUIRect Mentions, ModeButton; - View.HSplitTop(30.0f, &Mentions, &ModeButton); + CUIRect Mentions, IngameMoved, ModeButton; + View.HSplitTop(12.0f, &Mentions, &View); + View.HSplitTop(12.0f, &IngameMoved, &View); + View.HSplitTop(8.0f, nullptr, &ModeButton); ModeButton.VSplitLeft(65.0f, &ModeButton, nullptr); // mentions @@ -5283,6 +5285,14 @@ void CEditor::RenderModebar(CUIRect View) TextRender()->TextColor(TextRender()->DefaultTextColor()); } + // ingame moved warning + if(m_IngameMoved) + { + TextRender()->TextColor(ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f)); + UI()->DoLabel(&IngameMoved, Localize("Moved ingame"), 10.0f, TEXTALIGN_MC); + TextRender()->TextColor(TextRender()->DefaultTextColor()); + } + // mode button { const char *pModeLabel = ""; @@ -7220,6 +7230,12 @@ void CEditor::OnRender() CLineInput::RenderCandidates(); } +void CEditor::OnActivate() +{ + ResetMentions(); + ResetIngameMoved(); +} + void CEditor::LoadCurrentMap() { if(Load(m_pClient->GetCurrentMapPath(), IStorage::TYPE_SAVE)) diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 010829510..640dbcbef 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -866,16 +866,17 @@ public: m_PreventUnusedTilesWasWarned = false; m_AllowPlaceUnusedTiles = 0; m_BrushDrawDestructive = true; - - m_Mentions = 0; } void Init() override; void OnUpdate() override; void OnRender() override; + void OnActivate() override; bool HasUnsavedData() const override { return m_Map.m_Modified; } void UpdateMentions() override { m_Mentions++; } void ResetMentions() override { m_Mentions = 0; } + void OnIngameMoved() override { m_IngameMoved = true; } + void ResetIngameMoved() override { m_IngameMoved = false; } void HandleCursorMovement(); void HandleAutosave(); @@ -956,7 +957,8 @@ public: int m_AllowPlaceUnusedTiles; bool m_BrushDrawDestructive; - int m_Mentions; + int m_Mentions = 0; + bool m_IngameMoved = false; enum {