mirror of https://github.com/OpenRCT2/OpenRCT2.git
Create IWindowManager to open window from libopenrct2
This commit is contained in:
parent
f62a6713ff
commit
cbd53f920c
|
@ -36,6 +36,7 @@
|
|||
#include "SDLException.h"
|
||||
#include "TextComposition.h"
|
||||
#include "UiContext.h"
|
||||
#include "WindowManager.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
|
@ -62,6 +63,7 @@ private:
|
|||
constexpr static uint32 TOUCH_DOUBLE_TIMEOUT = 300;
|
||||
|
||||
IPlatformUiContext * const _platformUiContext;
|
||||
IWindowManager * const _windowManager;
|
||||
|
||||
CursorRepository _cursorRepository;
|
||||
|
||||
|
@ -89,6 +91,7 @@ private:
|
|||
public:
|
||||
UiContext(IPlatformEnvironment * env)
|
||||
: _platformUiContext(CreatePlatformUiContext()),
|
||||
_windowManager(CreateWindowManager()),
|
||||
_keyboardShortcuts(env)
|
||||
{
|
||||
if (SDL_Init(SDL_INIT_VIDEO) < 0)
|
||||
|
@ -566,6 +569,11 @@ public:
|
|||
return _platformUiContext->ShowDirectoryDialog(_window, title);
|
||||
}
|
||||
|
||||
IWindowManager * GetWindowManager() override
|
||||
{
|
||||
return _windowManager;
|
||||
}
|
||||
|
||||
private:
|
||||
void OnResize(sint32 width, sint32 height)
|
||||
{
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -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();
|
||||
} }
|
|
@ -67,12 +67,17 @@ namespace OpenRCT2
|
|||
extern "C"
|
||||
{
|
||||
#endif
|
||||
typedef struct rct_window rct_window;
|
||||
|
||||
void keyboard_shortcuts_reset();
|
||||
bool keyboard_shortcuts_load();
|
||||
bool keyboard_shortcuts_save();
|
||||
void keyboard_shortcuts_set(sint32 key);
|
||||
sint32 keyboard_shortcuts_get_from_key(sint32 key);
|
||||
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
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
#include <openrct2/interface/window.h>
|
||||
#include <openrct2/interface/widget.h>
|
||||
#include <openrct2/localisation/localisation.h>
|
||||
#include "../input/keyboard_shortcut.h"
|
||||
#include "../input/KeyboardShortcuts.h"
|
||||
|
||||
extern const rct_string_id ShortcutStringIds[];
|
||||
|
||||
|
@ -74,16 +74,18 @@ static rct_window_event_list window_shortcut_change_events = {
|
|||
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
|
||||
window_close_by_class(WC_CHANGE_KEYBOARD_SHORTCUT);
|
||||
// Save the item we are selecting for new window
|
||||
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->enabled_widgets = (1ULL << WIDX_CLOSE);
|
||||
window_init_scroll_widgets(w);
|
||||
return w;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -155,26 +155,25 @@ const rct_string_id ShortcutStringIds[] = {
|
|||
*
|
||||
* 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 = window_create_auto_pos(WW, WH, &window_shortcut_events, WC_KEYBOARD_SHORTCUT_LIST, WF_RESIZABLE);
|
||||
|
||||
w->widgets = window_shortcut_widgets;
|
||||
w->enabled_widgets = (1 << WIDX_CLOSE) | (1 << WIDX_RESET);
|
||||
window_init_scroll_widgets(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;
|
||||
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;
|
||||
}
|
||||
return w;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
#include "scenario/ScenarioRepository.h"
|
||||
#include "title/TitleScreen.h"
|
||||
#include "title/TitleSequenceManager.h"
|
||||
#include "ui/WindowManager.h"
|
||||
#include "Version.h"
|
||||
|
||||
extern "C"
|
||||
|
@ -652,6 +653,12 @@ extern "C"
|
|||
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)
|
||||
{
|
||||
try
|
||||
|
|
|
@ -18,6 +18,16 @@
|
|||
|
||||
#include "common.h"
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
{
|
||||
#endif
|
||||
#include "interface/window.h"
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef struct CursorState
|
||||
{
|
||||
sint32 x, y;
|
||||
|
@ -117,7 +127,7 @@ extern "C"
|
|||
sint32 context_get_height();
|
||||
bool context_has_focus();
|
||||
void context_set_cursor_trap(bool value);
|
||||
|
||||
rct_window * context_open_window(rct_windowclass wc);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -702,8 +702,6 @@ void window_guest_list_open();
|
|||
void window_guest_list_open_with_filter(sint32 type, sint32 index);
|
||||
void window_map_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);
|
||||
rct_window *window_staff_open(rct_peep* peep);
|
||||
void window_staff_fire_prompt_open(rct_peep* peep);
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include "../drawing/X8DrawingEngine.h"
|
||||
#include "UiContext.h"
|
||||
#include "WindowManager.h"
|
||||
|
||||
using namespace OpenRCT2::Drawing;
|
||||
|
||||
|
@ -26,6 +27,10 @@ namespace OpenRCT2 { namespace Ui
|
|||
*/
|
||||
class DummyUiContext final : public IUiContext
|
||||
{
|
||||
private:
|
||||
IWindowManager * const _windowManager = CreateDummyWindowManager();
|
||||
|
||||
public:
|
||||
void CreateWindow() override { }
|
||||
void CloseWindow() override { }
|
||||
void * GetWindow() override { return nullptr; }
|
||||
|
@ -39,32 +44,38 @@ namespace OpenRCT2 { namespace Ui
|
|||
void ProcessMessages() override { }
|
||||
void TriggerResize() override { }
|
||||
|
||||
virtual void ShowMessageBox(const std::string &message) override { }
|
||||
virtual std::string ShowFileDialog(const FileDialogDesc &desc) override { return std::string(); }
|
||||
virtual std::string ShowDirectoryDialog(const std::string &title) override { return std::string(); }
|
||||
void ShowMessageBox(const std::string &message) override { }
|
||||
std::string ShowFileDialog(const FileDialogDesc &desc) override { return std::string(); }
|
||||
std::string ShowDirectoryDialog(const std::string &title) override { return std::string(); }
|
||||
|
||||
// Input
|
||||
virtual const CursorState * GetCursorState() override { return nullptr; }
|
||||
virtual CURSOR_ID GetCursor() override { return CURSOR_ARROW; }
|
||||
virtual void SetCursor(CURSOR_ID cursor) override { }
|
||||
virtual void SetCursorVisible(bool value) override { }
|
||||
virtual void GetCursorPosition(sint32 * x, sint32 * y) override { }
|
||||
virtual void SetCursorPosition(sint32 x, sint32 y) override { }
|
||||
virtual void SetCursorTrap(bool value) override { }
|
||||
virtual const uint8 * GetKeysState() override { return nullptr; }
|
||||
virtual const uint8 * GetKeysPressed() override { return nullptr; }
|
||||
virtual void SetKeysPressed(uint32 keysym, uint8 scancode) override { }
|
||||
const CursorState * GetCursorState() override { return nullptr; }
|
||||
CURSOR_ID GetCursor() override { return CURSOR_ARROW; }
|
||||
void SetCursor(CURSOR_ID cursor) override { }
|
||||
void SetCursorVisible(bool value) override { }
|
||||
void GetCursorPosition(sint32 * x, sint32 * y) override { }
|
||||
void SetCursorPosition(sint32 x, sint32 y) override { }
|
||||
void SetCursorTrap(bool value) override { }
|
||||
const uint8 * GetKeysState() override { return nullptr; }
|
||||
const uint8 * GetKeysPressed() override { return nullptr; }
|
||||
void SetKeysPressed(uint32 keysym, uint8 scancode) override { }
|
||||
|
||||
// Drawing
|
||||
virtual Drawing::IDrawingEngine * CreateDrawingEngine(Drawing::DRAWING_ENGINE_TYPE type) override
|
||||
Drawing::IDrawingEngine * CreateDrawingEngine(Drawing::DRAWING_ENGINE_TYPE type) override
|
||||
{
|
||||
return new X8DrawingEngine();
|
||||
}
|
||||
|
||||
// Text input
|
||||
virtual bool IsTextInputActive() override { return false; }
|
||||
virtual TextInputSession * StartTextInput(utf8 * buffer, size_t bufferSize) override { return nullptr; }
|
||||
virtual void StopTextInput() override { }
|
||||
bool IsTextInputActive() override { return false; }
|
||||
TextInputSession * StartTextInput(utf8 * buffer, size_t bufferSize) override { return nullptr; }
|
||||
void StopTextInput() override { }
|
||||
|
||||
// In-game UI
|
||||
IWindowManager * GetWindowManager() override
|
||||
{
|
||||
return _windowManager;
|
||||
}
|
||||
};
|
||||
|
||||
IUiContext * CreateDummyUiContext()
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
} }
|
|
@ -32,6 +32,8 @@ namespace OpenRCT2
|
|||
|
||||
namespace Ui
|
||||
{
|
||||
interface IWindowManager;
|
||||
|
||||
enum class FULLSCREEN_MODE
|
||||
{
|
||||
WINDOWED,
|
||||
|
@ -126,6 +128,9 @@ namespace OpenRCT2
|
|||
virtual bool IsTextInputActive() abstract;
|
||||
virtual TextInputSession * StartTextInput(utf8 * buffer, size_t bufferSize) abstract;
|
||||
virtual void StopTextInput() abstract;
|
||||
|
||||
// In-game UI
|
||||
virtual IWindowManager * GetWindowManager() abstract;
|
||||
};
|
||||
|
||||
IUiContext * CreateDummyUiContext();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -738,7 +738,7 @@ static void window_options_mouseup(rct_window *w, rct_widgetindex widgetIndex)
|
|||
case WINDOW_OPTIONS_PAGE_CONTROLS_AND_INTERFACE:
|
||||
switch (widgetIndex) {
|
||||
case WIDX_HOTKEY_DROPDOWN:
|
||||
window_shortcut_keys_open();
|
||||
context_open_window(WC_KEYBOARD_SHORTCUT_LIST);
|
||||
break;
|
||||
case WIDX_SCREEN_EDGE_SCROLLING:
|
||||
gConfigGeneral.edge_scrolling ^= 1;
|
||||
|
|
Loading…
Reference in New Issue