mirror of https://github.com/OpenRCT2/OpenRCT2.git
Move in game console to UI library
This commit is contained in:
parent
395f124a0b
commit
dd0573b235
|
@ -24,6 +24,8 @@
|
|||
#include <openrct2/interface/Console.h>
|
||||
#include <openrct2-ui/interface/Window.h>
|
||||
#include <openrct2/localisation/Localisation.h>
|
||||
#include "interface/InGameConsole.h"
|
||||
#include "UiContext.h"
|
||||
|
||||
#ifdef __MACOSX__
|
||||
// macOS uses COMMAND rather than CTRL for many keyboard shortcuts
|
||||
|
@ -69,6 +71,8 @@ void TextComposition::Stop()
|
|||
|
||||
void TextComposition::HandleMessage(const SDL_Event * e)
|
||||
{
|
||||
auto& console = GetInGameConsole();
|
||||
|
||||
switch (e->type) {
|
||||
case SDL_TEXTEDITING:
|
||||
// When inputting Korean characters, `edit.length` is always zero
|
||||
|
@ -84,7 +88,7 @@ void TextComposition::HandleMessage(const SDL_Event * e)
|
|||
if (_session.Buffer != nullptr)
|
||||
{
|
||||
// HACK ` will close console, so don't input any text
|
||||
if (e->text.text[0] == '`' && console_is_open()) {
|
||||
if (e->text.text[0] == '`' && console.IsOpen()) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -93,7 +97,7 @@ void TextComposition::HandleMessage(const SDL_Event * e)
|
|||
Insert(newText);
|
||||
Memory::Free(newText);
|
||||
|
||||
console_refresh_caret();
|
||||
console.RefreshCaret();
|
||||
window_update_textbox();
|
||||
}
|
||||
break;
|
||||
|
@ -124,7 +128,7 @@ void TextComposition::HandleMessage(const SDL_Event * e)
|
|||
if (key == SDLK_BACKSPACE && (modifier & KEYBOARD_PRIMARY_MODIFIER))
|
||||
{
|
||||
Clear();
|
||||
console_refresh_caret();
|
||||
console.RefreshCaret();
|
||||
window_update_textbox();
|
||||
}
|
||||
|
||||
|
@ -138,17 +142,17 @@ void TextComposition::HandleMessage(const SDL_Event * e)
|
|||
_session.SelectionSize = endOffset - _session.SelectionStart;
|
||||
Delete();
|
||||
|
||||
console_refresh_caret();
|
||||
console.RefreshCaret();
|
||||
window_update_textbox();
|
||||
}
|
||||
break;
|
||||
case SDLK_HOME:
|
||||
CursorHome();
|
||||
console_refresh_caret();
|
||||
console.RefreshCaret();
|
||||
break;
|
||||
case SDLK_END:
|
||||
CursorEnd();
|
||||
console_refresh_caret();
|
||||
console.RefreshCaret();
|
||||
break;
|
||||
case SDLK_DELETE:
|
||||
{
|
||||
|
@ -157,7 +161,7 @@ void TextComposition::HandleMessage(const SDL_Event * e)
|
|||
_session.SelectionSize = _session.SelectionStart - startOffset;
|
||||
_session.SelectionStart = startOffset;
|
||||
Delete();
|
||||
console_refresh_caret();
|
||||
console.RefreshCaret();
|
||||
window_update_textbox();
|
||||
break;
|
||||
}
|
||||
|
@ -166,11 +170,11 @@ void TextComposition::HandleMessage(const SDL_Event * e)
|
|||
break;
|
||||
case SDLK_LEFT:
|
||||
CursorLeft();
|
||||
console_refresh_caret();
|
||||
console.RefreshCaret();
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
CursorRight();
|
||||
console_refresh_caret();
|
||||
console.RefreshCaret();
|
||||
break;
|
||||
case SDLK_v:
|
||||
if ((modifier & KEYBOARD_PRIMARY_MODIFIER) && SDL_HasClipboardText())
|
||||
|
|
|
@ -45,6 +45,8 @@
|
|||
#include <openrct2/interface/Console.h>
|
||||
#include <openrct2-ui/interface/Window.h>
|
||||
|
||||
#include "interface/InGameConsole.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
using namespace OpenRCT2::Drawing;
|
||||
using namespace OpenRCT2::Input;
|
||||
|
@ -87,7 +89,11 @@ private:
|
|||
uint32 _lastGestureTimestamp = 0;
|
||||
float _gestureRadius = 0;
|
||||
|
||||
InGameConsole _inGameConsole;
|
||||
|
||||
public:
|
||||
InGameConsole& GetInGameConsole() { return _inGameConsole; }
|
||||
|
||||
explicit UiContext(IPlatformEnvironment * env)
|
||||
: _platformUiContext(CreatePlatformUiContext()),
|
||||
_windowManager(CreateWindowManager()),
|
||||
|
@ -110,6 +116,16 @@ public:
|
|||
delete _platformUiContext;
|
||||
}
|
||||
|
||||
void Update() override
|
||||
{
|
||||
_inGameConsole.Update();
|
||||
}
|
||||
|
||||
void Draw(rct_drawpixelinfo * dpi) override
|
||||
{
|
||||
_inGameConsole.Draw(dpi);
|
||||
}
|
||||
|
||||
// Window
|
||||
void * GetWindow() override
|
||||
{
|
||||
|
@ -350,9 +366,9 @@ public:
|
|||
_cursorState.y = (sint32)(e.motion.y / gConfigGeneral.window_scale);
|
||||
break;
|
||||
case SDL_MOUSEWHEEL:
|
||||
if (console_is_open())
|
||||
if (_inGameConsole.IsOpen())
|
||||
{
|
||||
console_scroll(e.wheel.y * 3); // Scroll 3 lines at a time
|
||||
_inGameConsole.Scroll(e.wheel.y * 3); // Scroll 3 lines at a time
|
||||
break;
|
||||
}
|
||||
_cursorState.wheel -= e.wheel.y;
|
||||
|
@ -799,3 +815,9 @@ IUiContext * OpenRCT2::Ui::CreateUiContext(IPlatformEnvironment * env)
|
|||
{
|
||||
return new UiContext(env);
|
||||
}
|
||||
|
||||
InGameConsole& OpenRCT2::Ui::GetInGameConsole()
|
||||
{
|
||||
auto uiContext = static_cast<UiContext *>(GetContext()->GetUiContext());
|
||||
return uiContext->GetInGameConsole();
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ namespace OpenRCT2
|
|||
namespace Ui
|
||||
{
|
||||
struct FileDialogDesc;
|
||||
class InGameConsole;
|
||||
interface IUiContext;
|
||||
|
||||
interface IPlatformUiContext
|
||||
|
@ -44,5 +45,7 @@ namespace OpenRCT2
|
|||
|
||||
IUiContext * CreateUiContext(IPlatformEnvironment * env);
|
||||
IPlatformUiContext * CreatePlatformUiContext();
|
||||
|
||||
InGameConsole& GetInGameConsole();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,9 +25,13 @@
|
|||
#include <openrct2/interface/Console.h>
|
||||
#include <openrct2/paint/VirtualFloor.h>
|
||||
#include <openrct2-ui/windows/Window.h>
|
||||
#include "../interface/InGameConsole.h"
|
||||
#include "../UiContext.h"
|
||||
#include "KeyboardShortcuts.h"
|
||||
#include "Input.h"
|
||||
|
||||
using namespace OpenRCT2::Ui;
|
||||
|
||||
static void input_handle_console(sint32 key)
|
||||
{
|
||||
CONSOLE_INPUT input = CONSOLE_INPUT_NONE;
|
||||
|
@ -54,7 +58,8 @@ static void input_handle_console(sint32 key)
|
|||
}
|
||||
if (input != CONSOLE_INPUT_NONE)
|
||||
{
|
||||
console_input(input);
|
||||
auto& console = GetInGameConsole();
|
||||
console.Input(input);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -129,7 +134,8 @@ void input_handle_keyboard(bool isTitle)
|
|||
return;
|
||||
}
|
||||
|
||||
if (!console_is_open())
|
||||
auto& console = GetInGameConsole();
|
||||
if (!console.IsOpen())
|
||||
{
|
||||
if (!isTitle)
|
||||
{
|
||||
|
@ -188,14 +194,14 @@ void input_handle_keyboard(bool isTitle)
|
|||
// Reserve backtick for console
|
||||
if (key == SDL_SCANCODE_GRAVE)
|
||||
{
|
||||
if ((gConfigGeneral.debugging_tools && !context_is_input_active()) || console_is_open())
|
||||
if ((gConfigGeneral.debugging_tools && !context_is_input_active()) || console.IsOpen())
|
||||
{
|
||||
window_cancel_textbox();
|
||||
console_toggle();
|
||||
console.Toggle();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (console_is_open())
|
||||
else if (console.IsOpen())
|
||||
{
|
||||
input_handle_console(key);
|
||||
continue;
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
#include <algorithm>
|
||||
#include "Colour.h"
|
||||
#include "Console.h"
|
||||
#include "themes.h"
|
||||
#include "Window.h"
|
||||
#include "../config/Config.h"
|
||||
#include "../Context.h"
|
||||
#include "../core/Math.hpp"
|
||||
#include "../localisation/Language.h"
|
||||
#include "../Version.h"
|
||||
#include <openrct2/config/Config.h>
|
||||
#include <openrct2/Context.h>
|
||||
#include <openrct2/core/Math.hpp>
|
||||
#include <openrct2/interface/Colour.h>
|
||||
#include <openrct2/interface/themes.h>
|
||||
#include <openrct2/interface/Window.h>
|
||||
#include <openrct2/localisation/Language.h>
|
||||
#include <openrct2/Version.h>
|
||||
#include "InGameConsole.h"
|
||||
|
||||
using namespace OpenRCT2::Ui;
|
||||
|
||||
static InGameConsole _inGameConsole;
|
||||
|
||||
|
@ -309,50 +311,3 @@ sint32 InGameConsole::GetNumVisibleLines() const
|
|||
const sint32 drawableHeight = consoleHeight - 2 * lineHeight - 4; // input line, separator - padding
|
||||
return drawableHeight / lineHeight;
|
||||
}
|
||||
|
||||
// Old pass-through functions
|
||||
|
||||
bool console_is_open()
|
||||
{
|
||||
return _inGameConsole.IsOpen();
|
||||
}
|
||||
|
||||
void console_open()
|
||||
{
|
||||
_inGameConsole.Open();
|
||||
}
|
||||
|
||||
void console_toggle()
|
||||
{
|
||||
_inGameConsole.Toggle();
|
||||
}
|
||||
|
||||
void console_update()
|
||||
{
|
||||
_inGameConsole.Update();
|
||||
}
|
||||
|
||||
void console_draw(rct_drawpixelinfo *dpi)
|
||||
{
|
||||
_inGameConsole.Draw(dpi);
|
||||
}
|
||||
|
||||
void console_input(CONSOLE_INPUT input)
|
||||
{
|
||||
_inGameConsole.Input(input);
|
||||
}
|
||||
|
||||
void console_writeline(const utf8 * src, uint32 colourFormat)
|
||||
{
|
||||
_inGameConsole.WriteLine(src, colourFormat);
|
||||
}
|
||||
|
||||
void console_scroll(sint32 linesToScroll)
|
||||
{
|
||||
_inGameConsole.Scroll(linesToScroll);
|
||||
}
|
||||
|
||||
void console_refresh_caret()
|
||||
{
|
||||
_inGameConsole.RefreshCaret();
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
#include <openrct2/interface/Console.h>
|
||||
|
||||
namespace OpenRCT2 { namespace Ui
|
||||
{
|
||||
class InGameConsole : public InteractiveConsole
|
||||
{
|
||||
private:
|
||||
static constexpr sint32 CONSOLE_MAX_LINES = 300;
|
||||
static constexpr sint32 CONSOLE_HISTORY_SIZE = 64;
|
||||
static constexpr sint32 CONSOLE_INPUT_SIZE = 256;
|
||||
static constexpr sint32 CONSOLE_CARET_FLASH_THRESHOLD = 15;
|
||||
static constexpr sint32 CONSOLE_EDGE_PADDING = 4;
|
||||
static constexpr sint32 CONSOLE_CARET_WIDTH = 6;
|
||||
|
||||
bool _isOpen;
|
||||
sint32 _consoleLeft, _consoleTop, _consoleRight, _consoleBottom;
|
||||
sint32 _lastMainViewportX, _lastMainViewportY;
|
||||
std::deque<std::string> _consoleLines;
|
||||
utf8 _consoleCurrentLine[CONSOLE_INPUT_SIZE];
|
||||
sint32 _consoleCaretTicks;
|
||||
sint32 _consoleScrollPos = 0;
|
||||
TextInputSession * _consoleTextInputSession;
|
||||
utf8 _consoleHistory[CONSOLE_HISTORY_SIZE][CONSOLE_INPUT_SIZE];
|
||||
sint32 _consoleHistoryIndex = 0;
|
||||
sint32 _consoleHistoryCount = 0;
|
||||
|
||||
public:
|
||||
InGameConsole();
|
||||
InGameConsole(const InGameConsole& src) = delete;
|
||||
|
||||
bool IsOpen() const { return _isOpen; }
|
||||
|
||||
void Clear() override;
|
||||
void Open();
|
||||
void Close() override;
|
||||
void Toggle();
|
||||
void WriteLine(const std::string &s, uint32 colourFormat) override;
|
||||
|
||||
void Input(CONSOLE_INPUT input);
|
||||
void RefreshCaret();
|
||||
void Scroll(sint32 linesToScroll);
|
||||
|
||||
void Update();
|
||||
void Draw(rct_drawpixelinfo * dpi) const;
|
||||
|
||||
private:
|
||||
void ClearInput();
|
||||
void ClearLine();
|
||||
void HistoryAdd(const utf8 * src);
|
||||
void WritePrompt();
|
||||
void ScrollToEnd();
|
||||
void Invalidate() const;
|
||||
sint32 GetNumVisibleLines() const;
|
||||
};
|
||||
} }
|
|
@ -47,6 +47,10 @@
|
|||
#include <openrct2-ui/interface/LandTool.h>
|
||||
#include <openrct2/scenario/Scenario.h>
|
||||
#include <openrct2/world/Park.h>
|
||||
#include "../interface/InGameConsole.h"
|
||||
#include "../UiContext.h"
|
||||
|
||||
using namespace OpenRCT2::Ui;
|
||||
|
||||
enum {
|
||||
WIDX_PAUSE,
|
||||
|
@ -3124,8 +3128,11 @@ static void top_toolbar_debug_menu_dropdown(sint16 dropdownIndex)
|
|||
if (w) {
|
||||
switch (dropdownIndex) {
|
||||
case DDIDX_CONSOLE:
|
||||
console_open();
|
||||
{
|
||||
auto& console = GetInGameConsole();
|
||||
console.Open();
|
||||
break;
|
||||
}
|
||||
case DDIDX_TILE_INSPECTOR:
|
||||
context_open_window(WC_TILE_INSPECTOR);
|
||||
break;
|
||||
|
|
|
@ -175,6 +175,11 @@ namespace OpenRCT2
|
|||
return gExitCode;
|
||||
}
|
||||
|
||||
void WriteLine(const std::string &s) override
|
||||
{
|
||||
_stdInOutConsole.WriteLine(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Causes the OpenRCT2 game loop to finish.
|
||||
*/
|
||||
|
@ -793,8 +798,8 @@ namespace OpenRCT2
|
|||
|
||||
twitch_update();
|
||||
chat_update();
|
||||
console_update();
|
||||
_stdInOutConsole.ProcessEvalQueue();
|
||||
_uiContext->Update();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -92,6 +92,7 @@ namespace OpenRCT2
|
|||
virtual bool Initialise() abstract;
|
||||
virtual bool LoadParkFromFile(const std::string &path, bool loadTitleScreenOnFail = false) abstract;
|
||||
virtual bool LoadParkFromStream(IStream * stream, const std::string &path, bool loadTitleScreenFirstOnFail = false) abstract;
|
||||
virtual void WriteLine(const std::string &s) abstract;
|
||||
virtual void Finish() abstract;
|
||||
virtual void Quit() abstract;
|
||||
|
||||
|
|
|
@ -56,56 +56,6 @@ public:
|
|||
virtual void WriteLine(const std::string &s, uint32 colourFormat) abstract;
|
||||
};
|
||||
|
||||
class InGameConsole : public InteractiveConsole
|
||||
{
|
||||
private:
|
||||
static constexpr sint32 CONSOLE_MAX_LINES = 300;
|
||||
static constexpr sint32 CONSOLE_HISTORY_SIZE = 64;
|
||||
static constexpr sint32 CONSOLE_INPUT_SIZE = 256;
|
||||
static constexpr sint32 CONSOLE_CARET_FLASH_THRESHOLD = 15;
|
||||
static constexpr sint32 CONSOLE_EDGE_PADDING = 4;
|
||||
static constexpr sint32 CONSOLE_CARET_WIDTH = 6;
|
||||
|
||||
bool _isOpen;
|
||||
sint32 _consoleLeft, _consoleTop, _consoleRight, _consoleBottom;
|
||||
sint32 _lastMainViewportX, _lastMainViewportY;
|
||||
std::deque<std::string> _consoleLines;
|
||||
utf8 _consoleCurrentLine[CONSOLE_INPUT_SIZE];
|
||||
sint32 _consoleCaretTicks;
|
||||
sint32 _consoleScrollPos = 0;
|
||||
TextInputSession * _consoleTextInputSession;
|
||||
utf8 _consoleHistory[CONSOLE_HISTORY_SIZE][CONSOLE_INPUT_SIZE];
|
||||
sint32 _consoleHistoryIndex = 0;
|
||||
sint32 _consoleHistoryCount = 0;
|
||||
|
||||
public:
|
||||
InGameConsole();
|
||||
|
||||
bool IsOpen() const { return _isOpen; }
|
||||
|
||||
void Clear() override;
|
||||
void Open();
|
||||
void Close() override;
|
||||
void Toggle();
|
||||
void WriteLine(const std::string &s, uint32 colourFormat) override;
|
||||
|
||||
void Input(CONSOLE_INPUT input);
|
||||
void RefreshCaret();
|
||||
void Scroll(sint32 linesToScroll);
|
||||
|
||||
void Update();
|
||||
void Draw(rct_drawpixelinfo * dpi) const;
|
||||
|
||||
private:
|
||||
void ClearInput();
|
||||
void ClearLine();
|
||||
void HistoryAdd(const utf8 * src);
|
||||
void WritePrompt();
|
||||
void ScrollToEnd();
|
||||
void Invalidate() const;
|
||||
sint32 GetNumVisibleLines() const;
|
||||
};
|
||||
|
||||
class StdInOutConsole : public InteractiveConsole
|
||||
{
|
||||
private:
|
||||
|
@ -117,16 +67,6 @@ public:
|
|||
|
||||
void Clear() override;
|
||||
void Close() override;
|
||||
void WriteLine(const std::string &s) { InteractiveConsole::WriteLine(s); }
|
||||
void WriteLine(const std::string &s, uint32 colourFormat) override;
|
||||
};
|
||||
|
||||
// Old pass-through functions for in-game console
|
||||
bool console_is_open();
|
||||
void console_open();
|
||||
void console_toggle();
|
||||
void console_update();
|
||||
void console_draw(rct_drawpixelinfo *dpi);
|
||||
void console_input(CONSOLE_INPUT input);
|
||||
void console_writeline(const utf8 * src, uint32 colourFormat = FORMAT_WINDOW_COLOUR_2);
|
||||
void console_refresh_caret();
|
||||
void console_scroll(sint32 delta);
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include "../Context.h"
|
||||
#include "../core/Math.hpp"
|
||||
#include "../core/String.hpp"
|
||||
#include "../OpenRCT2.h"
|
||||
|
@ -44,6 +45,8 @@
|
|||
#include "http.h"
|
||||
#include "twitch.h"
|
||||
|
||||
using namespace OpenRCT2;
|
||||
|
||||
bool gTwitchEnable = false;
|
||||
|
||||
namespace Twitch
|
||||
|
@ -201,10 +204,11 @@ namespace Twitch
|
|||
request.type = HTTP_DATA_JSON;
|
||||
http_request_async(&request, [](http_response_t *jsonResponse) -> void
|
||||
{
|
||||
auto context = GetContext();
|
||||
if (jsonResponse == nullptr)
|
||||
{
|
||||
_twitchState = TWITCH_STATE_LEFT;
|
||||
console_writeline("Unable to connect to twitch channel.");
|
||||
context->WriteLine("Unable to connect to twitch channel.");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -221,7 +225,7 @@ namespace Twitch
|
|||
http_request_dispose(jsonResponse);
|
||||
|
||||
_twitchLastPulseTick = 0;
|
||||
console_writeline("Connected to twitch channel.");
|
||||
context->WriteLine("Connected to twitch channel.");
|
||||
}
|
||||
_twitchIdle = true;
|
||||
});
|
||||
|
@ -238,7 +242,7 @@ namespace Twitch
|
|||
_twitchJsonResponse = nullptr;
|
||||
}
|
||||
|
||||
console_writeline("Left twitch channel.");
|
||||
GetContext()->WriteLine("Left twitch channel.");
|
||||
_twitchState = TWITCH_STATE_LEFT;
|
||||
_twitchLastPulseTick = 0;
|
||||
gTwitchEnable = false;
|
||||
|
@ -256,7 +260,7 @@ namespace Twitch
|
|||
// _twitchState = TWITCH_STATE_LEFT;
|
||||
// _twitchIdle = true;
|
||||
//
|
||||
// console_writeline("Left twitch channel.");
|
||||
// GetContext()->WriteLine("Left twitch channel.");
|
||||
// });
|
||||
}
|
||||
|
||||
|
|
|
@ -52,7 +52,7 @@ void Painter::Paint(IDrawingEngine * de)
|
|||
|
||||
update_palette_effects();
|
||||
chat_draw(dpi);
|
||||
console_draw(dpi);
|
||||
_uiContext->Draw(dpi);
|
||||
|
||||
if ((gScreenFlags & SCREEN_FLAGS_TITLE_DEMO) && !title_should_hide_version_info())
|
||||
{
|
||||
|
|
|
@ -31,6 +31,9 @@ namespace OpenRCT2 { namespace Ui
|
|||
IWindowManager * const _windowManager = CreateDummyWindowManager();
|
||||
|
||||
public:
|
||||
void Update() override { }
|
||||
void Draw(rct_drawpixelinfo * dpi) override { }
|
||||
|
||||
void CreateWindow() override { }
|
||||
void CloseWindow() override { }
|
||||
void RecreateWindow() override { }
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include "../Context.h"
|
||||
#include "../interface/Cursors.h"
|
||||
|
||||
struct rct_drawpixelinfo;
|
||||
|
||||
namespace OpenRCT2
|
||||
{
|
||||
namespace Drawing
|
||||
|
@ -91,6 +93,9 @@ namespace OpenRCT2
|
|||
{
|
||||
virtual ~IUiContext() = default;
|
||||
|
||||
virtual void Update() abstract;
|
||||
virtual void Draw(rct_drawpixelinfo * dpi) abstract;
|
||||
|
||||
// Window
|
||||
virtual void CreateWindow() abstract;
|
||||
virtual void CloseWindow() abstract;
|
||||
|
|
Loading…
Reference in New Issue