Merge pull request #7143 from Marmare314/refactor-a2

extract editor layers into seperate headers
This commit is contained in:
Dennis Felsing 2023-10-03 11:54:10 +00:00 committed by GitHub
commit 8839698d41
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
29 changed files with 638 additions and 529 deletions

View file

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

View file

@ -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++)
{

View file

@ -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<CLayerTiles>(16, 16);
m_pTilesetPicker->m_pEditor = this;
m_pTilesetPicker = std::make_shared<CLayerTiles>(this, 16, 16);
m_pTilesetPicker->MakePalette();
m_pTilesetPicker->m_Readonly = true;
m_pQuadsetPicker = std::make_shared<CLayerQuads>();
m_pQuadsetPicker->m_pEditor = this;
m_pQuadsetPicker = std::make_shared<CLayerQuads>(this);
m_pQuadsetPicker->NewQuad(0, 0, 64, 64);
m_pQuadsetPicker->m_Readonly = true;

View file

@ -11,6 +11,18 @@
#include <game/mapitems.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/engine.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 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<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
{
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<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

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();
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<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

@ -1,7 +1,7 @@
#include <game/editor/editor.h>
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;

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(CEditor *pEditor, int w, int h);
void Resize(int NewW, int NewH) override;
void SetTile(int x, int y, CTile Tile) override;
};
#endif

View file

@ -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 <game/editor/editor.h>
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<CLayer> pLayerFront = std::make_shared<CLayerFront>(m_Width, m_Height);
std::shared_ptr<CLayer> pLayerFront = std::make_shared<CLayerFront>(m_pEditor, m_Width, m_Height);
m_pEditor->m_Map.MakeFrontLayer(pLayerFront);
m_pEditor->m_Map.m_pGameGroup->AddLayer(pLayerFront);
}

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

View file

@ -1,3 +1,5 @@
#include "layer_group.h"
#include <game/editor/editor.h>
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,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 <game/editor/editor.h>
#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<CLayerGroup> pBrush, CUIRect Rect)
{
// create new layers
std::shared_ptr<CLayerQuads> pGrabbed = std::make_shared<CLayerQuads>();
pGrabbed->m_pEditor = m_pEditor;
std::shared_ptr<CLayerQuads> pGrabbed = std::make_shared<CLayerQuads>(m_pEditor);
pGrabbed->m_Image = m_Image;
pBrush->AddLayer(pGrabbed);

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:
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<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,10 +1,13 @@
#include "layer_sounds.h"
#include <game/editor/editor.h>
#include <game/generated/client_data.h>
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<CLayerGroup> pBrush, CUIRect Rect)
{
// create new layer
std::shared_ptr<CLayerSounds> pGrabbed = std::make_shared<CLayerSounds>();
pGrabbed->m_pEditor = m_pEditor;
std::shared_ptr<CLayerSounds> pGrabbed = std::make_shared<CLayerSounds>(m_pEditor);
pGrabbed->m_Sound = m_Sound;
pBrush->AddLayer(pGrabbed);

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:
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<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,7 +1,9 @@
#include "layer_speedup.h"
#include <game/editor/editor.h>
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;

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(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<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,7 +1,9 @@
#include "layer_switch.h"
#include <game/editor/editor.h>
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;

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(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<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,7 +1,9 @@
#include "layer_tele.h"
#include <game/editor/editor.h>
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;

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(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<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. */
/* If you are missing that file, acquire a complete release at teeworlds.com. */
#include "layer_tiles.h"
#include <game/editor/editor.h>
#include <engine/keys.h>
@ -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<CLayerGroup> pBrush, CUIRect Rect)
// create new layers
if(this->m_Tele)
{
std::shared_ptr<CLayerTele> pGrabbed = std::make_shared<CLayerTele>(r.w, r.h);
std::shared_ptr<CLayerTele> pGrabbed = std::make_shared<CLayerTele>(m_pEditor, r.w, r.h);
InitGrabbedLayer(pGrabbed, this);
pBrush->AddLayer(pGrabbed);
@ -297,7 +300,7 @@ int CLayerTiles::BrushGrab(std::shared_ptr<CLayerGroup> pBrush, CUIRect Rect)
}
else if(this->m_Speedup)
{
std::shared_ptr<CLayerSpeedup> pGrabbed = std::make_shared<CLayerSpeedup>(r.w, r.h);
std::shared_ptr<CLayerSpeedup> pGrabbed = std::make_shared<CLayerSpeedup>(m_pEditor, r.w, r.h);
InitGrabbedLayer(pGrabbed, this);
pBrush->AddLayer(pGrabbed);
@ -327,7 +330,7 @@ int CLayerTiles::BrushGrab(std::shared_ptr<CLayerGroup> pBrush, CUIRect Rect)
}
else if(this->m_Switch)
{
std::shared_ptr<CLayerSwitch> pGrabbed = std::make_shared<CLayerSwitch>(r.w, r.h);
std::shared_ptr<CLayerSwitch> pGrabbed = std::make_shared<CLayerSwitch>(m_pEditor, r.w, r.h);
InitGrabbedLayer(pGrabbed, this);
pBrush->AddLayer(pGrabbed);
@ -356,7 +359,7 @@ int CLayerTiles::BrushGrab(std::shared_ptr<CLayerGroup> pBrush, CUIRect Rect)
else if(this->m_Tune)
{
std::shared_ptr<CLayerTune> pGrabbed = std::make_shared<CLayerTune>(r.w, r.h);
std::shared_ptr<CLayerTune> pGrabbed = std::make_shared<CLayerTune>(m_pEditor, r.w, r.h);
InitGrabbedLayer(pGrabbed, this);
pBrush->AddLayer(pGrabbed);
@ -382,7 +385,7 @@ int CLayerTiles::BrushGrab(std::shared_ptr<CLayerGroup> pBrush, CUIRect Rect)
}
else if(this->m_Front)
{
std::shared_ptr<CLayerFront> pGrabbed = std::make_shared<CLayerFront>(r.w, r.h);
std::shared_ptr<CLayerFront> pGrabbed = std::make_shared<CLayerFront>(m_pEditor, r.w, r.h);
InitGrabbedLayer(pGrabbed, this);
pBrush->AddLayer(pGrabbed);
@ -395,7 +398,7 @@ int CLayerTiles::BrushGrab(std::shared_ptr<CLayerGroup> pBrush, CUIRect Rect)
}
else
{
std::shared_ptr<CLayerTiles> pGrabbed = std::make_shared<CLayerFront>(r.w, r.h);
std::shared_ptr<CLayerTiles> pGrabbed = std::make_shared<CLayerFront>(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<CLayer> pLayer = std::make_shared<CLayerTele>(m_Width, m_Height);
std::shared_ptr<CLayer> pLayer = std::make_shared<CLayerTele>(m_pEditor, m_Width, m_Height);
m_pEditor->m_Map.MakeTeleLayer(pLayer);
m_pEditor->m_Map.m_pGameGroup->AddLayer(pLayer);
}

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(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<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,7 +1,9 @@
#include "layer_tune.h"
#include <game/editor/editor.h>
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;

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

@ -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<CLayerQuads> pLayer = std::make_shared<CLayerQuads>();
pLayer->m_pEditor = m_pEditor;
std::shared_ptr<CLayerQuads> pLayer = std::make_shared<CLayerQuads>(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<CLayerGame>(50, 50));
MakeGameLayer(std::make_shared<CLayerGame>(m_pEditor, 50, 50));
m_pGameGroup->AddLayer(m_pGameLayer);
m_pFrontLayer = nullptr;

View file

@ -640,7 +640,7 @@ bool CEditorMap::Load(const char *pFileName, int StorageType, const std::functio
std::shared_ptr<CLayerTiles> pTiles;
if(pTilemapItem->m_Flags & TILESLAYERFLAG_GAME)
{
pTiles = std::make_shared<CLayerGame>(pTilemapItem->m_Width, pTilemapItem->m_Height);
pTiles = std::make_shared<CLayerGame>(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<CLayerTele>(pTilemapItem->m_Width, pTilemapItem->m_Height);
pTiles = std::make_shared<CLayerTele>(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<CLayerSpeedup>(pTilemapItem->m_Width, pTilemapItem->m_Height);
pTiles = std::make_shared<CLayerSpeedup>(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<CLayerFront>(pTilemapItem->m_Width, pTilemapItem->m_Height);
pTiles = std::make_shared<CLayerFront>(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<CLayerSwitch>(pTilemapItem->m_Width, pTilemapItem->m_Height);
pTiles = std::make_shared<CLayerSwitch>(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<CLayerTune>(pTilemapItem->m_Width, pTilemapItem->m_Height);
pTiles = std::make_shared<CLayerTune>(m_pEditor, pTilemapItem->m_Width, pTilemapItem->m_Height);
MakeTuneLayer(pTiles);
}
else
{
pTiles = std::make_shared<CLayerTiles>(pTilemapItem->m_Width, pTilemapItem->m_Height);
pTiles = std::make_shared<CLayerTiles>(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<CLayerQuads> pQuads = std::make_shared<CLayerQuads>();
pQuads->m_pEditor = m_pEditor;
std::shared_ptr<CLayerQuads> pQuads = std::make_shared<CLayerQuads>(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<CLayerSounds> pSounds = std::make_shared<CLayerSounds>();
pSounds->m_pEditor = m_pEditor;
std::shared_ptr<CLayerSounds> pSounds = std::make_shared<CLayerSounds>(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<CLayerSounds> pSounds = std::make_shared<CLayerSounds>();
pSounds->m_pEditor = m_pEditor;
std::shared_ptr<CLayerSounds> pSounds = std::make_shared<CLayerSounds>(m_pEditor);
pSounds->m_Flags = pLayerItem->m_Flags;
pSounds->m_Sound = pSoundsItem->m_Sound;

View file

@ -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<CLayer> pTeleLayer = std::make_shared<CLayerTele>(pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height);
std::shared_ptr<CLayer> pTeleLayer = std::make_shared<CLayerTele>(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<CLayer> pSpeedupLayer = std::make_shared<CLayerSpeedup>(pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height);
std::shared_ptr<CLayer> pSpeedupLayer = std::make_shared<CLayerSpeedup>(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<CLayer> pTuneLayer = std::make_shared<CLayerTune>(pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height);
std::shared_ptr<CLayer> pTuneLayer = std::make_shared<CLayerTune>(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<CLayer> pFrontLayer = std::make_shared<CLayerFront>(pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height);
std::shared_ptr<CLayer> pFrontLayer = std::make_shared<CLayerFront>(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<CLayer> pSwitchLayer = std::make_shared<CLayerSwitch>(pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height);
std::shared_ptr<CLayer> pSwitchLayer = std::make_shared<CLayerSwitch>(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<CLayer> pQuadLayer = std::make_shared<CLayerQuads>();
pQuadLayer->m_pEditor = pEditor;
std::shared_ptr<CLayer> pQuadLayer = std::make_shared<CLayerQuads>(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<CLayer> pTileLayer = std::make_shared<CLayerTiles>(pEditor->m_Map.m_pGameLayer->m_Width, pEditor->m_Map.m_pGameLayer->m_Height);
std::shared_ptr<CLayer> pTileLayer = std::make_shared<CLayerTiles>(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<CLayer> pSoundLayer = std::make_shared<CLayerSounds>();
pSoundLayer->m_pEditor = pEditor;
std::shared_ptr<CLayer> pSoundLayer = std::make_shared<CLayerSounds>(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;

View file

@ -167,9 +167,8 @@ static std::shared_ptr<CLayerTiles> AddLayerWithImage(CEditor *pEditor, const st
std::shared_ptr<CEditorImage> pEditorImage = ImageInfoToEditorImage(pEditor, Image, pName);
pEditor->m_Map.m_vpImages.push_back(pEditorImage);
std::shared_ptr<CLayerTiles> pLayer = std::make_shared<CLayerTiles>(Width, Height);
std::shared_ptr<CLayerTiles> pLayer = std::make_shared<CLayerTiles>(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);