Create IWindowManager to open window from libopenrct2

This commit is contained in:
Ted John 2017-06-11 15:16:47 +01:00
parent f62a6713ff
commit cbd53f920c
14 changed files with 221 additions and 41 deletions

View File

@ -36,6 +36,7 @@
#include "SDLException.h" #include "SDLException.h"
#include "TextComposition.h" #include "TextComposition.h"
#include "UiContext.h" #include "UiContext.h"
#include "WindowManager.h"
extern "C" extern "C"
{ {
@ -62,6 +63,7 @@ private:
constexpr static uint32 TOUCH_DOUBLE_TIMEOUT = 300; constexpr static uint32 TOUCH_DOUBLE_TIMEOUT = 300;
IPlatformUiContext * const _platformUiContext; IPlatformUiContext * const _platformUiContext;
IWindowManager * const _windowManager;
CursorRepository _cursorRepository; CursorRepository _cursorRepository;
@ -89,6 +91,7 @@ private:
public: public:
UiContext(IPlatformEnvironment * env) UiContext(IPlatformEnvironment * env)
: _platformUiContext(CreatePlatformUiContext()), : _platformUiContext(CreatePlatformUiContext()),
_windowManager(CreateWindowManager()),
_keyboardShortcuts(env) _keyboardShortcuts(env)
{ {
if (SDL_Init(SDL_INIT_VIDEO) < 0) if (SDL_Init(SDL_INIT_VIDEO) < 0)
@ -566,6 +569,11 @@ public:
return _platformUiContext->ShowDirectoryDialog(_window, title); return _platformUiContext->ShowDirectoryDialog(_window, title);
} }
IWindowManager * GetWindowManager() override
{
return _windowManager;
}
private: private:
void OnResize(sint32 width, sint32 height) void OnResize(sint32 width, sint32 height)
{ {

View File

@ -0,0 +1,40 @@
#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#include <openrct2/ui/WindowManager.h>
#include "input/KeyboardShortcuts.h"
#include "WindowManager.h"
using namespace OpenRCT2::Ui;
class WindowManager final : public IWindowManager
{
public:
rct_window * OpenWindow(rct_windowclass wc) override
{
switch (wc) {
case WC_KEYBOARD_SHORTCUT_LIST:
return window_shortcut_keys_open();
default:
return nullptr;
}
}
};
IWindowManager * OpenRCT2::Ui::CreateWindowManager()
{
return new WindowManager();
}

View File

@ -0,0 +1,24 @@
#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#include <openrct2/common.h>
namespace OpenRCT2 { namespace Ui
{
interface IWindowManager;
IWindowManager * CreateWindowManager();
} }

View File

@ -67,12 +67,17 @@ namespace OpenRCT2
extern "C" extern "C"
{ {
#endif #endif
typedef struct rct_window rct_window;
void keyboard_shortcuts_reset(); void keyboard_shortcuts_reset();
bool keyboard_shortcuts_load(); bool keyboard_shortcuts_load();
bool keyboard_shortcuts_save(); bool keyboard_shortcuts_save();
void keyboard_shortcuts_set(sint32 key); void keyboard_shortcuts_set(sint32 key);
sint32 keyboard_shortcuts_get_from_key(sint32 key); sint32 keyboard_shortcuts_get_from_key(sint32 key);
void keyboard_shortcuts_format_string(char * buffer, size_t bufferSize, sint32 shortcut); void keyboard_shortcuts_format_string(char * buffer, size_t bufferSize, sint32 shortcut);
rct_window * window_shortcut_keys_open();
rct_window * window_shortcut_change_open(sint32 selected_key);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -18,7 +18,7 @@
#include <openrct2/interface/window.h> #include <openrct2/interface/window.h>
#include <openrct2/interface/widget.h> #include <openrct2/interface/widget.h>
#include <openrct2/localisation/localisation.h> #include <openrct2/localisation/localisation.h>
#include "../input/keyboard_shortcut.h" #include "../input/KeyboardShortcuts.h"
extern const rct_string_id ShortcutStringIds[]; extern const rct_string_id ShortcutStringIds[];
@ -74,16 +74,18 @@ static rct_window_event_list window_shortcut_change_events = {
NULL NULL
}; };
void window_shortcut_change_open(sint32 selected_key){ rct_window * window_shortcut_change_open(sint32 selected_key)
{
// Move this to window_shortcut_change_open // Move this to window_shortcut_change_open
window_close_by_class(WC_CHANGE_KEYBOARD_SHORTCUT); window_close_by_class(WC_CHANGE_KEYBOARD_SHORTCUT);
// Save the item we are selecting for new window // Save the item we are selecting for new window
gKeyboardShortcutChangeId = selected_key; gKeyboardShortcutChangeId = selected_key;
rct_window* w = window_create_centred(WW, WH, &window_shortcut_change_events, WC_CHANGE_KEYBOARD_SHORTCUT, 0); rct_window * w = window_create_centred(WW, WH, &window_shortcut_change_events, WC_CHANGE_KEYBOARD_SHORTCUT, 0);
w->widgets = window_shortcut_change_widgets; w->widgets = window_shortcut_change_widgets;
w->enabled_widgets = (1ULL << WIDX_CLOSE); w->enabled_widgets = (1ULL << WIDX_CLOSE);
window_init_scroll_widgets(w); window_init_scroll_widgets(w);
return w;
} }
/** /**

View File

@ -155,26 +155,25 @@ const rct_string_id ShortcutStringIds[] = {
* *
* rct2: 0x006E3884 * rct2: 0x006E3884
*/ */
void window_shortcut_keys_open() rct_window * window_shortcut_keys_open()
{ {
rct_window* w; rct_window * w = window_bring_to_front_by_class(WC_KEYBOARD_SHORTCUT_LIST);
if (w == NULL)
{
w = window_create_auto_pos(WW, WH, &window_shortcut_events, WC_KEYBOARD_SHORTCUT_LIST, WF_RESIZABLE);
w = window_bring_to_front_by_class(WC_KEYBOARD_SHORTCUT_LIST); w->widgets = window_shortcut_widgets;
w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_RESET);
window_init_scroll_widgets(w);
if (w) return; w->no_list_items = SHORTCUT_COUNT;
w->selected_list_item = -1;
w = window_create_auto_pos(WW, WH, &window_shortcut_events, WC_KEYBOARD_SHORTCUT_LIST, WF_RESIZABLE); w->min_width = WW;
w->min_height = WH;
w->widgets = window_shortcut_widgets; w->max_width = WW_SC_MAX;
w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_RESET); w->max_height = WH_SC_MAX;
window_init_scroll_widgets(w); }
return w;
w->no_list_items = SHORTCUT_COUNT;
w->selected_list_item = -1;
w->min_width = WW;
w->min_height = WH;
w->max_width = WW_SC_MAX;
w->max_height = WH_SC_MAX;
} }
/** /**

View File

@ -37,6 +37,7 @@
#include "scenario/ScenarioRepository.h" #include "scenario/ScenarioRepository.h"
#include "title/TitleScreen.h" #include "title/TitleScreen.h"
#include "title/TitleSequenceManager.h" #include "title/TitleSequenceManager.h"
#include "ui/WindowManager.h"
#include "Version.h" #include "Version.h"
extern "C" extern "C"
@ -652,6 +653,12 @@ extern "C"
GetContext()->GetUiContext()->SetCursorTrap(value); GetContext()->GetUiContext()->SetCursorTrap(value);
} }
rct_window * context_open_window(rct_windowclass wc)
{
auto windowManager = GetContext()->GetUiContext()->GetWindowManager();
return windowManager->OpenWindow(wc);
}
bool platform_open_common_file_dialog(utf8 * outFilename, file_dialog_desc * desc, size_t outSize) bool platform_open_common_file_dialog(utf8 * outFilename, file_dialog_desc * desc, size_t outSize)
{ {
try try

View File

@ -18,6 +18,16 @@
#include "common.h" #include "common.h"
#ifdef __cplusplus
extern "C"
{
#endif
#include "interface/window.h"
#ifdef __cplusplus
}
#endif
typedef struct CursorState typedef struct CursorState
{ {
sint32 x, y; sint32 x, y;
@ -117,7 +127,7 @@ extern "C"
sint32 context_get_height(); sint32 context_get_height();
bool context_has_focus(); bool context_has_focus();
void context_set_cursor_trap(bool value); void context_set_cursor_trap(bool value);
rct_window * context_open_window(rct_windowclass wc);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -702,8 +702,6 @@ void window_guest_list_open();
void window_guest_list_open_with_filter(sint32 type, sint32 index); void window_guest_list_open_with_filter(sint32 type, sint32 index);
void window_map_open(); void window_map_open();
void window_options_open(); void window_options_open();
void window_shortcut_keys_open();
void window_shortcut_change_open(sint32 selected_key);
void window_guest_open(rct_peep* peep); void window_guest_open(rct_peep* peep);
rct_window *window_staff_open(rct_peep* peep); rct_window *window_staff_open(rct_peep* peep);
void window_staff_fire_prompt_open(rct_peep* peep); void window_staff_fire_prompt_open(rct_peep* peep);

View File

@ -16,6 +16,7 @@
#include "../drawing/X8DrawingEngine.h" #include "../drawing/X8DrawingEngine.h"
#include "UiContext.h" #include "UiContext.h"
#include "WindowManager.h"
using namespace OpenRCT2::Drawing; using namespace OpenRCT2::Drawing;
@ -26,6 +27,10 @@ namespace OpenRCT2 { namespace Ui
*/ */
class DummyUiContext final : public IUiContext class DummyUiContext final : public IUiContext
{ {
private:
IWindowManager * const _windowManager = CreateDummyWindowManager();
public:
void CreateWindow() override { } void CreateWindow() override { }
void CloseWindow() override { } void CloseWindow() override { }
void * GetWindow() override { return nullptr; } void * GetWindow() override { return nullptr; }
@ -39,32 +44,38 @@ namespace OpenRCT2 { namespace Ui
void ProcessMessages() override { } void ProcessMessages() override { }
void TriggerResize() override { } void TriggerResize() override { }
virtual void ShowMessageBox(const std::string &message) override { } void ShowMessageBox(const std::string &message) override { }
virtual std::string ShowFileDialog(const FileDialogDesc &desc) override { return std::string(); } std::string ShowFileDialog(const FileDialogDesc &desc) override { return std::string(); }
virtual std::string ShowDirectoryDialog(const std::string &title) override { return std::string(); } std::string ShowDirectoryDialog(const std::string &title) override { return std::string(); }
// Input // Input
virtual const CursorState * GetCursorState() override { return nullptr; } const CursorState * GetCursorState() override { return nullptr; }
virtual CURSOR_ID GetCursor() override { return CURSOR_ARROW; } CURSOR_ID GetCursor() override { return CURSOR_ARROW; }
virtual void SetCursor(CURSOR_ID cursor) override { } void SetCursor(CURSOR_ID cursor) override { }
virtual void SetCursorVisible(bool value) override { } void SetCursorVisible(bool value) override { }
virtual void GetCursorPosition(sint32 * x, sint32 * y) override { } void GetCursorPosition(sint32 * x, sint32 * y) override { }
virtual void SetCursorPosition(sint32 x, sint32 y) override { } void SetCursorPosition(sint32 x, sint32 y) override { }
virtual void SetCursorTrap(bool value) override { } void SetCursorTrap(bool value) override { }
virtual const uint8 * GetKeysState() override { return nullptr; } const uint8 * GetKeysState() override { return nullptr; }
virtual const uint8 * GetKeysPressed() override { return nullptr; } const uint8 * GetKeysPressed() override { return nullptr; }
virtual void SetKeysPressed(uint32 keysym, uint8 scancode) override { } void SetKeysPressed(uint32 keysym, uint8 scancode) override { }
// Drawing // Drawing
virtual Drawing::IDrawingEngine * CreateDrawingEngine(Drawing::DRAWING_ENGINE_TYPE type) override Drawing::IDrawingEngine * CreateDrawingEngine(Drawing::DRAWING_ENGINE_TYPE type) override
{ {
return new X8DrawingEngine(); return new X8DrawingEngine();
} }
// Text input // Text input
virtual bool IsTextInputActive() override { return false; } bool IsTextInputActive() override { return false; }
virtual TextInputSession * StartTextInput(utf8 * buffer, size_t bufferSize) override { return nullptr; } TextInputSession * StartTextInput(utf8 * buffer, size_t bufferSize) override { return nullptr; }
virtual void StopTextInput() override { } void StopTextInput() override { }
// In-game UI
IWindowManager * GetWindowManager() override
{
return _windowManager;
}
}; };
IUiContext * CreateDummyUiContext() IUiContext * CreateDummyUiContext()

View File

@ -0,0 +1,30 @@
#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#include "WindowManager.h"
namespace OpenRCT2 { namespace Ui
{
class DummyWindowManager final : public IWindowManager
{
rct_window * OpenWindow(rct_windowclass wc) override { return nullptr; }
};
IWindowManager * CreateDummyWindowManager()
{
return new DummyWindowManager();
}
} }

View File

@ -32,6 +32,8 @@ namespace OpenRCT2
namespace Ui namespace Ui
{ {
interface IWindowManager;
enum class FULLSCREEN_MODE enum class FULLSCREEN_MODE
{ {
WINDOWED, WINDOWED,
@ -126,6 +128,9 @@ namespace OpenRCT2
virtual bool IsTextInputActive() abstract; virtual bool IsTextInputActive() abstract;
virtual TextInputSession * StartTextInput(utf8 * buffer, size_t bufferSize) abstract; virtual TextInputSession * StartTextInput(utf8 * buffer, size_t bufferSize) abstract;
virtual void StopTextInput() abstract; virtual void StopTextInput() abstract;
// In-game UI
virtual IWindowManager * GetWindowManager() abstract;
}; };
IUiContext * CreateDummyUiContext(); IUiContext * CreateDummyUiContext();

View File

@ -0,0 +1,41 @@
#pragma region Copyright (c) 2014-2017 OpenRCT2 Developers
/*****************************************************************************
* OpenRCT2, an open source clone of Roller Coaster Tycoon 2.
*
* OpenRCT2 is the work of many authors, a full list can be found in contributors.md
* For more information, visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* A full copy of the GNU General Public License can be found in licence.txt
*****************************************************************************/
#pragma endregion
#pragma once
#include "../common.h"
extern "C"
{
#include "../interface/window.h"
}
namespace OpenRCT2
{
namespace Ui
{
/**
* Manager of in-game windows and widgets.
*/
interface IWindowManager
{
virtual ~IWindowManager() = default;
virtual rct_window * OpenWindow(rct_windowclass wc) abstract;
};
IWindowManager * CreateDummyWindowManager();
}
}

View File

@ -738,7 +738,7 @@ static void window_options_mouseup(rct_window *w, rct_widgetindex widgetIndex)
case WINDOW_OPTIONS_PAGE_CONTROLS_AND_INTERFACE: case WINDOW_OPTIONS_PAGE_CONTROLS_AND_INTERFACE:
switch (widgetIndex) { switch (widgetIndex) {
case WIDX_HOTKEY_DROPDOWN: case WIDX_HOTKEY_DROPDOWN:
window_shortcut_keys_open(); context_open_window(WC_KEYBOARD_SHORTCUT_LIST);
break; break;
case WIDX_SCREEN_EDGE_SCROLLING: case WIDX_SCREEN_EDGE_SCROLLING:
gConfigGeneral.edge_scrolling ^= 1; gConfigGeneral.edge_scrolling ^= 1;