Elaztek Developer Hub
Blamite Game Engine - blam!  00398.09.22.23.2015.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 
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 
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 
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 
80  }
81 
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 }
ImGuiInputTextFlags_ReadOnly
@ ImGuiInputTextFlags_ReadOnly
Definition: imgui.h:769
ImGui::Checkbox
IMGUI_API bool Checkbox(const char *label, bool *v)
Definition: imgui_widgets.cpp:974
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:407
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
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:70
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
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
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
Blam::DebugUI::ImGUIDrawingGroup
Class representing an ImGUI drawing group/draw list item.
Definition: debug_ui.h:359
ImGui::Columns
IMGUI_API void Columns(int count=1, const char *id=NULL, bool border=true)
Definition: imgui_widgets.cpp:7572
it
ARPHIC PUBLIC LICENSE Ltd Yung Chi Taiwan All rights reserved except as specified below Everyone is permitted to copy and distribute verbatim copies of this license but changing it is forbidden Preamble The licenses for most software are designed to take away your freedom to share and change it By the ARPHIC PUBLIC LICENSE specifically permits and encourages you to use this provided that you give the recipients all the rights that we gave you and make sure they can get the modifications of this software Legal Terms Font means the TrueType fonts AR PL Mingti2L AR PL KaitiM AR PL KaitiM and the derivatives of those fonts created through any modification including modifying reordering converting changing font or adding deleting some characters in from glyph table PL means Public License Copyright Holder means whoever is named in the copyright or copyrights for the Font You means the or person redistributing or modifying the Font Freely Available means that you have the freedom to copy or modify the Font as well as redistribute copies of the Font under the same conditions you not price If you you can charge for this service Copying &Distribution You may copy and distribute verbatim copies of this Font in any without provided that you retain this license including modifying reordering converting changing font or adding deleting some characters in from glyph and copy and distribute such modifications under the terms of Section provided that the following conditions are such as by offering access to copy the modifications from a designated or distributing the modifications on a medium customarily used for software interchange c If the modified fonts normally reads commands interactively when you must cause it
Definition: ARPHICPL.TXT:36
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:60
ImGui::TextWrapped
IMGUI_API void TextWrapped(const char *fmt,...) IM_FMTARGS(1)
Definition: imgui_widgets.cpp:287
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
ImGui::Separator
IMGUI_API void Separator()
Definition: imgui_widgets.cpp:1284
Blam::DebugUI::Windows
Legacy namespace to contain data for the legacy ImGUI console.
Definition: ui.h:26
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