Made tilemap inspector lok good
This commit is contained in:
parent
fbb0574b81
commit
e8e93db51f
39
imgui.ini
39
imgui.ini
@ -10,41 +10,40 @@ Collapsed=1
|
||||
|
||||
[Window][WindowOverViewport_11111111]
|
||||
Pos=0,19
|
||||
Size=1280,701
|
||||
Size=1920,1158
|
||||
Collapsed=0
|
||||
|
||||
[Window][Inspector]
|
||||
Pos=900,19
|
||||
Size=380,701
|
||||
Pos=1573,19
|
||||
Size=347,1158
|
||||
Collapsed=0
|
||||
DockId=0x00000006,0
|
||||
|
||||
[Window][Scene Tree]
|
||||
Pos=0,19
|
||||
Size=342,348
|
||||
Size=342,575
|
||||
Collapsed=0
|
||||
DockId=0x00000003,0
|
||||
|
||||
[Window][Viewport]
|
||||
Pos=344,19
|
||||
Size=554,390
|
||||
Size=1227,847
|
||||
Collapsed=0
|
||||
DockId=0x00000007,0
|
||||
|
||||
[Window][##MainMenuBar]
|
||||
Pos=0,0
|
||||
Size=1280,19
|
||||
Collapsed=0
|
||||
|
||||
[Window][Performance Info]
|
||||
Pos=344,411
|
||||
Size=554,309
|
||||
Pos=344,868
|
||||
Size=1227,309
|
||||
Collapsed=0
|
||||
DockId=0x00000008,3
|
||||
|
||||
[Window][Console]
|
||||
Pos=344,411
|
||||
Size=554,309
|
||||
Pos=344,868
|
||||
Size=1227,309
|
||||
Collapsed=0
|
||||
DockId=0x00000008,0
|
||||
|
||||
@ -55,8 +54,8 @@ Collapsed=0
|
||||
DockId=0x00000007,1
|
||||
|
||||
[Window][Profiler]
|
||||
Pos=344,411
|
||||
Size=554,309
|
||||
Pos=344,868
|
||||
Size=1227,309
|
||||
Collapsed=0
|
||||
DockId=0x00000008,2
|
||||
|
||||
@ -79,25 +78,25 @@ Collapsed=0
|
||||
DockId=0x00000008,1
|
||||
|
||||
[Window][Color Correction]
|
||||
Pos=344,411
|
||||
Size=554,309
|
||||
Pos=344,868
|
||||
Size=1227,309
|
||||
Collapsed=0
|
||||
DockId=0x00000008,1
|
||||
|
||||
[Window][Asset Browser]
|
||||
Pos=0,369
|
||||
Size=342,351
|
||||
Pos=0,596
|
||||
Size=342,581
|
||||
Collapsed=0
|
||||
DockId=0x00000004,0
|
||||
|
||||
[Docking][Data]
|
||||
DockSpace ID=0x11111111 Window=0x1BBC0F80 Pos=0,19 Size=1280,701 Split=X
|
||||
DockNode ID=0x00000005 Parent=0x11111111 SizeRef=1538,1158 Split=X
|
||||
DockSpace ID=0x11111111 Window=0x1BBC0F80 Pos=0,19 Size=1920,1158 Split=X
|
||||
DockNode ID=0x00000005 Parent=0x11111111 SizeRef=1571,1158 Split=X
|
||||
DockNode ID=0x00000001 Parent=0x00000005 SizeRef=342,701 Split=Y Selected=0x12EF0F59
|
||||
DockNode ID=0x00000003 Parent=0x00000001 SizeRef=342,575 HiddenTabBar=1 Selected=0x12EF0F59
|
||||
DockNode ID=0x00000004 Parent=0x00000001 SizeRef=342,581 HiddenTabBar=1 Selected=0x36AF052B
|
||||
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1194,701 Split=Y Selected=0xC450F867
|
||||
DockNode ID=0x00000002 Parent=0x00000005 SizeRef=1227,701 Split=Y Selected=0xC450F867
|
||||
DockNode ID=0x00000007 Parent=0x00000002 SizeRef=606,847 CentralNode=1 HiddenTabBar=1 Selected=0xC450F867
|
||||
DockNode ID=0x00000008 Parent=0x00000002 SizeRef=606,309 Selected=0x9B5D3198
|
||||
DockNode ID=0x00000006 Parent=0x11111111 SizeRef=380,1158 HiddenTabBar=1 Selected=0x36DC96AB
|
||||
DockNode ID=0x00000006 Parent=0x11111111 SizeRef=347,1158 HiddenTabBar=1 Selected=0x36DC96AB
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
[COMPILE] g++ -std=c++20 -Wall -g -Isrc/include -Isrc/include/lua -Isrc/vendor -Isrc/vendor/imgui -Isrc/vendor/box2d -IC:/msys64/mingw64/include -IC:\msys64\mingw64\lib\libyaml-cpp.a -Isrc\vendor\imgui -MMD -MP -c src\src\editor\windows\Inspector.cpp -o src\build\editor\windows\Inspector.o
|
||||
[LINK] g++ src\build\Engine.o src\build\main.o src\build\Renderer.o src\build\Components\AnimationComponent.o src\build\Components\CameraComponent.o src\build\Components\LightComponent.o src\build\Components\ParticleComponent.o src\build\Components\PhysicsComponent.o src\build\Components\ScriptComponent.o src\build\Components\SpriteComponent.o src\build\Components\TextComonent.o src\build\Components\TilemapComponent.o src\build\core\utils\AssetManager.o src\build\core\utils\EngineConfig.o src\build\core\utils\ExceptionHandler.o src\build\core\utils\FileDialog.o src\build\core\utils\input.o src\build\core\utils\LoadingWindow.o src\build\core\utils\Logging.o src\build\core\utils\Profiler.o src\build\core\utils\Texture.o src\build\core\utils\utils.o src\build\editor\windows\AssetBrowser.o src\build\editor\windows\Inspector.o src\build\Entitys\Object.o src\build\utils\GameObjectsList.o src\build\utils\Shader.o src\build\utils\UID.o src\build\lapi.o src\build\lauxlib.o src\build\lbaselib.o src\build\lcode.o src\build\lcorolib.o src\build\lctype.o src\build\ldblib.o src\build\ldebug.o src\build\ldo.o src\build\ldump.o src\build\lfunc.o src\build\lgc.o src\build\linit.o src\build\liolib.o src\build\llex.o src\build\lmathlib.o src\build\lmem.o src\build\loadlib.o src\build\lobject.o src\build\lopcodes.o src\build\loslib.o src\build\lparser.o src\build\lstate.o src\build\lstring.o src\build\lstrlib.o src\build\ltable.o src\build\ltablib.o src\build\ltm.o src\build\lua.o src\build\luac.o src\build\lundump.o src\build\lutf8lib.o src\build\lvm.o src\build\lzio.o src\build\imgui.o src\build\imgui_demo.o src\build\imgui_draw.o src\build\imgui_impl_glfw.o src\build\imgui_impl_opengl3.o src\build\imgui_tables.o src\build\imgui_widgets.o src\build\aabb.o src\build\arena_allocator.o src\build\array.o src\build\bitset.o src\build\body.o src\build\broad_phase.o src\build\constraint_graph.o src\build\contact.o src\build\contact_solver.o src\build\core.o src\build\distance.o src\build\distance_joint.o src\build\dynamic_tree.o src\build\geometry.o src\build\hull.o src\build\id_pool.o src\build\island.o src\build\joint.o src\build\manifold.o src\build\math_functions.o src\build\motor_joint.o src\build\mouse_joint.o src\build\mover.o src\build\prismatic_joint.o src\build\revolute_joint.o src\build\sensor.o src\build\shape.o src\build\solver.o src\build\solver_set.o src\build\table.o src\build\timer.o src\build\types.o src\build\weld_joint.o src\build\wheel_joint.o src\build\world.o -o src\build\app.exe -LC:\msys64\mingw64\lib -lglfw3 -lglew32 -lopengl32 -lgdi32 -lyaml-cpp -lcomdlg32 -lssl -lcrypto
|
||||
[ERROR] Runtime crash
|
||||
Command 'src\build\app.exe' returned non-zero exit status 1.
|
||||
[RUN] Executed app.exe successfully.
|
||||
|
@ -1,27 +1,33 @@
|
||||
engine_version: 0.1.0
|
||||
scene_name: New Text Document
|
||||
scene_hash: ab18a816340bea7fd8b460cde813cb5277bc2a67ca413862f648cf030c93a85f
|
||||
scene_name: TilemapTest
|
||||
scene_hash: da1e2dee8a989a2dc8390342cf9c900f4de6ad42a54b5f9250189f01645bbf27
|
||||
format_version: 1
|
||||
objects:
|
||||
- name: TilemapTest
|
||||
uid: 4afa4d0c474b4fb9b9b80eb1bb31195a
|
||||
- name: Hello, Create
|
||||
uid: ef684c7c34b34d81a41d052066bc806c
|
||||
id: 0
|
||||
position: [0, 0]
|
||||
rotation: 0
|
||||
layer: 0
|
||||
visable: true
|
||||
components:
|
||||
- Type: TilemapComponent
|
||||
- type: TilemapComponent
|
||||
TextureUAID: 1
|
||||
TexelWidth: 1
|
||||
TexelHeight: 1
|
||||
TexelWidth: 16
|
||||
TexelHeight: 16
|
||||
TileSize:
|
||||
x: 32
|
||||
y: 32
|
||||
Tiles:
|
||||
- [6, 1, 15]
|
||||
- [6, 2, 14]
|
||||
- [0, 0, 1]
|
||||
- [6, 0, 16]
|
||||
- [4, 3, 11]
|
||||
- [1, 0, 2]
|
||||
- [5, 3, 12]
|
||||
- [2, 0, 3]
|
||||
- [6, 3, 13]
|
||||
- [0, 1, 4]
|
||||
- [1, 1, 5]
|
||||
- [2, 1, 6]
|
||||
@ -29,19 +35,13 @@ objects:
|
||||
- [1, 2, 8]
|
||||
- [2, 2, 9]
|
||||
- [3, 3, 10]
|
||||
- [4, 3, 11]
|
||||
- [5, 3, 12]
|
||||
- [6, 3, 13]
|
||||
- [6, 2, 14]
|
||||
- [6, 1, 15]
|
||||
- [6, 0, 16]
|
||||
children: []
|
||||
color_correction:
|
||||
brightness: 1
|
||||
saturation: 1
|
||||
gamma: 1
|
||||
bloom: true
|
||||
intensity: 1.2
|
||||
intensity: 1.20000005
|
||||
threshold: 1
|
||||
Assets:
|
||||
- uaid: 1
|
||||
@ -49,4 +49,4 @@ Assets:
|
||||
filename: 6656e7221e49a1774d2fb280357e56f8d25d9d95.png
|
||||
filetype: png
|
||||
type: 0
|
||||
size: [1024, 1024]
|
||||
size: [1024, 1024]
|
@ -1,6 +1,6 @@
|
||||
#include "TilemapComponent.h"
|
||||
#include "../Renderer.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
TilemapComponent::TilemapComponent(Object* owner)
|
||||
: Component(owner)
|
||||
@ -75,7 +75,7 @@ const std::unordered_map<uint64_t, int>& TilemapComponent::GetTileData() const {
|
||||
void TilemapComponent::Save(YAML::Emitter& out) const
|
||||
{
|
||||
out << YAML::BeginMap;
|
||||
out << YAML::Key << "Type" << YAML::Value << GetName();
|
||||
out << YAML::Key << "type" << YAML::Value << GetName();
|
||||
out << YAML::Key << "TextureUAID" << YAML::Value << textureUAID;
|
||||
out << YAML::Key << "TexelWidth" << YAML::Value << atlas.GetTexelSize().x;
|
||||
out << YAML::Key << "TexelHeight" << YAML::Value << atlas.GetTexelSize().y;
|
||||
|
@ -1204,6 +1204,7 @@ void Engine::LoadScene(const std::string &path)
|
||||
loadingUI.Update(currentStep, currentDetail, 0.05f);
|
||||
|
||||
Logger::LogVerbose("[LoadScene] Loading Assets");
|
||||
AssetManager::ClearAllAssets();
|
||||
AssetManager::Load(root["Assets"]);
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,6 @@
|
||||
#include "../Components/ParticleComponent.h"
|
||||
#include "../Components/AnimationComponent.h"
|
||||
|
||||
|
||||
|
||||
#include "../core/utils/Logging.h"
|
||||
#include "../utils/UID.h"
|
||||
|
||||
@ -54,7 +52,6 @@ void Object::SetLocalPosition(glm::vec2 pos)
|
||||
localPosition = pos;
|
||||
}
|
||||
|
||||
|
||||
glm::vec2 Object::GetWorldPosition() const
|
||||
{
|
||||
if (parent)
|
||||
@ -66,7 +63,6 @@ glm::vec2 Object::GetWorldPosition() const
|
||||
return localPosition;
|
||||
}
|
||||
|
||||
|
||||
float Object::GetLocalRotation() const
|
||||
{
|
||||
return localRotationDeg;
|
||||
@ -142,26 +138,42 @@ void Object::Load(const YAML::Node &node)
|
||||
layer = node["layer"] ? node["layer"].as<int>() : 0;
|
||||
visable = node["visable"] ? node["visable"].as<bool>() : true;
|
||||
|
||||
Logger::LogVerbose("[LoadScene] Loading Object: [%s, %d]", name.c_str(), uid.id);
|
||||
Logger::LogVerbose("[LoadScene] Loading Object: ['%s', %d]", name.c_str(), uid.id);
|
||||
|
||||
components.clear();
|
||||
if (node["components"])
|
||||
{
|
||||
for (const auto &compNode : node["components"])
|
||||
{
|
||||
std::string type = compNode["type"].as<std::string>();
|
||||
|
||||
if (type == "SpriteComponent") AddComponent<SpriteComponent>()->Load(compNode);
|
||||
else if (type == "CameraComponent") AddComponent<CameraComponent>()->Load(compNode);
|
||||
else if (type == "LightComponent") AddComponent<LightComponent>()->Load(compNode);
|
||||
else if (type == "TilemapComponent") AddComponent<TilemapComponent>()->Load(compNode);
|
||||
else if (type == "TextComponent") AddComponent<TextComponent>()->Load(compNode);
|
||||
else if (type == "ScriptComponent") AddComponent<ScriptComponent>()->Load(compNode);
|
||||
else if (type == "ParticleComponent") AddComponent<ParticleComponent>()->Load(compNode);
|
||||
else if (type == "AnimationComponent") AddComponent<AnimationComponent>()->Load(compNode);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
std::string type = compNode["type"].as<std::string>();
|
||||
|
||||
if (type == "SpriteComponent")
|
||||
AddComponent<SpriteComponent>()->Load(compNode);
|
||||
else if (type == "CameraComponent")
|
||||
AddComponent<CameraComponent>()->Load(compNode);
|
||||
else if (type == "LightComponent")
|
||||
AddComponent<LightComponent>()->Load(compNode);
|
||||
else if (type == "TilemapComponent")
|
||||
AddComponent<TilemapComponent>()->Load(compNode);
|
||||
else if (type == "TextComponent")
|
||||
AddComponent<TextComponent>()->Load(compNode);
|
||||
else if (type == "ScriptComponent")
|
||||
AddComponent<ScriptComponent>()->Load(compNode);
|
||||
else if (type == "ParticleComponent")
|
||||
AddComponent<ParticleComponent>()->Load(compNode);
|
||||
else if (type == "AnimationComponent")
|
||||
AddComponent<AnimationComponent>()->Load(compNode);
|
||||
else
|
||||
{
|
||||
Logger::LogError("Invalid Componenet type '%s' found in component '%s'(%d)", type.c_str(), name.c_str(), uid.id);
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
{
|
||||
Logger::LogError("Failed to load '%s' (ID: %d). %s", name.c_str(), uid.id, e.what());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,7 +147,7 @@ void DrawInspectorUI(std::shared_ptr<Object> selected)
|
||||
{
|
||||
auto path = OpenFileDialog(FileDialogType::Images);
|
||||
if (!path.empty())
|
||||
sprite->SetTexture(path); // Auto-registers and sets UAID
|
||||
sprite->SetTexture(path);
|
||||
}
|
||||
}
|
||||
|
||||
@ -424,20 +424,19 @@ void DrawInspectorUI(std::shared_ptr<Object> selected)
|
||||
{
|
||||
ImGui::SeparatorText("Tilemap Component");
|
||||
|
||||
static int texelWidth = (int)tilemap->GetAtlas().GetTexelSize().x;
|
||||
static int texelHeight = (int)tilemap->GetAtlas().GetTexelSize().y;
|
||||
static core::types::Vec2 tileSize = tilemap->GetTileSize();
|
||||
int texelWidth = (int)tilemap->GetTileSize().x;
|
||||
int texelHeight = (int)tilemap->GetTileSize().y;
|
||||
core::types::Vec2 tileSize = tilemap->GetTileSize();
|
||||
|
||||
uint64_t uaid = tilemap->GetTextureUAID();
|
||||
const auto *asset = AssetManager::GetAssetByID(uaid);
|
||||
|
||||
ImGui::SeparatorText("Texture Atlas");
|
||||
|
||||
// --- Atlas file name or (None) ---
|
||||
std::string texFile = asset ? GetFilenameFromPath(asset->path) : "(None)";
|
||||
ImGui::Text("%s", texFile.c_str());
|
||||
|
||||
// --- Drag and Drop Target ---
|
||||
// Drag and drop texture
|
||||
if (ImGui::BeginDragDropTarget())
|
||||
{
|
||||
if (const ImGuiPayload *payload = ImGui::AcceptDragDropPayload("ASSET_TEXTURE"))
|
||||
@ -451,7 +450,7 @@ void DrawInspectorUI(std::shared_ptr<Object> selected)
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
|
||||
// --- Load via file dialog ---
|
||||
// Load from dialog
|
||||
if (ImGui::SmallButton("Load##TilemapTex"))
|
||||
{
|
||||
std::string path = OpenFileDialog(FileDialogType::Images);
|
||||
@ -459,24 +458,116 @@ void DrawInspectorUI(std::shared_ptr<Object> selected)
|
||||
tilemap->SetTextureAtlas(loaded->uaid, texelWidth, texelHeight);
|
||||
}
|
||||
|
||||
|
||||
// --- Tile Size ---
|
||||
if (ImGui::DragFloat2("Tile Size", &tileSize.x, 1.0f, 1.0f, 512.0f))
|
||||
tilemap->SetTileSize(tileSize);
|
||||
|
||||
// --- Apply changes to atlas ---
|
||||
// Re-apply
|
||||
if (ImGui::Button("Apply"))
|
||||
{
|
||||
if (const auto *texAsset = AssetManager::GetAssetByID(tilemap->GetTextureUAID()))
|
||||
tilemap->SetTextureAtlas(texAsset->uaid, texelWidth, texelHeight);
|
||||
}
|
||||
|
||||
// --- Atlas Preview ---
|
||||
if (tilemap->GetTexture() && tilemap->GetTexture())
|
||||
// Atlas preview and grid
|
||||
if (tilemap->GetTexture())
|
||||
{
|
||||
float previewSize = ImGui::GetContentRegionAvail().x;
|
||||
ImGui::SeparatorText("Atlas Preview");
|
||||
ImGui::Image((ImTextureID)(uintptr_t)tilemap->GetTexture()->GetID(), ImVec2(previewSize, previewSize));
|
||||
|
||||
auto texture = tilemap->GetTexture();
|
||||
ImTextureID texID = (ImTextureID)(uintptr_t)texture->GetID();
|
||||
|
||||
int texWidth = (int)texture->GetSize().x;
|
||||
int texHeight = (int)texture->GetSize().y;
|
||||
|
||||
// Validate texel size
|
||||
if (texelWidth <= 0 || texelHeight <= 0)
|
||||
{
|
||||
ImGui::TextColored(ImVec4(1, 0.4f, 0.4f, 1), "Invalid texel size (must be >= 1)");
|
||||
ImGui::Separator();
|
||||
}
|
||||
|
||||
int numCols = texWidth / texelWidth;
|
||||
int numRows = texHeight / texelHeight;
|
||||
|
||||
if (numCols == 0 || numRows == 0)
|
||||
{
|
||||
ImGui::TextColored(ImVec4(1, 0.4f, 0.4f, 1), "Texel size too large for atlas resolution.");
|
||||
ImGui::Separator();
|
||||
}
|
||||
|
||||
// Maintain aspect ratio
|
||||
float previewSize = ImGui::GetContentRegionAvail().x;
|
||||
float aspect = texHeight / (float)texWidth;
|
||||
ImVec2 imageSize = ImVec2(previewSize, previewSize * aspect);
|
||||
ImVec2 imagePos = ImGui::GetCursorScreenPos();
|
||||
|
||||
ImGui::Image(texID, imageSize);
|
||||
|
||||
// Grid scale (tile-to-preview size)
|
||||
float scaleX = imageSize.x / (float)texWidth;
|
||||
float scaleY = imageSize.y / (float)texHeight;
|
||||
float cellW = texelWidth * scaleX;
|
||||
float cellH = texelHeight * scaleY;
|
||||
|
||||
ImDrawList *drawList = ImGui::GetWindowDrawList();
|
||||
const ImU32 gridColor = IM_COL32(255, 255, 255, 48);
|
||||
int linesDrawn = 0;
|
||||
|
||||
// Vertical lines
|
||||
for (int col = 0; col <= numCols; ++col)
|
||||
{
|
||||
float x = imagePos.x + col * cellW;
|
||||
if (x > imagePos.x + imageSize.x)
|
||||
break;
|
||||
drawList->AddLine(ImVec2(x, imagePos.y), ImVec2(x, imagePos.y + imageSize.y), gridColor);
|
||||
linesDrawn++;
|
||||
}
|
||||
|
||||
// Horizontal lines
|
||||
for (int row = 0; row <= numRows; ++row)
|
||||
{
|
||||
float y = imagePos.y + row * cellH;
|
||||
if (y > imagePos.y + imageSize.y)
|
||||
break;
|
||||
drawList->AddLine(ImVec2(imagePos.x, y), ImVec2(imagePos.x + imageSize.x, y), gridColor);
|
||||
linesDrawn++;
|
||||
}
|
||||
|
||||
// --- Highlight tile under mouse ---
|
||||
ImVec2 mousePos = ImGui::GetMousePos();
|
||||
bool mouseOver = ImGui::IsItemHovered();
|
||||
|
||||
if (mouseOver)
|
||||
{
|
||||
// Convert mouse position to tile coordinates
|
||||
float localX = mousePos.x - imagePos.x;
|
||||
float localY = mousePos.y - imagePos.y;
|
||||
|
||||
int tileX = (int)(localX / cellW);
|
||||
int tileY = (int)(localY / cellH);
|
||||
|
||||
if (tileX >= 0 && tileX < numCols && tileY >= 0 && tileY < numRows)
|
||||
{
|
||||
float highlightX = imagePos.x + tileX * cellW;
|
||||
float highlightY = imagePos.y + tileY * cellH;
|
||||
|
||||
ImVec2 min = ImVec2(highlightX, highlightY);
|
||||
ImVec2 max = ImVec2(highlightX + cellW, highlightY + cellH);
|
||||
|
||||
const ImU32 glowColor = IM_COL32(255, 255, 0, 64); // translucent yellow
|
||||
drawList->AddRectFilled(min, max, glowColor, 2.0f);
|
||||
|
||||
// Optional: Outline
|
||||
drawList->AddRect(min, max, IM_COL32(255, 255, 0, 128), 2.0f);
|
||||
|
||||
ImGui::Text("Hovered Tile: (%d, %d)", tileX, tileY);
|
||||
}
|
||||
}
|
||||
|
||||
// Debug
|
||||
ImGui::Text("Atlas Resolution: %d x %d", texWidth, texHeight);
|
||||
ImGui::Text("Tile Grid: %d x %d", numCols, numRows);
|
||||
ImGui::Text("Grid Lines: %d", linesDrawn);
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
Loading…
Reference in New Issue
Block a user