From 6d63e99f6db1fe5dd09157d5466613201e52d547 Mon Sep 17 00:00:00 2001 From: Ted John Date: Thu, 11 Jan 2018 21:31:12 +0000 Subject: [PATCH] Refactor and write some helpers for window --- src/openloco/window.h | 4 +++- src/openloco/windowmgr.cpp | 12 ++++++++++++ src/openloco/windowmgr.h | 6 +++++- src/openloco/windows/promptbrowsewnd.cpp | 6 +++--- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/openloco/window.h b/src/openloco/window.h index 16a5ca16..330dc92d 100644 --- a/src/openloco/window.h +++ b/src/openloco/window.h @@ -28,7 +28,9 @@ namespace openloco::ui uint16_t var_83E; uint8_t pad_840[0x85A - 0x840]; 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]; }; }; diff --git a/src/openloco/windowmgr.cpp b/src/openloco/windowmgr.cpp index 7392cf4e..ade406a2 100644 --- a/src/openloco/windowmgr.cpp +++ b/src/openloco/windowmgr.cpp @@ -11,6 +11,18 @@ namespace openloco::ui::windowmgr } loco_global _current_modal_type; + loco_global_array _windows; + loco_global _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() { diff --git a/src/openloco/windowmgr.h b/src/openloco/windowmgr.h index 314cd991..fc3bbbed 100644 --- a/src/openloco/windowmgr.h +++ b/src/openloco/windowmgr.h @@ -7,9 +7,11 @@ namespace openloco::ui { enum class window_type { + town = 33, + industry = 34, window_39 = 39, text_input = 51, - load_game = 52, + prompt_browse = 52, prompt_ok_cancel = 54, undefined = 255 }; @@ -19,6 +21,8 @@ namespace openloco::ui::windowmgr { window_type current_modal_type(); void current_modal_type(window_type type); + window * get(size_t index); + size_t num_windows(); void update(); void resize(); diff --git a/src/openloco/windows/promptbrowsewnd.cpp b/src/openloco/windows/promptbrowsewnd.cpp index c70f1e32..8d3bccba 100644 --- a/src/openloco/windows/promptbrowsewnd.cpp +++ b/src/openloco/windows/promptbrowsewnd.cpp @@ -66,7 +66,7 @@ namespace openloco::ui::windows std::strcpy(_text_input_buffer, baseName.c_str()); 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) { window->widgets = (widget *)0x0050AD58; @@ -81,7 +81,7 @@ namespace openloco::ui::windows sub_4CEB67(LOCO_GLOBAL(0x0050ADAC, int16_t) - LOCO_GLOBAL(0x0050ADAA, int16_t)); window->colours[0] = colour::black; 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( []() { @@ -92,7 +92,7 @@ namespace openloco::ui::windows windowmgr::update(); LOCO_CALLPROC_X(0x004C98CF); 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); std::strcpy(szPath, _directory);