Fix rounding gaps in header menus

This commit is contained in:
Grinch_ 2021-12-17 02:17:49 +06:00
parent 56e9f5962c
commit 54052ac7ec
5 changed files with 96 additions and 24 deletions

View File

@ -25,14 +25,6 @@ void CheatMenu::DrawWindow()
{
if (m_bShowMenu)
{
static ImVec2 fScreenSize = ImVec2(-1, -1);
ImVec2 size(screen::GetScreenWidth(), screen::GetScreenHeight());
if (fScreenSize.x != -1 && fScreenSize.y != -1)
{
m_fMenuSize.x += (size.x - fScreenSize.x) / 4.0f;
m_fMenuSize.y += (size.y - fScreenSize.y) / 1.2f;
}
ImGui::SetNextWindowSize(m_fMenuSize);
if (ImGui::Begin(MENU_TITLE, NULL, ImGuiWindowFlags_NoCollapse || ImGuiWindowFlags_NoTitleBar))
@ -51,7 +43,14 @@ void CheatMenu::DrawWindow()
Ui::DrawHeaders(header);
}
if (m_bSizeChangedExternal)
{
m_bSizeChangedExternal = false;
}
else
{
m_fMenuSize = ImGui::GetWindowSize();
}
gConfig.SetValue("window.sizeX", m_fMenuSize.x);
gConfig.SetValue("window.sizeY", m_fMenuSize.y);
@ -77,7 +76,7 @@ CheatMenu::CheatMenu()
pCallbackFunc = std::bind(&DrawWindow);
// Load menu settings
Ui::m_HeaderId = gConfig.GetValue("window.id", std::string(""));
Ui::m_HeaderId = gConfig.GetValue("window.idnum", -1);
m_fMenuSize.x = gConfig.GetValue("window.sizeX", screen::GetScreenWidth() / 4.0f);
m_fMenuSize.y = gConfig.GetValue("window.sizeY", screen::GetScreenHeight() / 1.2f);
srand(CTimer::m_snTimeInMilliseconds);
@ -179,3 +178,10 @@ void CheatMenu::ApplyStyle()
style->Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.06f, 0.05f, 0.06f, 0.95f);
style->Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.6f);
}
void CheatMenu::ResetMenuSize()
{
m_fMenuSize.x = screen::GetScreenWidth() / 4.0f;
m_fMenuSize.y = screen::GetScreenHeight() / 1.2f;
m_bSizeChangedExternal = true;
}

View File

@ -25,6 +25,7 @@ class CheatMenu : Hook, Animation, Game, Menu, Ped, Player, Teleport, Vehicle, V
private:
static inline bool m_bShowMenu = false;
static inline ImVec2 m_fMenuSize = ImVec2(screen::GetScreenWidth() / 4, screen::GetScreenHeight() / 1.2);
static inline bool m_bSizeChangedExternal = false;
static inline CallbackTable header{
{"Teleport", &Teleport::Draw}, {"Player", &Player::Draw}, {"Ped", &Ped::Draw},
@ -42,4 +43,6 @@ private:
public:
CheatMenu();
static void ResetMenuSize();
};

View File

@ -4,6 +4,7 @@
#include "ui.h"
#include "util.h"
#include "updater.h"
#include "cheatmenu.h"
#ifdef GTASA
#include "teleport.h"
@ -343,6 +344,20 @@ void Menu::ProcessCommands()
void Menu::Draw()
{
ImGui::Spacing();
if (ImGui::Button("Reset config", ImVec2(Ui::GetSize(2))))
{
gConfig.m_Data.clear();
SetHelpMessage("Config reset", false, false, false);
}
ImGui::SameLine();
if (ImGui::Button("Reset size", ImVec2(Ui::GetSize(2))))
{
CheatMenu::ResetMenuSize();
SetHelpMessage("Menu size reset", false, false, false);
}
ImGui::Spacing();
if (ImGui::BeginTabBar("Menu", ImGuiTabBarFlags_NoTooltip + ImGuiTabBarFlags_FittingPolicyScroll))
{
if (ImGui::BeginTabItem("Overlay"))

View File

@ -227,29 +227,52 @@ void Ui::CenterdText(const std::string& text)
void Ui::DrawHeaders(CallbackTable& data)
{
static void* pCallback;
static int buttonInRow = 3;
ImVec2 size = GetSize(buttonInRow, false);
ImVec2 size = GetSize(3, false);
ImGuiStyle &style = ImGui::GetStyle();
ImVec4 buttonCol = style.Colors[ImGuiCol_Button];
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
ImGui::PushFont(FontMgr::GetFont("header"));
ImDrawList *pDrawList = ImGui::GetWindowDrawList();
for (int i = 0; i < data.size(); ++i)
{
const char* btn_text = data[i].first.c_str();
if (btn_text == m_HeaderId)
ImVec4 color;
if (i == m_HeaderId)
{
style.Colors[ImGuiCol_Button] = style.Colors[ImGuiCol_ButtonActive];
color = style.Colors[ImGuiCol_ButtonActive];
pCallback = data[i].second;
}
if (ImGui::Button(btn_text, size))
else
{
m_HeaderId = btn_text;
gConfig.SetValue("window.id", m_HeaderId);
color = style.Colors[ImGuiCol_Button];
}
if (ImGui::InvisibleButton(btn_text, size))
{
m_HeaderId = i;
gConfig.SetValue("window.idnum", m_HeaderId);
pCallback = data[i].second;
}
style.Colors[ImGuiCol_Button] = buttonCol;
if (ImGui::IsItemHovered())
{
color = style.Colors[ImGuiCol_ButtonHovered];
}
// hardcoded
ImDrawFlags flags = ImDrawFlags_RoundCornersNone;
if (i == 0) flags = ImDrawFlags_RoundCornersTopLeft;
if (i == 2) flags = ImDrawFlags_RoundCornersTopRight;
if (i == 6) flags = ImDrawFlags_RoundCornersBottomLeft;
if (i == 8) flags = ImDrawFlags_RoundCornersBottomRight;
ImVec2 min = ImGui::GetItemRectMin();
ImVec2 max = ImGui::GetItemRectMax();
ImVec2 size = ImGui::CalcTextSize(btn_text);
pDrawList->AddRectFilled(min, max, ImGui::GetColorU32(color), style.FrameRounding, flags);
ImGui::RenderTextClipped(min + style.FramePadding, max - style.FramePadding, btn_text, NULL, &size, style.ButtonTextAlign);
if (i % 3 != 2)
{
@ -260,7 +283,7 @@ void Ui::DrawHeaders(CallbackTable& data)
ImGui::PopStyleVar();
ImGui::Dummy(ImVec2(0, 10));
if (m_HeaderId == "")
if (m_HeaderId == -1)
{
// Show Welcome page
ImGui::NewLine();
@ -530,7 +553,7 @@ void Ui::DrawJSON(ResourceStore& data,
if (ImGui::IsItemClicked(1) && func_right_click != nullptr)
{
jsonPopup.function = func_right_click;
jsonPopup.rootKey = root.key();
jsonPopup.root = root.key();
jsonPopup.key = name;
jsonPopup.value = _data.value();
}
@ -546,7 +569,7 @@ void Ui::DrawJSON(ResourceStore& data,
ImGui::Text(jsonPopup.key.c_str());
ImGui::Separator();
if (ImGui::MenuItem("Remove"))
jsonPopup.function(jsonPopup.rootKey, jsonPopup.key, jsonPopup.value);
jsonPopup.function(jsonPopup.root, jsonPopup.key, jsonPopup.value);
if (ImGui::MenuItem("Close"))
@ -966,7 +989,9 @@ bool Ui::ColorButton(int color_id, std::vector<float>& color, ImVec2 size)
std::string label = "Color " + std::to_string(color_id);
if (ImGui::ColorButton(label.c_str(), ImVec4(color[0], color[1], color[2], 1), 0, size))
{
rtn = true;
}
if (ImGui::IsItemHovered())
{

View File

@ -1,6 +1,7 @@
#pragma once
#include "pch.h"
// TODO: Fix this messy code
class Ui
{
public:
@ -20,7 +21,7 @@ public:
{
std::function<void(std::string&, std::string&, std::string&)> function;
std::string key;
std::string rootKey;
std::string root;
std::string value;
};
@ -29,7 +30,7 @@ public:
std::function<void(std::string&)> function;
std::string value;
};
static inline std::string m_HeaderId;
static inline int m_HeaderId;
static inline JsonPopUpData jsonPopup;
static inline ImgPopUpData imgPopup;
@ -96,7 +97,9 @@ void Ui::EditAddress(const char* label, const int address, const int min, const
int items = 3;
if (min == def)
{
items = 2;
}
ImGui::Columns(items, nullptr, false);
ImGui::Text(("Min: " + std::to_string(min)).c_str());
@ -114,31 +117,43 @@ void Ui::EditAddress(const char* label, const int address, const int min, const
ImGui::Spacing();
if (ImGui::InputInt(("Set value##" + std::string(label)).c_str(), &val))
{
patch::Set<T>(address, val, false);
}
ImGui::Spacing();
if (val < min)
{
val = min;
}
if (val > max)
{
val = max;
}
if (ImGui::Button(("Minimum##" + std::string(label)).c_str(), GetSize(items)))
{
patch::Set<T>(address, min, false);
}
if (items == 3)
{
ImGui::SameLine();
if (ImGui::Button(("Default##" + std::string(label)).c_str(), GetSize(3)))
{
patch::Set<T>(address, def, false);
}
}
ImGui::SameLine();
if (ImGui::Button(("Maximum##" + std::string(label)).c_str(), GetSize(items)))
{
patch::Set<T>(address, max, false);
}
ImGui::Spacing();
ImGui::Separator();
@ -163,22 +178,30 @@ void Ui::EditReference(const char* label, T& address, const int min, const int d
ImGui::Spacing();
if (ImGui::InputInt(("Set value##" + std::string(label)).c_str(), &val))
{
address = static_cast<float>(val);
}
ImGui::Spacing();
if (ImGui::Button(("Minimum##" + std::string(label)).c_str(), GetSize(3)))
{
address = static_cast<float>(min);
}
ImGui::SameLine();
if (ImGui::Button(("Default##" + std::string(label)).c_str(), GetSize(3)))
{
address = static_cast<float>(def);
}
ImGui::SameLine();
if (ImGui::Button(("Maximum##" + std::string(label)).c_str(), GetSize(3)))
{
address = static_cast<float>(max);
}
ImGui::Spacing();
ImGui::Separator();