From 419bebf7ff355fec470f31c1db452ce619ae0013 Mon Sep 17 00:00:00 2001 From: Corantin H Date: Fri, 9 Feb 2024 19:48:29 +0100 Subject: [PATCH 1/4] Add `const` qualifier to interface getters in `editor.h` --- src/game/editor/editor.h | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 68db5da7d..ad997ce34 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -301,16 +301,16 @@ class CEditor : public IEditor static const ColorRGBA ms_DefaultPropColor; public: - class IInput *Input() { return m_pInput; } - class IClient *Client() { return m_pClient; } - class IConfigManager *ConfigManager() { return m_pConfigManager; } - class CConfig *Config() { return m_pConfig; } - class IConsole *Console() { return m_pConsole; } - class IEngine *Engine() { return m_pEngine; } - class IGraphics *Graphics() { return m_pGraphics; } - class ISound *Sound() { return m_pSound; } - class ITextRender *TextRender() { return m_pTextRender; } - class IStorage *Storage() { return m_pStorage; } + class IInput *Input() const { return m_pInput; } + class IClient *Client() const { return m_pClient; } + class IConfigManager *ConfigManager() const { return m_pConfigManager; } + class CConfig *Config() const { return m_pConfig; } + class IConsole *Console() const { return m_pConsole; } + class IEngine *Engine() const { return m_pEngine; } + class IGraphics *Graphics() const { return m_pGraphics; } + class ISound *Sound() const { return m_pSound; } + class ITextRender *TextRender() const { return m_pTextRender; } + class IStorage *Storage() const { return m_pStorage; } CUI *UI() { return &m_UI; } CRenderTools *RenderTools() { return &m_RenderTools; } From 9e724950d0d3bb173bf93126aae0d4ab48ed0e75 Mon Sep 17 00:00:00 2001 From: Corantin H Date: Fri, 9 Feb 2024 19:49:38 +0100 Subject: [PATCH 2/4] Fix quad grid snapping Check for grid alignment before aligning quads to other quads --- src/game/editor/editor.cpp | 40 ++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 44d07b98a..6f812871c 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -1587,6 +1587,8 @@ void CEditor::ComputePointAlignments(const std::shared_ptr &pLayer, if(!g_Config.m_EdAlignQuads) return; + bool IgnoreGrid = Input()->AltIsPressed(); + // Perform computation from the original position of this point int Threshold = f2fx(maximum(10.0f, 10.0f * m_MouseWScale)); CPoint OrigPoint = m_QuadDragOriginalPoints.at(QuadIndex)[PointIndex]; @@ -1605,8 +1607,14 @@ void CEditor::ComputePointAlignments(const std::shared_ptr &pLayer, int DiffX = absolute(DX); int DiffY = absolute(DY); - // Check the X axis - if(DiffX <= Threshold) + const float PX = fx2f(pQuadPoint->x); + const float PY = fx2f(pQuadPoint->y); + float SnappedPX = PX; + float SnappedPY = PY; + if(MapView()->MapGrid()->IsEnabled() && !IgnoreGrid) + MapView()->MapGrid()->SnapToGrid(SnappedPX, SnappedPY); + + if(DiffX <= Threshold && (SnappedPX == PX || DiffX == 0)) { // Only store alignments that have the smallest difference if(DiffX < SmallestDiffX) @@ -1627,7 +1635,8 @@ void CEditor::ComputePointAlignments(const std::shared_ptr &pLayer, }); } } - if(DiffY <= Threshold) + + if(DiffY <= Threshold && (SnappedPY == PY || DiffY == 0)) { // Only store alignments that have the smallest difference if(DiffY < SmallestDiffY) @@ -1777,6 +1786,8 @@ void CEditor::ComputeAABBAlignments(const std::shared_ptr &pLayer, int SmallestDiffX = Threshold + 1, SmallestDiffY = Threshold + 1; std::vector vAlignmentsX, vAlignmentsY; + bool IgnoreGrid = Input()->AltIsPressed(); + auto &&CheckAlignment = [&](CPoint &Aligned, int Point) { CPoint ToCheck = AABB.m_aPoints[Point] + ivec2(OffsetX, OffsetY); int DX = Aligned.x - ToCheck.x; @@ -1784,7 +1795,14 @@ void CEditor::ComputeAABBAlignments(const std::shared_ptr &pLayer, int DiffX = absolute(DX); int DiffY = absolute(DY); - if(DiffX <= Threshold) + const float PX = fx2f(Aligned.x); + const float PY = fx2f(Aligned.y); + float SnappedPX = PX; + float SnappedPY = PY; + if(MapView()->MapGrid()->IsEnabled() && !IgnoreGrid) + MapView()->MapGrid()->SnapToGrid(SnappedPX, SnappedPY); + + if(DiffX <= Threshold && (SnappedPX == PX || DiffX == 0)) { if(DiffX < SmallestDiffX) { @@ -1803,7 +1821,8 @@ void CEditor::ComputeAABBAlignments(const std::shared_ptr &pLayer, }); } } - if(DiffY <= Threshold) + + if(DiffY <= Threshold && (SnappedPY == PY || DiffY == 0)) { if(DiffY < SmallestDiffY) { @@ -1935,12 +1954,13 @@ void CEditor::QuadSelectionAABB(const std::shared_ptr &pLayer, SAxi for(int Selected : m_vSelectedQuads) { CQuad *pQuad = &pLayer->m_vQuads[Selected]; - for(auto &Point : pQuad->m_aPoints) + for(int i = 0; i < 4; i++) { - Min.x = minimum(Min.x, Point.x); - Min.y = minimum(Min.y, Point.y); - Max.x = maximum(Max.x, Point.x); - Max.y = maximum(Max.y, Point.y); + auto *pPoint = &pQuad->m_aPoints[i]; + Min.x = minimum(Min.x, pPoint->x); + Min.y = minimum(Min.y, pPoint->y); + Max.x = maximum(Max.x, pPoint->x); + Max.y = maximum(Max.y, pPoint->y); } } CPoint Center = (Min + Max) / 2.0f; From bd5149c48c3b0352c9a419b177673a7e9548751d Mon Sep 17 00:00:00 2001 From: Corantin H Date: Fri, 9 Feb 2024 19:54:28 +0100 Subject: [PATCH 3/4] Prevent brush placing when paning editor view --- src/game/editor/editor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 6f812871c..3e4252f44 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -3383,7 +3383,7 @@ void CEditor::DoMapEditor(CUIRect View) m_pBrush->Clear(); } - if(UI()->MouseButton(0) && s_Operation == OP_NONE && !m_QuadKnifeActive) + if(!Input()->ModifierIsPressed() && UI()->MouseButton(0) && s_Operation == OP_NONE && !m_QuadKnifeActive) { UI()->SetActiveItem(s_pEditorID); From f9ba9d819b4c77547dfa351c05dbc5295ba16b20 Mon Sep 17 00:00:00 2001 From: Corantin H Date: Fri, 9 Feb 2024 20:39:12 +0100 Subject: [PATCH 4/4] Add more `const` qualifiers to editor methods --- src/game/editor/editor.cpp | 14 +++++++------- src/game/editor/editor.h | 14 +++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 3e4252f44..f2b66acb0 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -319,7 +319,7 @@ int CEditor::DoButton_DraggableEx(const void *pID, const char *pText, int Checke return UI()->DoDraggableButtonLogic(pID, Checked, pRect, pClicked, pAbrupted); } -void CEditor::RenderBackground(CUIRect View, IGraphics::CTextureHandle Texture, float Size, float Brightness) +void CEditor::RenderBackground(CUIRect View, IGraphics::CTextureHandle Texture, float Size, float Brightness) const { Graphics()->TextureSet(Texture); Graphics()->BlendNormal(); @@ -1547,7 +1547,7 @@ void CEditor::DoPointDrag(const std::shared_ptr &pLayer, CQuad *pQu pQuad->m_aPoints[PointIndex].y = m_QuadDragOriginalPoints[QuadIndex][PointIndex].y + OffsetY; } -CEditor::EAxis CEditor::GetDragAxis(int OffsetX, int OffsetY) +CEditor::EAxis CEditor::GetDragAxis(int OffsetX, int OffsetY) const { if(Input()->ShiftIsPressed()) if(absolute(OffsetX) < absolute(OffsetY)) @@ -1558,7 +1558,7 @@ CEditor::EAxis CEditor::GetDragAxis(int OffsetX, int OffsetY) return EAxis::AXIS_NONE; } -void CEditor::DrawAxis(EAxis Axis, CPoint &OriginalPoint, CPoint &Point) +void CEditor::DrawAxis(EAxis Axis, CPoint &OriginalPoint, CPoint &Point) const { if(Axis == EAxis::AXIS_NONE) return; @@ -1892,7 +1892,7 @@ void CEditor::ComputeAABBAlignments(const std::shared_ptr &pLayer, vAlignments.insert(vAlignments.end(), vAlignmentsY.begin(), vAlignmentsY.end()); } -void CEditor::DrawPointAlignments(const std::vector &vAlignments, int OffsetX, int OffsetY) +void CEditor::DrawPointAlignments(const std::vector &vAlignments, int OffsetX, int OffsetY) const { if(!g_Config.m_EdAlignQuads) return; @@ -1916,7 +1916,7 @@ void CEditor::DrawPointAlignments(const std::vector &vAlignments } } -void CEditor::DrawAABB(const SAxisAlignedBoundingBox &AABB, int OffsetX, int OffsetY) +void CEditor::DrawAABB(const SAxisAlignedBoundingBox &AABB, int OffsetX, int OffsetY) const { // Drawing an AABB is simply converting the points from fixed to float // Then making lines out of quads and drawing them @@ -2006,7 +2006,7 @@ void CEditor::ApplyAlignments(const std::vector &vAlignments, in OffsetY += AdjustY; } -void CEditor::ApplyAxisAlignment(int &OffsetX, int &OffsetY) +void CEditor::ApplyAxisAlignment(int &OffsetX, int &OffsetY) const { // This is used to preserve axis alignment when pressing `Shift` // Should be called before any other computation @@ -8361,7 +8361,7 @@ void CEditor::Reset(bool CreateDefault) m_MapSettingsCommandContext.Reset(); } -int CEditor::GetTextureUsageFlag() +int CEditor::GetTextureUsageFlag() const { return Graphics()->Uses2DTextureArrays() ? IGraphics::TEXLOAD_TO_2D_ARRAY_TEXTURE : IGraphics::TEXLOAD_TO_3D_TEXTURE; } diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index ad997ce34..dfbd47766 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -288,7 +288,7 @@ class CEditor : public IEditor IGraphics::CTextureHandle m_SwitchTexture; IGraphics::CTextureHandle m_TuneTexture; - int GetTextureUsageFlag(); + int GetTextureUsageFlag() const; enum EPreviewState { @@ -823,7 +823,7 @@ public: template int RenderEditBoxDropdown(SEditBoxDropdownContext *pDropdown, CUIRect View, CLineInput *pLineInput, int x, float MaxHeight, bool AutoWidth, const std::vector &vData, const FDropdownRenderCallback &fnMatchCallback); - void RenderBackground(CUIRect View, IGraphics::CTextureHandle Texture, float Size, float Brightness); + void RenderBackground(CUIRect View, IGraphics::CTextureHandle Texture, float Size, float Brightness) const; SEditResult UiDoValueSelector(void *pID, CUIRect *pRect, const char *pLabel, int Current, int Min, int Max, int Step, float Scale, const char *pToolTip, bool IsDegree = false, bool IsHex = false, int corners = IGraphics::CORNER_ALL, const ColorRGBA *pColor = nullptr, bool ShowValue = true); @@ -919,9 +919,9 @@ public: void DoQuad(int LayerIndex, const std::shared_ptr &pLayer, CQuad *pQuad, int Index); void PreparePointDrag(const std::shared_ptr &pLayer, CQuad *pQuad, int QuadIndex, int PointIndex); void DoPointDrag(const std::shared_ptr &pLayer, CQuad *pQuad, int QuadIndex, int PointIndex, int OffsetX, int OffsetY); - EAxis GetDragAxis(int OffsetX, int OffsetY); - void DrawAxis(EAxis Axis, CPoint &OriginalPoint, CPoint &Point); - void DrawAABB(const SAxisAlignedBoundingBox &AABB, int OffsetX = 0, int OffsetY = 0); + EAxis GetDragAxis(int OffsetX, int OffsetY) const; + void DrawAxis(EAxis Axis, CPoint &OriginalPoint, CPoint &Point) const; + void DrawAABB(const SAxisAlignedBoundingBox &AABB, int OffsetX = 0, int OffsetY = 0) const; ColorRGBA GetButtonColor(const void *pID, int Checked); // Alignment methods @@ -945,10 +945,10 @@ public: void ComputePointAlignments(const std::shared_ptr &pLayer, CQuad *pQuad, int QuadIndex, int PointIndex, int OffsetX, int OffsetY, std::vector &vAlignments, bool Append = false) const; void ComputePointsAlignments(const std::shared_ptr &pLayer, bool Pivot, int OffsetX, int OffsetY, std::vector &vAlignments) const; void ComputeAABBAlignments(const std::shared_ptr &pLayer, const SAxisAlignedBoundingBox &AABB, int OffsetX, int OffsetY, std::vector &vAlignments) const; - void DrawPointAlignments(const std::vector &vAlignments, int OffsetX, int OffsetY); + void DrawPointAlignments(const std::vector &vAlignments, int OffsetX, int OffsetY) const; void QuadSelectionAABB(const std::shared_ptr &pLayer, SAxisAlignedBoundingBox &OutAABB); void ApplyAlignments(const std::vector &vAlignments, int &OffsetX, int &OffsetY); - void ApplyAxisAlignment(int &OffsetX, int &OffsetY); + void ApplyAxisAlignment(int &OffsetX, int &OffsetY) const; bool ReplaceImage(const char *pFilename, int StorageType, bool CheckDuplicate); static bool ReplaceImageCallback(const char *pFilename, int StorageType, void *pUser);