Skip to content

Commit c30af18

Browse files
Implement merge review requests
1 parent 6a8bd48 commit c30af18

File tree

3 files changed

+25
-38
lines changed

3 files changed

+25
-38
lines changed

CubeModLoader/CWSDK

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit e42dab995860553cfdf78a3c0d8ee8da9738ee83
1+
Subproject commit 6a8ea237e2351dc296ba43d7f5093bb97fe1aa5b

CubeModLoader/ModWidget.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <process.h>
55

66
static std::string file_name = "mods-settings.cwb";
7+
static const int MODS_PER_PAGE = 7;
78
void* VTABLE[43];
89

910
mod::ModWidget* mod::ModWidget::ctor(cube::Game* game, plasma::Node* node, plasma::Node* background, std::vector<DLL*>* mods)
@@ -50,7 +51,8 @@ void mod::ModWidget::MouseUp(cube::MouseButton mouse_button)
5051
this->node->SetVisibility(false);
5152
if (this->changed)
5253
{
53-
char* argument_list[] = { "cubeworld.exe", NULL };
54+
// Restart the game
55+
char* argument_list[] = { (char *)"cubeworld.exe", NULL };
5456
_execvp("cubeworld.exe", argument_list);
5557
}
5658
break;
@@ -83,23 +85,14 @@ void mod::ModWidget::MouseUp(cube::MouseButton mouse_button)
8385

8486
bool mod::ModWidget::NextPageAvailable()
8587
{
86-
return (this->page + 1) * 7 < this->mods->size();
88+
return (this->page + 1) * MODS_PER_PAGE < this->mods->size();
8789
}
8890

8991
bool mod::ModWidget::PreviousPageAvailable()
9092
{
9193
return this->page > 0;
9294
}
9395

94-
bool BtnIsHovered(FloatVector2* mouse_pos, float min_x, float max_x, int height)
95-
{
96-
if (mouse_pos->x < min_x || max_x <= mouse_pos->x || mouse_pos->y < height - 20 || height + 10 <= mouse_pos->y)
97-
{
98-
return false;
99-
}
100-
return true;
101-
}
102-
10396
void mod::ModWidget::Draw(ModWidget* widget)
10497
{
10598
const static float text_size = 18.0f; // Original 18.0f
@@ -151,7 +144,7 @@ void mod::ModWidget::Draw(ModWidget* widget)
151144

152145
// Draw x to exit
153146
widget->SetTextPivot(plasma::TextPivot::Right);
154-
if (BtnIsHovered(&mouse_pos, size.x - 30, size.x - 10, 20 + text_size))
147+
if (plasma::Widget::IsSquareHovered(&mouse_pos, size.x - 30, 20, 20, 30))
155148
{
156149
widget->SetTextColor(&hover_color);
157150
widget->hover_state = ModWidget::HoverState::Exit;
@@ -178,7 +171,7 @@ void mod::ModWidget::Draw(ModWidget* widget)
178171
}
179172

180173
int y_pos = (4 + 2 * y_count) * (10 + text_size);
181-
if (BtnIsHovered(&mouse_pos, 0, size.x, y_pos))
174+
if (plasma::Widget::IsSquareHovered(&mouse_pos, 0, y_pos - 20, size.x, 30))
182175
{
183176
widget->SetTextColor(&hover_color);
184177
widget->hover_state = HoverState::Toggle;
@@ -204,7 +197,7 @@ void mod::ModWidget::Draw(ModWidget* widget)
204197
{
205198
widget->SetTextColor(&disabled_color);
206199
}
207-
else if (BtnIsHovered(&mouse_pos, 20, 20 + text_size, size.y - text_size))
200+
else if (plasma::Widget::IsSquareHovered(&mouse_pos, 20, size.y - text_size - 20, 20, 30))
208201
{
209202
widget->hover_state = HoverState::Previous;
210203
widget->SetTextColor(&hover_color);
@@ -219,7 +212,7 @@ void mod::ModWidget::Draw(ModWidget* widget)
219212
{
220213
widget->SetTextColor(&disabled_color);
221214
}
222-
else if (BtnIsHovered(&mouse_pos, size.x - text_size - 20, size.x -20, size.y - text_size))
215+
else if (plasma::Widget::IsSquareHovered(&mouse_pos, size.x - text_size - 20, size.y - text_size - 20, 20, 30))
223216
{
224217
widget->hover_state = HoverState::Next;
225218
widget->SetTextColor(&hover_color);
@@ -229,7 +222,7 @@ void mod::ModWidget::Draw(ModWidget* widget)
229222
// Draw current page
230223
widget->SetTextColor(&text_color);
231224
widget->SetTextPivot(plasma::TextPivot::Center);
232-
std::wstring page = std::to_wstring(widget->page + 1) + L"/" + std::to_wstring((int)(widget->mods->size() / 7) + 1);
225+
std::wstring page = std::to_wstring(widget->page + 1) + L"/" + std::to_wstring((int)(widget->mods->size() / MODS_PER_PAGE) + 1);
233226
widget->DrawString(&pos, &page, size.x / 2, size.y - text_size);
234227
}
235228

CubeModLoader/callbacks/gui/cube__StartMenuWidget__Draw.h

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
#pragma once
22
#include "../../CWSDK/cwsdk.h"
33

4-
bool BtnIsHovered(FloatVector2* mouse_pos, float width, int height)
5-
{
6-
if (mouse_pos->x < 0 || width <= mouse_pos->x || mouse_pos->y < height - 20 || height + 10 <= mouse_pos->y)
7-
{
8-
return false;
9-
}
10-
return true;
11-
}
12-
13-
// Todo: Using time constraints and not instructions
144
void DrawModdedText(cube::StartMenuWidget* widget)
155
{
166
// Color rotation of the modded text
@@ -54,21 +44,14 @@ void DrawModdedText(cube::StartMenuWidget* widget)
5444

5545
extern "C" void cube__StartMenuWidget__Draw(cube::StartMenuWidget * widget)
5646
{
57-
/*std::wstring wstr_mod_node(L"mod-node");
58-
plasma::Node* node = widget->game->plasma_engine->root_node->FindChildByName(&wstr_mod_node);
59-
if (node != nullptr && node->IsVisible())
60-
{
61-
return;
62-
}*/
63-
6447
const static float text_size = 36.0f; // Original 18.0f
6548
const static float border_size = 4.0f; // Original 4.0f
6649
const int num_btns = 5;
6750

6851
float width;
6952
int y_offset = -20;
7053
int btn_height = 50;
71-
bool options_active;
54+
bool other_widget_active;
7255

7356
FloatVector2 pos = FloatVector2(0, 0);
7457
FloatVector2 mouse_pos;
@@ -108,7 +91,18 @@ extern "C" void cube__StartMenuWidget__Draw(cube::StartMenuWidget * widget)
10891

10992
mouse_pos = *widget->GetRelativeMousePosition(&mouse_pos);
11093
width = widget->GetXSize();
111-
options_active = widget->game->gui.options_widget->node->display->IsVisible();
94+
other_widget_active = widget->game->gui.options_widget->node->display->IsVisible();
95+
96+
// If options widget is not active, check if the mod widget is active
97+
if (!other_widget_active)
98+
{
99+
std::wstring wstr_mod_node(L"mod-node");
100+
plasma::Node* node = widget->game->plasma_engine->root_node->FindChildByName(&wstr_mod_node);
101+
if (node != nullptr && node->IsVisible())
102+
{
103+
other_widget_active = true;
104+
}
105+
}
112106

113107
widget->SetTextSize(text_size);
114108
widget->SetBorderSize(border_size);
@@ -120,7 +114,7 @@ extern "C" void cube__StartMenuWidget__Draw(cube::StartMenuWidget * widget)
120114
for (int i = 0; i < num_btns; i++)
121115
{
122116
int btn_y = y_offset + i * btn_height;
123-
if (!BtnIsHovered(&mouse_pos, width, btn_y) || options_active)
117+
if (!plasma::Widget::IsSquareHovered(&mouse_pos, 0, btn_y - 20, width, 30))
124118
{
125119
widget->SetTextColor(&text_color);
126120
}
@@ -137,7 +131,7 @@ extern "C" void cube__StartMenuWidget__Draw(cube::StartMenuWidget * widget)
137131

138132
if (character_slot < 0 || character_slot >= character_count)
139133
{
140-
if (BtnIsHovered(&mouse_pos, width, btn_y))
134+
if (plasma::Widget::IsSquareHovered(&mouse_pos, 0, btn_y - 20, width, 30))
141135
{
142136
widget->hover_state = cube::StartMenuWidget::HoverState::None;
143137
}

0 commit comments

Comments
 (0)