Skip to content

Commit

Permalink
Values near the sliders can be edited now
Browse files Browse the repository at this point in the history
  • Loading branch information
QuestionableM committed Dec 28, 2024
1 parent 061174b commit 9272a37
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 16 deletions.
57 changes: 47 additions & 10 deletions Code/BetterPaintToolGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@ void BetterPaintToolGui::colorBScrollChangePosition(MyGUI::ScrollBar* _sender, s
this->updateColorSlider("ScrollB");
}

void BetterPaintToolGui::colorREditTextChanged(MyGUI::EditBox* _sender)
{
this->updateColorSliderFromTextInput("ScrollR");
}

void BetterPaintToolGui::colorGEditTextChanged(MyGUI::EditBox* _sender)
{
this->updateColorSliderFromTextInput("ScrollG");
}

void BetterPaintToolGui::colorBEditTextChanged(MyGUI::EditBox* _sender)
{
this->updateColorSliderFromTextInput("ScrollB");
}

void BetterPaintToolGui::eventPresetColorsTabPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id)
{
if (_sender->castType<MyGUI::Button>()->getStateSelected())
Expand Down Expand Up @@ -174,7 +189,7 @@ void BetterPaintToolGui::getSliderData(MyGUI::Widget* slider_parent, SliderData*
{
p_sliderData->slider = slider_parent->findWidget("Slider")->castType<MyGUI::ScrollBar>();
p_sliderData->name = slider_parent->findWidget("Name")->castType<MyGUI::TextBox>();
p_sliderData->value = slider_parent->findWidget("Value")->castType<MyGUI::TextBox>();
p_sliderData->value = slider_parent->findWidget("Value")->castType<MyGUI::EditBox>();
}

Color BetterPaintToolGui::getColorFromSliders()
Expand Down Expand Up @@ -257,10 +272,12 @@ MyGUI::Widget* BetterPaintToolGui::getHexInputBox()
void BetterPaintToolGui::setupColorSlider(
const std::string& widget_name,
const std::string& visual_name,
t_scroll_callback_sig callback)
t_scroll_callback_sig callback,
t_edit_text_callback_sig edit_text_callback)
{
MyGUI::Widget* v_pSliderHolder = m_pMainPanel->findWidget(widget_name);
MyGUI::Singleton<MyGUI::LayoutManager>::getInstancePtr()->loadLayout("$GAME_DATA/Gui/Layouts/Options/OptionsItem_Slider.layout", "", v_pSliderHolder);
MyGUI::Singleton<MyGUI::LayoutManager>::getInstancePtr()->loadLayout(
"$GAME_DATA/Gui/Layouts/Tool/Tool_PaintTool_Slider_DLL_Injected.layout", "", v_pSliderHolder);

SliderData v_slider;
this->getSliderData(v_pSliderHolder, &v_slider);
Expand All @@ -271,8 +288,31 @@ void BetterPaintToolGui::setupColorSlider(

v_slider.name->setCaption(visual_name);
v_slider.value->setCaption("0");
v_slider.value->setNeedKeyFocus(true);
v_slider.value->setNeedMouseFocus(true);
v_slider.value->setMaxTextLength(3);

v_slider.slider->eventScrollChangePosition += MyGUI::newDelegate(this, callback);
v_slider.value->eventEditTextChange += MyGUI::newDelegate(this, edit_text_callback);
}

void BetterPaintToolGui::updateHexInputAndColorPickersFromSliders()
{
const Color v_sliderColor = this->getColorFromSliders();
this->updateHexValueFromColor(v_sliderColor);
this->updateHsvAndColorPickersFromColor(v_sliderColor);
}

void BetterPaintToolGui::updateColorSliderFromTextInput(const std::string& widget_name)
{
SliderData v_slider;
this->getSliderData(m_pMainPanel->findWidget(widget_name), &v_slider);

const std::string& v_textValue = v_slider.value->getCaption().asUTF8();
const std::size_t v_scrollPos = std::min<std::size_t>(std::strtoull(v_textValue.c_str(), nullptr, 10), 255);
v_slider.slider->setScrollPosition(v_scrollPos);

this->updateHexInputAndColorPickersFromSliders();
}

void BetterPaintToolGui::updateColorSlider(const std::string& widget_name)
Expand All @@ -283,10 +323,7 @@ void BetterPaintToolGui::updateColorSlider(const std::string& widget_name)
const std::size_t v_pos = v_slider.slider->getScrollPosition();
v_slider.value->setCaption(std::to_string(v_pos));

const Color v_slider_color = this->getColorFromSliders();

this->updateHexValueFromColor(v_slider_color);
this->updateHsvAndColorPickersFromColor(v_slider_color);
this->updateHexInputAndColorPickersFromSliders();
}

void BetterPaintToolGui::setColorSliderPos(const std::string& widget_name, std::size_t value)
Expand Down Expand Up @@ -447,9 +484,9 @@ void BetterPaintToolGui::initializeHooked()

{
//Setup the scroll bars
this->setupColorSlider("ScrollR", "Red", &BetterPaintToolGui::colorRScrollChangePosition);
this->setupColorSlider("ScrollG", "Green", &BetterPaintToolGui::colorGScrollChangePosition);
this->setupColorSlider("ScrollB", "Blue", &BetterPaintToolGui::colorBScrollChangePosition);
this->setupColorSlider("ScrollR", "Red", &BetterPaintToolGui::colorRScrollChangePosition, &BetterPaintToolGui::colorREditTextChanged);
this->setupColorSlider("ScrollG", "Green", &BetterPaintToolGui::colorGScrollChangePosition, &BetterPaintToolGui::colorGEditTextChanged);
this->setupColorSlider("ScrollB", "Blue", &BetterPaintToolGui::colorBScrollChangePosition, &BetterPaintToolGui::colorBEditTextChanged);
}

{
Expand Down
14 changes: 12 additions & 2 deletions Code/BetterPaintToolGui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ struct SliderData
{
MyGUI::ScrollBar* slider;
MyGUI::TextBox* name;
MyGUI::TextBox* value;
MyGUI::EditBox* value;
};

class BetterPaintTool;
Expand All @@ -17,6 +17,7 @@ class BetterPaintToolGui : public PaintToolGui
public:
using t_init_func_sig = void(*)(BetterPaintToolGui*);
using t_scroll_callback_sig = void(BetterPaintToolGui::*)(MyGUI::ScrollBar*, size_t);
using t_edit_text_callback_sig = void(BetterPaintToolGui::*)(MyGUI::EditBox*);

//MYGUI callbacks
void requestCoordItem(MyGUI::ItemBox* _sender, MyGUI::IntCoord& _coord, bool _drag);
Expand All @@ -29,6 +30,9 @@ class BetterPaintToolGui : public PaintToolGui
void colorRScrollChangePosition(MyGUI::ScrollBar* _sender, size_t _position);
void colorGScrollChangePosition(MyGUI::ScrollBar* _sender, size_t _position);
void colorBScrollChangePosition(MyGUI::ScrollBar* _sender, size_t _position);
void colorREditTextChanged(MyGUI::EditBox* _sender);
void colorGEditTextChanged(MyGUI::EditBox* _sender);
void colorBEditTextChanged(MyGUI::EditBox* _sender);
void eventPresetColorsTabPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);
void eventCustomColorTabPressed(MyGUI::Widget* _sender, int _left, int _top, MyGUI::MouseButton _id);

Expand All @@ -51,7 +55,13 @@ class BetterPaintToolGui : public PaintToolGui
MyGUI::Widget* getHexInputBox();

//Color slider functions
void setupColorSlider(const std::string& widget_name, const std::string& visual_name, t_scroll_callback_sig callback);
void setupColorSlider(
const std::string& widget_name,
const std::string& visual_name,
t_scroll_callback_sig callback,
t_edit_text_callback_sig edit_text_callback);
void updateColorSliderFromTextInput(const std::string& widget_name);
void updateHexInputAndColorPickersFromSliders();
void updateColorSlider(const std::string& widget_name);
void setColorSliderPos(const std::string& widget_name, std::size_t value);

Expand Down
43 changes: 39 additions & 4 deletions Code/CustomPaintToolGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#include <fstream>

std::string CustomPaintToolGui::CustomLayoutPath = "$GAME_DATA/Gui/Layouts/Tool/Tool_PaintTool_DLL_Injected.layout";
std::string CustomPaintToolGui::CustomLayoutSliderPath = "$GAME_DATA/Gui/Layouts/Tool/Tool_PaintTool_Slider_DLL_Injected.layout";

std::string CustomPaintToolGui::getCustomPaintToolGuiString()
{
const char file_data[] =
static const char file_data[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<MyGUI type=\"Layout\" version=\"3.2.0\">"
"\t<Widget type=\"Widget\" skin=\"PanelEmpty\" name=\"MainPanel\" position_real=\"0 0 0.3125 0.36944444444444446\">"
Expand Down Expand Up @@ -93,6 +94,39 @@ std::string CustomPaintToolGui::getCustomPaintToolGuiString()
return std::string(file_data, sizeof(file_data) - 1);
}

std::string CustomPaintToolGui::getCustomPaintToolSliderGuiString()
{
static const char v_fileData[] =
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
"<MyGUI type=\"Layout\" version=\"3.2.0\">"
"\t<Widget type=\"TextBox\" skin=\"TextBox\" name=\"Name\" position_real=\"0 0 0.350877 1\">"
"\t\t<Property key=\"Caption\" value=\"LABEL\" />"
"\t\t<Property key=\"FontName\" value=\"SM_TextLabel\" />"
"\t\t<Property key=\"TextAlign\" value=\"Left VCenter\" />"
"\t\t<Property key=\"NeedMouse\" value=\"false\" />"
"\t</Widget>"
"\t<Widget type=\"Widget\" skin=\"WhiteSkin\" name=\"Line\" position_real=\"0 1 0.991228 0.025\">"
"\t\t<Property key=\"Alpha\" value=\"0.05\" />"
"\t\t<Property key=\"NeedMouse\" value=\"false\" />"
"\t\t<Property key=\"NeedKey\" value=\"false\" />"
"\t</Widget>"
"\t<Widget type=\"ScrollBar\" skin=\"InventoryHSlider\" name=\"Slider\" position_real=\"0.412281 0.25 0.587719 0.45\">"
"\t\t<Property key=\"Range\" value=\"101\" />"
"\t</Widget>"
"\t<Widget type=\"EditBox\" skin=\"EditBoxEmpty\" name=\"Value\" position_real=\"0.223684 0.25 0.175439 0.5\">"
"\t\t<Property key=\"FontName\" value=\"SM_ListItem\" />"
"\t\t<Property key=\"Caption\" value=\"-1234567890\" />"
"\t\t<Property key=\"TextAlign\" value=\"Right VCenter\" />"
"\t\t<Property key=\"NeedKey\" value=\"true\" />"
"\t\t<Property key=\"NeedMouse\" value=\"true\" />"
"\t\t<Property key=\"TextColour\" value=\"1 0.831373 0.290196\" />"
"\t</Widget>"
"\t<CodeGeneratorSettings />"
"</MyGUI>";

return std::string(v_fileData, sizeof(v_fileData) - 1);
}

bool file_exists(const std::string& path)
{
std::string v_replaced_path = path;
Expand All @@ -118,8 +152,9 @@ void write_string_to_file(const std::string& path, const std::string& data)

void CustomPaintToolGui::writeIfNotExists()
{
if (file_exists(CustomPaintToolGui::CustomLayoutPath))
return;
if (!file_exists(CustomPaintToolGui::CustomLayoutPath))
write_string_to_file(CustomPaintToolGui::CustomLayoutPath, CustomPaintToolGui::getCustomPaintToolGuiString());

write_string_to_file(CustomPaintToolGui::CustomLayoutPath, CustomPaintToolGui::getCustomPaintToolGuiString());
if (!file_exists(CustomPaintToolGui::CustomLayoutSliderPath))
write_string_to_file(CustomPaintToolGui::CustomLayoutSliderPath, CustomPaintToolGui::getCustomPaintToolSliderGuiString());
}
2 changes: 2 additions & 0 deletions Code/CustomPaintToolGui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ class CustomPaintToolGui
{
public:
static std::string CustomLayoutPath;
static std::string CustomLayoutSliderPath;

static std::string getCustomPaintToolGuiString();
static std::string getCustomPaintToolSliderGuiString();

static void writeIfNotExists();
};
26 changes: 26 additions & 0 deletions Layout/OptionsItem_Slider.layout
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" ?>
<MyGUI type="Layout" version="3.2.0">
<Widget type="TextBox" skin="TextBox" name="Name" position_real="0 0 0.350877 1">
<Property key="Caption" value="LABEL" />
<Property key="FontName" value="SM_TextLabel" />
<Property key="TextAlign" value="Left VCenter" />
<Property key="NeedMouse" value="false" />
</Widget>
<Widget type="Widget" skin="WhiteSkin" name="Line" position_real="0 1 0.991228 0.025">
<Property key="Alpha" value="0.05" />
<Property key="NeedMouse" value="false" />
<Property key="NeedKey" value="false" />
</Widget>
<Widget type="ScrollBar" skin="InventoryHSlider" name="Slider" position_real="0.412281 0.25 0.587719 0.45">
<Property key="Range" value="101" />
</Widget>
<Widget type="EditBox" skin="EditBoxEmpty" name="Value" position_real="0.223684 0.25 0.175439 0.5">
<Property key="FontName" value="SM_ListItem" />
<Property key="Caption" value="-1234567890" />
<Property key="TextAlign" value="Right VCenter" />
<Property key="NeedKey" value="true" />
<Property key="NeedMouse" value="true" />
<Property key="TextColour" value="1 0.831373 0.290196" />
</Widget>
<CodeGeneratorSettings />
</MyGUI>

0 comments on commit 9272a37

Please sign in to comment.