iw5-mod/src/launcher/launcher.cpp

89 lines
2.1 KiB
C++
Raw Normal View History

2018-12-23 07:17:08 -05:00
#include <std_include.hpp>
#include "launcher.hpp"
2019-01-05 11:32:34 -05:00
#include "utils/nt.hpp"
2018-12-23 07:17:08 -05:00
2019-01-05 05:44:45 -05:00
launcher::launcher()
2019-01-05 17:55:17 -05:00
{
this->create_settings_menu();
this->create_main_menu();
}
void launcher::create_main_menu()
2018-12-23 07:17:08 -05:00
{
2019-01-05 17:34:46 -05:00
this->main_window_.register_callback("selectMode", [this](html_frame::callback_params* params)
2019-01-05 11:32:34 -05:00
{
2019-01-05 19:10:30 -05:00
if (params->arguments.empty()) return;
2019-01-05 11:32:34 -05:00
const auto param = params->arguments[0];
2019-01-05 19:10:30 -05:00
if (!param.is_number()) return;
2019-01-05 11:32:34 -05:00
const auto number = param.get_number();
2019-01-05 19:10:30 -05:00
if (number == singleplayer || number == multiplayer)
2019-01-05 11:32:34 -05:00
{
this->select_mode(static_cast<mode>(number));
}
});
2019-01-05 17:34:46 -05:00
this->main_window_.register_callback("showSettings", [this](html_frame::callback_params*)
{
this->settings_window_.show();
});
2019-01-05 19:10:30 -05:00
this->main_window_.set_callback(
[](window* window, const UINT message, const WPARAM w_param, const LPARAM l_param) -> LRESULT
2019-01-05 17:55:17 -05:00
{
2019-01-05 19:10:30 -05:00
if (message == WM_CLOSE)
{
window::close_all();
}
2019-01-05 17:55:17 -05:00
2019-01-05 19:10:30 -05:00
return DefWindowProcA(*window, message, w_param, l_param);
});
2019-01-05 17:34:46 -05:00
this->main_window_.create("Open-IW5", 615, 300);
this->main_window_.load_html(load_content(MENU_MAIN));
this->main_window_.show();
2018-12-23 07:17:08 -05:00
}
2019-01-05 17:55:17 -05:00
void launcher::create_settings_menu()
{
2019-01-05 19:10:30 -05:00
this->settings_window_.set_callback(
[](window* window, const UINT message, const WPARAM w_param, const LPARAM l_param) -> LRESULT
2019-01-05 17:55:17 -05:00
{
2019-01-05 19:10:30 -05:00
if (message == WM_CLOSE)
{
window->hide();
return TRUE;
}
2019-01-05 17:55:17 -05:00
2019-01-05 19:10:30 -05:00
return DefWindowProcA(*window, message, w_param, l_param);
});
2019-01-05 17:55:17 -05:00
2019-01-06 07:22:49 -05:00
this->settings_window_.create("Open-IW5 Settings", 400, 200, WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU);
2019-01-05 17:55:17 -05:00
this->settings_window_.load_html(load_content(MENU_SETTINGS));
}
2018-12-23 12:25:22 -05:00
launcher::mode launcher::run() const
2018-12-23 07:17:08 -05:00
{
2019-01-05 17:34:46 -05:00
window::run();
2018-12-23 12:25:22 -05:00
return this->mode_;
}
void launcher::select_mode(const mode mode)
{
this->mode_ = mode;
2019-01-05 17:34:46 -05:00
this->settings_window_.close();
this->main_window_.close();
2018-12-23 12:25:22 -05:00
}
2019-01-05 11:32:34 -05:00
2019-01-05 17:55:17 -05:00
std::string launcher::load_content(const int res)
2019-01-05 11:32:34 -05:00
{
2019-01-05 17:55:17 -05:00
const auto resource = FindResource(utils::nt::module(), MAKEINTRESOURCE(res), RT_RCDATA);
2019-01-26 15:37:46 -05:00
if (!resource) return {};
2019-01-05 11:32:34 -05:00
2019-01-05 17:34:46 -05:00
const auto handle = LoadResource(nullptr, resource);
2019-01-05 11:32:34 -05:00
if (!handle) return {};
2019-01-05 17:34:46 -05:00
return std::string(LPSTR(LockResource(handle)), SizeofResource(nullptr, resource));
2019-01-05 11:32:34 -05:00
}