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] 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,