puzzle ids
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
#include "bx/bx.h"
|
||||
#include "imgui.h"
|
||||
#include <cassert>
|
||||
#include <cstdio>
|
||||
|
||||
namespace
|
||||
{
|
||||
@@ -186,6 +187,11 @@ namespace Generated
|
||||
{
|
||||
constexpr float UIPuzBoxSize = 26;
|
||||
|
||||
void WritePuzzleFilePath(char* buf, int32_t bufSize, uint16_t puzID)
|
||||
{
|
||||
bx::snprintf(buf, bufSize, "%s/%u.pzl", Puzzle::PuzzleFileDir, puzID);
|
||||
}
|
||||
|
||||
const char* GetShortNodeName(const PuzzleNode& node)
|
||||
{
|
||||
PuzzleElementType::Enum elemMax = PuzzleElementType::None;
|
||||
@@ -203,7 +209,22 @@ namespace Generated
|
||||
bool isVisible = true;
|
||||
if (ImGui::Begin("Puzzle", &isVisible))
|
||||
{
|
||||
ImGui::Text("%s", obj.PuzzleName);
|
||||
if (ImGui::Button("Delete Puzzle"))
|
||||
{
|
||||
char filepath[128]{0};
|
||||
WritePuzzleFilePath(filepath, sizeof(filepath), obj.ID);
|
||||
remove(filepath);
|
||||
obj.ID = UINT16_MAX;
|
||||
ImGui::End();
|
||||
return false;
|
||||
}
|
||||
int32_t val = obj.ID;
|
||||
if (ImGui::InputInt("ID", &val))
|
||||
{
|
||||
obj.ID = val;
|
||||
dataChanged = true;
|
||||
}
|
||||
dataChanged = ImGui::InputText("Name", obj.PuzzleName, sizeof(obj.PuzzleName)) || dataChanged;
|
||||
|
||||
int32_t W = obj.WidthTiles;
|
||||
int32_t H = obj.HeightTiles;
|
||||
@@ -232,13 +253,31 @@ namespace Generated
|
||||
|
||||
for (int32_t y = 0; y < obj.HeightTiles; ++y)
|
||||
{
|
||||
ImGui::PushID(y);
|
||||
for (int32_t x = 0; x < obj.WidthTiles; ++x)
|
||||
{
|
||||
ImGui::PushID(x);
|
||||
PuzzleNode& node = obj.PlacedNodes[Puzzle::Config::MaxPuzzleSizeTiles * y + x];
|
||||
ImVec2 pos = ImVec2{puzCursorStart.x + x * UIPuzBoxSize + 5, puzCursorStart.y + y * UIPuzBoxSize};
|
||||
ImGui::SetCursorScreenPos(pos);
|
||||
ImGui::Text("%s", GetShortNodeName(node));
|
||||
ImGui::SetCursorScreenPos(pos);
|
||||
if (x % Puzzle::Config::CardSize == 0 && y % Puzzle::Config::CardSize == 0)
|
||||
{
|
||||
ImGui::InvisibleButton("bn", {UIPuzBoxSize * 2, UIPuzBoxSize * 2});
|
||||
if (ImGui::BeginDragDropTarget())
|
||||
{
|
||||
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("cardtype", 0))
|
||||
{
|
||||
uint32_t CardIdx = *reinterpret_cast<uint32_t*>(payload->Data);
|
||||
obj.PlacedCards[obj.PlacedCardCount].RefCard = {(uint16_t)CardIdx};
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
}
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
for (int32_t y = 0; y <= obj.HeightTiles; ++y)
|
||||
@@ -256,15 +295,13 @@ namespace Generated
|
||||
x % Puzzle::Config::CardSize == 0 ? 0xFFFFFFFF : 0x11FFFFFF);
|
||||
}
|
||||
|
||||
ImGui::Spacing();
|
||||
ImGui::Spacing();
|
||||
ImVec2 pos = ImVec2{puzCursorStart.x + obj.WidthTiles * UIPuzBoxSize + 5,
|
||||
puzCursorStart.y + obj.HeightTiles * UIPuzBoxSize};
|
||||
|
||||
ImGui::SetCursorScreenPos(pos);
|
||||
ImGui::NewLine();
|
||||
if (ImGui::TreeNodeEx("Available Cards", ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_Framed))
|
||||
{
|
||||
for (int32_t i = 0; i < obj.AvailableCardCount; ++i)
|
||||
{
|
||||
ImGui::Text("Card");
|
||||
}
|
||||
ImGui::TreePop();
|
||||
}
|
||||
}
|
||||
@@ -273,10 +310,10 @@ namespace Generated
|
||||
if (dataChanged)
|
||||
{
|
||||
char path[128]{0};
|
||||
bx::snprintf(path, sizeof(path), "game/data/puzzles/%s.pzl", obj.PuzzleName);
|
||||
WritePuzzleFilePath(path, sizeof(path), obj.ID);
|
||||
Serializer ser;
|
||||
ser.Init(path);
|
||||
if (Save(&obj, 1, ser))
|
||||
if (ser.WriteT("PZZL", obj))
|
||||
{
|
||||
LOG("Saved to %s", path);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user