Blamite Game Engine - blam!  00296.01.12.21.0102.blamite
The core library for the Blamite Game Engine.
engine_text_viewer.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include "../../debug_ui.h"
4 
5 #include <Strings/components/utils/string/string.h>
6 
8 #include "components/3rdparty/imgui/misc/imgui_stdlib.h"
9 
10 namespace Blam::DebugUI::Windows
11 {
16  {
17  private:
18  char search_buffer[128];
19  bool use_columns = true;
20  std::string current_string_id = "";
21 
22  void GenerateStringControl(BlamEngineString string)
23  {
24  ImGui::PushID(std::string("#_stringedit_" + string.id).c_str());
25  ImGui::InputText(string.id.c_str(), &string.text, ImGuiInputTextFlags_ReadOnly);
26  ImGui::PopID();
27  }
28 
29  public:
30  void Draw()
31  {
32  if (show)
33  {
34  if (ImGui::Begin(ENGINE_TEXT("engine_text_viewer_title").c_str(), &show))
35  {
36  ImGui::InputTextWithHint("", ENGINE_TEXT("engine_text_viewer_search_placeholder").c_str(), search_buffer, 128);
37 
38  ImGui::Checkbox(ENGINE_TEXT("engine_text_viewer_use_columns").c_str(), &use_columns);
39 
40  ImGui::Separator();
41 
42  std::map<std::string, BlamEngineString>* strings = Blam::EngineText::GetEngineStrings();
43  std::map<std::string, BlamEngineString>::iterator it;
44 
45  std::string search_filter = std::string(search_buffer);
46 
47  if (use_columns)
48  {
49  ImGui::Columns(2);
50  ImGui::SetColumnWidth(0, (300.0f * *Blam::Globals::GetGlobalAsFloat("ui_scale_factor")));
51 
52  if (ImGui::ListBoxHeader("", ImVec2(ImGui::GetColumnWidth() - 15, -1)))
53  {
54  for (it = strings->begin(); it != strings->end(); it++)
55  {
56  bool is_active_item = false;
57  bool matches_filter = false;
58 
59  if (it->first == current_string_id)
60  {
61  is_active_item = true;
62  }
63 
64  if (BlamStrings::Utils::String::Contains(it->second.id, search_filter) || search_filter.length() == 0
65  || BlamStrings::Utils::String::Contains(it->second.text, search_filter))
66  {
67  matches_filter = true;
68  }
69 
70  if (matches_filter)
71  {
72  if (ImGui::Selectable(it->first.c_str(), is_active_item))
73  {
74  current_string_id = it->first;
75  }
76  }
77  }
78 
79  ImGui::ListBoxFooter();
80  }
81 
82  ImGui::NextColumn();
83 
84  if (Blam::EngineText::StringExists(current_string_id))
85  {
86  ImGui::TextWrapped(BlamStrings::Utils::String::Replace(ENGINE_TEXT(current_string_id), "\\r", "").c_str());
87  }
88  else
89  {
90  ImGui::TextWrapped(BlamStrings::Utils::String::Replace(ENGINE_TEXT("engine_text_viewer_nothing_selected"), "\\r", "").c_str());
91  }
92  }
93  else
94  {
95  for (it = strings->begin(); it != strings->end(); it++)
96  {
97  bool matches_filter = false;
98 
99  if (BlamStrings::Utils::String::Contains(it->second.id, search_filter) || search_filter.length() == 0
100  || BlamStrings::Utils::String::Contains(it->second.text, search_filter))
101  {
102  matches_filter = true;
103  }
104 
105  if (matches_filter)
106  {
107  GenerateStringControl(it->second);
108  }
109  }
110  }
111  }
112  ImGui::End();
113  }
114  }
115  };
116 }
Blam::Globals::GetGlobalAsFloat
BLAM float * GetGlobalAsFloat(std::string name)
Retrieves a global's value as a float.
Definition: globals.cpp:400
engine_text.h
Blam::EngineText::StringExists
BLAM bool StringExists(std::string id)
Looks through the list of loaded engine strings to see if a given string has been loaded.
Definition: engine_text.cpp:85
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:362
Blam::DebugUI::ImGUIDrawingGroup
Class representing an ImGUI drawing group/draw list item.
Definition: debug_ui.h:359
Blam::EngineText::GetEngineStrings
BLAM std::map< std::string, BlamEngineString > * GetEngineStrings()
Retrieves the list of all loaded engine strings.
Definition: engine_text.cpp:75
Blam::DebugUI::Windows::GameEngineTextViewer
Class for the engine Globals editor.
Definition: engine_text_viewer.hpp:15
ENGINE_TEXT
#define ENGINE_TEXT(string_id)
Definition: engine_text.h:7
Blam::DebugUI::Windows::GameEngineTextViewer::Draw
void Draw()
Draws the contents of the group.
Definition: engine_text_viewer.hpp:30
Blam::DebugUI::Windows
Legacy namespace to contain data for the legacy ImGUI console.
Definition: debug_ui.h:434