Initial commit

This commit is contained in:
Hash Borgir
2024-04-16 21:45:38 -06:00
commit 3159020c38
533 changed files with 135446 additions and 0 deletions

View File

@@ -0,0 +1,91 @@
#pragma once
#include <d2tweaks/ui/controls/control.h>
#include <d2tweaks/ui/rect.h>
#include <cstdint>
#include <functional>
#include <pugixml.hpp>
namespace diablo2 {
namespace structures {
struct cell_file;
}
}
namespace d2_tweaks {
namespace common {
class asset;
}
namespace ui {
namespace controls {
class image;
class button final : public control {
rect m_rect;
image* m_image;
int32_t m_frame_down;
int32_t m_frame_up;
int32_t m_click_sound;
bool m_is_down;
int32_t m_current_frame;
uint32_t m_res_count;
std::wstring m_popup;
std::function<void()> m_on_click;
std::vector<respos> m_respos;
public:
button(menu* menu, const rect& rect, const std::function<void()>& onClick,
common::asset* image, int32_t frameDown, int32_t frameUp, int32_t clickSound = -1);
explicit button(menu* menu, const pugi::xml_node& node);
virtual ~button();
void set_x(int32_t value) override;
int32_t get_x() const override {
return m_rect.get_x();
}
void set_y(int32_t value) override;
int32_t get_y() const override {
return m_rect.get_y();
}
std::wstring popup() const {
return m_popup;
}
void set_popup(const std::wstring& popup) {
m_popup = popup;
}
void set_current_frame(int32_t value) {
m_current_frame = value;
}
int32_t get_current_frame() {
return m_current_frame;
}
std::function<void()> get_on_click() const {
return m_on_click;
}
void set_on_click(const std::function<void()>& on_click) {
m_on_click = on_click;
}
void draw() override;
void draw(int32_t offsetX, int32_t offsetY) override;
void left_mouse(int32_t offsetX, int32_t offsetY, bool up, bool& block) override;
void right_mouse(int32_t offsetX, int32_t offsetY, bool up, bool& block) override;
void key_event(int32_t offsetX, int32_t offsetY, uint32_t key, bool up, bool& block) override;
};
}
}
}

View File

@@ -0,0 +1,85 @@
#pragma once
#include <d2tweaks/ui/controls/control.h>
#include <pugixml.hpp>
#include <functional>
#include <d2tweaks/ui/rect.h>
namespace d2_tweaks {
namespace common {
class asset;
}
}
namespace d2_tweaks {
namespace ui {
namespace controls {
class image;
class label;
class checkbox : public control {
rect m_rect;
image* m_image;
label* m_label;
std::wstring m_popup;
int32_t m_frame_checked;
int32_t m_frame_unchecked;
int32_t m_click_sound;
bool m_is_down;
bool m_state;
std::function<void(bool)> m_on_click;
public:
explicit checkbox(menu* menu, const std::wstring& text, const rect& rect, const std::function<void()>& onClick,
common::asset* image, int32_t frameChecked, int32_t frameUnchecked, int32_t clickSound = -1);
explicit checkbox(menu* menu, const pugi::xml_node& node);
void set_x(int32_t value) override;
int32_t get_x() const override {
return m_rect.get_x();
}
void set_y(int32_t value) override;
int32_t get_y() const override {
return m_rect.get_y();
}
std::wstring popup() const {
return m_popup;
}
void set_popup(const std::wstring& popup) {
m_popup = popup;
}
std::function<void(bool)> get_on_click() const {
return m_on_click;
}
void set_on_click(const std::function<void(bool)>& on_click) {
m_on_click = on_click;
}
bool get_state() const {
return m_state;
}
void set_state(bool value) {
m_state = value;
}
void draw() override;
void draw(int32_t offsetX, int32_t offsetY) override;
void left_mouse(int32_t offsetX, int32_t offsetY, bool up, bool& block) override;
void right_mouse(int32_t offsetX, int32_t offsetY, bool up, bool& block) override;
void key_event(int32_t offsetX, int32_t offsetY, uint32_t key, bool up, bool& block) override;
};
}
}
}

View File

@@ -0,0 +1,120 @@
#pragma once
#include <string>
#include <cstdint>
namespace d2_tweaks {
namespace ui {
class menu;
namespace controls {
struct respos {
uint32_t res_x;
uint32_t res_y;
uint32_t pos_x;
uint32_t pos_y;
};
class control {
control* m_parent;
menu* m_menu;
std::string m_name;
bool m_enabled = false;
bool m_visible = false;
int32_t m_x;
int32_t m_y;
int32_t m_width;
int32_t m_height;
public:
control(menu* menu, int32_t x, int32_t y, int32_t w, int32_t h) : m_parent(nullptr),
m_menu(menu),
m_x(x), m_y(y),
m_width(w), m_height(h) {}
virtual ~control() = default;
control* get_parent() const {
return m_parent;
}
void set_parent(control* const parent) {
m_parent = parent;
}
menu* get_menu() const {
return m_menu;
}
void set_menu(menu* const menu) {
m_menu = menu;
}
std::string get_name() const {
return m_name;
}
void set_name(const std::string& name) {
m_name = name;
}
virtual bool get_enabled() const {
return m_enabled;
}
virtual void set_enabled(bool value) {
m_enabled = value;
}
virtual bool get_visible() const {
return m_visible;
}
virtual void set_visible(bool value) {
m_visible = value;
}
virtual int32_t get_x() const {
return m_x;
}
virtual void set_x(int32_t value) {
m_x = value;
}
virtual int32_t get_y() const {
return m_y;
}
virtual void set_y(int32_t value) {
m_y = value;
}
virtual int32_t get_width() const {
return m_width;
}
virtual void set_width(const int32_t width) {
m_width = width;
}
virtual int32_t get_height() const {
return m_height;
}
virtual void set_height(const int32_t height) {
m_height = height;
}
virtual void draw() = 0;
virtual void draw(int32_t offsetX, int32_t offsetY) = 0;
virtual void left_mouse(int32_t offsetX, int32_t offsetY, bool up, bool& block) = 0;
virtual void right_mouse(int32_t offsetX, int32_t offsetY, bool up, bool& block) = 0;
virtual void key_event(int32_t offsetX, int32_t offsetY, uint32_t key, bool up, bool& block) = 0;
};
}
}
}

View File

@@ -0,0 +1,31 @@
#pragma once
#include <d2tweaks/ui/controls/control.h>
#include <pugixml.hpp>
#include <vector>
namespace d2_tweaks {
namespace ui {
class menu;
namespace controls {
class group : public control {
std::vector<control*> m_controls;
public:
explicit group(menu* menu, int32_t x, int32_t y);
explicit group(menu* menu, const pugi::xml_node& node);
void draw() override;
void draw(int32_t offsetX, int32_t offsetY) override;
void left_mouse(int32_t offsetX, int32_t offsetY, bool up, bool& block) override;
void right_mouse(int32_t offsetX, int32_t offsetY, bool up, bool& block) override;
void key_event(int32_t offsetX, int32_t offsetY, uint32_t key, bool up, bool& block) override;
private:
void add_control(control* control);
};
}
}
}

View File

@@ -0,0 +1,45 @@
#pragma once
#include <d2tweaks/ui/controls/control.h>
#include <diablo2/structures/gfxdata.h>
#include <pugixml.hpp>
#include <d2tweaks/ui/rect.h>
namespace d2_tweaks {
namespace common {
class asset;
}
namespace ui {
namespace controls {
class image : public control {
common::asset* m_image;
int32_t m_frame;
rect m_rect;
bool m_block_click;
diablo2::structures::gfxdata m_draw_info;
public:
explicit image(menu* menu, common::asset* image, int32_t x = 0, int32_t y = 0, int32_t frame = 0);
explicit image(menu* menu, const pugi::xml_node& node);
void set_frame(int32_t frame) {
m_frame = static_cast<uint32_t>(frame);
}
int32_t get_frame() const {
return static_cast<int32_t>(m_frame);
}
void draw() override;
void draw(int32_t offsetX, int32_t offsetY) override;
void left_mouse(int32_t offsetX, int32_t offsetY, bool up, bool& block) override;
void right_mouse(int32_t offsetX, int32_t offsetY, bool up, bool& block) override;
void key_event(int32_t offsetX, int32_t offsetY, uint32_t key, bool up, bool& block) override;
};
}
}
}

View File

@@ -0,0 +1,61 @@
#pragma once
#include <d2tweaks/ui/controls/control.h>
#include <vector>
#include <pugixml.hpp>
#include <diablo2/d2win.h>
namespace d2_tweaks {
namespace ui {
namespace controls {
class label : public control {
std::wstring m_text;
bool m_text_owned;
diablo2::ui_color_t m_color;
diablo2::ui_font_t m_font;
uint32_t m_res_count;
std::vector<respos> m_respos;
public:
explicit label(menu* menu, const std::wstring& text, int32_t x = 0, int32_t y = 0,
diablo2::ui_color_t color = diablo2::UI_COLOR_WHITE,
diablo2::ui_font_t font = diablo2::UI_FONT_16);
explicit label(menu* menu, const pugi::xml_node& node);
void set_text(const std::wstring& text) {
m_text = text;
}
const std::wstring& get_text() const {
return m_text;
}
diablo2::ui_color_t get_color() const {
return m_color;
}
void set_color(const diablo2::ui_color_t color) {
m_color = color;
}
diablo2::ui_font_t get_font() const {
return m_font;
}
void set_font(const diablo2::ui_font_t font) {
m_font = font;
}
void draw() override;
void draw(int32_t offsetX, int32_t offsetY) override;
void left_mouse(int32_t offsetX, int32_t offsetY, bool up, bool& block) override;
void right_mouse(int32_t offsetX, int32_t offsetY, bool up, bool& block) override;
void key_event(int32_t offsetX, int32_t offsetY, uint32_t key, bool up, bool& block) override;
};
}
}
}

View File

@@ -0,0 +1,88 @@
#pragma once
#include <vector>
#include <string>
#include <unordered_map>
namespace d2_tweaks {
namespace ui {
namespace controls {
class control;
}
struct respos {
uint32_t res_x;
uint32_t res_y;
uint32_t pos_x;
uint32_t pos_y;
};
class menu {
bool m_enabled = false;
bool m_visible = false;
std::string m_name;
int32_t m_x;
int32_t m_y;
int32_t m_width;
int32_t m_height;
uint32_t m_res_count;
std::vector<controls::control*> m_controls;
std::unordered_map<std::string, controls::control*> m_named_controls;
std::vector<respos> m_respos;
public:
virtual ~menu() = default;
menu();
const std::vector<controls::control*>& get_controls() const {
return m_controls;
}
const std::string& get_name() const {
return m_name;
}
virtual bool get_enabled() const {
return m_enabled;
}
virtual void set_enabled(bool value) {
m_enabled = value;
}
virtual bool get_visible() const {
return m_visible;
}
virtual void set_visible(bool value) {
m_visible = value;
}
bool load_xml(const char* path);
template<typename TControl = controls::control>
TControl* get_control(const std::string& name) {
const auto it = m_named_controls.find(name);
if (it == m_named_controls.end())
return nullptr;
return static_cast<TControl*>(it->second);
}
virtual void add_control(controls::control* control);
//virtual controls::control* get_control(const std::string& name);
virtual void remove_control(controls::control* control);
virtual void draw();
virtual bool left_mouse(bool up);
virtual bool right_mouse(bool up);
virtual bool key_event(uint32_t key, bool up);
};
}
}

View File

@@ -0,0 +1,57 @@
#pragma once
#include <cstdint>
namespace d2_tweaks {
namespace ui {
//Special ui rectangle with starting point in the left bottom corner
class rect {
int32_t m_x, m_y, m_w, m_h;
public:
rect() : m_x(0), m_y(0), m_w(0), m_h(0) {}
rect(int32_t x, int32_t y, int32_t width, int32_t height) : m_x(x), m_y(y), m_w(width), m_h(height) {}
int32_t get_x() const {
return m_x;
}
void set_x(int32_t value) {
m_x = value;
}
int32_t get_y() const {
return m_y;
}
void set_y(int32_t value) {
m_y = value;
}
void set_width(int32_t value) {
m_w = value;
}
int32_t get_width() const {
return m_w;
}
void set_height(int32_t value) {
m_h = value;
}
int32_t get_height() const {
return m_h;
}
bool contains(int32_t x, int32_t y) const {
return x >= m_x && x < m_x + m_w &&
y > m_y - m_h && y <= m_y;
}
bool contains(int32_t x, int32_t y, int32_t offsetX, int32_t offsetY) const {
return x >= m_x + offsetX && x < m_x + offsetX + m_w &&
y > m_y + offsetY - m_h && y <= m_y + offsetY;
}
};
}
}

View File

@@ -0,0 +1,39 @@
#pragma once
#include <Windows.h>
#include <fw/singleton.h>
#include <vector>
#include <string>
namespace d2_tweaks {
namespace ui {
class menu;
class ui_manager final : public singleton<ui_manager> {
std::vector<menu*> m_menus;
bool m_was_down_before_left = false;
bool m_was_down_before_right = false;
bool m_mouse_state_left = false;
bool m_mouse_state_right = false;
public:
explicit ui_manager(token);
void add_menu(menu* m);
menu* get_menu(const std::string& name);
void remove_menu(menu* m);
void draw();
private:
static LRESULT __stdcall wnd_proc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
void process_inputs();
bool process_left_mouse(bool up);
bool process_right_mouse(bool up);
bool process_key_event(uint32_t key, bool up);
};
}
}