Skip to content

Commit e59f570

Browse files
committed
Move duplicate TriggerEvent functions to GUIUtils
1 parent 7821a1d commit e59f570

File tree

5 files changed

+28
-45
lines changed

5 files changed

+28
-45
lines changed

gframe/event_handler.cpp

+2-15
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,6 @@
4343

4444
namespace {
4545

46-
inline void TriggerEvent(irr::gui::IGUIElement* target, irr::gui::EGUI_EVENT_TYPE type) {
47-
irr::SEvent event;
48-
event.EventType = irr::EET_GUI_EVENT;
49-
event.GUIEvent.EventType = type;
50-
event.GUIEvent.Caller = target;
51-
ygo::mainGame->device->postEventFromUser(event);
52-
}
53-
54-
inline void SetCheckbox(irr::gui::IGUICheckBox* chk, bool state) {
55-
chk->setChecked(state);
56-
TriggerEvent(chk, irr::gui::EGET_CHECKBOX_CHANGED);
57-
}
58-
5946
#if EDOPRO_ANDROID || EDOPRO_IOS
6047
inline bool TransformEvent(const irr::SEvent& event, bool& stopPropagation) {
6148
return porting::transformEvent(event, stopPropagation);
@@ -2208,8 +2195,8 @@ bool ClientField::OnCommonEvent(const irr::SEvent& event, bool& stopPropagation)
22082195
case irr::KEY_F9: {
22092196
if (!event.KeyInput.PressedDown) {
22102197
const auto new_val = !mainGame->current_topdown;
2211-
SetCheckbox(mainGame->gSettings.chkTopdown, new_val);
2212-
SetCheckbox(mainGame->gSettings.chkKeepFieldRatio, new_val);
2198+
GUIUtils::SetCheckbox(mainGame->device, mainGame->gSettings.chkTopdown, new_val);
2199+
GUIUtils::SetCheckbox(mainGame->device, mainGame->gSettings.chkKeepFieldRatio, new_val);
22132200
}
22142201
return true;
22152202
}

gframe/gframe.cpp

+2-15
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,10 @@ ygo::ClientUpdater* ygo::gClientUpdater = nullptr;
3737
JWrapper* gJWrapper = nullptr;
3838

3939
namespace {
40-
inline void TriggerEvent(irr::gui::IGUIElement* target, irr::gui::EGUI_EVENT_TYPE type) {
41-
irr::SEvent event;
42-
event.EventType = irr::EET_GUI_EVENT;
43-
event.GUIEvent.EventType = type;
44-
event.GUIEvent.Caller = target;
45-
ygo::mainGame->device->postEventFromUser(event);
46-
}
47-
48-
inline void SetCheckbox(irr::gui::IGUICheckBox* chk, bool state) {
49-
chk->setChecked(state);
50-
TriggerEvent(chk, irr::gui::EGET_CHECKBOX_CHANGED);
51-
}
52-
5340
void CheckArguments(const args_t& args) {
5441
if(args[LAUNCH_PARAM::MUTE].enabled) {
55-
SetCheckbox(ygo::mainGame->tabSettings.chkEnableSound, false);
56-
SetCheckbox(ygo::mainGame->tabSettings.chkEnableMusic, false);
42+
ygo::GUIUtils::SetCheckbox(ygo::mainGame->device, ygo::mainGame->tabSettings.chkEnableSound, false);
43+
ygo::GUIUtils::SetCheckbox(ygo::mainGame->device, ygo::mainGame->tabSettings.chkEnableMusic, false);
5744
}
5845
}
5946

gframe/menu_handler.cpp

+4-15
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,6 @@ static void LoadReplay() {
8989
start_turn = 0;
9090
ReplayMode::StartReplay(start_turn, (mainGame->chkYrp->isChecked() || replay.IsOldReplayMode()));
9191
}
92-
static inline void TriggerEvent(irr::gui::IGUIElement* target, irr::gui::EGUI_EVENT_TYPE type) {
93-
irr::SEvent event;
94-
event.EventType = irr::EET_GUI_EVENT;
95-
event.GUIEvent.EventType = type;
96-
event.GUIEvent.Caller = target;
97-
ygo::mainGame->device->postEventFromUser(event);
98-
}
99-
100-
static inline void ClickButton(irr::gui::IGUIElement* btn) {
101-
TriggerEvent(btn, irr::gui::EGET_BUTTON_CLICKED);
102-
}
10392
bool MenuHandler::OnEvent(const irr::SEvent& event) {
10493
bool stopPropagation = false;
10594
if(mainGame->dField.OnCommonEvent(event, stopPropagation))
@@ -1124,15 +1113,15 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
11241113
open_file = true;
11251114
open_file_name = Utils::ToPathString(to_open_file);
11261115
if(!mainGame->wSinglePlay->isVisible())
1127-
ClickButton(mainGame->btnSingleMode);
1128-
ClickButton(mainGame->btnLoadSinglePlay);
1116+
GUIUtils::ClickButton(mainGame->device, mainGame->btnSingleMode);
1117+
GUIUtils::ClickButton(mainGame->device, mainGame->btnLoadSinglePlay);
11291118
return true;
11301119
} else if(mainGame->coreloaded && (extension == L"yrpx" || extension == L"yrp") && !mainGame->wSinglePlay->isVisible()) {
11311120
open_file = true;
11321121
open_file_name = Utils::ToPathString(to_open_file);
11331122
if(!mainGame->wReplay->isVisible())
1134-
ClickButton(mainGame->btnReplayMode);
1135-
ClickButton(mainGame->btnLoadReplay);
1123+
GUIUtils::ClickButton(mainGame->device, mainGame->btnReplayMode);
1124+
GUIUtils::ClickButton(mainGame->device, mainGame->btnLoadReplay);
11361125
return true;
11371126
} else if(extension == L"pem" || extension == L"cer" || extension == L"crt") {
11381127
gGameConfig->override_ssl_certificate_path = BufferIO::EncodeUTF8(to_open_file);

gframe/utils_gui.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -409,4 +409,21 @@ std::string GUIUtils::SerializeWindowPosition(std::shared_ptr<irr::IrrlichtDevic
409409
#endif
410410
}
411411

412+
void GUIUtils::TriggerEvent(std::shared_ptr<irr::IrrlichtDevice>& device, irr::gui::IGUIElement* target, /*irr::gui::EGUI_EVENT_TYPE*/ int type) {
413+
irr::SEvent event;
414+
event.EventType = irr::EET_GUI_EVENT;
415+
event.GUIEvent.EventType = static_cast<irr::gui::EGUI_EVENT_TYPE>(type);
416+
event.GUIEvent.Caller = target;
417+
device->postEventFromUser(event);
418+
}
419+
420+
void GUIUtils::ClickButton(std::shared_ptr<irr::IrrlichtDevice>& device, irr::gui::IGUIElement* btn) {
421+
TriggerEvent(device, btn, irr::gui::EGET_BUTTON_CLICKED);
422+
}
423+
424+
void GUIUtils::SetCheckbox(std::shared_ptr<irr::IrrlichtDevice>& device, irr::gui::IGUICheckBox* chk, bool state) {
425+
chk->setChecked(state);
426+
TriggerEvent(device, chk, irr::gui::EGET_CHECKBOX_CHANGED);
427+
}
428+
412429
}

gframe/utils_gui.h

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ void ToggleFullscreen(std::shared_ptr<irr::IrrlichtDevice>& device, bool& fullsc
2424
void ShowErrorWindow(epro::stringview context, epro::stringview message);
2525
void ToggleSwapInterval(irr::video::IVideoDriver* driver, int interval);
2626
std::string SerializeWindowPosition(std::shared_ptr<irr::IrrlichtDevice>& device);
27+
void TriggerEvent(std::shared_ptr<irr::IrrlichtDevice>& device, irr::gui::IGUIElement* target, /*irr::gui::EGUI_EVENT_TYPE*/ int type);
28+
void ClickButton(std::shared_ptr<irr::IrrlichtDevice>& device, irr::gui::IGUIElement* btn);
29+
void SetCheckbox(std::shared_ptr<irr::IrrlichtDevice>& device, irr::gui::IGUICheckBox* chk, bool state);
2730

2831
}
2932

0 commit comments

Comments
 (0)