Refactor and write some helpers for window

This commit is contained in:
Ted John 2018-01-11 21:31:12 +00:00
parent 9d3d4a6c2b
commit 6d63e99f6d
4 changed files with 23 additions and 5 deletions

View File

@ -28,7 +28,9 @@ namespace openloco::ui
uint16_t var_83E; uint16_t var_83E;
uint8_t pad_840[0x85A - 0x840]; uint8_t pad_840[0x85A - 0x840];
uint16_t var_85A; uint16_t var_85A;
uint8_t pad_85C[0x886 - 0x85C]; uint8_t pad_85C[0x882 - 0x85C];
uint8_t type; // 0x882
uint8_t pad_883[0x886 - 0x883];
uint8_t colours[2]; uint8_t colours[2];
}; };
}; };

View File

@ -11,6 +11,18 @@ namespace openloco::ui::windowmgr
} }
loco_global<uint8_t, 0x005233B6> _current_modal_type; loco_global<uint8_t, 0x005233B6> _current_modal_type;
loco_global_array<window, 12, 0x011370AC> _windows;
loco_global<window *, 0x0113D754> _windows_end;
window * get(size_t index)
{
return &_windows.get()[index];
}
size_t num_windows()
{
return ((uintptr_t)*_windows_end - (uintptr_t)_windows.get()) / sizeof(window);
}
window_type current_modal_type() window_type current_modal_type()
{ {

View File

@ -7,9 +7,11 @@ namespace openloco::ui
{ {
enum class window_type enum class window_type
{ {
town = 33,
industry = 34,
window_39 = 39, window_39 = 39,
text_input = 51, text_input = 51,
load_game = 52, prompt_browse = 52,
prompt_ok_cancel = 54, prompt_ok_cancel = 54,
undefined = 255 undefined = 255
}; };
@ -19,6 +21,8 @@ namespace openloco::ui::windowmgr
{ {
window_type current_modal_type(); window_type current_modal_type();
void current_modal_type(window_type type); void current_modal_type(window_type type);
window * get(size_t index);
size_t num_windows();
void update(); void update();
void resize(); void resize();

View File

@ -66,7 +66,7 @@ namespace openloco::ui::windows
std::strcpy(_text_input_buffer, baseName.c_str()); std::strcpy(_text_input_buffer, baseName.c_str());
sub_446A93(); sub_446A93();
auto window = windowmgr::create_window_centred(window_type::load_game, 500, 380, 0x1202, (void *)0x004FB308); auto window = windowmgr::create_window_centred(window_type::prompt_browse, 500, 380, 0x1202, (void *)0x004FB308);
if (window != nullptr) if (window != nullptr)
{ {
window->widgets = (widget *)0x0050AD58; window->widgets = (widget *)0x0050AD58;
@ -81,7 +81,7 @@ namespace openloco::ui::windows
sub_4CEB67(LOCO_GLOBAL(0x0050ADAC, int16_t) - LOCO_GLOBAL(0x0050ADAA, int16_t)); sub_4CEB67(LOCO_GLOBAL(0x0050ADAC, int16_t) - LOCO_GLOBAL(0x0050ADAA, int16_t));
window->colours[0] = colour::black; window->colours[0] = colour::black;
window->colours[1] = colour::saturated_green; window->colours[1] = colour::saturated_green;
windowmgr::current_modal_type(window_type::load_game); windowmgr::current_modal_type(window_type::prompt_browse);
prompt_tick_loop( prompt_tick_loop(
[]() []()
{ {
@ -92,7 +92,7 @@ namespace openloco::ui::windows
windowmgr::update(); windowmgr::update();
LOCO_CALLPROC_X(0x004C98CF); LOCO_CALLPROC_X(0x004C98CF);
LOCO_CALLPROC_X(0x004CF63B); LOCO_CALLPROC_X(0x004CF63B);
return windowmgr::find(window_type::load_game) != nullptr; return windowmgr::find(window_type::prompt_browse) != nullptr;
}); });
windowmgr::current_modal_type(window_type::undefined); windowmgr::current_modal_type(window_type::undefined);
std::strcpy(szPath, _directory); std::strcpy(szPath, _directory);