Skip to content

Commit

Permalink
Ui
Browse files Browse the repository at this point in the history
  • Loading branch information
Joey0980 committed Jan 27, 2024
1 parent 2196a7a commit 4952a14
Show file tree
Hide file tree
Showing 8 changed files with 131 additions and 12 deletions.
1 change: 1 addition & 0 deletions Terraformer.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="include\map.h" />
<ClInclude Include="include\terraformer.h" />
<ClInclude Include="src\Map.h" />
<ClInclude Include="vendor\include\glad\glad.h" />
<ClInclude Include="vendor\include\GLFW\glfw3.h" />
Expand Down
3 changes: 3 additions & 0 deletions Terraformer.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@
<ClInclude Include="include\map.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="include\terraformer.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Library Include="vendor\lib\glfw3.lib" />
Expand Down
Binary file modified dist/CS_W1.a2ls
Binary file not shown.
49 changes: 48 additions & 1 deletion dist/imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,53 @@ Size=1920,1050
Collapsed=0
DockId=0x8B93E3BD,0

[Window][Terraformer | Editing map: a]
Pos=60,60
Size=1120,342
Collapsed=0

[Window][Terraformer | Editing map: aa]
Pos=60,60
Size=1120,342
Collapsed=0

[Window][Terraformer | Editing map: aaa]
Pos=60,60
Size=1120,342
Collapsed=0

[Window][Terraformer | Editing map: aaad]
Pos=60,60
Size=1120,342
Collapsed=0

[Window][Terraformer | Editing map: C]
Pos=0,30
Size=1920,1050
Collapsed=0
DockId=0x8B93E3BD,0

[Window][Terraformer | Editing map: CS]
Pos=272,251
Size=1120,342
Collapsed=0

[Window][Terraformer | Editing map: New WorldC]
Pos=60,60
Size=1120,342
Collapsed=0

[Window][Terraformer | Editing map: CC]
Pos=60,60
Size=1120,342
Collapsed=0

[Window][Terraformer | Editing map: D]
Pos=0,30
Size=1920,1050
Collapsed=0
DockId=0x8B93E3BD,0

[Docking][Data]
DockSpace ID=0x8B93E3BD Window=0xA787BDB4 Pos=505,569 Size=1920,1050 CentralNode=1 Selected=0xCF79E78A
DockSpace ID=0x8B93E3BD Window=0xA787BDB4 Pos=49,113 Size=1920,1050 CentralNode=1 Selected=0x30BE4982

3 changes: 3 additions & 0 deletions include/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ class Map {
void AddNode();
void AddPath();

void RemoveNode(u32 index);
void RemovePath(u32 index);

void Save(const std::string& filePath);

MapData::Header header;
Expand Down
3 changes: 3 additions & 0 deletions include/terraformer.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@ class Terraformer {
Map* map = nullptr;
std::string message = "";

int selectedNode = -1;
int selectedPath = -1;

void Update();

void UINodes();
void UIPaths();
void UIProperties();

void LoadFile(const std::string& filePath);
void NewFile();
Expand Down
9 changes: 9 additions & 0 deletions src/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ void Map::AddPath() {
this->paths.push_back(path);
}

void Map::RemoveNode(u32 index) {
this->nodes.erase(this->nodes.begin() + index);
}

void Map::RemovePath(u32 index) {
delete[] this->paths[index].unlockCriteriaData;
this->paths.erase(this->paths.begin() + index);
}

void Map::Save(const std::string& filePath) {
std::ofstream file(filePath, std::ios::binary);

Expand Down
75 changes: 64 additions & 11 deletions src/terraformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,45 @@ void Terraformer::Update() {
}

if (ImGui::Begin((std::string{"Terraformer | Editing map: "} + std::string{this->map->worldInfo.name}).c_str())) {
this->UIProperties();
ImGui::NewLine();
this->UINodes();
ImGui::SameLine();
this->UIPaths();
} ImGui::End();
}

void Terraformer::UINodes() {
ImGui::PushID("nodes");
if (ImGui::Button("+", ImVec2(40, 0))) {
this->map->AddNode();
}
ImGui::SameLine();
if (ImGui::Button("-", ImVec2(40, 0))) {
if (this->selectedNode != -1) {
this->map->RemoveNode(this->selectedNode);
this->selectedNode = -1;
}
}
ImGui::PopID();

ImGui::BeginChild("Nodes", ImVec2(500, 0), true);
for (u32 i = 0; i < this->map->nodes.size(); i++) {


MapData::Node& node = this->map->nodes[i];

const bool selected = (i == this->selectedNode);

ImGui::PushID(i);
if (ImGui::Selectable((std::string{"Node "} + std::to_string(i)).c_str(), selected, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowDoubleClick)) {
if (selectedNode == i) {
this->selectedNode = -1;
} else {
this->selectedNode = i;
}
}

ImGui::Text("Node %d", i);
ImGui::InputText("Bone Name", node.boneName, sizeof(node.boneName));
ImGui::Combo("Type", (int*)&node.type, "Normal\0Passthrough\0Level\0");

Expand All @@ -63,18 +88,30 @@ void Terraformer::UINodes() {

ImGui::PopID();

if (i != this->map->nodes.size() - 1) {
ImGui::Separator();
}
//if (i != this->map->nodes.size() - 1) {
// ImGui::Separator();
//}
}

if (ImGui::Button("Add Node")) {
this->map->AddNode();
}
ImGui::EndChild();
}

void Terraformer::UIPaths() {
ImGui::PushID("paths");
if (ImGui::Button("+", ImVec2(40, 0))) {
this->map->AddPath();
}
ImGui::SameLine();
if (ImGui::Button("-", ImVec2(40, 0))) {
if (this->selectedPath != -1) {
this->map->RemovePath(this->selectedPath);
this->selectedPath = -1;
}
}
ImGui::PopID();

ImGui::SameLine();

ImGui::BeginChild("Paths", ImVec2(500, 0), true);

static const char* const animationString =
Expand Down Expand Up @@ -105,8 +142,19 @@ void Terraformer::UIPaths() {
for (u32 i = 0; i < this->map->paths.size(); i++) {
MapData::Path& path = this->map->paths[i];

const bool selected = (i == this->selectedPath);

ImGui::PushID(i);
ImGui::Text("Path %d", i);
if (ImGui::Selectable((std::string{ "Path " } + std::to_string(i)).c_str(), selected, ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowDoubleClick)) {
if (selectedPath == i) {
this->selectedPath = -1;
}
else {
this->selectedPath = i;
}
}


ImGui::Combo("Starting Node", (int*)&path.startingNodeIndex, nodeNames.c_str());
ImGui::Combo("Ending Node", (int*)&path.endingNodeIndex, nodeNames.c_str());
ImGui::InputFloat("Speed", &path.speed);
Expand All @@ -118,12 +166,17 @@ void Terraformer::UIPaths() {
}
}

if (ImGui::Button("Add Path")) {
this->map->AddPath();
}
ImGui::EndChild();
}

void Terraformer::UIProperties() {
ImGui::BeginChild("Properties", ImVec2(1010, 200), true);
ImGui::InputText("World Name", this->map->worldInfo.name, sizeof(this->map->worldInfo.name));
ImGui::InputScalar("World ID", ImGuiDataType_U32, &this->map->worldInfo.worldID);
//ImGui::InputScalar("Map ID", ImGuiDataType_S32, &this->map->);
ImGui::EndChild();
}

void Terraformer::LoadFile(const std::string& filePath) {
std::cout << "Loading file: " << filePath << std::endl;

Expand Down

0 comments on commit 4952a14

Please sign in to comment.