extract editor layers into seperate headers

This commit is contained in:
marmare314 2023-09-05 14:03:10 +02:00
parent 78b70ebcf8
commit d400687876
22 changed files with 585 additions and 468 deletions

View file

@ -2278,16 +2278,27 @@ if(CLIENT)
map_view.h map_view.h
mapitems/image.cpp mapitems/image.cpp
mapitems/image.h mapitems/image.h
mapitems/layer.h
mapitems/layer_front.cpp mapitems/layer_front.cpp
mapitems/layer_front.h
mapitems/layer_game.cpp mapitems/layer_game.cpp
mapitems/layer_game.h
mapitems/layer_group.cpp mapitems/layer_group.cpp
mapitems/layer_group.h
mapitems/layer_quads.cpp mapitems/layer_quads.cpp
mapitems/layer_quads.h
mapitems/layer_sounds.cpp mapitems/layer_sounds.cpp
mapitems/layer_sounds.h
mapitems/layer_speedup.cpp mapitems/layer_speedup.cpp
mapitems/layer_speedup.h
mapitems/layer_switch.cpp mapitems/layer_switch.cpp
mapitems/layer_switch.h
mapitems/layer_tele.cpp mapitems/layer_tele.cpp
mapitems/layer_tele.h
mapitems/layer_tiles.cpp mapitems/layer_tiles.cpp
mapitems/layer_tiles.h
mapitems/layer_tune.cpp mapitems/layer_tune.cpp
mapitems/layer_tune.h
mapitems/map.cpp mapitems/map.cpp
mapitems/map_io.cpp mapitems/map_io.cpp
mapitems/sound.cpp mapitems/sound.cpp

View file

@ -11,6 +11,18 @@
#include <game/mapitems.h> #include <game/mapitems.h>
#include <game/mapitems_ex.h> #include <game/mapitems_ex.h>
#include <game/editor/mapitems/layer.h>
#include <game/editor/mapitems/layer_front.h>
#include <game/editor/mapitems/layer_game.h>
#include <game/editor/mapitems/layer_group.h>
#include <game/editor/mapitems/layer_quads.h>
#include <game/editor/mapitems/layer_sounds.h>
#include <game/editor/mapitems/layer_speedup.h>
#include <game/editor/mapitems/layer_switch.h>
#include <game/editor/mapitems/layer_tele.h>
#include <game/editor/mapitems/layer_tiles.h>
#include <game/editor/mapitems/layer_tune.h>
#include <engine/editor.h> #include <engine/editor.h>
#include <engine/engine.h> #include <engine/engine.h>
#include <engine/graphics.h> #include <engine/graphics.h>
@ -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<CLayerGroup> pBrush, CUIRect Rect) { return 0; }
virtual void FillSelection(bool Empty, std::shared_ptr<CLayer> pBrush, CUIRect Rect) {}
virtual void BrushDraw(std::shared_ptr<CLayer> pBrush, float x, float y) {}
virtual void BrushPlace(std::shared_ptr<CLayer> 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<CLayer> 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<std::shared_ptr<CLayer>> 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<CLayer> &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 CEditorImage;
class CEditorSound; class CEditorSound;
@ -513,213 +381,6 @@ enum
PROPTYPE_AUTOMAPPER, 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<typename T>
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<typename T>
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<typename T>
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<CLayerTiles> &pLayer);
void BrushSelecting(CUIRect Rect) override;
int BrushGrab(std::shared_ptr<CLayerGroup> pBrush, CUIRect Rect) override;
void FillSelection(bool Empty, std::shared_ptr<CLayer> pBrush, CUIRect Rect) override;
void BrushDraw(std::shared_ptr<CLayer> pBrush, float wx, float wy) override;
void BrushFlipX() override;
void BrushFlipY() override;
void BrushRotate(float Amount) override;
std::shared_ptr<CLayer> 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<std::shared_ptr<CLayerTiles>> &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<CLayerGroup> pBrush, CUIRect Rect) override;
void BrushPlace(std::shared_ptr<CLayer> 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<CLayer> Duplicate() const override;
int m_Image;
std::vector<CQuad> 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 class CDataFileWriterFinishJob : public IJob
{ {
char m_aRealFileName[IO_MAX_PATH_LENGTH]; char m_aRealFileName[IO_MAX_PATH_LENGTH];
@ -1474,121 +1135,4 @@ public:
inline class IGraphics *CLayer::Graphics() { return m_pEditor->Graphics(); } inline class IGraphics *CLayer::Graphics() { return m_pEditor->Graphics(); }
inline class ITextRender *CLayer::TextRender() { return m_pEditor->TextRender(); } 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<CLayerTiles> &pLayer) override;
void BrushDraw(std::shared_ptr<CLayer> pBrush, float wx, float wy) override;
void BrushFlipX() override;
void BrushFlipY() override;
void BrushRotate(float Amount) override;
void FillSelection(bool Empty, std::shared_ptr<CLayer> 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<CLayerTiles> &pLayer) override;
void BrushDraw(std::shared_ptr<CLayer> pBrush, float wx, float wy) override;
void BrushFlipX() override;
void BrushFlipY() override;
void BrushRotate(float Amount) override;
void FillSelection(bool Empty, std::shared_ptr<CLayer> 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<CLayerTiles> &pLayer) override;
void BrushDraw(std::shared_ptr<CLayer> pBrush, float wx, float wy) override;
void BrushFlipX() override;
void BrushFlipY() override;
void BrushRotate(float Amount) override;
void FillSelection(bool Empty, std::shared_ptr<CLayer> 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<CLayerTiles> &pLayer) override;
void BrushDraw(std::shared_ptr<CLayer> pBrush, float wx, float wy) override;
void BrushFlipX() override;
void BrushFlipY() override;
void BrushRotate(float Amount) override;
void FillSelection(bool Empty, std::shared_ptr<CLayer> 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<CLayerGroup> pBrush, CUIRect Rect) override;
void BrushPlace(std::shared_ptr<CLayer> 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<CLayer> Duplicate() const override;
int m_Sound;
std::vector<CSoundSource> m_vSources;
};
#endif #endif

View file

@ -0,0 +1,80 @@
#ifndef GAME_EDITOR_MAPITEMS_LAYER_H
#define GAME_EDITOR_MAPITEMS_LAYER_H
#include <base/system.h>
#include <game/client/ui.h>
#include <game/client/ui_rect.h>
#include <game/mapitems.h>
#include <memory>
using FIndexModifyFunction = std::function<void(int *pIndex)>;
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<CLayerGroup> pBrush, CUIRect Rect) { return 0; }
virtual void FillSelection(bool Empty, std::shared_ptr<CLayer> pBrush, CUIRect Rect) {}
virtual void BrushDraw(std::shared_ptr<CLayer> pBrush, float x, float y) {}
virtual void BrushPlace(std::shared_ptr<CLayer> 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<CLayer> 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

View file

@ -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

View file

@ -1,5 +1,7 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* (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. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */
#include "layer_game.h"
#include <game/editor/editor.h> #include <game/editor/editor.h>
CLayerGame::CLayerGame(int w, int h) : CLayerGame::CLayerGame(int w, int h) :

View file

@ -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

View file

@ -1,3 +1,5 @@
#include "layer_group.h"
#include <game/editor/editor.h> #include <game/editor/editor.h>
CLayerGroup::CLayerGroup() CLayerGroup::CLayerGroup()

View file

@ -0,0 +1,88 @@
#ifndef GAME_EDITOR_MAPITEMS_LAYER_GROUP_H
#define GAME_EDITOR_MAPITEMS_LAYER_GROUP_H
#include "layer.h"
#include <game/mapitems_ex.h>
#include <memory>
#include <vector>
class CLayerGroup
{
public:
class CEditorMap *m_pMap;
std::vector<std::shared_ptr<CLayer>> 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<CLayer> &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

View file

@ -1,5 +1,7 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* (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. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */
#include "layer_quads.h"
#include <game/editor/editor.h> #include <game/editor/editor.h>
#include "image.h" #include "image.h"

View file

@ -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<CLayerGroup> pBrush, CUIRect Rect) override;
void BrushPlace(std::shared_ptr<CLayer> 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<CLayer> Duplicate() const override;
int m_Image;
std::vector<CQuad> m_vQuads;
};
#endif

View file

@ -1,3 +1,5 @@
#include "layer_sounds.h"
#include <game/editor/editor.h> #include <game/editor/editor.h>
#include <game/generated/client_data.h> #include <game/generated/client_data.h>

View file

@ -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<CLayerGroup> pBrush, CUIRect Rect) override;
void BrushPlace(std::shared_ptr<CLayer> 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<CLayer> Duplicate() const override;
int m_Sound;
std::vector<CSoundSource> m_vSources;
};
#endif

View file

@ -1,3 +1,5 @@
#include "layer_speedup.h"
#include <game/editor/editor.h> #include <game/editor/editor.h>
CLayerSpeedup::CLayerSpeedup(int w, int h) : CLayerSpeedup::CLayerSpeedup(int w, int h) :

View file

@ -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<CLayerTiles> &pLayer) override;
void BrushDraw(std::shared_ptr<CLayer> pBrush, float wx, float wy) override;
void BrushFlipX() override;
void BrushFlipY() override;
void BrushRotate(float Amount) override;
void FillSelection(bool Empty, std::shared_ptr<CLayer> pBrush, CUIRect Rect) override;
};
#endif

View file

@ -1,3 +1,5 @@
#include "layer_switch.h"
#include <game/editor/editor.h> #include <game/editor/editor.h>
CLayerSwitch::CLayerSwitch(int w, int h) : CLayerSwitch::CLayerSwitch(int w, int h) :

View file

@ -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<CLayerTiles> &pLayer) override;
void BrushDraw(std::shared_ptr<CLayer> pBrush, float wx, float wy) override;
void BrushFlipX() override;
void BrushFlipY() override;
void BrushRotate(float Amount) override;
void FillSelection(bool Empty, std::shared_ptr<CLayer> pBrush, CUIRect Rect) override;
virtual bool ContainsElementWithId(int Id);
};
#endif

View file

@ -1,3 +1,5 @@
#include "layer_tele.h"
#include <game/editor/editor.h> #include <game/editor/editor.h>
CLayerTele::CLayerTele(int w, int h) : CLayerTele::CLayerTele(int w, int h) :

View file

@ -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<CLayerTiles> &pLayer) override;
void BrushDraw(std::shared_ptr<CLayer> pBrush, float wx, float wy) override;
void BrushFlipX() override;
void BrushFlipY() override;
void BrushRotate(float Amount) override;
void FillSelection(bool Empty, std::shared_ptr<CLayer> pBrush, CUIRect Rect) override;
virtual bool ContainsElementWithId(int Id);
};
#endif

View file

@ -1,5 +1,7 @@
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */ /* (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. */ /* If you are missing that file, acquire a complete release at teeworlds.com. */
#include "layer_tiles.h"
#include <game/editor/editor.h> #include <game/editor/editor.h>
#include <engine/keys.h> #include <engine/keys.h>

View file

@ -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<typename T>
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<typename T>
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<typename T>
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<CLayerTiles> &pLayer);
void BrushSelecting(CUIRect Rect) override;
int BrushGrab(std::shared_ptr<CLayerGroup> pBrush, CUIRect Rect) override;
void FillSelection(bool Empty, std::shared_ptr<CLayer> pBrush, CUIRect Rect) override;
void BrushDraw(std::shared_ptr<CLayer> pBrush, float wx, float wy) override;
void BrushFlipX() override;
void BrushFlipY() override;
void BrushRotate(float Amount) override;
std::shared_ptr<CLayer> 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<std::shared_ptr<CLayerTiles>> &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

View file

@ -1,3 +1,5 @@
#include "layer_tune.h"
#include <game/editor/editor.h> #include <game/editor/editor.h>
CLayerTune::CLayerTune(int w, int h) : CLayerTune::CLayerTune(int w, int h) :

View file

@ -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<CLayerTiles> &pLayer) override;
void BrushDraw(std::shared_ptr<CLayer> pBrush, float wx, float wy) override;
void BrushFlipX() override;
void BrushFlipY() override;
void BrushRotate(float Amount) override;
void FillSelection(bool Empty, std::shared_ptr<CLayer> pBrush, CUIRect Rect) override;
};
#endif