mirror of
https://github.com/hedge-dev/UnleashedRecomp.git
synced 2025-10-30 07:11:05 +00:00
reddog: implemented custom button
This commit is contained in:
parent
72a0507c66
commit
892e24f71e
5 changed files with 93 additions and 10 deletions
|
|
@ -468,8 +468,10 @@ BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/re
|
|||
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/reddog/button_pin_2.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/reddog/button_pin_2.dds" ARRAY_NAME "g_button_pin_2")
|
||||
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/reddog/checkbox_1.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/reddog/checkbox_1.dds" ARRAY_NAME "g_checkbox_1")
|
||||
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/reddog/checkbox_2.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/reddog/checkbox_2.dds" ARRAY_NAME "g_checkbox_2")
|
||||
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/reddog/debug_icon.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/reddog/debug_icon.dds" ARRAY_NAME "g_debug_icon")
|
||||
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/reddog/common_button_1.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/reddog/common_button_1.dds" ARRAY_NAME "g_common_button_1")
|
||||
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/reddog/common_button_2.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/reddog/common_button_2.dds" ARRAY_NAME "g_common_button_2")
|
||||
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/reddog/common_icon.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/reddog/common_icon.dds" ARRAY_NAME "g_common_icon")
|
||||
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/reddog/debug_icon.dds" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/reddog/debug_icon.dds" ARRAY_NAME "g_debug_icon")
|
||||
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/reddog/mouse_cursor.bmp" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/reddog/mouse_cursor.bmp" ARRAY_NAME "g_mouse_cursor")
|
||||
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/reddog/mouse_cursor_h.bmp" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/reddog/mouse_cursor_h.bmp" ARRAY_NAME "g_mouse_cursor_h")
|
||||
BIN2C(TARGET_OBJ UnleashedRecomp SOURCE_FILE "${RESOURCES_SOURCE_PATH}/images/reddog/mouse_cursor_slant_l.bmp" DEST_FILE "${RESOURCES_OUTPUT_PATH}/images/reddog/mouse_cursor_slant_l.bmp" ARRAY_NAME "g_mouse_cursor_slant_l")
|
||||
|
|
|
|||
|
|
@ -490,6 +490,8 @@ void GameWindow::ResetDimensions()
|
|||
Config::WindowY = s_y;
|
||||
Config::WindowWidth = s_width;
|
||||
Config::WindowHeight = s_height;
|
||||
|
||||
SetDimensions(s_width, s_height, s_x, s_y);
|
||||
}
|
||||
|
||||
uint32_t GameWindow::GetWindowFlags()
|
||||
|
|
|
|||
|
|
@ -1,23 +1,78 @@
|
|||
#include "reddog_controls.h"
|
||||
#include <gpu/video.h>
|
||||
#include <ui/imgui_utils.h>
|
||||
|
||||
#include <res/images/reddog/checkbox_1.dds.h>
|
||||
#include <res/images/reddog/checkbox_2.dds.h>
|
||||
#include <res/images/reddog/common_button_1.dds.h>
|
||||
#include <res/images/reddog/common_button_2.dds.h>
|
||||
|
||||
constexpr float BUTTON_SIZE = 32.0f;
|
||||
constexpr float CHECKBOX_SIZE = 16.0f;
|
||||
|
||||
static std::unique_ptr<GuestTexture> g_upCheckbox1;
|
||||
static std::unique_ptr<GuestTexture> g_upCheckbox2;
|
||||
static std::unique_ptr<GuestTexture> g_upCommonButton1;
|
||||
static std::unique_ptr<GuestTexture> g_upCommonButton2;
|
||||
|
||||
void Reddog::InitControlsResources()
|
||||
{
|
||||
g_upCheckbox1 = LoadTexture(g_checkbox_1, sizeof(g_checkbox_1));
|
||||
g_upCheckbox2 = LoadTexture(g_checkbox_2, sizeof(g_checkbox_2));
|
||||
g_upCommonButton1 = LoadTexture(g_common_button_1, sizeof(g_common_button_1));
|
||||
g_upCommonButton2 = LoadTexture(g_common_button_2, sizeof(g_common_button_2));
|
||||
}
|
||||
|
||||
bool Reddog::Button(const char* label)
|
||||
{
|
||||
auto window = ImGui::GetCurrentWindow();
|
||||
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
||||
auto& ctx = *GImGui;
|
||||
auto& style = ctx.Style;
|
||||
auto id = window->GetID(label);
|
||||
auto pos = window->DC.CursorPos;
|
||||
|
||||
ImVec2 labelSize = { 0, 0 };
|
||||
|
||||
if (label && label[0] != '\0')
|
||||
labelSize = ImGui::CalcTextSize(label, nullptr, true);
|
||||
|
||||
ImVec2 size = { BUTTON_SIZE + labelSize.x, BUTTON_SIZE };
|
||||
ImRect rect(pos, { pos.x + size.x, pos.y + size.y });
|
||||
ImRect paddedRect({ rect.Min.x, rect.Min.y - 1 }, { rect.Max.x, rect.Max.y + 1 });
|
||||
|
||||
ImGui::ItemSize(paddedRect, style.FramePadding.y);
|
||||
|
||||
if (!ImGui::ItemAdd(rect, id))
|
||||
return false;
|
||||
|
||||
bool isHovered, isHeld;
|
||||
bool isPressed = ImGui::ButtonBehavior(rect, id, &isHovered, &isHeld);
|
||||
|
||||
auto texture = isHeld && isHovered
|
||||
? g_upCommonButton2.get()
|
||||
: g_upCommonButton1.get();
|
||||
|
||||
auto left = PIXELS_TO_UV_COORDS(32, 32, 0, 0, 9, 32);
|
||||
auto centre = PIXELS_TO_UV_COORDS(32, 32, 9, 0, 14, 32);
|
||||
auto right = PIXELS_TO_UV_COORDS(32, 32, 23, 0, 9, 32);
|
||||
|
||||
window->DrawList->AddImage(texture, rect.Min, { rect.Min.x + 9, rect.Max.y }, GET_UV_COORDS(left));
|
||||
window->DrawList->AddImage(texture, { rect.Min.x + 9, rect.Min.y }, { rect.Max.x - 9, rect.Max.y }, GET_UV_COORDS(centre));
|
||||
window->DrawList->AddImage(texture, { rect.Max.x - 9, rect.Min.y }, rect.Max, GET_UV_COORDS(right));
|
||||
|
||||
if (label && label[0] != '\0')
|
||||
ImGui::RenderText({ rect.Min.x + (size.x - labelSize.x) * 0.5f, rect.Min.y + (size.y - labelSize.y) * 0.5f }, label);
|
||||
|
||||
return isPressed;
|
||||
}
|
||||
|
||||
bool Reddog::Checkbox(const char* label, bool* v)
|
||||
{
|
||||
ImGuiWindow* window = ImGui::GetCurrentWindow();
|
||||
auto window = ImGui::GetCurrentWindow();
|
||||
|
||||
if (window->SkipItems)
|
||||
return false;
|
||||
|
|
@ -29,16 +84,16 @@ bool Reddog::Checkbox(const char* label, bool* v)
|
|||
auto pos = window->DC.CursorPos;
|
||||
|
||||
ImVec2 size = { CHECKBOX_SIZE, CHECKBOX_SIZE };
|
||||
ImRect checkBoundingBox(pos, ImVec2(pos.x + size.x, pos.y + size.y));
|
||||
ImRect totalBoundingBox(pos, ImVec2(pos.x + size.x + (labelSize.x > 0.0f ? style.ItemInnerSpacing.x + labelSize.x : 0.0f), pos.y + size.y));
|
||||
ImRect testRect(pos, { pos.x + size.x, pos.y + size.y });
|
||||
ImRect totalRect(pos, { pos.x + size.x + (labelSize.x > 0.0f ? style.ItemInnerSpacing.x + labelSize.x : 0.0f), pos.y + size.y });
|
||||
|
||||
ImGui::ItemSize(totalBoundingBox, style.FramePadding.y);
|
||||
ImGui::ItemSize(totalRect, style.FramePadding.y);
|
||||
|
||||
if (!ImGui::ItemAdd(totalBoundingBox, id))
|
||||
if (!ImGui::ItemAdd(totalRect, id))
|
||||
return false;
|
||||
|
||||
bool isHovered, isHeld;
|
||||
bool isPressed = ImGui::ButtonBehavior(checkBoundingBox, id, &isHovered, &isHeld);
|
||||
bool isPressed = ImGui::ButtonBehavior(testRect, id, &isHovered, &isHeld);
|
||||
|
||||
if (isPressed)
|
||||
{
|
||||
|
|
@ -50,10 +105,17 @@ bool Reddog::Checkbox(const char* label, bool* v)
|
|||
? g_upCheckbox2.get()
|
||||
: g_upCheckbox1.get();
|
||||
|
||||
window->DrawList->AddImage(texture, checkBoundingBox.Min, checkBoundingBox.Max);
|
||||
window->DrawList->AddImage(texture, testRect.Min, testRect.Max);
|
||||
|
||||
if (labelSize.x > 0.0f)
|
||||
ImGui::RenderText({ checkBoundingBox.Max.x + style.ItemInnerSpacing.x, checkBoundingBox.Min.y + style.FramePadding.y }, label);
|
||||
ImGui::RenderText({ testRect.Max.x + style.ItemInnerSpacing.x, testRect.Min.y + style.FramePadding.y }, label);
|
||||
|
||||
return isPressed;
|
||||
}
|
||||
|
||||
void Reddog::Separator(float upperPadding, float lowerPadding)
|
||||
{
|
||||
ImGui::Dummy(ImVec2(0.0f, upperPadding));
|
||||
ImGui::Separator();
|
||||
ImGui::Dummy(ImVec2(0.0f, lowerPadding));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,5 +3,7 @@
|
|||
namespace Reddog
|
||||
{
|
||||
void InitControlsResources();
|
||||
bool Button(const char* label);
|
||||
bool Checkbox(const char* label, bool* v);
|
||||
void Separator(float upperPadding = 0, float lowerPadding = 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
#include "view_window.h"
|
||||
#include <kernel/memory.h>
|
||||
#include <ui/reddog/reddog_controls.h>
|
||||
#include <ui/game_window.h>
|
||||
#include <user/config.h>
|
||||
|
||||
static ViewWindow g_window{ "View" };
|
||||
|
||||
|
|
@ -8,7 +10,20 @@ void ViewWindow::Draw()
|
|||
{
|
||||
if (Begin())
|
||||
{
|
||||
Reddog::Checkbox("Render HUD", (bool*)g_memory.Translate(0x8328BB26));
|
||||
Reddog::Checkbox("Draw HUD (F8)", (bool*)g_memory.Translate(0x8328BB26));
|
||||
Reddog::Separator();
|
||||
|
||||
if (Reddog::Button("Reset Window Dimensions (F2)"))
|
||||
{
|
||||
Config::Fullscreen = GameWindow::SetFullscreen(false);
|
||||
GameWindow::ResetDimensions();
|
||||
}
|
||||
|
||||
if (Reddog::Button("Recentre Window (F3)"))
|
||||
{
|
||||
if (!GameWindow::IsFullscreen())
|
||||
GameWindow::SetDimensions(GameWindow::s_width, GameWindow::s_height);
|
||||
}
|
||||
}
|
||||
End();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue