2018-12-23 07:17:08 -05:00
|
|
|
#include <std_include.hpp>
|
|
|
|
#include "launcher.hpp"
|
2019-01-05 05:44:45 -05:00
|
|
|
#include "html_frame.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()
|
2018-12-23 07:17:08 -05:00
|
|
|
{
|
2018-12-23 12:25:22 -05:00
|
|
|
this->window_.set_callback(std::bind(&launcher::handler, this, std::placeholders::_1, std::placeholders::_2,
|
|
|
|
std::placeholders::_3));
|
2019-01-05 05:44:45 -05:00
|
|
|
|
2019-01-05 11:32:34 -05:00
|
|
|
this->html_frame_.register_callback("selectMode", [this](html_frame::callback_params* params)
|
|
|
|
{
|
|
|
|
if(params->arguments.empty()) return;
|
|
|
|
|
|
|
|
const auto param = params->arguments[0];
|
|
|
|
if(!param.is_number()) return;
|
|
|
|
|
|
|
|
const auto number = param.get_number();
|
|
|
|
if(number == singleplayer || number == multiplayer)
|
|
|
|
{
|
|
|
|
this->select_mode(static_cast<mode>(number));
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2019-01-05 05:44:45 -05:00
|
|
|
this->window_.create("Open-IW5", 615, 300);
|
2019-01-05 11:32:34 -05:00
|
|
|
this->html_frame_.load_html(load_content());
|
2018-12-23 07:17:08 -05:00
|
|
|
}
|
|
|
|
|
2018-12-23 12:25:22 -05:00
|
|
|
launcher::mode launcher::run() const
|
2018-12-23 07:17:08 -05:00
|
|
|
{
|
|
|
|
this->window_.run();
|
2018-12-23 12:25:22 -05:00
|
|
|
|
|
|
|
return this->mode_;
|
|
|
|
}
|
|
|
|
|
|
|
|
LRESULT launcher::handler(const UINT message, const WPARAM w_param, const LPARAM l_param)
|
|
|
|
{
|
2019-01-05 05:44:45 -05:00
|
|
|
if (message == WM_SIZE)
|
2018-12-23 12:25:22 -05:00
|
|
|
{
|
2019-01-05 05:44:45 -05:00
|
|
|
this->html_frame_.resize(LOWORD(l_param), HIWORD(l_param));
|
|
|
|
return 0;
|
2018-12-23 12:25:22 -05:00
|
|
|
}
|
2019-01-05 05:44:45 -05:00
|
|
|
|
|
|
|
if (message == WM_CREATE)
|
2018-12-23 12:25:22 -05:00
|
|
|
{
|
2019-01-05 05:44:45 -05:00
|
|
|
this->html_frame_.initialize(this->window_);
|
|
|
|
return 0;
|
2018-12-23 12:25:22 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return DefWindowProc(this->window_, message, w_param, l_param);
|
|
|
|
}
|
|
|
|
|
|
|
|
void launcher::select_mode(const mode mode)
|
|
|
|
{
|
|
|
|
this->mode_ = mode;
|
|
|
|
this->window_.close();
|
|
|
|
}
|
2019-01-05 11:32:34 -05:00
|
|
|
|
|
|
|
std::string launcher::load_content()
|
|
|
|
{
|
|
|
|
const auto res = FindResource(::utils::nt::module(), MAKEINTRESOURCE(MAIN_MENU), RT_RCDATA);
|
|
|
|
if (!res) return {};
|
|
|
|
|
|
|
|
const auto handle = LoadResource(nullptr, res);
|
|
|
|
if (!handle) return {};
|
|
|
|
|
|
|
|
return std::string(LPSTR(LockResource(handle)), SizeofResource(nullptr, res));
|
|
|
|
}
|