2020-12-02 16:19:16 -05:00
|
|
|
#pragma once
|
|
|
|
#include "pch.h"
|
|
|
|
|
|
|
|
class Ui
|
|
|
|
{
|
|
|
|
private:
|
2021-06-18 12:49:11 -04:00
|
|
|
inline static std::string m_CurrentHotkey;
|
2021-03-02 14:18:37 -05:00
|
|
|
|
2020-12-02 16:19:16 -05:00
|
|
|
public:
|
2021-06-18 12:49:11 -04:00
|
|
|
struct NamedMemory
|
|
|
|
{
|
2020-12-02 16:19:16 -05:00
|
|
|
std::string name;
|
|
|
|
int addr;
|
|
|
|
};
|
|
|
|
|
2021-06-18 12:49:11 -04:00
|
|
|
struct NamedValue
|
|
|
|
{
|
2020-12-02 16:19:16 -05:00
|
|
|
std::string name;
|
|
|
|
int value;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct JsonPopUpData
|
|
|
|
{
|
|
|
|
std::function<void(std::string&, std::string&, std::string&)> function;
|
|
|
|
std::string key;
|
2021-06-18 12:49:11 -04:00
|
|
|
std::string rootKey;
|
2020-12-02 16:19:16 -05:00
|
|
|
std::string value;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ImgPopUpData
|
|
|
|
{
|
|
|
|
std::function<void(std::string&)> function;
|
|
|
|
std::string value;
|
|
|
|
};
|
2021-06-18 12:49:11 -04:00
|
|
|
|
|
|
|
inline static JsonPopUpData jsonPopup;
|
|
|
|
inline static ImgPopUpData imgPopup;
|
2021-03-02 14:18:37 -05:00
|
|
|
|
2020-12-21 15:24:07 -05:00
|
|
|
static void CenterdText(const std::string& text);
|
2021-02-24 16:54:45 -05:00
|
|
|
static bool ColorButton(int color_id, std::vector<float>& color, ImVec2 size);
|
2021-06-18 12:49:11 -04:00
|
|
|
static bool CheckboxAddress(const char* label, int addr = NULL, const char* hint = nullptr);
|
|
|
|
static bool CheckboxAddressEx(const char* label, int addr = NULL, int enabled_val = 1, int disabled_val = 0,
|
|
|
|
const char* hint = nullptr);
|
2020-12-02 16:19:16 -05:00
|
|
|
static bool CheckboxAddressVar(const char* label, bool val, int addr, const char* hint = nullptr);
|
2021-06-18 12:49:11 -04:00
|
|
|
static bool CheckboxAddressVarEx(const char* label, bool val, int addr, int enabled_val, int disabled_val,
|
|
|
|
const char* hint = nullptr);
|
2020-12-02 16:19:16 -05:00
|
|
|
static bool CheckboxBitFlag(const char* label, uint flag, const char* hint = nullptr);
|
2021-06-18 12:49:11 -04:00
|
|
|
static bool CheckboxWithHint(const char* label, bool* state, const char* hint = nullptr, bool is_disabled = false);
|
2021-02-25 17:45:41 -05:00
|
|
|
static void DrawHeaders(CallbackTable& data);
|
2020-12-02 16:19:16 -05:00
|
|
|
|
2021-06-18 12:49:11 -04:00
|
|
|
static void DrawJSON(CJson& json, std::vector<std::string>& combo_items, std::string& selected_item,
|
|
|
|
ImGuiTextFilter& filter,
|
|
|
|
std::function<void(std::string&, std::string&, std::string&)> func_left_click,
|
|
|
|
std::function<void(std::string&, std::string&, std::string&)> func_right_click);
|
2021-07-17 09:42:09 -04:00
|
|
|
static void DrawImages( std::vector<std::unique_ptr<STextureStructure>>& img_vec, ImVec2 image_size,
|
|
|
|
std::vector<std::string>& category_vec, std::string& selected_item, ImGuiTextFilter& filter,
|
|
|
|
std::function<void(std::string&)> on_left_click,
|
|
|
|
std::function<void(std::string&)> on_right_click,
|
|
|
|
std::function<std::string(std::string&)> get_name_func,
|
|
|
|
std::function<bool(std::string&)> verify_func = nullptr,
|
|
|
|
const char** custom_names = nullptr, size_t length = 0);
|
2020-12-02 16:19:16 -05:00
|
|
|
|
|
|
|
template <typename T>
|
2021-06-18 12:49:11 -04:00
|
|
|
static void EditAddress(const char* label, int address, int min = 0, int def = 0, int max = 100);
|
|
|
|
static void EditBits(const char* label, int address, const std::vector<std::string>& names);
|
2021-07-24 13:21:52 -04:00
|
|
|
static void EditFloat(const char* label, int address, float min, float def, float max, float mul = 1, float change = 1.0f);
|
2020-12-02 16:19:16 -05:00
|
|
|
template <typename T>
|
2021-06-18 12:49:11 -04:00
|
|
|
static void EditReference(const char* label, T& address, int min = 0, int def = 0, int max = 100);
|
2021-02-24 16:54:45 -05:00
|
|
|
static void EditRadioButtonAddress(const char* label, std::vector<NamedMemory>& named_mem);
|
|
|
|
static void EditRadioButtonAddressEx(const char* label, int addr, std::vector<NamedValue>& named_val);
|
2021-06-18 12:49:11 -04:00
|
|
|
static void EditStat(const char* label, int stat_id, int min = 0, int def = 0, int max = 1000);
|
2020-12-02 16:19:16 -05:00
|
|
|
|
|
|
|
static void FilterWithHint(const char* label, ImGuiTextFilter& filter, const char* hint);
|
|
|
|
|
|
|
|
static ImVec2 GetSize(short count = 1, bool spacing = true);
|
|
|
|
|
2021-01-16 12:48:06 -05:00
|
|
|
static bool HotKey(const char* label, HotKeyData& key_data);
|
|
|
|
static bool HotKeyPressed(HotKeyData& hotkey);
|
|
|
|
static std::string GetHotKeyNameString(HotKeyData& hotkey);
|
2020-12-02 16:19:16 -05:00
|
|
|
|
|
|
|
static bool ListBox(const char* label, std::vector<std::string>& all_items, int& selected);
|
|
|
|
static bool ListBoxStr(const char* label, std::vector<std::string>& all_items, std::string& selected);
|
2021-07-17 09:42:09 -04:00
|
|
|
static bool ListBoxCustomNames(const char* label, std::vector<std::string>& all_items, std::string& selected, const char* custom_names[] = nullptr, size_t length = 0);
|
2020-12-02 16:19:16 -05:00
|
|
|
|
2021-02-24 16:54:45 -05:00
|
|
|
static void RadioButtonAddress(const char* label, std::vector<NamedMemory>& named_mem);
|
|
|
|
static void RadioButtonAddressEx(const char* label, int addr, std::vector<NamedValue>& named_val);
|
2020-12-02 16:19:16 -05:00
|
|
|
|
|
|
|
static void ColorPickerAddress(const char* label, int base_addr, ImVec4&& default_color);
|
|
|
|
static void ShowTooltip(const char* text);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
2021-02-24 16:54:45 -05:00
|
|
|
void Ui::EditAddress(const char* label, const int address, const int min, const int def, const int max)
|
2020-12-02 16:19:16 -05:00
|
|
|
{
|
|
|
|
if (ImGui::CollapsingHeader(label))
|
|
|
|
{
|
2021-06-18 12:49:11 -04:00
|
|
|
int val = patch::Get<T>(address, false);
|
2020-12-02 16:19:16 -05:00
|
|
|
|
|
|
|
int items = 3;
|
|
|
|
|
|
|
|
if (min == def)
|
|
|
|
items = 2;
|
|
|
|
|
2021-06-18 12:49:11 -04:00
|
|
|
ImGui::Columns(items, nullptr, false);
|
2020-12-02 16:19:16 -05:00
|
|
|
ImGui::Text(("Min: " + std::to_string(min)).c_str());
|
2021-02-24 16:54:45 -05:00
|
|
|
|
2020-12-02 16:19:16 -05:00
|
|
|
if (items == 3)
|
|
|
|
{
|
|
|
|
ImGui::NextColumn();
|
|
|
|
ImGui::Text(("Def: " + std::to_string(def)).c_str());
|
|
|
|
}
|
2021-02-24 16:54:45 -05:00
|
|
|
|
2020-12-02 16:19:16 -05:00
|
|
|
ImGui::NextColumn();
|
|
|
|
ImGui::Text(("Max: " + std::to_string(max)).c_str());
|
|
|
|
ImGui::Columns(1);
|
|
|
|
|
|
|
|
ImGui::Spacing();
|
|
|
|
|
|
|
|
if (ImGui::InputInt(("Set value##" + std::string(label)).c_str(), &val))
|
|
|
|
patch::Set<T>(address, val, false);
|
|
|
|
|
|
|
|
ImGui::Spacing();
|
|
|
|
|
2021-01-19 05:02:33 -05:00
|
|
|
if (val < min)
|
|
|
|
val = min;
|
2021-02-24 16:54:45 -05:00
|
|
|
|
2021-01-19 05:02:33 -05:00
|
|
|
if (val > max)
|
|
|
|
val = max;
|
|
|
|
|
2021-06-18 12:49:11 -04:00
|
|
|
if (ImGui::Button(("Minimum##" + std::string(label)).c_str(), GetSize(items)))
|
2020-12-02 16:19:16 -05:00
|
|
|
patch::Set<T>(address, min, false);
|
|
|
|
|
|
|
|
if (items == 3)
|
|
|
|
{
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
2021-06-18 12:49:11 -04:00
|
|
|
if (ImGui::Button(("Default##" + std::string(label)).c_str(), GetSize(3)))
|
2020-12-02 16:19:16 -05:00
|
|
|
patch::Set<T>(address, def, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
2021-06-18 12:49:11 -04:00
|
|
|
if (ImGui::Button(("Maximum##" + std::string(label)).c_str(), GetSize(items)))
|
2020-12-02 16:19:16 -05:00
|
|
|
patch::Set<T>(address, max, false);
|
|
|
|
|
|
|
|
ImGui::Spacing();
|
|
|
|
ImGui::Separator();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2021-02-24 16:54:45 -05:00
|
|
|
void Ui::EditReference(const char* label, T& address, const int min, const int def, const int max)
|
2020-12-02 16:19:16 -05:00
|
|
|
{
|
|
|
|
if (ImGui::CollapsingHeader(label))
|
|
|
|
{
|
|
|
|
int val = static_cast<int>(address);
|
|
|
|
|
2021-06-18 12:49:11 -04:00
|
|
|
ImGui::Columns(3, nullptr, false);
|
2020-12-02 16:19:16 -05:00
|
|
|
ImGui::Text(("Min: " + std::to_string(min)).c_str());
|
|
|
|
ImGui::NextColumn();
|
|
|
|
ImGui::Text(("Def: " + std::to_string(def)).c_str());
|
|
|
|
ImGui::NextColumn();
|
|
|
|
ImGui::Text(("Max: " + std::to_string(max)).c_str());
|
|
|
|
ImGui::Columns(1);
|
|
|
|
|
|
|
|
ImGui::Spacing();
|
|
|
|
|
|
|
|
if (ImGui::InputInt(("Set value##" + std::string(label)).c_str(), &val))
|
|
|
|
address = static_cast<float>(val);
|
|
|
|
|
|
|
|
ImGui::Spacing();
|
|
|
|
|
2021-06-18 12:49:11 -04:00
|
|
|
if (ImGui::Button(("Minimum##" + std::string(label)).c_str(), GetSize(3)))
|
2020-12-02 16:19:16 -05:00
|
|
|
address = static_cast<float>(min);
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
2021-06-18 12:49:11 -04:00
|
|
|
if (ImGui::Button(("Default##" + std::string(label)).c_str(), GetSize(3)))
|
2020-12-02 16:19:16 -05:00
|
|
|
address = static_cast<float>(def);
|
|
|
|
|
|
|
|
ImGui::SameLine();
|
|
|
|
|
2021-06-18 12:49:11 -04:00
|
|
|
if (ImGui::Button(("Maximum##" + std::string(label)).c_str(), GetSize(3)))
|
2020-12-02 16:19:16 -05:00
|
|
|
address = static_cast<float>(max);
|
|
|
|
|
|
|
|
ImGui::Spacing();
|
|
|
|
ImGui::Separator();
|
|
|
|
}
|
2021-06-18 12:49:11 -04:00
|
|
|
}
|