diff --git a/CMakeLists.txt b/CMakeLists.txt index b1b9b96c5..4f9a53759 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2278,16 +2278,27 @@ if(CLIENT) map_view.h mapitems/image.cpp mapitems/image.h + mapitems/layer.h mapitems/layer_front.cpp + mapitems/layer_front.h mapitems/layer_game.cpp + mapitems/layer_game.h mapitems/layer_group.cpp + mapitems/layer_group.h mapitems/layer_quads.cpp + mapitems/layer_quads.h mapitems/layer_sounds.cpp + mapitems/layer_sounds.h mapitems/layer_speedup.cpp + mapitems/layer_speedup.h mapitems/layer_switch.cpp + mapitems/layer_switch.h mapitems/layer_tele.cpp + mapitems/layer_tele.h mapitems/layer_tiles.cpp + mapitems/layer_tiles.h mapitems/layer_tune.cpp + mapitems/layer_tune.h mapitems/map.cpp mapitems/map_io.cpp mapitems/sound.cpp diff --git a/src/game/editor/auto_map.cpp b/src/game/editor/auto_map.cpp index 831be5b6d..f8cf86ed0 100644 --- a/src/game/editor/auto_map.cpp +++ b/src/game/editor/auto_map.cpp @@ -404,7 +404,7 @@ void CAutoMapper::ProceedLocalized(CLayerTiles *pLayer, int ConfigID, int Seed, int UpdateToX = clamp(X + Width + 3 * pConf->m_EndX, 0, pLayer->m_Width); int UpdateToY = clamp(Y + Height + 3 * pConf->m_EndY, 0, pLayer->m_Height); - CLayerTiles *pUpdateLayer = new CLayerTiles(UpdateToX - UpdateFromX, UpdateToY - UpdateFromY); + CLayerTiles *pUpdateLayer = new CLayerTiles(Editor(), UpdateToX - UpdateFromX, UpdateToY - UpdateFromY); for(int y = UpdateFromY; y < UpdateToY; y++) { @@ -452,7 +452,7 @@ void CAutoMapper::Proceed(CLayerTiles *pLayer, int ConfigID, int Seed, int SeedO CLayerTiles *pReadLayer; if(pRun->m_AutomapCopy) { - pReadLayer = new CLayerTiles(pLayer->m_Width, pLayer->m_Height); + pReadLayer = new CLayerTiles(Editor(), pLayer->m_Width, pLayer->m_Height); for(int y = 0; y < pLayer->m_Height; y++) { diff --git a/src/game/editor/editor.cpp b/src/game/editor/editor.cpp index 50be9e718..007303d13 100644 --- a/src/game/editor/editor.cpp +++ b/src/game/editor/editor.cpp @@ -7542,13 +7542,11 @@ void CEditor::Init() m_BackgroundTexture = Graphics()->LoadTexture("editor/background.png", IStorage::TYPE_ALL); m_CursorTexture = Graphics()->LoadTexture("editor/cursor.png", IStorage::TYPE_ALL); - m_pTilesetPicker = std::make_shared(16, 16); - m_pTilesetPicker->m_pEditor = this; + m_pTilesetPicker = std::make_shared(this, 16, 16); m_pTilesetPicker->MakePalette(); m_pTilesetPicker->m_Readonly = true; - m_pQuadsetPicker = std::make_shared(); - m_pQuadsetPicker->m_pEditor = this; + m_pQuadsetPicker = std::make_shared(this); m_pQuadsetPicker->NewQuad(0, 0, 64, 64); m_pQuadsetPicker->m_Readonly = true; diff --git a/src/game/editor/editor.h b/src/game/editor/editor.h index 287a4db77..2a848780d 100644 --- a/src/game/editor/editor.h +++ b/src/game/editor/editor.h @@ -11,6 +11,18 @@ #include #include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + #include #include #include @@ -185,150 +197,6 @@ public: } }; -class CLayerGroup; - -class CLayer -{ -public: - class CEditor *m_pEditor; - class IGraphics *Graphics(); - class ITextRender *TextRender(); - - CLayer() - { - m_Type = LAYERTYPE_INVALID; - str_copy(m_aName, "(invalid)"); - m_Visible = true; - m_Readonly = false; - m_Flags = 0; - m_pEditor = nullptr; - } - - CLayer(const CLayer &Other) - { - str_copy(m_aName, Other.m_aName); - m_Flags = Other.m_Flags; - m_pEditor = Other.m_pEditor; - m_Type = Other.m_Type; - m_Visible = true; - m_Readonly = false; - } - - virtual ~CLayer() - { - } - - virtual void BrushSelecting(CUIRect Rect) {} - virtual int BrushGrab(std::shared_ptr pBrush, CUIRect Rect) { return 0; } - virtual void FillSelection(bool Empty, std::shared_ptr pBrush, CUIRect Rect) {} - virtual void BrushDraw(std::shared_ptr pBrush, float x, float y) {} - virtual void BrushPlace(std::shared_ptr pBrush, float x, float y) {} - virtual void BrushFlipX() {} - virtual void BrushFlipY() {} - virtual void BrushRotate(float Amount) {} - - virtual bool IsEntitiesLayer() const { return false; } - - virtual void Render(bool Tileset = false) {} - virtual CUI::EPopupMenuFunctionResult RenderProperties(CUIRect *pToolbox) { return CUI::POPUP_KEEP_OPEN; } - - virtual void ModifyImageIndex(FIndexModifyFunction pfnFunc) {} - virtual void ModifyEnvelopeIndex(FIndexModifyFunction pfnFunc) {} - virtual void ModifySoundIndex(FIndexModifyFunction pfnFunc) {} - - virtual std::shared_ptr Duplicate() const = 0; - - virtual void GetSize(float *pWidth, float *pHeight) - { - *pWidth = 0; - *pHeight = 0; - } - - char m_aName[12]; - int m_Type; - int m_Flags; - - bool m_Readonly; - bool m_Visible; -}; - -class CLayerGroup -{ -public: - class CEditorMap *m_pMap; - - std::vector> m_vpLayers; - - int m_OffsetX; - int m_OffsetY; - - int m_ParallaxX; - int m_ParallaxY; - int m_CustomParallaxZoom; - int m_ParallaxZoom; - - int m_UseClipping; - int m_ClipX; - int m_ClipY; - int m_ClipW; - int m_ClipH; - - char m_aName[12]; - bool m_GameGroup; - bool m_Visible; - bool m_Collapse; - - CLayerGroup(); - ~CLayerGroup(); - - void Convert(CUIRect *pRect); - void Render(); - void MapScreen(); - void Mapping(float *pPoints); - - void GetSize(float *pWidth, float *pHeight) const; - - void DeleteLayer(int Index); - void DuplicateLayer(int Index); - int SwapLayers(int Index0, int Index1); - - bool IsEmpty() const - { - return m_vpLayers.empty(); - } - - void OnEdited() - { - if(!m_CustomParallaxZoom) - m_ParallaxZoom = GetParallaxZoomDefault(m_ParallaxX, m_ParallaxY); - } - - void Clear() - { - m_vpLayers.clear(); - } - - void AddLayer(const std::shared_ptr &pLayer); - - void ModifyImageIndex(FIndexModifyFunction Func) - { - for(auto &pLayer : m_vpLayers) - pLayer->ModifyImageIndex(Func); - } - - void ModifyEnvelopeIndex(FIndexModifyFunction Func) - { - for(auto &pLayer : m_vpLayers) - pLayer->ModifyEnvelopeIndex(Func); - } - - void ModifySoundIndex(FIndexModifyFunction Func) - { - for(auto &pLayer : m_vpLayers) - pLayer->ModifySoundIndex(Func); - } -}; - class CEditorImage; class CEditorSound; @@ -513,213 +381,6 @@ enum PROPTYPE_AUTOMAPPER, }; -enum -{ - DIRECTION_LEFT = 0, - DIRECTION_RIGHT, - DIRECTION_UP, - DIRECTION_DOWN, -}; - -struct RECTi -{ - int x, y; - int w, h; -}; - -class CLayerTiles : public CLayer -{ -protected: - template - void ShiftImpl(T *pTiles, int Direction, int ShiftBy) - { - switch(Direction) - { - case DIRECTION_LEFT: - ShiftBy = minimum(ShiftBy, m_Width); - for(int y = 0; y < m_Height; ++y) - { - if(ShiftBy < m_Width) - mem_move(&pTiles[y * m_Width], &pTiles[y * m_Width + ShiftBy], (m_Width - ShiftBy) * sizeof(T)); - mem_zero(&pTiles[y * m_Width + (m_Width - ShiftBy)], ShiftBy * sizeof(T)); - } - break; - case DIRECTION_RIGHT: - ShiftBy = minimum(ShiftBy, m_Width); - for(int y = 0; y < m_Height; ++y) - { - if(ShiftBy < m_Width) - mem_move(&pTiles[y * m_Width + ShiftBy], &pTiles[y * m_Width], (m_Width - ShiftBy) * sizeof(T)); - mem_zero(&pTiles[y * m_Width], ShiftBy * sizeof(T)); - } - break; - case DIRECTION_UP: - ShiftBy = minimum(ShiftBy, m_Height); - for(int y = ShiftBy; y < m_Height; ++y) - { - mem_copy(&pTiles[(y - ShiftBy) * m_Width], &pTiles[y * m_Width], m_Width * sizeof(T)); - } - for(int y = m_Height - ShiftBy; y < m_Height; ++y) - { - mem_zero(&pTiles[y * m_Width], m_Width * sizeof(T)); - } - break; - case DIRECTION_DOWN: - ShiftBy = minimum(ShiftBy, m_Height); - for(int y = m_Height - ShiftBy - 1; y >= 0; --y) - { - mem_copy(&pTiles[(y + ShiftBy) * m_Width], &pTiles[y * m_Width], m_Width * sizeof(T)); - } - for(int y = 0; y < ShiftBy; ++y) - { - mem_zero(&pTiles[y * m_Width], m_Width * sizeof(T)); - } - break; - } - } - template - void BrushFlipXImpl(T *pTiles) - { - for(int y = 0; y < m_Height; y++) - for(int x = 0; x < m_Width / 2; x++) - std::swap(pTiles[y * m_Width + x], pTiles[(y + 1) * m_Width - 1 - x]); - } - template - void BrushFlipYImpl(T *pTiles) - { - for(int y = 0; y < m_Height / 2; y++) - for(int x = 0; x < m_Width; x++) - std::swap(pTiles[y * m_Width + x], pTiles[(m_Height - 1 - y) * m_Width + x]); - } - -public: - CLayerTiles(int w, int h); - CLayerTiles(const CLayerTiles &Other); - ~CLayerTiles(); - - virtual CTile GetTile(int x, int y); - virtual void SetTile(int x, int y, CTile Tile); - - virtual void Resize(int NewW, int NewH); - virtual void Shift(int Direction); - - void MakePalette(); - void Render(bool Tileset = false) override; - - int ConvertX(float x) const; - int ConvertY(float y) const; - void Convert(CUIRect Rect, RECTi *pOut); - void Snap(CUIRect *pRect); - void Clamp(RECTi *pRect); - - virtual bool IsEntitiesLayer() const override; - - virtual bool IsEmpty(const std::shared_ptr &pLayer); - void BrushSelecting(CUIRect Rect) override; - int BrushGrab(std::shared_ptr pBrush, CUIRect Rect) override; - void FillSelection(bool Empty, std::shared_ptr pBrush, CUIRect Rect) override; - void BrushDraw(std::shared_ptr pBrush, float wx, float wy) override; - void BrushFlipX() override; - void BrushFlipY() override; - void BrushRotate(float Amount) override; - - std::shared_ptr Duplicate() const override; - - virtual void ShowInfo(); - CUI::EPopupMenuFunctionResult RenderProperties(CUIRect *pToolbox) override; - - struct SCommonPropState - { - enum - { - MODIFIED_SIZE = 1 << 0, - MODIFIED_COLOR = 1 << 1, - }; - int m_Modified = 0; - int m_Width = -1; - int m_Height = -1; - int m_Color = 0; - }; - static CUI::EPopupMenuFunctionResult RenderCommonProperties(SCommonPropState &State, CEditor *pEditor, CUIRect *pToolbox, std::vector> &vpLayers); - - void ModifyImageIndex(FIndexModifyFunction pfnFunc) override; - void ModifyEnvelopeIndex(FIndexModifyFunction pfnFunc) override; - - void PrepareForSave(); - void ExtractTiles(int TilemapItemVersion, const CTile *pSavedTiles, size_t SavedTilesSize); - - void GetSize(float *pWidth, float *pHeight) override - { - *pWidth = m_Width * 32.0f; - *pHeight = m_Height * 32.0f; - } - - void FlagModified(int x, int y, int w, int h); - - int m_Game; - int m_Image; - int m_Width; - int m_Height; - CColor m_Color; - int m_ColorEnv; - int m_ColorEnvOffset; - CTile *m_pTiles; - - // DDRace - - int m_AutoMapperConfig; - int m_Seed; - bool m_AutoAutoMap; - int m_Tele; - int m_Speedup; - int m_Front; - int m_Switch; - int m_Tune; - char m_aFileName[IO_MAX_PATH_LENGTH]; -}; - -class CLayerQuads : public CLayer -{ -public: - CLayerQuads(); - CLayerQuads(const CLayerQuads &Other); - ~CLayerQuads(); - - void Render(bool QuadPicker = false) override; - CQuad *NewQuad(int x, int y, int Width, int Height); - int SwapQuads(int Index0, int Index1); - - void BrushSelecting(CUIRect Rect) override; - int BrushGrab(std::shared_ptr pBrush, CUIRect Rect) override; - void BrushPlace(std::shared_ptr pBrush, float wx, float wy) override; - void BrushFlipX() override; - void BrushFlipY() override; - void BrushRotate(float Amount) override; - - CUI::EPopupMenuFunctionResult RenderProperties(CUIRect *pToolbox) override; - - void ModifyImageIndex(FIndexModifyFunction pfnFunc) override; - void ModifyEnvelopeIndex(FIndexModifyFunction pfnFunc) override; - - void GetSize(float *pWidth, float *pHeight) override; - std::shared_ptr Duplicate() const override; - - int m_Image; - std::vector m_vQuads; -}; - -class CLayerGame : public CLayerTiles -{ -public: - CLayerGame(int w, int h); - ~CLayerGame(); - - CTile GetTile(int x, int y) override; - void SetTile(int x, int y, CTile Tile) override; - - CUI::EPopupMenuFunctionResult RenderProperties(CUIRect *pToolbox) override; -}; - class CDataFileWriterFinishJob : public IJob { char m_aRealFileName[IO_MAX_PATH_LENGTH]; @@ -1474,121 +1135,4 @@ public: inline class IGraphics *CLayer::Graphics() { return m_pEditor->Graphics(); } inline class ITextRender *CLayer::TextRender() { return m_pEditor->TextRender(); } -// DDRace - -class CLayerTele : public CLayerTiles -{ -public: - CLayerTele(int w, int h); - ~CLayerTele(); - - CTeleTile *m_pTeleTile; - unsigned char m_TeleNum; - - void Resize(int NewW, int NewH) override; - void Shift(int Direction) override; - bool IsEmpty(const std::shared_ptr &pLayer) override; - void BrushDraw(std::shared_ptr pBrush, float wx, float wy) override; - void BrushFlipX() override; - void BrushFlipY() override; - void BrushRotate(float Amount) override; - void FillSelection(bool Empty, std::shared_ptr pBrush, CUIRect Rect) override; - virtual bool ContainsElementWithId(int Id); -}; - -class CLayerSpeedup : public CLayerTiles -{ -public: - CLayerSpeedup(int w, int h); - ~CLayerSpeedup(); - - CSpeedupTile *m_pSpeedupTile; - int m_SpeedupForce; - int m_SpeedupMaxSpeed; - int m_SpeedupAngle; - - void Resize(int NewW, int NewH) override; - void Shift(int Direction) override; - bool IsEmpty(const std::shared_ptr &pLayer) override; - void BrushDraw(std::shared_ptr pBrush, float wx, float wy) override; - void BrushFlipX() override; - void BrushFlipY() override; - void BrushRotate(float Amount) override; - void FillSelection(bool Empty, std::shared_ptr pBrush, CUIRect Rect) override; -}; - -class CLayerFront : public CLayerTiles -{ -public: - CLayerFront(int w, int h); - - void Resize(int NewW, int NewH) override; - void SetTile(int x, int y, CTile Tile) override; -}; - -class CLayerSwitch : public CLayerTiles -{ -public: - CLayerSwitch(int w, int h); - ~CLayerSwitch(); - - CSwitchTile *m_pSwitchTile; - unsigned char m_SwitchNumber; - unsigned char m_SwitchDelay; - - void Resize(int NewW, int NewH) override; - void Shift(int Direction) override; - bool IsEmpty(const std::shared_ptr &pLayer) override; - void BrushDraw(std::shared_ptr pBrush, float wx, float wy) override; - void BrushFlipX() override; - void BrushFlipY() override; - void BrushRotate(float Amount) override; - void FillSelection(bool Empty, std::shared_ptr pBrush, CUIRect Rect) override; - virtual bool ContainsElementWithId(int Id); -}; - -class CLayerTune : public CLayerTiles -{ -public: - CLayerTune(int w, int h); - ~CLayerTune(); - - CTuneTile *m_pTuneTile; - unsigned char m_TuningNumber; - - void Resize(int NewW, int NewH) override; - void Shift(int Direction) override; - bool IsEmpty(const std::shared_ptr &pLayer) override; - void BrushDraw(std::shared_ptr pBrush, float wx, float wy) override; - void BrushFlipX() override; - void BrushFlipY() override; - void BrushRotate(float Amount) override; - void FillSelection(bool Empty, std::shared_ptr pBrush, CUIRect Rect) override; -}; - -class CLayerSounds : public CLayer -{ -public: - CLayerSounds(); - CLayerSounds(const CLayerSounds &Other); - ~CLayerSounds(); - - void Render(bool Tileset = false) override; - CSoundSource *NewSource(int x, int y); - - void BrushSelecting(CUIRect Rect) override; - int BrushGrab(std::shared_ptr pBrush, CUIRect Rect) override; - void BrushPlace(std::shared_ptr pBrush, float wx, float wy) override; - - CUI::EPopupMenuFunctionResult RenderProperties(CUIRect *pToolbox) override; - - void ModifyEnvelopeIndex(FIndexModifyFunction pfnFunc) override; - void ModifySoundIndex(FIndexModifyFunction pfnFunc) override; - - std::shared_ptr Duplicate() const override; - - int m_Sound; - std::vector m_vSources; -}; - #endif diff --git a/src/game/editor/mapitems/layer.h b/src/game/editor/mapitems/layer.h new file mode 100644 index 000000000..298337d05 --- /dev/null +++ b/src/game/editor/mapitems/layer.h @@ -0,0 +1,80 @@ +#ifndef GAME_EDITOR_MAPITEMS_LAYER_H +#define GAME_EDITOR_MAPITEMS_LAYER_H + +#include +#include +#include +#include + +#include + +using FIndexModifyFunction = std::function; + +class CLayerGroup; + +class CLayer +{ +public: + class CEditor *m_pEditor; + class IGraphics *Graphics(); + class ITextRender *TextRender(); + + explicit CLayer(CEditor *pEditor) + { + m_Type = LAYERTYPE_INVALID; + str_copy(m_aName, "(invalid)"); + m_Visible = true; + m_Readonly = false; + m_Flags = 0; + m_pEditor = pEditor; + } + + CLayer(const CLayer &Other) + { + str_copy(m_aName, Other.m_aName); + m_Flags = Other.m_Flags; + m_pEditor = Other.m_pEditor; + m_Type = Other.m_Type; + m_Visible = true; + m_Readonly = false; + } + + virtual ~CLayer() + { + } + + virtual void BrushSelecting(CUIRect Rect) {} + virtual int BrushGrab(std::shared_ptr pBrush, CUIRect Rect) { return 0; } + virtual void FillSelection(bool Empty, std::shared_ptr pBrush, CUIRect Rect) {} + virtual void BrushDraw(std::shared_ptr pBrush, float x, float y) {} + virtual void BrushPlace(std::shared_ptr pBrush, float x, float y) {} + virtual void BrushFlipX() {} + virtual void BrushFlipY() {} + virtual void BrushRotate(float Amount) {} + + virtual bool IsEntitiesLayer() const { return false; } + + virtual void Render(bool Tileset = false) {} + virtual CUI::EPopupMenuFunctionResult RenderProperties(CUIRect *pToolbox) { return CUI::POPUP_KEEP_OPEN; } + + virtual void ModifyImageIndex(FIndexModifyFunction pfnFunc) {} + virtual void ModifyEnvelopeIndex(FIndexModifyFunction pfnFunc) {} + virtual void ModifySoundIndex(FIndexModifyFunction pfnFunc) {} + + virtual std::shared_ptr Duplicate() const = 0; + + virtual void GetSize(float *pWidth, float *pHeight) + { + *pWidth = 0; + *pHeight = 0; + } + + char m_aName[12]; + int m_Type; + int m_Flags; + + bool m_Readonly; + bool m_Visible; +}; + +#endif diff --git a/src/game/editor/mapitems/layer_front.cpp b/src/game/editor/mapitems/layer_front.cpp index 01ae277b8..47d260586 100644 --- a/src/game/editor/mapitems/layer_front.cpp +++ b/src/game/editor/mapitems/layer_front.cpp @@ -1,7 +1,7 @@ #include -CLayerFront::CLayerFront(int w, int h) : - CLayerTiles(w, h) +CLayerFront::CLayerFront(CEditor *pEditor, int w, int h) : + CLayerTiles(pEditor, w, h) { str_copy(m_aName, "Front"); m_Front = 1; diff --git a/src/game/editor/mapitems/layer_front.h b/src/game/editor/mapitems/layer_front.h new file mode 100644 index 000000000..f5aeb3a58 --- /dev/null +++ b/src/game/editor/mapitems/layer_front.h @@ -0,0 +1,15 @@ +#ifndef GAME_EDITOR_MAPITEMS_LAYER_FRONT_H +#define GAME_EDITOR_MAPITEMS_LAYER_FRONT_H + +#include "layer_tiles.h" + +class CLayerFront : public CLayerTiles +{ +public: + CLayerFront(CEditor *pEditor, int w, int h); + + void Resize(int NewW, int NewH) override; + void SetTile(int x, int y, CTile Tile) override; +}; + +#endif diff --git a/src/game/editor/mapitems/layer_game.cpp b/src/game/editor/mapitems/layer_game.cpp index fd9f82e47..48d061811 100644 --- a/src/game/editor/mapitems/layer_game.cpp +++ b/src/game/editor/mapitems/layer_game.cpp @@ -1,9 +1,11 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ +#include "layer_game.h" + #include -CLayerGame::CLayerGame(int w, int h) : - CLayerTiles(w, h) +CLayerGame::CLayerGame(CEditor *pEditor, int w, int h) : + CLayerTiles(pEditor, w, h) { str_copy(m_aName, "Game"); m_Game = 1; @@ -30,7 +32,7 @@ void CLayerGame::SetTile(int x, int y, CTile Tile) { if(!m_pEditor->m_Map.m_pFrontLayer) { - std::shared_ptr pLayerFront = std::make_shared(m_Width, m_Height); + std::shared_ptr pLayerFront = std::make_shared(m_pEditor, m_Width, m_Height); m_pEditor->m_Map.MakeFrontLayer(pLayerFront); m_pEditor->m_Map.m_pGameGroup->AddLayer(pLayerFront); } diff --git a/src/game/editor/mapitems/layer_game.h b/src/game/editor/mapitems/layer_game.h new file mode 100644 index 000000000..4c00c7e7f --- /dev/null +++ b/src/game/editor/mapitems/layer_game.h @@ -0,0 +1,18 @@ +#ifndef GAME_EDITOR_MAPITEMS_LAYER_GAME_H +#define GAME_EDITOR_MAPITEMS_LAYER_GAME_H + +#include "layer_tiles.h" + +class CLayerGame : public CLayerTiles +{ +public: + CLayerGame(CEditor *pEditor, int w, int h); + ~CLayerGame(); + + CTile GetTile(int x, int y) override; + void SetTile(int x, int y, CTile Tile) override; + + CUI::EPopupMenuFunctionResult RenderProperties(CUIRect *pToolbox) override; +}; + +#endif diff --git a/src/game/editor/mapitems/layer_group.cpp b/src/game/editor/mapitems/layer_group.cpp index 2f01d77eb..66671d729 100644 --- a/src/game/editor/mapitems/layer_group.cpp +++ b/src/game/editor/mapitems/layer_group.cpp @@ -1,3 +1,5 @@ +#include "layer_group.h" + #include CLayerGroup::CLayerGroup() diff --git a/src/game/editor/mapitems/layer_group.h b/src/game/editor/mapitems/layer_group.h new file mode 100644 index 000000000..9f3c1f8b6 --- /dev/null +++ b/src/game/editor/mapitems/layer_group.h @@ -0,0 +1,88 @@ +#ifndef GAME_EDITOR_MAPITEMS_LAYER_GROUP_H +#define GAME_EDITOR_MAPITEMS_LAYER_GROUP_H + +#include "layer.h" + +#include + +#include +#include + +class CLayerGroup +{ +public: + class CEditorMap *m_pMap; + + std::vector> m_vpLayers; + + int m_OffsetX; + int m_OffsetY; + + int m_ParallaxX; + int m_ParallaxY; + int m_CustomParallaxZoom; + int m_ParallaxZoom; + + int m_UseClipping; + int m_ClipX; + int m_ClipY; + int m_ClipW; + int m_ClipH; + + char m_aName[12]; + bool m_GameGroup; + bool m_Visible; + bool m_Collapse; + + CLayerGroup(); + ~CLayerGroup(); + + void Convert(CUIRect *pRect); + void Render(); + void MapScreen(); + void Mapping(float *pPoints); + + void GetSize(float *pWidth, float *pHeight) const; + + void DeleteLayer(int Index); + void DuplicateLayer(int Index); + int SwapLayers(int Index0, int Index1); + + bool IsEmpty() const + { + return m_vpLayers.empty(); + } + + void OnEdited() + { + if(!m_CustomParallaxZoom) + m_ParallaxZoom = GetParallaxZoomDefault(m_ParallaxX, m_ParallaxY); + } + + void Clear() + { + m_vpLayers.clear(); + } + + void AddLayer(const std::shared_ptr &pLayer); + + void ModifyImageIndex(FIndexModifyFunction Func) + { + for(auto &pLayer : m_vpLayers) + pLayer->ModifyImageIndex(Func); + } + + void ModifyEnvelopeIndex(FIndexModifyFunction Func) + { + for(auto &pLayer : m_vpLayers) + pLayer->ModifyEnvelopeIndex(Func); + } + + void ModifySoundIndex(FIndexModifyFunction Func) + { + for(auto &pLayer : m_vpLayers) + pLayer->ModifySoundIndex(Func); + } +}; + +#endif diff --git a/src/game/editor/mapitems/layer_quads.cpp b/src/game/editor/mapitems/layer_quads.cpp index b16eeba4a..1855ad62a 100644 --- a/src/game/editor/mapitems/layer_quads.cpp +++ b/src/game/editor/mapitems/layer_quads.cpp @@ -1,10 +1,13 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ +#include "layer_quads.h" + #include #include "image.h" -CLayerQuads::CLayerQuads() +CLayerQuads::CLayerQuads(CEditor *pEditor) : + CLayer(pEditor) { m_Type = LAYERTYPE_QUADS; m_aName[0] = '\0'; @@ -107,8 +110,7 @@ void CLayerQuads::BrushSelecting(CUIRect Rect) int CLayerQuads::BrushGrab(std::shared_ptr pBrush, CUIRect Rect) { // create new layers - std::shared_ptr pGrabbed = std::make_shared(); - pGrabbed->m_pEditor = m_pEditor; + std::shared_ptr pGrabbed = std::make_shared(m_pEditor); pGrabbed->m_Image = m_Image; pBrush->AddLayer(pGrabbed); diff --git a/src/game/editor/mapitems/layer_quads.h b/src/game/editor/mapitems/layer_quads.h new file mode 100644 index 000000000..7ba890e68 --- /dev/null +++ b/src/game/editor/mapitems/layer_quads.h @@ -0,0 +1,36 @@ +#ifndef GAME_EDITOR_MAPITEMS_LAYER_QUADS_H +#define GAME_EDITOR_MAPITEMS_LAYER_QUADS_H + +#include "layer.h" + +class CLayerQuads : public CLayer +{ +public: + explicit CLayerQuads(CEditor *pEditor); + CLayerQuads(const CLayerQuads &Other); + ~CLayerQuads(); + + void Render(bool QuadPicker = false) override; + CQuad *NewQuad(int x, int y, int Width, int Height); + int SwapQuads(int Index0, int Index1); + + void BrushSelecting(CUIRect Rect) override; + int BrushGrab(std::shared_ptr pBrush, CUIRect Rect) override; + void BrushPlace(std::shared_ptr pBrush, float wx, float wy) override; + void BrushFlipX() override; + void BrushFlipY() override; + void BrushRotate(float Amount) override; + + CUI::EPopupMenuFunctionResult RenderProperties(CUIRect *pToolbox) override; + + void ModifyImageIndex(FIndexModifyFunction pfnFunc) override; + void ModifyEnvelopeIndex(FIndexModifyFunction pfnFunc) override; + + void GetSize(float *pWidth, float *pHeight) override; + std::shared_ptr Duplicate() const override; + + int m_Image; + std::vector m_vQuads; +}; + +#endif diff --git a/src/game/editor/mapitems/layer_sounds.cpp b/src/game/editor/mapitems/layer_sounds.cpp index 9a8d8547c..325b83fe8 100644 --- a/src/game/editor/mapitems/layer_sounds.cpp +++ b/src/game/editor/mapitems/layer_sounds.cpp @@ -1,10 +1,13 @@ +#include "layer_sounds.h" + #include #include static const float s_SourceVisualSize = 32.0f; -CLayerSounds::CLayerSounds() +CLayerSounds::CLayerSounds(CEditor *pEditor) : + CLayer(pEditor) { m_Type = LAYERTYPE_SOUNDS; m_aName[0] = '\0'; @@ -142,8 +145,7 @@ void CLayerSounds::BrushSelecting(CUIRect Rect) int CLayerSounds::BrushGrab(std::shared_ptr pBrush, CUIRect Rect) { // create new layer - std::shared_ptr pGrabbed = std::make_shared(); - pGrabbed->m_pEditor = m_pEditor; + std::shared_ptr pGrabbed = std::make_shared(m_pEditor); pGrabbed->m_Sound = m_Sound; pBrush->AddLayer(pGrabbed); diff --git a/src/game/editor/mapitems/layer_sounds.h b/src/game/editor/mapitems/layer_sounds.h new file mode 100644 index 000000000..0d89329f6 --- /dev/null +++ b/src/game/editor/mapitems/layer_sounds.h @@ -0,0 +1,31 @@ +#ifndef GAME_EDITOR_MAPITEMS_LAYER_SOUNDS_H +#define GAME_EDITOR_MAPITEMS_LAYER_SOUNDS_H + +#include "layer.h" + +class CLayerSounds : public CLayer +{ +public: + explicit CLayerSounds(CEditor *pEditor); + CLayerSounds(const CLayerSounds &Other); + ~CLayerSounds(); + + void Render(bool Tileset = false) override; + CSoundSource *NewSource(int x, int y); + + void BrushSelecting(CUIRect Rect) override; + int BrushGrab(std::shared_ptr pBrush, CUIRect Rect) override; + void BrushPlace(std::shared_ptr pBrush, float wx, float wy) override; + + CUI::EPopupMenuFunctionResult RenderProperties(CUIRect *pToolbox) override; + + void ModifyEnvelopeIndex(FIndexModifyFunction pfnFunc) override; + void ModifySoundIndex(FIndexModifyFunction pfnFunc) override; + + std::shared_ptr Duplicate() const override; + + int m_Sound; + std::vector m_vSources; +}; + +#endif diff --git a/src/game/editor/mapitems/layer_speedup.cpp b/src/game/editor/mapitems/layer_speedup.cpp index 0c2e2e715..bcdd43d06 100644 --- a/src/game/editor/mapitems/layer_speedup.cpp +++ b/src/game/editor/mapitems/layer_speedup.cpp @@ -1,7 +1,9 @@ +#include "layer_speedup.h" + #include -CLayerSpeedup::CLayerSpeedup(int w, int h) : - CLayerTiles(w, h) +CLayerSpeedup::CLayerSpeedup(CEditor *pEditor, int w, int h) : + CLayerTiles(pEditor, w, h) { str_copy(m_aName, "Speedup"); m_Speedup = 1; diff --git a/src/game/editor/mapitems/layer_speedup.h b/src/game/editor/mapitems/layer_speedup.h new file mode 100644 index 000000000..74d0a14c5 --- /dev/null +++ b/src/game/editor/mapitems/layer_speedup.h @@ -0,0 +1,27 @@ +#ifndef GAME_EDITOR_MAPITEMS_LAYER_SPEEDUP_H +#define GAME_EDITOR_MAPITEMS_LAYER_SPEEDUP_H + +#include "layer_tiles.h" + +class CLayerSpeedup : public CLayerTiles +{ +public: + CLayerSpeedup(CEditor *pEditor, int w, int h); + ~CLayerSpeedup(); + + CSpeedupTile *m_pSpeedupTile; + int m_SpeedupForce; + int m_SpeedupMaxSpeed; + int m_SpeedupAngle; + + void Resize(int NewW, int NewH) override; + void Shift(int Direction) override; + bool IsEmpty(const std::shared_ptr &pLayer) override; + void BrushDraw(std::shared_ptr pBrush, float wx, float wy) override; + void BrushFlipX() override; + void BrushFlipY() override; + void BrushRotate(float Amount) override; + void FillSelection(bool Empty, std::shared_ptr pBrush, CUIRect Rect) override; +}; + +#endif diff --git a/src/game/editor/mapitems/layer_switch.cpp b/src/game/editor/mapitems/layer_switch.cpp index 1d0d978a4..ef46a33f1 100644 --- a/src/game/editor/mapitems/layer_switch.cpp +++ b/src/game/editor/mapitems/layer_switch.cpp @@ -1,7 +1,9 @@ +#include "layer_switch.h" + #include -CLayerSwitch::CLayerSwitch(int w, int h) : - CLayerTiles(w, h) +CLayerSwitch::CLayerSwitch(CEditor *pEditor, int w, int h) : + CLayerTiles(pEditor, w, h) { str_copy(m_aName, "Switch"); m_Switch = 1; diff --git a/src/game/editor/mapitems/layer_switch.h b/src/game/editor/mapitems/layer_switch.h new file mode 100644 index 000000000..4011105cc --- /dev/null +++ b/src/game/editor/mapitems/layer_switch.h @@ -0,0 +1,27 @@ +#ifndef GAME_EDITOR_MAPITEMS_LAYER_SWITCH_H +#define GAME_EDITOR_MAPITEMS_LAYER_SWITCH_H + +#include "layer_tiles.h" + +class CLayerSwitch : public CLayerTiles +{ +public: + CLayerSwitch(CEditor *pEditor, int w, int h); + ~CLayerSwitch(); + + CSwitchTile *m_pSwitchTile; + unsigned char m_SwitchNumber; + unsigned char m_SwitchDelay; + + void Resize(int NewW, int NewH) override; + void Shift(int Direction) override; + bool IsEmpty(const std::shared_ptr &pLayer) override; + void BrushDraw(std::shared_ptr pBrush, float wx, float wy) override; + void BrushFlipX() override; + void BrushFlipY() override; + void BrushRotate(float Amount) override; + void FillSelection(bool Empty, std::shared_ptr pBrush, CUIRect Rect) override; + virtual bool ContainsElementWithId(int Id); +}; + +#endif diff --git a/src/game/editor/mapitems/layer_tele.cpp b/src/game/editor/mapitems/layer_tele.cpp index 56afbce78..6b397b4db 100644 --- a/src/game/editor/mapitems/layer_tele.cpp +++ b/src/game/editor/mapitems/layer_tele.cpp @@ -1,7 +1,9 @@ +#include "layer_tele.h" + #include -CLayerTele::CLayerTele(int w, int h) : - CLayerTiles(w, h) +CLayerTele::CLayerTele(CEditor *pEditor, int w, int h) : + CLayerTiles(pEditor, w, h) { str_copy(m_aName, "Tele"); m_Tele = 1; diff --git a/src/game/editor/mapitems/layer_tele.h b/src/game/editor/mapitems/layer_tele.h new file mode 100644 index 000000000..d33755185 --- /dev/null +++ b/src/game/editor/mapitems/layer_tele.h @@ -0,0 +1,26 @@ +#ifndef GAME_EDITOR_MAPITEMS_LAYER_TELE_H +#define GAME_EDITOR_MAPITEMS_LAYER_TELE_H + +#include "layer_tiles.h" + +class CLayerTele : public CLayerTiles +{ +public: + CLayerTele(CEditor *pEditor, int w, int h); + ~CLayerTele(); + + CTeleTile *m_pTeleTile; + unsigned char m_TeleNum; + + void Resize(int NewW, int NewH) override; + void Shift(int Direction) override; + bool IsEmpty(const std::shared_ptr &pLayer) override; + void BrushDraw(std::shared_ptr pBrush, float wx, float wy) override; + void BrushFlipX() override; + void BrushFlipY() override; + void BrushRotate(float Amount) override; + void FillSelection(bool Empty, std::shared_ptr pBrush, CUIRect Rect) override; + virtual bool ContainsElementWithId(int Id); +}; + +#endif diff --git a/src/game/editor/mapitems/layer_tiles.cpp b/src/game/editor/mapitems/layer_tiles.cpp index cee314d73..83d2e5776 100644 --- a/src/game/editor/mapitems/layer_tiles.cpp +++ b/src/game/editor/mapitems/layer_tiles.cpp @@ -1,5 +1,7 @@ /* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */ +#include "layer_tiles.h" + #include #include @@ -7,7 +9,8 @@ #include "image.h" -CLayerTiles::CLayerTiles(int w, int h) +CLayerTiles::CLayerTiles(CEditor *pEditor, int w, int h) : + CLayer(pEditor) { m_Type = LAYERTYPE_TILES; m_aName[0] = '\0'; @@ -271,7 +274,7 @@ int CLayerTiles::BrushGrab(std::shared_ptr pBrush, CUIRect Rect) // create new layers if(this->m_Tele) { - std::shared_ptr pGrabbed = std::make_shared(r.w, r.h); + std::shared_ptr pGrabbed = std::make_shared(m_pEditor, r.w, r.h); InitGrabbedLayer(pGrabbed, this); pBrush->AddLayer(pGrabbed); @@ -297,7 +300,7 @@ int CLayerTiles::BrushGrab(std::shared_ptr pBrush, CUIRect Rect) } else if(this->m_Speedup) { - std::shared_ptr pGrabbed = std::make_shared(r.w, r.h); + std::shared_ptr pGrabbed = std::make_shared(m_pEditor, r.w, r.h); InitGrabbedLayer(pGrabbed, this); pBrush->AddLayer(pGrabbed); @@ -327,7 +330,7 @@ int CLayerTiles::BrushGrab(std::shared_ptr pBrush, CUIRect Rect) } else if(this->m_Switch) { - std::shared_ptr pGrabbed = std::make_shared(r.w, r.h); + std::shared_ptr pGrabbed = std::make_shared(m_pEditor, r.w, r.h); InitGrabbedLayer(pGrabbed, this); pBrush->AddLayer(pGrabbed); @@ -356,7 +359,7 @@ int CLayerTiles::BrushGrab(std::shared_ptr pBrush, CUIRect Rect) else if(this->m_Tune) { - std::shared_ptr pGrabbed = std::make_shared(r.w, r.h); + std::shared_ptr pGrabbed = std::make_shared(m_pEditor, r.w, r.h); InitGrabbedLayer(pGrabbed, this); pBrush->AddLayer(pGrabbed); @@ -382,7 +385,7 @@ int CLayerTiles::BrushGrab(std::shared_ptr pBrush, CUIRect Rect) } else if(this->m_Front) { - std::shared_ptr pGrabbed = std::make_shared(r.w, r.h); + std::shared_ptr pGrabbed = std::make_shared(m_pEditor, r.w, r.h); InitGrabbedLayer(pGrabbed, this); pBrush->AddLayer(pGrabbed); @@ -395,7 +398,7 @@ int CLayerTiles::BrushGrab(std::shared_ptr pBrush, CUIRect Rect) } else { - std::shared_ptr pGrabbed = std::make_shared(r.w, r.h); + std::shared_ptr pGrabbed = std::make_shared(m_pEditor, r.w, r.h); InitGrabbedLayer(pGrabbed, this); pBrush->AddLayer(pGrabbed); @@ -741,7 +744,7 @@ CUI::EPopupMenuFunctionResult CLayerTiles::RenderProperties(CUIRect *pToolBox) { if(!m_pEditor->m_Map.m_pTeleLayer) { - std::shared_ptr pLayer = std::make_shared(m_Width, m_Height); + std::shared_ptr pLayer = std::make_shared(m_pEditor, m_Width, m_Height); m_pEditor->m_Map.MakeTeleLayer(pLayer); m_pEditor->m_Map.m_pGameGroup->AddLayer(pLayer); } diff --git a/src/game/editor/mapitems/layer_tiles.h b/src/game/editor/mapitems/layer_tiles.h new file mode 100644 index 000000000..48717db3c --- /dev/null +++ b/src/game/editor/mapitems/layer_tiles.h @@ -0,0 +1,171 @@ +#ifndef GAME_EDITOR_MAPITEMS_LAYER_TILES_H +#define GAME_EDITOR_MAPITEMS_LAYER_TILES_H + +#include "layer.h" + +enum +{ + DIRECTION_LEFT = 0, + DIRECTION_RIGHT, + DIRECTION_UP, + DIRECTION_DOWN, +}; + +struct RECTi +{ + int x, y; + int w, h; +}; + +class CLayerTiles : public CLayer +{ +protected: + template + void ShiftImpl(T *pTiles, int Direction, int ShiftBy) + { + switch(Direction) + { + case DIRECTION_LEFT: + ShiftBy = minimum(ShiftBy, m_Width); + for(int y = 0; y < m_Height; ++y) + { + if(ShiftBy < m_Width) + mem_move(&pTiles[y * m_Width], &pTiles[y * m_Width + ShiftBy], (m_Width - ShiftBy) * sizeof(T)); + mem_zero(&pTiles[y * m_Width + (m_Width - ShiftBy)], ShiftBy * sizeof(T)); + } + break; + case DIRECTION_RIGHT: + ShiftBy = minimum(ShiftBy, m_Width); + for(int y = 0; y < m_Height; ++y) + { + if(ShiftBy < m_Width) + mem_move(&pTiles[y * m_Width + ShiftBy], &pTiles[y * m_Width], (m_Width - ShiftBy) * sizeof(T)); + mem_zero(&pTiles[y * m_Width], ShiftBy * sizeof(T)); + } + break; + case DIRECTION_UP: + ShiftBy = minimum(ShiftBy, m_Height); + for(int y = ShiftBy; y < m_Height; ++y) + { + mem_copy(&pTiles[(y - ShiftBy) * m_Width], &pTiles[y * m_Width], m_Width * sizeof(T)); + } + for(int y = m_Height - ShiftBy; y < m_Height; ++y) + { + mem_zero(&pTiles[y * m_Width], m_Width * sizeof(T)); + } + break; + case DIRECTION_DOWN: + ShiftBy = minimum(ShiftBy, m_Height); + for(int y = m_Height - ShiftBy - 1; y >= 0; --y) + { + mem_copy(&pTiles[(y + ShiftBy) * m_Width], &pTiles[y * m_Width], m_Width * sizeof(T)); + } + for(int y = 0; y < ShiftBy; ++y) + { + mem_zero(&pTiles[y * m_Width], m_Width * sizeof(T)); + } + break; + } + } + template + void BrushFlipXImpl(T *pTiles) + { + for(int y = 0; y < m_Height; y++) + for(int x = 0; x < m_Width / 2; x++) + std::swap(pTiles[y * m_Width + x], pTiles[(y + 1) * m_Width - 1 - x]); + } + template + void BrushFlipYImpl(T *pTiles) + { + for(int y = 0; y < m_Height / 2; y++) + for(int x = 0; x < m_Width; x++) + std::swap(pTiles[y * m_Width + x], pTiles[(m_Height - 1 - y) * m_Width + x]); + } + +public: + CLayerTiles(CEditor *pEditor, int w, int h); + CLayerTiles(const CLayerTiles &Other); + ~CLayerTiles(); + + virtual CTile GetTile(int x, int y); + virtual void SetTile(int x, int y, CTile Tile); + + virtual void Resize(int NewW, int NewH); + virtual void Shift(int Direction); + + void MakePalette(); + void Render(bool Tileset = false) override; + + int ConvertX(float x) const; + int ConvertY(float y) const; + void Convert(CUIRect Rect, RECTi *pOut); + void Snap(CUIRect *pRect); + void Clamp(RECTi *pRect); + + virtual bool IsEntitiesLayer() const override; + + virtual bool IsEmpty(const std::shared_ptr &pLayer); + void BrushSelecting(CUIRect Rect) override; + int BrushGrab(std::shared_ptr pBrush, CUIRect Rect) override; + void FillSelection(bool Empty, std::shared_ptr pBrush, CUIRect Rect) override; + void BrushDraw(std::shared_ptr pBrush, float wx, float wy) override; + void BrushFlipX() override; + void BrushFlipY() override; + void BrushRotate(float Amount) override; + + std::shared_ptr Duplicate() const override; + + virtual void ShowInfo(); + CUI::EPopupMenuFunctionResult RenderProperties(CUIRect *pToolbox) override; + + struct SCommonPropState + { + enum + { + MODIFIED_SIZE = 1 << 0, + MODIFIED_COLOR = 1 << 1, + }; + int m_Modified = 0; + int m_Width = -1; + int m_Height = -1; + int m_Color = 0; + }; + static CUI::EPopupMenuFunctionResult RenderCommonProperties(SCommonPropState &State, CEditor *pEditor, CUIRect *pToolbox, std::vector> &vpLayers); + + void ModifyImageIndex(FIndexModifyFunction pfnFunc) override; + void ModifyEnvelopeIndex(FIndexModifyFunction pfnFunc) override; + + void PrepareForSave(); + void ExtractTiles(int TilemapItemVersion, const CTile *pSavedTiles, size_t SavedTilesSize); + + void GetSize(float *pWidth, float *pHeight) override + { + *pWidth = m_Width * 32.0f; + *pHeight = m_Height * 32.0f; + } + + void FlagModified(int x, int y, int w, int h); + + int m_Game; + int m_Image; + int m_Width; + int m_Height; + CColor m_Color; + int m_ColorEnv; + int m_ColorEnvOffset; + CTile *m_pTiles; + + // DDRace + + int m_AutoMapperConfig; + int m_Seed; + bool m_AutoAutoMap; + int m_Tele; + int m_Speedup; + int m_Front; + int m_Switch; + int m_Tune; + char m_aFileName[IO_MAX_PATH_LENGTH]; +}; + +#endif diff --git a/src/game/editor/mapitems/layer_tune.cpp b/src/game/editor/mapitems/layer_tune.cpp index 13c8ee17b..619336943 100644 --- a/src/game/editor/mapitems/layer_tune.cpp +++ b/src/game/editor/mapitems/layer_tune.cpp @@ -1,7 +1,9 @@ +#include "layer_tune.h" + #include -CLayerTune::CLayerTune(int w, int h) : - CLayerTiles(w, h) +CLayerTune::CLayerTune(CEditor *pEditor, int w, int h) : + CLayerTiles(pEditor, w, h) { str_copy(m_aName, "Tune"); m_Tune = 1; diff --git a/src/game/editor/mapitems/layer_tune.h b/src/game/editor/mapitems/layer_tune.h new file mode 100644 index 000000000..8706778ec --- /dev/null +++ b/src/game/editor/mapitems/layer_tune.h @@ -0,0 +1,25 @@ +#ifndef GAME_EDITOR_MAPITEMS_LAYER_TUNE_H +#define GAME_EDITOR_MAPITEMS_LAYER_TUNE_H + +#include "layer_tiles.h" + +class CLayerTune : public CLayerTiles +{ +public: + CLayerTune(CEditor *pEditor, int w, int h); + ~CLayerTune(); + + CTuneTile *m_pTuneTile; + unsigned char m_TuningNumber; + + void Resize(int NewW, int NewH) override; + void Shift(int Direction) override; + bool IsEmpty(const std::shared_ptr &pLayer) override; + void BrushDraw(std::shared_ptr pBrush, float wx, float wy) override; + void BrushFlipX() override; + void BrushFlipY() override; + void BrushRotate(float Amount) override; + void FillSelection(bool Empty, std::shared_ptr pBrush, CUIRect Rect) override; +}; + +#endif diff --git a/src/game/editor/mapitems/map.cpp b/src/game/editor/mapitems/map.cpp index 48c58acd1..256c32333 100644 --- a/src/game/editor/mapitems/map.cpp +++ b/src/game/editor/mapitems/map.cpp @@ -127,8 +127,7 @@ void CEditorMap::CreateDefault(IGraphics::CTextureHandle EntitiesTexture) pGroup->m_ParallaxY = 0; pGroup->m_CustomParallaxZoom = 0; pGroup->m_ParallaxZoom = 0; - std::shared_ptr pLayer = std::make_shared(); - pLayer->m_pEditor = m_pEditor; + std::shared_ptr pLayer = std::make_shared(m_pEditor); CQuad *pQuad = pLayer->NewQuad(0, 0, 1600, 1200); pQuad->m_aColors[0].r = pQuad->m_aColors[1].r = 94; pQuad->m_aColors[0].g = pQuad->m_aColors[1].g = 132; @@ -140,7 +139,7 @@ void CEditorMap::CreateDefault(IGraphics::CTextureHandle EntitiesTexture) // add game layer and reset front, tele, speedup, tune and switch layer pointers MakeGameGroup(NewGroup()); - MakeGameLayer(std::make_shared(50, 50)); + MakeGameLayer(std::make_shared(m_pEditor, 50, 50)); m_pGameGroup->AddLayer(m_pGameLayer); m_pFrontLayer = nullptr; diff --git a/src/game/editor/mapitems/map_io.cpp b/src/game/editor/mapitems/map_io.cpp index 6224494f8..42422bd38 100644 --- a/src/game/editor/mapitems/map_io.cpp +++ b/src/game/editor/mapitems/map_io.cpp @@ -640,7 +640,7 @@ bool CEditorMap::Load(const char *pFileName, int StorageType, const std::functio std::shared_ptr pTiles; if(pTilemapItem->m_Flags & TILESLAYERFLAG_GAME) { - pTiles = std::make_shared(pTilemapItem->m_Width, pTilemapItem->m_Height); + pTiles = std::make_shared(m_pEditor, pTilemapItem->m_Width, pTilemapItem->m_Height); MakeGameLayer(pTiles); MakeGameGroup(pGroup); } @@ -649,7 +649,7 @@ bool CEditorMap::Load(const char *pFileName, int StorageType, const std::functio if(pTilemapItem->m_Version <= 2) pTilemapItem->m_Tele = *((const int *)(pTilemapItem) + 15); - pTiles = std::make_shared(pTilemapItem->m_Width, pTilemapItem->m_Height); + pTiles = std::make_shared(m_pEditor, pTilemapItem->m_Width, pTilemapItem->m_Height); MakeTeleLayer(pTiles); } else if(pTilemapItem->m_Flags & TILESLAYERFLAG_SPEEDUP) @@ -657,7 +657,7 @@ bool CEditorMap::Load(const char *pFileName, int StorageType, const std::functio if(pTilemapItem->m_Version <= 2) pTilemapItem->m_Speedup = *((const int *)(pTilemapItem) + 16); - pTiles = std::make_shared(pTilemapItem->m_Width, pTilemapItem->m_Height); + pTiles = std::make_shared(m_pEditor, pTilemapItem->m_Width, pTilemapItem->m_Height); MakeSpeedupLayer(pTiles); } else if(pTilemapItem->m_Flags & TILESLAYERFLAG_FRONT) @@ -665,7 +665,7 @@ bool CEditorMap::Load(const char *pFileName, int StorageType, const std::functio if(pTilemapItem->m_Version <= 2) pTilemapItem->m_Front = *((const int *)(pTilemapItem) + 17); - pTiles = std::make_shared(pTilemapItem->m_Width, pTilemapItem->m_Height); + pTiles = std::make_shared(m_pEditor, pTilemapItem->m_Width, pTilemapItem->m_Height); MakeFrontLayer(pTiles); } else if(pTilemapItem->m_Flags & TILESLAYERFLAG_SWITCH) @@ -673,7 +673,7 @@ bool CEditorMap::Load(const char *pFileName, int StorageType, const std::functio if(pTilemapItem->m_Version <= 2) pTilemapItem->m_Switch = *((const int *)(pTilemapItem) + 18); - pTiles = std::make_shared(pTilemapItem->m_Width, pTilemapItem->m_Height); + pTiles = std::make_shared(m_pEditor, pTilemapItem->m_Width, pTilemapItem->m_Height); MakeSwitchLayer(pTiles); } else if(pTilemapItem->m_Flags & TILESLAYERFLAG_TUNE) @@ -681,12 +681,12 @@ bool CEditorMap::Load(const char *pFileName, int StorageType, const std::functio if(pTilemapItem->m_Version <= 2) pTilemapItem->m_Tune = *((const int *)(pTilemapItem) + 19); - pTiles = std::make_shared(pTilemapItem->m_Width, pTilemapItem->m_Height); + pTiles = std::make_shared(m_pEditor, pTilemapItem->m_Width, pTilemapItem->m_Height); MakeTuneLayer(pTiles); } else { - pTiles = std::make_shared(pTilemapItem->m_Width, pTilemapItem->m_Height); + pTiles = std::make_shared(m_pEditor, pTilemapItem->m_Width, pTilemapItem->m_Height); pTiles->m_pEditor = m_pEditor; pTiles->m_Color = pTilemapItem->m_Color; pTiles->m_ColorEnv = pTilemapItem->m_ColorEnv; @@ -819,8 +819,7 @@ bool CEditorMap::Load(const char *pFileName, int StorageType, const std::functio { const CMapItemLayerQuads *pQuadsItem = (CMapItemLayerQuads *)pLayerItem; - std::shared_ptr pQuads = std::make_shared(); - pQuads->m_pEditor = m_pEditor; + std::shared_ptr pQuads = std::make_shared(m_pEditor); pQuads->m_Flags = pLayerItem->m_Flags; pQuads->m_Image = pQuadsItem->m_Image; if(pQuads->m_Image < -1 || pQuads->m_Image >= (int)m_vpImages.size()) @@ -842,8 +841,7 @@ bool CEditorMap::Load(const char *pFileName, int StorageType, const std::functio if(pSoundsItem->m_Version < 1 || pSoundsItem->m_Version > CMapItemLayerSounds::CURRENT_VERSION) continue; - std::shared_ptr pSounds = std::make_shared(); - pSounds->m_pEditor = m_pEditor; + std::shared_ptr pSounds = std::make_shared(m_pEditor); pSounds->m_Flags = pLayerItem->m_Flags; pSounds->m_Sound = pSoundsItem->m_Sound; @@ -868,8 +866,7 @@ bool CEditorMap::Load(const char *pFileName, int StorageType, const std::functio if(pSoundsItem->m_Version < 1 || pSoundsItem->m_Version > CMapItemLayerSounds::CURRENT_VERSION) continue; - std::shared_ptr pSounds = std::make_shared(); - pSounds->m_pEditor = m_pEditor; + std::shared_ptr pSounds = std::make_shared(m_pEditor); pSounds->m_Flags = pLayerItem->m_Flags; pSounds->m_Sound = pSoundsItem->m_Sound; diff --git a/src/game/editor/popups.cpp b/src/game/editor/popups.cpp index c9b1a71d1..2e95227ba 100644 --- a/src/game/editor/popups.cpp +++ b/src/game/editor/popups.cpp @@ -394,7 +394,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupGroup(void *pContext, CUIRect View, static int s_NewTeleLayerButton = 0; if(pEditor->DoButton_Editor(&s_NewTeleLayerButton, "Add tele layer", 0, &Button, 0, "Creates a new tele layer")) { - std::shared_ptr pTeleLayer = std::make_shared(pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height); + std::shared_ptr pTeleLayer = std::make_shared(pEditor, pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height); pEditor->m_Map.MakeTeleLayer(pTeleLayer); pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->AddLayer(pTeleLayer); pEditor->SelectLayer(pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->m_vpLayers.size() - 1); @@ -411,7 +411,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupGroup(void *pContext, CUIRect View, static int s_NewSpeedupLayerButton = 0; if(pEditor->DoButton_Editor(&s_NewSpeedupLayerButton, "Add speedup layer", 0, &Button, 0, "Creates a new speedup layer")) { - std::shared_ptr pSpeedupLayer = std::make_shared(pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height); + std::shared_ptr pSpeedupLayer = std::make_shared(pEditor, pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height); pEditor->m_Map.MakeSpeedupLayer(pSpeedupLayer); pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->AddLayer(pSpeedupLayer); pEditor->SelectLayer(pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->m_vpLayers.size() - 1); @@ -428,7 +428,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupGroup(void *pContext, CUIRect View, static int s_NewTuneLayerButton = 0; if(pEditor->DoButton_Editor(&s_NewTuneLayerButton, "Add tune layer", 0, &Button, 0, "Creates a new tuning layer")) { - std::shared_ptr pTuneLayer = std::make_shared(pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height); + std::shared_ptr pTuneLayer = std::make_shared(pEditor, pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height); pEditor->m_Map.MakeTuneLayer(pTuneLayer); pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->AddLayer(pTuneLayer); pEditor->SelectLayer(pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->m_vpLayers.size() - 1); @@ -445,7 +445,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupGroup(void *pContext, CUIRect View, static int s_NewFrontLayerButton = 0; if(pEditor->DoButton_Editor(&s_NewFrontLayerButton, "Add front layer", 0, &Button, 0, "Creates a new item layer")) { - std::shared_ptr pFrontLayer = std::make_shared(pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height); + std::shared_ptr pFrontLayer = std::make_shared(pEditor, pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height); pEditor->m_Map.MakeFrontLayer(pFrontLayer); pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->AddLayer(pFrontLayer); pEditor->SelectLayer(pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->m_vpLayers.size() - 1); @@ -462,7 +462,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupGroup(void *pContext, CUIRect View, static int s_NewSwitchLayerButton = 0; if(pEditor->DoButton_Editor(&s_NewSwitchLayerButton, "Add switch layer", 0, &Button, 0, "Creates a new switch layer")) { - std::shared_ptr pSwitchLayer = std::make_shared(pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height); + std::shared_ptr pSwitchLayer = std::make_shared(pEditor, pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height); pEditor->m_Map.MakeSwitchLayer(pSwitchLayer); pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->AddLayer(pSwitchLayer); pEditor->SelectLayer(pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->m_vpLayers.size() - 1); @@ -477,8 +477,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupGroup(void *pContext, CUIRect View, static int s_NewQuadLayerButton = 0; if(pEditor->DoButton_Editor(&s_NewQuadLayerButton, "Add quads layer", 0, &Button, 0, "Creates a new quad layer")) { - std::shared_ptr pQuadLayer = std::make_shared(); - pQuadLayer->m_pEditor = pEditor; + std::shared_ptr pQuadLayer = std::make_shared(pEditor); pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->AddLayer(pQuadLayer); pEditor->SelectLayer(pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->m_vpLayers.size() - 1); pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->m_Collapse = false; @@ -491,7 +490,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupGroup(void *pContext, CUIRect View, static int s_NewTileLayerButton = 0; if(pEditor->DoButton_Editor(&s_NewTileLayerButton, "Add tile layer", 0, &Button, 0, "Creates a new tile layer")) { - std::shared_ptr pTileLayer = std::make_shared(pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height); + std::shared_ptr pTileLayer = std::make_shared(pEditor, pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height); pTileLayer->m_pEditor = pEditor; pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->AddLayer(pTileLayer); pEditor->SelectLayer(pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->m_vpLayers.size() - 1); @@ -505,8 +504,7 @@ CUI::EPopupMenuFunctionResult CEditor::PopupGroup(void *pContext, CUIRect View, static int s_NewSoundLayerButton = 0; if(pEditor->DoButton_Editor(&s_NewSoundLayerButton, "Add sound layer", 0, &Button, 0, "Creates a new sound layer")) { - std::shared_ptr pSoundLayer = std::make_shared(); - pSoundLayer->m_pEditor = pEditor; + std::shared_ptr pSoundLayer = std::make_shared(pEditor); pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->AddLayer(pSoundLayer); pEditor->SelectLayer(pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->m_vpLayers.size() - 1); pEditor->m_Map.m_vpGroups[pEditor->m_SelectedGroup]->m_Collapse = false; diff --git a/src/game/editor/tileart.cpp b/src/game/editor/tileart.cpp index c798bcbe2..e6e88ef97 100644 --- a/src/game/editor/tileart.cpp +++ b/src/game/editor/tileart.cpp @@ -167,9 +167,8 @@ static std::shared_ptr AddLayerWithImage(CEditor *pEditor, const st std::shared_ptr pEditorImage = ImageInfoToEditorImage(pEditor, Image, pName); pEditor->m_Map.m_vpImages.push_back(pEditorImage); - std::shared_ptr pLayer = std::make_shared(Width, Height); + std::shared_ptr pLayer = std::make_shared(pEditor, Width, Height); str_copy(pLayer->m_aName, pName); - pLayer->m_pEditor = pEditor; pLayer->m_Image = pEditor->m_Map.m_vpImages.size() - 1; pGroup->AddLayer(pLayer);