Blamite Game Engine - Blam (Core)
tag_editor.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../../debug_ui.h"
4 
8 
10 {
15  {
16  private:
17  int active_tag_index = -1;
18  int active_class_index = 0;
19  std::string selected_class_label = "<choose>";
20 
21  bool show_create_popup = false;
22 
23  public:
25  {
26  if (show_create_popup)
27  {
28  ImGui::OpenPopup("Create New Tag...");
29  if (ImGui::BeginPopupModal("Create New Tag...", &show_create_popup))
30  {
31  ImGui::PushItemWidth(90.0f);
32  if (ImGui::BeginCombo("tag class", selected_class_label.c_str()))
33  {
34  for (int i = 0; i < Blam::Content::Tags::GetRegisteredTagClasses()->size(); i++)
35  {
37 
38  std::string label = "[" + tag_class->class_name_short + "] " + tag_class->class_name_long;
39 
40  if (ImGui::Selectable(label.c_str()))
41  {
42  active_class_index = i;
43  }
44  }
45  ImGui::EndCombo();
46  }
47  ImGui::PopItemWidth();
48 
49  if (ImGui::Button("OK"))
50  {
52 
53  if (tag_class)
54  {
55  void* new_tag_address = NULL;
56  Blam::Content::Tags::RegisterCreatedTag(new_tag_address, tag_class->class_name_short);
57  }
58  else
59  {
60  Blam::Logger::LogEvent("### WARNING tag_editor: failed to create new tag, no tag class found with registration index " + std::to_string(active_class_index), WSV_WARNING, Blam::Logger::ReportType::UIDebug);
61  }
62 
63  show_create_popup = false;
64  }
65 
66  ImGui::SameLine();
67 
68  if (ImGui::Button("Cancel"))
69  {
70  show_create_popup = false;
71  }
72 
73  ImGui::EndPopup();
74  }
75  ImGui::EndPopup();
76  }
77  }
78 
82  void Draw()
83  {
85 
86  // About Blamite
87  if (show)
88  {
89  if (ImGui::Begin("Tag Editor", &show))
90  {
91  std::vector<tag_memory_data>* tags = Blam::Content::Tags::GetLoadedTags();
92 
93  if (ImGui::Button("create new tag"))
94  {
95  show_create_popup = true;
96  }
97 
98  ImGui::Separator();
99 
100  ImGui::Columns(2);
101 
102  ImGui::SetColumnWidth(0, 200);
103 
104  if (ImGui::ListBoxHeader("", ImVec2(ImGui::GetColumnWidth() - 15, -1)))
105  {
106  for (int i = 0; i < tags->size(); i++)
107  {
108  tag_memory_data data = tags->at(i);
109 
110  bool is_active_item = false;
111 
112  if (i == active_tag_index)
113  {
114  is_active_item = true;
115  }
116 
117  if (ImGui::Selectable(data.path, is_active_item))
118  {
119  active_tag_index = i;
120  }
121 
122  if (ImGui::IsItemHovered())
123  {
124  ImGui::BeginTooltip();
125  ImGui::PushTextWrapPos(450.0f);
126  ImGui::Text("tag information");
127  ImGui::Separator();
128 
129  std::string tag_path = "path: " + std::string(data.path);
130  std::string tag_index = "index: " + std::to_string(i);
131  std::string tag_address = "address: 0x" + Blam::Converters::BytesToString(data.address, 4);
132  std::string tag_class = "class: " + data.tag_class;
133  std::string tag_size = "size: " + std::to_string(data.size);
134 
135  ImGui::Text(tag_path.c_str());
136  ImGui::Text(tag_index.c_str());
137  ImGui::Text(tag_address.c_str());
138  ImGui::Text(tag_class.c_str());
139  ImGui::Text(tag_size.c_str());
140 
141  ImGui::PopTextWrapPos();
142  ImGui::EndTooltip();
143  }
144  }
145 
146  ImGui::ListBoxFooter();
147  }
148 
149  ImGui::NextColumn();
150 
151  if (active_tag_index < 0)
152  {
153  ImGui::Text("select a tag to modify");
154  }
155  else if (active_tag_index > tags->size())
156  {
157  std::string message = "selected index " + std::to_string(active_tag_index) +
158  " was too high (max is " + std::to_string(tags->size()) + ")";
159 
160  ImGui::Text(message.c_str());
161  }
162  else
163  {
164  tag_memory_data data = tags->at(active_tag_index);
165 
166  if (ImGui::BeginTabBar("tag_editor_tabs"))
167  {
168  if (ImGui::BeginTabItem("tag information"))
169  {
170  std::string tag_path = "path: " + std::string(data.path);
171  std::string tag_index = "index: " + std::to_string(active_tag_index);
172  std::string tag_address = "address: 0x" + Blam::Converters::BytesToString(data.address, 4);
173  std::string tag_class = "class: " + data.tag_class;
174  std::string tag_size = "size: " + std::to_string(data.size);
175 
176  ImGui::Text(tag_path.c_str());
177  ImGui::Text(tag_index.c_str());
178  ImGui::Text(tag_address.c_str());
179  ImGui::Text(tag_class.c_str());
180  ImGui::Text(tag_size.c_str());
181 
182  ImGui::EndTabItem();
183  }
184 
185  if (ImGui::BeginTabItem("meta editor"))
186  {
187  if (data.origin == TagOrigin::BinaryFile || data.origin == TagOrigin::Memory)
188  {
189  if (ImGui::Button("save to disk"))
190  {
191  Blam::Content::Tags::SaveTag(data.address, data.tag_class, data.size, data.path);
192  }
193 
194  ImGui::SameLine();
195 
196  if (ImGui::Button("reload from disk"))
197  {
199  }
200  }
201 
203 
204  ImGui::EndTabItem();
205  }
206 
207 
208  ImGui::EndTabBar();
209  }
210  }
211  }
212  ImGui::End();
213  }
214  }
215  };
216 }
Blam::Content::Tags::LoadTagFromFile
BLAM HRESULT LoadTagFromFile(std::string tag_path)
Loads a tag from the engine's tag directory (default is '.
Definition: tags.cpp:156
Blam::Logger::LogEvent
BLAM void LogEvent(std::string message)
Logs a message to the log and/or console.
Definition: aliases.cpp:33
tag_memory_data::tag_class
std::string tag_class
The tag's short class name.
Definition: tags.h:45
bitmap.h
tag_memory_data::address
void * address
The address pointing to the start of the tag's data.
Definition: tags.h:31
Blam::Content::Tags::TagClass::class_name_long
std::string class_name_long
The longer class name. Typically shown alongside short name for user-friendliness.
Definition: tagclass.h:33
tags.h
Blam::Content::Tags::TagClass::class_name_short
std::string class_name_short
The short, 4-character name of the tag class.
Definition: tagclass.h:34
tag_memory_data::size
int size
The size of the tag's data in memory.
Definition: tags.h:32
Blam::Logger::UIDebug
@ UIDebug
Report file for all UI messages.
Definition: logger.h:81
tag_memory_data::origin
TagOrigin origin
The origin of the tag.
Definition: tags.h:46
Memory
@ Memory
Indicates the tag originated from the engine's memory.
Definition: tags.h:20
Blam::DebugUI::ImGUIDrawingGroup::show
bool show
Controls whether or not the group should be shown. May not be used in all groups.
Definition: debug_ui.h:441
Blam::DebugUI::ImGUIDrawingGroup
Class representing an ImGUI drawing group/draw list item.
Definition: debug_ui.h:408
Blam::DebugUI::Windows::TagEditor::Draw
void Draw()
Draws the tag editor window.
Definition: tag_editor.hpp:82
Blam::Content::Tags::RegisterCreatedTag
BLAM std::string RegisterCreatedTag(void *tag, std::string tag_class)
Definition: tags.cpp:45
tag_memory_data
Class representing a tag's data.
Definition: tags.h:28
Blam::DebugUI::Windows::TagEditor::CreateNewTagModal
void CreateNewTagModal()
Definition: tag_editor.hpp:24
Blam::Content::Tags::TagClass
Class representing a tag class.
Definition: tagclass.h:30
Blam::Content::Tags::GetLoadedTags
BLAM std::vector< tag_memory_data > * GetLoadedTags()
Retrieves the list of loaded tag data.
Definition: tags.cpp:507
Blam::DebugUI::Windows::TagEditor
Class for the realtime tag editor.
Definition: tag_editor.hpp:14
Blam::Content::Tags::ShowImPropertyEditor
BLAM void ShowImPropertyEditor(void *tag, std::string tag_class)
Shows an ImGUI editor for a given tag.
Definition: tags.cpp:21
tagclass.h
Blam::DebugUI::Windows
Legacy namespace to contain data for the legacy ImGUI console.
Definition: debug_ui.h:493
Blam::Converters::BytesToString
std::string BytesToString(void *bytes, int bytes_length)
Converts a series of bytes to a string.
Definition: converters.cpp:164
Text
@ Text
Master text object that wraps around both BitmapText and DWText.
Definition: render_stack.h:73
Blam::Content::Tags::GetRegisteredTagClasses
BLAM std::vector< TagClass * > * GetRegisteredTagClasses()
Retrieves the list of all registered tag classes.
Definition: tagclass.cpp:72
WSV_WARNING
#define WSV_WARNING
Macro for 'Warning' log seveirty. Original pre-enum value was 3.
Definition: logger.h:18
Blam::Content::Tags::SaveTag
BLAM HRESULT SaveTag(void *tag_data, std::string tag_class, int tag_size, std::string tag_path)
Saves a tag data to a file.
Definition: tags.cpp:381
BinaryFile
@ BinaryFile
Indicates the tag originated from a binary file.
Definition: tags.h:19
tag_memory_data::path
char path[256]
The tag's path.
Definition: tags.h:44