Elaztek Developer Hub
Blamite Game Engine - blam!  00423.10.27.24.0533.blamite
The core library for the Blamite Game Engine.
engine_text_viewer.hpp
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <Strings/components/utils/string/string.h>
6 
9 
14 {
15 private:
16  char search_buffer[128];
17  bool use_columns = true;
18  std::string current_string_id = "";
19 
20  void GenerateStringControl(BlamEngineString string)
21  {
22  ImGui::PushID(std::string("#_stringedit_" + string.id).c_str());
23  ImGui::InputText(string.id.c_str(), &string.text, ImGuiInputTextFlags_ReadOnly);
24  ImGui::PopID();
25  }
26 
27 public:
28  void Draw()
29  {
30  if (!show)
31  {
32  return;
33  }
34 
35  if (ImGui::Begin(ENGINE_TEXT("engine_text_viewer_title").c_str(), &show))
36  {
37  ImGui::InputTextWithHint("", ENGINE_TEXT("engine_text_viewer_search_placeholder").c_str(), search_buffer, 128);
38 
39  ImGui::Checkbox(ENGINE_TEXT("engine_text_viewer_use_columns").c_str(), &use_columns);
40 
42 
43  std::map<std::string, BlamEngineString>* strings = Blam::EngineText::GetEngineStrings();
44  std::map<std::string, BlamEngineString>::iterator it;
45 
46  std::string search_filter = std::string(search_buffer);
47 
48  if (use_columns)
49  {
50  ImGui::Columns(2);
51  ImGui::SetColumnWidth(0, (300.0f * *Blam::Globals::GetGlobalAsFloat("ui_scale_factor")));
52 
54  {
55  for (it = strings->begin(); it != strings->end(); it++)
56  {
57  bool is_active_item = false;
58  bool matches_filter = false;
59 
60  if (it->first == current_string_id)
61  {
62  is_active_item = true;
63  }
64 
65  if (BlamStrings::Utils::String::Contains(it->second.id, search_filter) || search_filter.length() == 0
66  || BlamStrings::Utils::String::Contains(it->second.text, search_filter))
67  {
68  matches_filter = true;
69  }
70 
71  if (matches_filter)
72  {
73  if (ImGui::Selectable(it->first.c_str(), is_active_item))
74  {
75  current_string_id = it->first;
76  }
77  }
78  }
79 
81  }
82 
84 
85  if (Blam::EngineText::StringExists(current_string_id))
86  {
87  ImGui::TextWrapped(BlamStrings::Utils::String::Replace(ENGINE_TEXT(current_string_id), "\\r", "").c_str());
88  }
89  else
90  {
91  ImGui::TextWrapped(BlamStrings::Utils::String::Replace(ENGINE_TEXT("engine_text_viewer_nothing_selected"), "\\r", "").c_str());
92  }
93  }
94  else
95  {
96  for (it = strings->begin(); it != strings->end(); it++)
97  {
98  bool matches_filter = false;
99 
100  if (BlamStrings::Utils::String::Contains(it->second.id, search_filter) || search_filter.length() == 0
101  || BlamStrings::Utils::String::Contains(it->second.text, search_filter))
102  {
103  matches_filter = true;
104  }
105 
106  if (matches_filter)
107  {
108  GenerateStringControl(it->second);
109  }
110  }
111  }
112  }
113  ImGui::End();
114  }
115 };
BlamImGuiWindow_GameEngineTextViewer
Class for the engine Globals editor.
Definition: engine_text_viewer.hpp:13
ImGuiInputTextFlags_ReadOnly
@ ImGuiInputTextFlags_ReadOnly
Definition: imgui.h:769
ImGui::Checkbox
IMGUI_API bool Checkbox(const char *label, bool *v)
Definition: imgui_widgets.cpp:974
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::ListBoxFooter
IMGUI_API void ListBoxFooter()
Definition: imgui_widgets.cpp:5668
ImGui::InputText
IMGUI_API bool InputText(const char *label, char *buf, size_t buf_size, ImGuiInputTextFlags flags=0, ImGuiInputTextCallback callback=NULL, void *user_data=NULL)
Definition: imgui_widgets.cpp:3068
ImGui::NextColumn
IMGUI_API void NextColumn()
Definition: imgui_widgets.cpp:7445
Blam::Globals::GetGlobalAsFloat
BLAM float * GetGlobalAsFloat(std::string name)
Retrieves a global's value as a float.
Definition: globals.cpp:403
ImGui::End
IMGUI_API void End()
Definition: imgui.cpp:6016
ImGui::SetColumnWidth
IMGUI_API void SetColumnWidth(int column_index, float width)
Definition: imgui_widgets.cpp:7297
engine_text.h
imgui_stdlib.h
BlamImGuiWindow
Class representing an ImGUI window.
Definition: imgui.h:31
ImVec2
Definition: imgui.h:179
ImGui::Begin
IMGUI_API bool Begin(const char *name, bool *p_open=NULL, ImGuiWindowFlags flags=0)
Definition: imgui.cpp:5397
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:68
ImGui::GetColumnWidth
IMGUI_API float GetColumnWidth(int column_index=-1)
Definition: imgui_widgets.cpp:7262
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::InputTextWithHint
IMGUI_API bool InputTextWithHint(const char *label, const char *hint, char *buf, size_t buf_size, ImGuiInputTextFlags flags=0, ImGuiInputTextCallback callback=NULL, void *user_data=NULL)
Definition: imgui_widgets.cpp:3079
ImGui::Columns
IMGUI_API void Columns(int count=1, const char *id=NULL, bool border=true)
Definition: imgui_widgets.cpp:7572
ImGui::PopID
IMGUI_API void PopID()
Definition: imgui.cpp:7026
Blam::EngineText::GetEngineStrings
BLAM std::map< std::string, BlamEngineString > * GetEngineStrings()
Retrieves the list of all loaded engine strings.
Definition: engine_text.cpp:58
ImGui::TextWrapped
IMGUI_API void TextWrapped(const char *fmt,...) IM_FMTARGS(1)
Definition: imgui_widgets.cpp:287
ENGINE_TEXT
#define ENGINE_TEXT(string_id)
Definition: engine_text.h:7
BlamImGuiWindow_GameEngineTextViewer::Draw
void Draw()
Draws the contents of the group.
Definition: engine_text_viewer.hpp:28
imgui.h
ImGui::Separator
IMGUI_API void Separator()
Definition: imgui_widgets.cpp:1284
ImGui::PushID
IMGUI_API void PushID(const char *str_id)
Definition: imgui.cpp:6995
ImGui::ListBoxHeader
IMGUI_API bool ListBoxHeader(const char *label, const ImVec2 &size=ImVec2(0, 0))
Definition: imgui_widgets.cpp:5614