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/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..07564446f --- /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(); + + 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; +}; + +#endif diff --git a/src/game/editor/mapitems/layer_front.h b/src/game/editor/mapitems/layer_front.h new file mode 100644 index 000000000..d839ea1d0 --- /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(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..698248d2a 100644 --- a/src/game/editor/mapitems/layer_game.cpp +++ b/src/game/editor/mapitems/layer_game.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_game.h" + #include CLayerGame::CLayerGame(int w, int h) : diff --git a/src/game/editor/mapitems/layer_game.h b/src/game/editor/mapitems/layer_game.h new file mode 100644 index 000000000..3f8824675 --- /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(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..7f1966c6e 100644 --- a/src/game/editor/mapitems/layer_quads.cpp +++ b/src/game/editor/mapitems/layer_quads.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_quads.h" + #include #include "image.h" diff --git a/src/game/editor/mapitems/layer_quads.h b/src/game/editor/mapitems/layer_quads.h new file mode 100644 index 000000000..2f7e89e37 --- /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: + 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; +}; + +#endif diff --git a/src/game/editor/mapitems/layer_sounds.cpp b/src/game/editor/mapitems/layer_sounds.cpp index 9a8d8547c..a8c8d38db 100644 --- a/src/game/editor/mapitems/layer_sounds.cpp +++ b/src/game/editor/mapitems/layer_sounds.cpp @@ -1,3 +1,5 @@ +#include "layer_sounds.h" + #include #include diff --git a/src/game/editor/mapitems/layer_sounds.h b/src/game/editor/mapitems/layer_sounds.h new file mode 100644 index 000000000..9e5ef80b6 --- /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: + 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_speedup.cpp b/src/game/editor/mapitems/layer_speedup.cpp index 0c2e2e715..eb101d031 100644 --- a/src/game/editor/mapitems/layer_speedup.cpp +++ b/src/game/editor/mapitems/layer_speedup.cpp @@ -1,3 +1,5 @@ +#include "layer_speedup.h" + #include CLayerSpeedup::CLayerSpeedup(int w, int h) : diff --git a/src/game/editor/mapitems/layer_speedup.h b/src/game/editor/mapitems/layer_speedup.h new file mode 100644 index 000000000..a9ea708e1 --- /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(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..26c8977d6 100644 --- a/src/game/editor/mapitems/layer_switch.cpp +++ b/src/game/editor/mapitems/layer_switch.cpp @@ -1,3 +1,5 @@ +#include "layer_switch.h" + #include CLayerSwitch::CLayerSwitch(int w, int h) : diff --git a/src/game/editor/mapitems/layer_switch.h b/src/game/editor/mapitems/layer_switch.h new file mode 100644 index 000000000..4ad48d0cc --- /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(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..e6690960d 100644 --- a/src/game/editor/mapitems/layer_tele.cpp +++ b/src/game/editor/mapitems/layer_tele.cpp @@ -1,3 +1,5 @@ +#include "layer_tele.h" + #include CLayerTele::CLayerTele(int w, int h) : diff --git a/src/game/editor/mapitems/layer_tele.h b/src/game/editor/mapitems/layer_tele.h new file mode 100644 index 000000000..f6ea0756e --- /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(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..154ed54f1 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 diff --git a/src/game/editor/mapitems/layer_tiles.h b/src/game/editor/mapitems/layer_tiles.h new file mode 100644 index 000000000..194bd5524 --- /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(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..2c36329d9 100644 --- a/src/game/editor/mapitems/layer_tune.cpp +++ b/src/game/editor/mapitems/layer_tune.cpp @@ -1,3 +1,5 @@ +#include "layer_tune.h" + #include CLayerTune::CLayerTune(int w, int h) : diff --git a/src/game/editor/mapitems/layer_tune.h b/src/game/editor/mapitems/layer_tune.h new file mode 100644 index 000000000..e357d8d8d --- /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(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