|
|
|
@ -8,7 +8,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
#include "tile_set_view.h"
|
|
|
|
#include "tile_set_view.h"
|
|
|
|
#include "../map_editor.h"
|
|
|
|
#include "../map_editor.h"
|
|
|
|
#include "../tile_set.h"
|
|
|
|
#include <editor/project/contents/tile_set.h>
|
|
|
|
#include <assets/types/image.h>
|
|
|
|
#include <assets/types/image.h>
|
|
|
|
#include <editor/editor.h>
|
|
|
|
#include <editor/editor.h>
|
|
|
|
#include <core/core.h>
|
|
|
|
#include <core/core.h>
|
|
|
|
@ -21,7 +21,7 @@ namespace lunarium { namespace editor
|
|
|
|
{
|
|
|
|
{
|
|
|
|
TileSetView::TileSetView(MapEditor* editor)
|
|
|
|
TileSetView::TileSetView(MapEditor* editor)
|
|
|
|
: Panel(gui::PanelType::PT_TILE_SET_VIEW, "Tile Set View", gui::PanelDockZone::DDZ_RIGHT, true),
|
|
|
|
: Panel(gui::PanelType::PT_TILE_SET_VIEW, "Tile Set View", gui::PanelDockZone::DDZ_RIGHT, true),
|
|
|
|
mpEditor(editor), mpTileSet(nullptr), mpViewImage(nullptr), mFrameBuffer(-1),
|
|
|
|
mpEditor(editor), mpSelectedTileSet(nullptr), mpViewImage(nullptr), mFrameBuffer(-1),
|
|
|
|
mViewOffset({0, 0}), mViewZoom(1.0f), mMouseDown(false)
|
|
|
|
mViewOffset({0, 0}), mViewZoom(1.0f), mMouseDown(false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
@ -47,7 +47,7 @@ namespace lunarium { namespace editor
|
|
|
|
// Check that it's within the window
|
|
|
|
// Check that it's within the window
|
|
|
|
bool is_in_window = x >= 0.0f && x < mWorkAreaSize.X && y >= 0.0f && y < mWorkAreaSize.Y;
|
|
|
|
bool is_in_window = x >= 0.0f && x < mWorkAreaSize.X && y >= 0.0f && y < mWorkAreaSize.Y;
|
|
|
|
|
|
|
|
|
|
|
|
if (is_in_window && mpTileSet)
|
|
|
|
if (is_in_window && mpSelectedTileSet)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Adjust for scrolling
|
|
|
|
// Adjust for scrolling
|
|
|
|
x += mScrollOffset.X;
|
|
|
|
x += mScrollOffset.X;
|
|
|
|
@ -56,8 +56,8 @@ namespace lunarium { namespace editor
|
|
|
|
//Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Mouse Pos scrolled (%f, %f)", x, y);
|
|
|
|
//Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Mouse Pos scrolled (%f, %f)", x, y);
|
|
|
|
|
|
|
|
|
|
|
|
// Find selected tile
|
|
|
|
// Find selected tile
|
|
|
|
mSelectedTile.X = x / mpTileSet->GetTileSize().Width;
|
|
|
|
mSelectedTile.X = x / mpSelectedTileSet->GetTileSize().Width;
|
|
|
|
mSelectedTile.Y = y / mpTileSet->GetTileSize().Height;
|
|
|
|
mSelectedTile.Y = y / mpSelectedTileSet->GetTileSize().Height;
|
|
|
|
|
|
|
|
|
|
|
|
//Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Updating Tile Selection: tile (%d, %d)", mSelectedTile.X, mSelectedTile.Y);
|
|
|
|
//Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Updating Tile Selection: tile (%d, %d)", mSelectedTile.X, mSelectedTile.Y);
|
|
|
|
|
|
|
|
|
|
|
|
@ -73,11 +73,11 @@ namespace lunarium { namespace editor
|
|
|
|
|
|
|
|
|
|
|
|
if (mInvalidate)
|
|
|
|
if (mInvalidate)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (mpTileSet)
|
|
|
|
if (mpSelectedTileSet)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (mFrameBuffer == -1)
|
|
|
|
if (mFrameBuffer == -1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mFrameBuffer = Core::Graphics().CreateRenderTexture(mpTileSet->GetImage()->GetWidth(), mpTileSet->GetImage()->GetHeight(), 4);
|
|
|
|
mFrameBuffer = Core::Graphics().CreateRenderTexture(mpSelectedTileSet->GetImage()->GetWidth(), mpSelectedTileSet->GetImage()->GetHeight(), 4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Invalidating tile set window");
|
|
|
|
//Logger::Log(Editor::LogCat, LogLevel::INFO_VERBOSE, "Invalidating tile set window");
|
|
|
|
@ -86,12 +86,12 @@ namespace lunarium { namespace editor
|
|
|
|
Core::Graphics().SetClearColor(Color::Transparent());
|
|
|
|
Core::Graphics().SetClearColor(Color::Transparent());
|
|
|
|
Core::GetInstance().BeginRenderToTexture(mFrameBuffer).LogIfFailed(Editor::LogCat);
|
|
|
|
Core::GetInstance().BeginRenderToTexture(mFrameBuffer).LogIfFailed(Editor::LogCat);
|
|
|
|
|
|
|
|
|
|
|
|
mpTileSet->Render(&Core::Graphics());
|
|
|
|
mpSelectedTileSet->Render(&Core::Graphics());
|
|
|
|
|
|
|
|
|
|
|
|
// Draw selected tile highlight
|
|
|
|
// Draw selected tile highlight
|
|
|
|
if (mSelectedTile.X >= 0 && mSelectedTile.Y >= 0)
|
|
|
|
if (mSelectedTile.X >= 0 && mSelectedTile.Y >= 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Rectangle selection = mpTileSet->GetTileRect(mSelectedTile);
|
|
|
|
Rectangle selection = mpSelectedTileSet->GetTileRect(mSelectedTile);
|
|
|
|
Core::Graphics().DrawBox(selection, Color::Red(), 1.5f);
|
|
|
|
Core::Graphics().DrawBox(selection, Color::Red(), 1.5f);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -126,12 +126,31 @@ namespace lunarium { namespace editor
|
|
|
|
|
|
|
|
|
|
|
|
float child_height = ImGui::GetFrameHeight() * 2;
|
|
|
|
float child_height = ImGui::GetFrameHeight() * 2;
|
|
|
|
ImGui::BeginChild(ImGui::GetID(GetName()), ImVec2(ImGui::GetWindowSize().x, child_height), true);
|
|
|
|
ImGui::BeginChild(ImGui::GetID(GetName()), ImVec2(ImGui::GetWindowSize().x, child_height), true);
|
|
|
|
ImGui::TextUnformatted("THIS IS SOME PLACEHOLDER TEXT -- ADD TOOLS HERE FOR SELECTING TILE SETS");
|
|
|
|
// ImGui::TextUnformatted("THIS IS SOME PLACEHOLDER TEXT -- ADD TOOLS HERE FOR SELECTING TILE SETS");
|
|
|
|
ImGui::EndChild();
|
|
|
|
std::string name = "";
|
|
|
|
|
|
|
|
if (mpSelectedTileSet)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
name = mpSelectedTileSet->GetFileLocation().filename().string();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (ImGui::BeginCombo("Tile Sets", name.c_str()))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
auto tile_sets = mpEditor->GetTileSets();
|
|
|
|
|
|
|
|
for (auto iter = tile_sets->begin(); iter != tile_sets->end(); iter++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bool selected = false;
|
|
|
|
|
|
|
|
if (ImGui::Selectable(iter->second->GetFileLocation().filename().string().c_str(), &selected))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ImGui::SetItemDefaultFocus();
|
|
|
|
|
|
|
|
mpSelectedTileSet = iter->second;
|
|
|
|
|
|
|
|
Invalidate();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImGui::EndCombo();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ImVec2 test = ImGui::GetWindowSize();
|
|
|
|
ImGui::EndChild();
|
|
|
|
test.y -= child_height;
|
|
|
|
|
|
|
|
//ImGui::BeginChild(ImGui::GetID(GetName()), ImVec2(ImGui::GetWindowSize().x, test.y));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mWorkAreaPos = { ImGui::GetWindowPos().x, ImGui::GetWindowPos().y };
|
|
|
|
mWorkAreaPos = { ImGui::GetWindowPos().x, ImGui::GetWindowPos().y };
|
|
|
|
mWorkAreaSize = { ImGui::GetWindowSize().x, ImGui::GetWindowSize().y };
|
|
|
|
mWorkAreaSize = { ImGui::GetWindowSize().x, ImGui::GetWindowSize().y };
|
|
|
|
@ -151,20 +170,19 @@ namespace lunarium { namespace editor
|
|
|
|
ImVec2(mpViewImage->GetWidth(), mpViewImage->GetHeight()), ImVec2(0, 1), ImVec2(1, 0)); // the last 2 params are flipping the image on the y
|
|
|
|
ImVec2(mpViewImage->GetWidth(), mpViewImage->GetHeight()), ImVec2(0, 1), ImVec2(1, 0)); // the last 2 params are flipping the image on the y
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//ImGui::EndChild();
|
|
|
|
|
|
|
|
ImGui::End();
|
|
|
|
ImGui::End();
|
|
|
|
return mIsOpen;
|
|
|
|
return mIsOpen;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TileSetView::SetTileSet(TileSet* set)
|
|
|
|
void TileSetView::SetTileSet(TileSet* set)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
mpTileSet = set;
|
|
|
|
mpSelectedTileSet = set;
|
|
|
|
Invalidate(true);
|
|
|
|
Invalidate(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
TileSet* TileSetView::GetTileSet()
|
|
|
|
TileSet* TileSetView::GetTileSet()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return mpTileSet;
|
|
|
|
return mpSelectedTileSet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|