diff --git a/src/game/client/components/menu_background.cpp b/src/game/client/components/menu_background.cpp index 622e1cdc1..3fedfd746 100644 --- a/src/game/client/components/menu_background.cpp +++ b/src/game/client/components/menu_background.cpp @@ -19,9 +19,9 @@ using namespace std::chrono_literals; -std::vector GenerateMenuBackgroundPositions() +std::array GenerateMenuBackgroundPositions() { - std::vector Positions(CMenuBackground::NUM_POS); + std::array Positions; Positions[CMenuBackground::POS_START] = vec2(500.0f, 500.0f); Positions[CMenuBackground::POS_BROWSER_INTERNET] = vec2(1000.0f, 1000.0f); diff --git a/src/game/client/components/menu_background.h b/src/game/client/components/menu_background.h index ad64a15d4..89648310e 100644 --- a/src/game/client/components/menu_background.h +++ b/src/game/client/components/menu_background.h @@ -28,8 +28,6 @@ public: bool operator<(const CTheme &Other) const { return m_Name < Other.m_Name; } }; -std::vector GenerateMenuBackgroundPositions(); - class CMenuBackground : public CBackground { std::chrono::nanoseconds m_ThemeScanStartTime{0}; @@ -85,7 +83,7 @@ public: vec2 m_MenuCenter; vec2 m_RotationCenter; - std::vector m_aPositions; + std::array m_aPositions; int m_CurrentPosition; vec2 m_AnimationStartPos; bool m_ChangedPosition; @@ -119,4 +117,6 @@ public: std::vector &GetThemes(); }; +std::array GenerateMenuBackgroundPositions(); + #endif diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index b801fccfc..1d851044a 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -2827,6 +2827,7 @@ void CEditor::DoMapEditor(CUIRect View) // menu proof selection if(m_MenuProofBorders && !m_ShowPicker) { + ResetMenuBackgroundPositions(); for(int i = 0; i < (int)m_vMenuBackgroundPositions.size(); i++) { vec2 Pos = m_vMenuBackgroundPositions[i]; @@ -6911,15 +6912,7 @@ void CEditor::Init() ms_PickerColor = ColorHSVA(1.0f, 0.0f, 0.0f); - m_vMenuBackgroundPositions = GenerateMenuBackgroundPositions(); - for(size_t i = 0; i < m_vMenuBackgroundPositions.size(); i++) - { - for(size_t j = 0; j < m_vMenuBackgroundPositions.size(); j++) - { - if(i != j && distance(m_vMenuBackgroundPositions[i], m_vMenuBackgroundPositions[j]) < 0.001f) - m_vMenuBackgroundPositions[j] = vec2(0, 0); - } - } + ResetMenuBackgroundPositions(); } void CEditor::PlaceBorderTiles() @@ -7067,6 +7060,40 @@ void CEditor::LoadCurrentMap() IEditor *CreateEditor() { return new CEditor; } +void CEditor::ResetMenuBackgroundPositions() +{ + std::array aBackgroundPositions = GenerateMenuBackgroundPositions(); + m_vMenuBackgroundPositions.assign(aBackgroundPositions.begin(), aBackgroundPositions.end()); + + CLayerGame *pLayer = m_Map.m_pGameLayer; + if(pLayer) + { + for(int y = 0; y < pLayer->m_Height; ++y) + { + for(int x = 0; x < pLayer->m_Width; ++x) + { + CTile Tile = pLayer->GetTile(x, y); + if(Tile.m_Index >= TILE_TIME_CHECKPOINT_FIRST && Tile.m_Index <= TILE_TIME_CHECKPOINT_LAST) + { + int ArrayIndex = clamp((Tile.m_Index - TILE_TIME_CHECKPOINT_FIRST), 0, CMenuBackground::NUM_POS); + m_vMenuBackgroundPositions[ArrayIndex] = vec2(x * 32.0f + 16.0f, y * 32.0f + 16.0f); + } + + x += Tile.m_Skip; + } + } + } + + for(size_t i = 0; i < m_vMenuBackgroundPositions.size(); i++) + { + for(size_t j = 0; j < m_vMenuBackgroundPositions.size(); j++) + { + if(i != j && distance(m_vMenuBackgroundPositions[i], m_vMenuBackgroundPositions[j]) < 0.001f) + m_vMenuBackgroundPositions[j] = vec2(0, 0); + } + } +} + // DDRace void CEditorMap::MakeTeleLayer(CLayer *pLayer) diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 0390a763e..48a7822e6 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -902,6 +902,8 @@ public: void LoadCurrentMap(); void Render(); + void ResetMenuBackgroundPositions(); + std::vector GetSelectedQuads(); CLayer *GetSelectedLayerType(int Index, int Type) const; CLayer *GetSelectedLayer(int Index) const; diff --git a/src/game/editor/io.cpp b/src/game/editor/io.cpp index 63eebb7a9..59f3b947a 100644 --- a/src/game/editor/io.cpp +++ b/src/game/editor/io.cpp @@ -406,6 +406,7 @@ bool CEditor::Load(const char *pFileName, int StorageType) str_copy(m_aFileName, pFileName, 512); SortImages(); SelectGameLayer(); + ResetMenuBackgroundPositions(); } else {