Elaztek Developer Hub
Blamite Game Engine - blam!  00423.10.27.24.0533.blamite
The core library for the Blamite Game Engine.
world_editor.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <limits.h>
6 
9 
14 {
15 private:
17  bool show_add_primitive_dialog = false;
18  std::string primitive_type_name = "cuboid";
19  int index_to_remove = -1;
20 
21 public:
22 
27  {
28  ImGui::OpenPopup("Add Object");
29  if (ImGui::BeginPopupModal("Add Object", &show_add_primitive_dialog))
30  {
31  if (ImGui::BeginCombo("object type", primitive_type_name.c_str()))
32  {
33  if (ImGui::Selectable("cuboid"))
34  {
35  selected_primitive_type = BlamWorldObjectType::PrimitiveCuboid;
36  primitive_type_name = "cuboid";
37  }
38 
39  if (ImGui::Selectable("cylinder"))
40  {
41  selected_primitive_type = BlamWorldObjectType::PrimitiveCylinder;
42  primitive_type_name = "cylinder";
43  }
44 
45  if (ImGui::Selectable("sphere"))
46  {
47  selected_primitive_type = BlamWorldObjectType::PrimitiveSphere;
48  primitive_type_name = "sphere";
49  }
50 
51  if (ImGui::Selectable("line"))
52  {
53  selected_primitive_type = BlamWorldObjectType::PrimitiveLine;
54  primitive_type_name = "line";
55  }
56 
57  if (ImGui::Selectable("grid"))
58  {
59  selected_primitive_type = BlamWorldObjectType::GizmoGrid;
60  primitive_type_name = "grid";
61  }
62 
64  }
65 
66  if (ImGui::Button("OK"))
67  {
69  {
70  BlamWorldObject* new_primitive = nullptr;
71 
72  if (selected_primitive_type == BlamWorldObjectType::PrimitiveCuboid)
73  {
75  }
76  else if (selected_primitive_type == BlamWorldObjectType::PrimitiveCylinder)
77  {
79  }
80  else if (selected_primitive_type == BlamWorldObjectType::PrimitiveSphere)
81  {
83  }
84  else if (selected_primitive_type == BlamWorldObjectType::PrimitiveLine)
85  {
87  }
88  else if (selected_primitive_type == BlamWorldObjectType::GizmoGrid)
89  {
91  }
92 
93  if (new_primitive)
94  {
95  Blam::World::GetWorldState()->AddObject(new_primitive);
96  }
97  }
98 
99  show_add_primitive_dialog = false;
100  }
101 
102  ImGui::SameLine();
103 
104  if (ImGui::Button("Cancel"))
105  {
106  show_add_primitive_dialog = false;
107  }
108 
109  ImGui::EndPopup();
110  }
111  }
112 
113  void Draw()
114  {
115  if (!show)
116  {
117  return;
118  }
119 
120  if (ImGui::Begin("World State Editor", &show))
121  {
123 
124  if (ImGui::Button("initialize world state"))
125  {
127  }
128 
129  ImGui::SameLine();
130 
131  if (ImGui::Button("destroy world state"))
132  {
134  world_state = nullptr;
135  }
136 
137  if (world_state)
138  {
139  if (ImGui::Button("add primitive"))
140  {
141  show_add_primitive_dialog = true;
142  }
143 
144  ImGui::SameLine();
145 
146  if (ImGui::Button("delete @ "))
147  {
148  if (index_to_remove > -1 && index_to_remove < world_state->GetObjectCount())
149  {
150  BlamWorldObject* object = world_state->GetObjectAtIndex(index_to_remove);
151  world_state->RemoveObject(object->id);
152  object = nullptr;
153  }
154  }
155 
156  ImGui::SameLine();
157 
158  ImGui::InputInt("", &index_to_remove);
159 
160  for (int i = 0; i < world_state->GetObjectCount(); i++)
161  {
162  BlamWorldObject* object = world_state->GetObjectAtIndex(i);
163 
164  if (!object)
165  {
166  continue;
167  }
168 
169  std::string entry_name = object->GetName() + " (object " + std::to_string(i) + ")";
170 
171  if (ImGui::CollapsingHeader(entry_name.c_str()))
172  {
173  ImGui::PushID(object->id);
174  object->ShowImGuiEditControls();
175  ImGui::PopID();
176  }
177  }
178  }
179  else
180  {
181  ImGui::Text("world state not loaded");
182  }
183  }
184  ImGui::End();
185 
186  if (show_add_primitive_dialog)
187  {
189  }
190  }
191 };
Blam::World::GetWorldState
BLAM BlamWorldState * GetWorldState()
Retrieves the current world state.
Definition: world.cpp:40
object
Definition: object.h:25
BlamWorldState::AddObject
void AddObject(BlamWorldObject *object)
Definition: BlamWorldState.cpp:85
ImGui::EndPopup
IMGUI_API void EndPopup()
Definition: imgui.cpp:7675
BlamImGuiWindow::show
bool show
Controls whether or not the group should be shown. May not be used in all groups.
Definition: imgui.h:34
ImGui::BeginPopupModal
IMGUI_API bool BeginPopupModal(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
Definition: imgui.cpp:7647
Blam::World::InitializeWorldState
BLAM void InitializeWorldState()
Initializes a new world state.
Definition: world.cpp:9
BlamWorldObjectType
BlamWorldObjectType
Definition: world_objects.h:79
world.h
ImGui::End
IMGUI_API void End()
Definition: imgui.cpp:6016
BlamImGuiWindow_WorldEditor::Draw
void Draw()
Draws the contents of the group.
Definition: world_editor.hpp:113
BlamWorldState::GetObjectCount
int GetObjectCount()
Definition: BlamWorldState.cpp:120
imgui_stdlib.h
ImGui::SameLine
IMGUI_API void SameLine(float offset_from_start_x=0.0f, float spacing=-1.0f)
Definition: imgui.cpp:7147
BlamImGuiWindow
Class representing an ImGUI window.
Definition: imgui.h:31
BlamWorldObject::GetName
std::string GetName()
Definition: BlamWorldObject.cpp:243
BlamWorldObject_PrimitiveLine
Definition: world_objects.h:385
BlamImGuiWindow_WorldEditor
Class for the World Editor utility.
Definition: world_editor.hpp:13
BlamWorldObjectType::PrimitiveCylinder
@ PrimitiveCylinder
ImGui::Begin
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
Definition: imgui.cpp:5397
ImGui::CollapsingHeader
IMGUI_API bool CollapsingHeader(const char *label, ImGuiTreeNodeFlags flags=0)
Definition: imgui_widgets.cpp:5422
ImGui::OpenPopup
IMGUI_API void OpenPopup(const char *str_id)
Definition: imgui.cpp:7453
Blam::World::DestroyWorldState
BLAM void DestroyWorldState()
Destroys the current world state.
Definition: world.cpp:29
BlamWorldState::GetObjectAtIndex
BlamWorldObject * GetObjectAtIndex(int index)
Definition: BlamWorldState.cpp:141
BlamWorldObject_PrimitiveCylinder
Definition: world_objects.h:361
ImGui::Text
IMGUI_API void Text(const char *fmt,...) IM_FMTARGS(1)
Definition: imgui_widgets.cpp:238
ImGui::BeginCombo
IMGUI_API bool BeginCombo(const char *label, const char *preview_value, ImGuiComboFlags flags=0)
Definition: imgui_widgets.cpp:1416
ImGui::Selectable
IMGUI_API bool Selectable(const char *label, bool selected=false, ImGuiSelectableFlags flags=0, const ImVec2 &size=ImVec2(0, 0))
Definition: imgui_widgets.cpp:5469
ImGui::PopID
IMGUI_API void PopID()
Definition: imgui.cpp:7026
BlamWorldObjectType::GizmoGrid
@ GizmoGrid
BlamWorldObjectType::PrimitiveLine
@ PrimitiveLine
BlamWorldState::RemoveObject
bool RemoveObject(uint64_t object_id, bool delete_data=true)
Definition: BlamWorldState.cpp:100
BlamWorldObjectType::PrimitiveSphere
@ PrimitiveSphere
ImGui::EndCombo
IMGUI_API void EndCombo()
Definition: imgui_widgets.cpp:1522
BlamWorldObject_PrimitiveCuboid
Definition: world_objects.h:321
BlamWorldObject_GizmoGrid
Definition: world_objects.h:438
BlamWorldObject
Class representing a world object.
Definition: world_objects.h:119
BlamWorldObject_PrimitiveSphere
Definition: world_objects.h:331
BlamWorldObjectType::PrimitiveCuboid
@ PrimitiveCuboid
BlamImGuiWindow_WorldEditor::ShowAddPrimitivePopup
void ShowAddPrimitivePopup()
Displays the Add Primitive dialog, if opened.
Definition: world_editor.hpp:26
imgui.h
ImGui::PushID
IMGUI_API void PushID(const char *str_id)
Definition: imgui.cpp:6995
BlamWorldState
Class representing a world state.
Definition: world_objects.h:540
ImGui::Button
IMGUI_API bool Button(const char *label, const ImVec2 &size=ImVec2(0, 0))
Definition: imgui_widgets.cpp:644
ImGui::InputInt
IMGUI_API bool InputInt(const char *label, int *v, int step=1, int step_fast=100, ImGuiInputTextFlags flags=0)
Definition: imgui_widgets.cpp:3031