Separates out the tile map into it's own class
Refactors some file names and locations (igraphics.h -> graphics.h, types.h/cpp moved to core)Gui_Panel_Refactor
parent
7e6f2907f2
commit
f4e5de912d
@ -1,8 +1,9 @@
|
|||||||
add_library(utils stb/stb_image_write.cpp stb/stb_image.cpp args.cpp binaryFileBuffer.cpp frameCounter.cpp
|
add_library(utils stb/stb_image_write.cpp stb/stb_image.cpp args.cpp binaryFileBuffer.cpp frameCounter.cpp
|
||||||
helpers.cpp highResTimer.cpp logger.cpp opRes.cpp types.cpp)
|
helpers.cpp highResTimer.cpp logger.cpp opRes.cpp)
|
||||||
|
|
||||||
target_include_directories(utils
|
target_include_directories(utils
|
||||||
PUBLIC "${PROJECT_BINARY_DIR}"
|
PUBLIC "${PROJECT_BINARY_DIR}"
|
||||||
|
PUBLIC ../../
|
||||||
PUBLIC ../../../external/glm
|
PUBLIC ../../../external/glm
|
||||||
PUBLIC ../../../external/box2d/include
|
PUBLIC ../../../external/box2d/include
|
||||||
)
|
)
|
||||||
|
|||||||
@ -0,0 +1,113 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* File - map_canvas.cpp
|
||||||
|
* Author - Joey Pollack
|
||||||
|
* Date - 2022/02/14 (y/m/d)
|
||||||
|
* Mod Date - 2022/02/14 (y/m/d)
|
||||||
|
* Description - the canvas panel for painting map tiles
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "map_canvas.h"
|
||||||
|
#include "../map_editor.h"
|
||||||
|
#include <gui/dearimgui/imgui.h>
|
||||||
|
#include <core/core.h>
|
||||||
|
#include <graphics/graphics.h>
|
||||||
|
#include <assets/types/image.h>
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
|
namespace lunarium { namespace editor
|
||||||
|
{
|
||||||
|
MapCanvas::MapCanvas(MapEditor* editor)
|
||||||
|
: Panel(gui::PanelType::PT_MAP_CANVAS, "Map Canvas", gui::PanelDockZone::DDZ_CENTER, true),
|
||||||
|
mpMapEditor(editor), mpCanvasImage(nullptr), mMap(nullptr), mSelectedTile({-1, -1})
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapCanvas::Update(float delta)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool MapCanvas::DoFrame()
|
||||||
|
{
|
||||||
|
if (!mIsOpen)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!ImGui::Begin(GetName(), &mIsOpen))
|
||||||
|
{
|
||||||
|
ImGui::End();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ImVec2 pos = ImGui::GetWindowPos();
|
||||||
|
ImVec2 size = ImGui::GetWindowSize();
|
||||||
|
|
||||||
|
// Adjust for the tab bar
|
||||||
|
pos.y += ImGui::GetFrameHeight();
|
||||||
|
size.y -= ImGui::GetFrameHeight();
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
float x = io.MousePos.x - pos.x;
|
||||||
|
float y = io.MousePos.y - pos.y;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
std::ostringstream oss;
|
||||||
|
oss << "Mouse Position on Panel: ";
|
||||||
|
if (x < 0.0f || y < 0.0f || x > size.x || y > size.y)
|
||||||
|
{
|
||||||
|
oss << "OUTSIDE PANEL";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
oss << "(" << x << ", " << y << ")";
|
||||||
|
}
|
||||||
|
|
||||||
|
oss << "\nFrameHeight: " << ImGui::GetFrameHeight();
|
||||||
|
oss <<"\nFrameHeightWithSpacing: " << ImGui::GetFrameHeightWithSpacing();
|
||||||
|
mMouseStatusInfo = oss.str();
|
||||||
|
|
||||||
|
//ImGui::Text(mMouseStatusInfo.c_str());
|
||||||
|
if (mpCanvasImage)
|
||||||
|
{
|
||||||
|
ImGui::Image((ImTextureID)mpCanvasImage->GetGLTextureID64(), ImVec2(mpCanvasImage->GetWidth(), mpCanvasImage->GetHeight()));
|
||||||
|
}
|
||||||
|
|
||||||
|
ImGui::End();
|
||||||
|
return mIsOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapCanvas::Render(lunarium::IGraphics* g)
|
||||||
|
{
|
||||||
|
// Render tile map
|
||||||
|
mMap->Render(g);
|
||||||
|
|
||||||
|
// Render grid if it's turned on
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void MapCanvas::SetTileMap(TileMap* pMap)
|
||||||
|
{
|
||||||
|
mMap = pMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapCanvas::SetCanvasImage(Image* image)
|
||||||
|
{
|
||||||
|
mpCanvasImage = image;
|
||||||
|
}
|
||||||
|
|
||||||
|
void MapCanvas::SetSelectedTile(TileRef tile)
|
||||||
|
{
|
||||||
|
mSelectedTile = tile;
|
||||||
|
}
|
||||||
|
|
||||||
|
TileRef MapCanvas::GetSelectedTile() const
|
||||||
|
{
|
||||||
|
return mSelectedTile;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}}
|
||||||
@ -0,0 +1,49 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* File - map_canvas.h
|
||||||
|
* Author - Joey Pollack
|
||||||
|
* Date - 2022/02/14 (y/m/d)
|
||||||
|
* Mod Date - 2022/02/14 (y/m/d)
|
||||||
|
* Description - the canvas panel for painting map tiles
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef MAP_CANVAS_H_
|
||||||
|
#define MAP_CANVAS_H_
|
||||||
|
|
||||||
|
#include <gui/panel.h>
|
||||||
|
#include "../tile_map.h"
|
||||||
|
#include <core/types.h>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace lunarium { class Image; class IGraphics; }
|
||||||
|
|
||||||
|
namespace lunarium { namespace editor
|
||||||
|
{
|
||||||
|
class MapEditor;
|
||||||
|
|
||||||
|
class MapCanvas : public gui::Panel
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MapCanvas(MapEditor* editor);
|
||||||
|
void Update(float delta);
|
||||||
|
bool DoFrame();
|
||||||
|
void Render(lunarium::IGraphics* g);
|
||||||
|
|
||||||
|
void SetTileMap(TileMap* pMap);
|
||||||
|
void SetCanvasImage(Image* image);
|
||||||
|
|
||||||
|
void SetSelectedTile(TileRef tile);
|
||||||
|
TileRef GetSelectedTile() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
MapEditor* mpMapEditor;
|
||||||
|
std::string mMouseStatusInfo;
|
||||||
|
Image* mpCanvasImage;
|
||||||
|
TileMap* mMap;
|
||||||
|
TileRef mSelectedTile;
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
|
};
|
||||||
|
}}
|
||||||
|
|
||||||
|
#endif // MAP_CANVAS_H_
|
||||||
@ -0,0 +1,60 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* File - tile_map.h
|
||||||
|
* Author - Joey Pollack
|
||||||
|
* Date - 2022/02/15 (y/m/d)
|
||||||
|
* Mod Date - 2022/02/15 (y/m/d)
|
||||||
|
* Description - Contains a single tile map
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#include "tile_map.h"
|
||||||
|
#include <core/core.h>
|
||||||
|
#include <graphics/graphics.h>
|
||||||
|
|
||||||
|
namespace lunarium { namespace editor
|
||||||
|
{
|
||||||
|
void TileMap::ClearMap()
|
||||||
|
{
|
||||||
|
for(int i = 0; i < mSizeInTiles.Width; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < mSizeInTiles.Height; j++)
|
||||||
|
{
|
||||||
|
mpMap[i][j] = { -1, -1 };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void TileMap::ResizeMap(Sizei size)
|
||||||
|
{
|
||||||
|
TileRef** new_map = new TileRef*[size.Width];
|
||||||
|
for(int i = 0; i < size.Width; i++)
|
||||||
|
{
|
||||||
|
new_map[i] = new TileRef[size.Height];
|
||||||
|
}
|
||||||
|
|
||||||
|
int smaller_width = mSizeInTiles.Width < size.Width ? mSizeInTiles.Width : size.Width;
|
||||||
|
int smaller_height = mSizeInTiles.Height < size.Height ? mSizeInTiles.Height : size.Height;
|
||||||
|
|
||||||
|
for(int i = 0; i < smaller_width; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < smaller_height; j++)
|
||||||
|
{
|
||||||
|
new_map[i][j] = mpMap[i][j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i = 0; i < mSizeInTiles.Width; i++)
|
||||||
|
{
|
||||||
|
delete[] mpMap[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
delete[] mpMap;
|
||||||
|
mSizeInTiles = size;
|
||||||
|
mpMap = new_map;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void TileMap::Render(lunarium::IGraphics* g)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}}
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
/******************************************************************************
|
||||||
|
* File - tile_map.h
|
||||||
|
* Author - Joey Pollack
|
||||||
|
* Date - 2022/02/15 (y/m/d)
|
||||||
|
* Mod Date - 2022/02/15 (y/m/d)
|
||||||
|
* Description - Contains a single tile map
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
#ifndef TILE_MAP_H_
|
||||||
|
#define TILE_MAP_H_
|
||||||
|
|
||||||
|
#include <core/types.h>
|
||||||
|
|
||||||
|
namespace lunarium { class IGraphics; }
|
||||||
|
|
||||||
|
namespace lunarium { namespace editor
|
||||||
|
{
|
||||||
|
// Allows tiles from multiple tilesets to be used in one map
|
||||||
|
// A tile ID of -1 will mean "no tile" and result in a transparent spot
|
||||||
|
// when rendered
|
||||||
|
struct TileRef
|
||||||
|
{
|
||||||
|
int TileSetID;
|
||||||
|
int TileID;
|
||||||
|
};
|
||||||
|
|
||||||
|
class TileMap
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void SetTile(TileRef, Vec2i location);
|
||||||
|
TileRef GetTile(Vec2i location);
|
||||||
|
|
||||||
|
void ClearMap();
|
||||||
|
void ResizeMap(Sizei size);
|
||||||
|
|
||||||
|
// Call during render to texture phase
|
||||||
|
void Render(lunarium::IGraphics* g);
|
||||||
|
|
||||||
|
private:
|
||||||
|
TileRef** mpMap;
|
||||||
|
Sizei mSizeInTiles;
|
||||||
|
|
||||||
|
};
|
||||||
|
}}
|
||||||
|
|
||||||
|
#endif // TILE_MAP_H_
|
||||||
Loading…
Reference in New Issue