From 5d1bec5a83cd6f0cee2b7d6b7e4e1e0f89132f42 Mon Sep 17 00:00:00 2001 From: VoxelDoesCode Date: Fri, 11 Nov 2022 20:16:07 -0500 Subject: [PATCH] Change editor UI, fix an overflow bug. clang clang2 --- src/game/editor/editor.cpp | 101 +++++++++++++++++++++++-------------- src/game/editor/editor.h | 1 + 2 files changed, 63 insertions(+), 39 deletions(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 3c05faac5..bcc2803b5 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -461,6 +461,18 @@ int CEditor::DoButton_Ex(const void *pID, const char *pText, int Checked, const return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); } +int CEditor::DoButton_FontIcon(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip, int Corners, float FontSize, int AlignVert) +{ + pRect->Draw(GetButtonColor(pID, Checked), Corners, 3.0f); + CUIRect NewRect = *pRect; + SLabelProperties Props; + Props.m_AlignVertically = AlignVert; + TextRender()->SetCurFont(TextRender()->GetFont(TEXT_FONT_ICON_FONT)); + UI()->DoLabel(&NewRect, pText, FontSize, TEXTALIGN_CENTER, Props); + TextRender()->SetCurFont(nullptr); + return DoButton_Editor_Common(pID, pText, Checked, pRect, Flags, pToolTip); +} + int CEditor::DoButton_ButtonInc(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip) { pRect->Draw(GetButtonColor(pID, Checked), IGraphics::CORNER_R, 3.0f); @@ -952,24 +964,34 @@ void CEditor::DoToolbar(CUIRect ToolBar) TB_Top.VSplitLeft(5.0f, nullptr, &TB_Top); // zoom group - TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); + TB_Top.VSplitLeft(20.0f, &Button, &TB_Top); static int s_ZoomOutButton = 0; - if(DoButton_Ex(&s_ZoomOutButton, "ZO", 0, &Button, 0, "[NumPad-] Zoom out", IGraphics::CORNER_L)) - m_ZoomLevel += 50; + if(DoButton_FontIcon(&s_ZoomOutButton, "-", 0, &Button, 0, "[NumPad-] Zoom out", IGraphics::CORNER_L)) + { + if(m_ZoomLevel + 50 > 2000) + m_ZoomLevel = 2000; + else + m_ZoomLevel += 50; + } - TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); + TB_Top.VSplitLeft(25.0f, &Button, &TB_Top); static int s_ZoomNormalButton = 0; - if(DoButton_Ex(&s_ZoomNormalButton, "1:1", 0, &Button, 0, "[NumPad*] Zoom to normal and remove editor offset", 0)) + if(DoButton_FontIcon(&s_ZoomNormalButton, "\xEF\x80\x82", 0, &Button, 0, "[NumPad*] Zoom to normal and remove editor offset", 0)) { m_EditorOffsetX = 0; m_EditorOffsetY = 0; m_ZoomLevel = 100; } - TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); + TB_Top.VSplitLeft(20.0f, &Button, &TB_Top); static int s_ZoomInButton = 0; - if(DoButton_Ex(&s_ZoomInButton, "ZI", 0, &Button, 0, "[NumPad+] Zoom in", IGraphics::CORNER_R)) - m_ZoomLevel -= 50; + if(DoButton_FontIcon(&s_ZoomInButton, "+", 0, &Button, 0, "[NumPad+] Zoom in", IGraphics::CORNER_R)) + { + if(m_ZoomLevel - 50 < 10) + m_ZoomLevel = 10; + else + m_ZoomLevel -= 50; + } TB_Top.VSplitLeft(5.0f, nullptr, &TB_Top); @@ -978,24 +1000,25 @@ void CEditor::DoToolbar(CUIRect ToolBar) int Enabled = m_Brush.IsEmpty() ? -1 : 0; // flip buttons - TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); + TB_Top.VSplitLeft(25.0f, &Button, &TB_Top); static int s_FlipXButton = 0; - if(DoButton_Ex(&s_FlipXButton, "X/X", Enabled, &Button, 0, "[N] Flip brush horizontal", IGraphics::CORNER_L) || (Input()->KeyPress(KEY_N) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) + if(DoButton_FontIcon(&s_FlipXButton, "\xEF\x8C\xB7", Enabled, &Button, 0, "[N] Flip brush horizontal", IGraphics::CORNER_L) || (Input()->KeyPress(KEY_N) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) { for(auto &pLayer : m_Brush.m_vpLayers) pLayer->BrushFlipX(); } - TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); + TB_Top.VSplitLeft(25.0f, &Button, &TB_Top); static int s_FlipyButton = 0; - if(DoButton_Ex(&s_FlipyButton, "Y/Y", Enabled, &Button, 0, "[M] Flip brush vertical", IGraphics::CORNER_R) || (Input()->KeyPress(KEY_M) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) + if(DoButton_FontIcon(&s_FlipyButton, "\xEF\x81\xBD", Enabled, &Button, 0, "[M] Flip brush vertical", IGraphics::CORNER_R) || (Input()->KeyPress(KEY_M) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) { for(auto &pLayer : m_Brush.m_vpLayers) pLayer->BrushFlipY(); } + TB_Top.VSplitLeft(5.0f, nullptr, &TB_Top); // rotate buttons - TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); + TB_Top.VSplitLeft(25.0f, &Button, &TB_Top); static int s_RotationAmount = 90; bool TileLayer = false; // check for tile layers in brush selection @@ -1006,19 +1029,20 @@ void CEditor::DoToolbar(CUIRect ToolBar) s_RotationAmount = maximum(90, (s_RotationAmount / 90) * 90); break; } - s_RotationAmount = UiDoValueSelector(&s_RotationAmount, &Button, "", s_RotationAmount, TileLayer ? 90 : 1, 359, TileLayer ? 90 : 1, TileLayer ? 10.0f : 2.0f, "Rotation of the brush in degrees. Use left mouse button to drag and change the value. Hold shift to be more precise.", true); - TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); static int s_CcwButton = 0; - if(DoButton_Ex(&s_CcwButton, "CCW", Enabled, &Button, 0, "[R] Rotates the brush counter clockwise", IGraphics::CORNER_L) || (Input()->KeyPress(KEY_R) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) + if(DoButton_FontIcon(&s_CcwButton, "\xEF\x8B\xAA", Enabled, &Button, 0, "[R] Rotates the brush counter clockwise", IGraphics::CORNER_ALL) || (Input()->KeyPress(KEY_R) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) { for(auto &pLayer : m_Brush.m_vpLayers) pLayer->BrushRotate(-s_RotationAmount / 360.0f * pi * 2); } TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); + s_RotationAmount = UiDoValueSelector(&s_RotationAmount, &Button, "", s_RotationAmount, TileLayer ? 90 : 1, 359, TileLayer ? 90 : 1, TileLayer ? 10.0f : 2.0f, "Rotation of the brush in degrees. Use left mouse button to drag and change the value. Hold shift to be more precise.", true); + + TB_Top.VSplitLeft(25.0f, &Button, &TB_Top); static int s_CwButton = 0; - if(DoButton_Ex(&s_CwButton, "CW", Enabled, &Button, 0, "[T] Rotates the brush clockwise", IGraphics::CORNER_R) || (Input()->KeyPress(KEY_T) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) + if(DoButton_FontIcon(&s_CwButton, "\xEF\x8B\xB9", Enabled, &Button, 0, "[T] Rotates the brush clockwise", IGraphics::CORNER_ALL) || (Input()->KeyPress(KEY_T) && m_Dialog == DIALOG_NONE && m_EditBoxActive == 0)) { for(auto &pLayer : m_Brush.m_vpLayers) pLayer->BrushRotate(s_RotationAmount / 360.0f * pi * 2); @@ -1030,47 +1054,46 @@ void CEditor::DoToolbar(CUIRect ToolBar) // animation speed if(m_Animate) { - TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); - static int s_AnimFasterButton = 0; - if(DoButton_Ex(&s_AnimFasterButton, "A+", 0, &Button, 0, "Increase animation speed", IGraphics::CORNER_L)) - m_AnimateSpeed += 0.5f; - - TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); - static int s_AnimNormalButton = 0; - if(DoButton_Ex(&s_AnimNormalButton, "1", 0, &Button, 0, "Normal animation speed", 0)) - m_AnimateSpeed = 1.0f; - - TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); + TB_Top.VSplitLeft(20.0f, &Button, &TB_Top); static int s_AnimSlowerButton = 0; - if(DoButton_Ex(&s_AnimSlowerButton, "A-", 0, &Button, 0, "Decrease animation speed", IGraphics::CORNER_R)) + if(DoButton_FontIcon(&s_AnimSlowerButton, "-", 0, &Button, 0, "Decrease animation speed", IGraphics::CORNER_L)) { if(m_AnimateSpeed > 0.5f) m_AnimateSpeed -= 0.5f; } + TB_Top.VSplitLeft(25.0f, &Button, &TB_Top); + static int s_AnimNormalButton = 0; + if(DoButton_FontIcon(&s_AnimNormalButton, "\xEF\x85\x84", 0, &Button, 0, "Normal animation speed", 0)) + m_AnimateSpeed = 1.0f; + + TB_Top.VSplitLeft(20.0f, &Button, &TB_Top); + static int s_AnimFasterButton = 0; + if(DoButton_FontIcon(&s_AnimFasterButton, "+", 0, &Button, 0, "Increase animation speed", IGraphics::CORNER_R)) + m_AnimateSpeed += 0.5f; + TB_Top.VSplitLeft(5.0f, &Button, &TB_Top); } // grid zoom if(m_GridActive) { - TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); + TB_Top.VSplitLeft(20.0f, &Button, &TB_Top); static int s_GridIncreaseButton = 0; - if(DoButton_Ex(&s_GridIncreaseButton, "G-", 0, &Button, 0, "Decrease grid", IGraphics::CORNER_L)) + if(DoButton_FontIcon(&s_GridIncreaseButton, "-", 0, &Button, 0, "Decrease grid", IGraphics::CORNER_L)) { if(m_GridFactor > 1) m_GridFactor--; } - TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); + TB_Top.VSplitLeft(25.0f, &Button, &TB_Top); static int s_GridNormalButton = 0; - if(DoButton_Ex(&s_GridNormalButton, "1", 0, &Button, 0, "Normal grid", 0)) + if(DoButton_FontIcon(&s_GridNormalButton, "\xEF\xA1\x8C", 0, &Button, 0, "Normal grid", 0)) m_GridFactor = 1; - TB_Top.VSplitLeft(30.0f, &Button, &TB_Top); - + TB_Top.VSplitLeft(20.0f, &Button, &TB_Top); static int s_GridDecreaseButton = 0; - if(DoButton_Ex(&s_GridDecreaseButton, "G+", 0, &Button, 0, "Increase grid", IGraphics::CORNER_R)) + if(DoButton_FontIcon(&s_GridDecreaseButton, "+", 0, &Button, 0, "Increase grid", IGraphics::CORNER_R)) { if(m_GridFactor < 15) m_GridFactor++; @@ -3327,8 +3350,8 @@ void CEditor::RenderLayers(CUIRect LayersBox) LayersBox.HSplitTop(RowHeight, &Slot, &LayersBox); if(s_ScrollRegion.AddRect(Slot)) { - Slot.VSplitLeft(12.0f, &VisibleToggle, &Slot); - if(DoButton_Ex(&m_Map.m_vpGroups[g]->m_Visible, m_Map.m_vpGroups[g]->m_Visible ? "V" : "H", m_Map.m_vpGroups[g]->m_Collapse ? 1 : 0, &VisibleToggle, 0, "Toggle group visibility", IGraphics::CORNER_L, 10.0f, 0)) + Slot.VSplitLeft(15.0f, &VisibleToggle, &Slot); + if(DoButton_FontIcon(&m_Map.m_vpGroups[g]->m_Visible, m_Map.m_vpGroups[g]->m_Visible ? "\xEF\x81\xAE" : "\xEF\x81\xB0", m_Map.m_vpGroups[g]->m_Collapse ? 1 : 0, &VisibleToggle, 0, "Toggle group visibility", IGraphics::CORNER_L, 8.0f, 0)) m_Map.m_vpGroups[g]->m_Visible = !m_Map.m_vpGroups[g]->m_Visible; str_format(aBuf, sizeof(aBuf), "#%d %s", g, m_Map.m_vpGroups[g]->m_aName); @@ -3389,7 +3412,7 @@ void CEditor::RenderLayers(CUIRect LayersBox) Slot.VSplitLeft(12.0f, nullptr, &Slot); Slot.VSplitLeft(15.0f, &VisibleToggle, &Button); - if(DoButton_Ex(&m_Map.m_vpGroups[g]->m_vpLayers[i]->m_Visible, m_Map.m_vpGroups[g]->m_vpLayers[i]->m_Visible ? "V" : "H", 0, &VisibleToggle, 0, "Toggle layer visibility", IGraphics::CORNER_L, 10.0f, 0)) + if(DoButton_FontIcon(&m_Map.m_vpGroups[g]->m_vpLayers[i]->m_Visible, m_Map.m_vpGroups[g]->m_vpLayers[i]->m_Visible ? "\xEF\x81\xAE" : "\xEF\x81\xB0", 0, &VisibleToggle, 0, "Toggle layer visibility", IGraphics::CORNER_L, 8.0f, 0)) m_Map.m_vpGroups[g]->m_vpLayers[i]->m_Visible = !m_Map.m_vpGroups[g]->m_vpLayers[i]->m_Visible; if(m_Map.m_vpGroups[g]->m_vpLayers[i]->m_aName[0]) diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 4a1bd0795..a23a8b3ae 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -1051,6 +1051,7 @@ public: 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 AlignVert = 1); + 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 AlignVert = 1); int DoButton_ButtonDec(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip); int DoButton_ButtonInc(const void *pID, const char *pText, int Checked, const CUIRect *pRect, int Flags, const char *pToolTip);