mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-17 03:53:07 +01:00
Replace gConsoleOpen with function
This commit is contained in:
@@ -84,7 +84,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] == '`' && gConsoleOpen) {
|
||||
if (e->text.text[0] == '`' && console_is_open()) {
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -350,7 +350,7 @@ public:
|
||||
_cursorState.y = (sint32)(e.motion.y / gConfigGeneral.window_scale);
|
||||
break;
|
||||
case SDL_MOUSEWHEEL:
|
||||
if (gConsoleOpen)
|
||||
if (console_is_open())
|
||||
{
|
||||
console_scroll(e.wheel.y * 3); // Scroll 3 lines at a time
|
||||
break;
|
||||
|
||||
@@ -129,7 +129,7 @@ void input_handle_keyboard(bool isTitle)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!gConsoleOpen)
|
||||
if (!console_is_open())
|
||||
{
|
||||
if (!isTitle)
|
||||
{
|
||||
@@ -188,14 +188,14 @@ void input_handle_keyboard(bool isTitle)
|
||||
// Reserve backtick for console
|
||||
if (key == SDL_SCANCODE_GRAVE)
|
||||
{
|
||||
if ((gConfigGeneral.debugging_tools && !context_is_input_active()) || gConsoleOpen)
|
||||
if ((gConfigGeneral.debugging_tools && !context_is_input_active()) || console_is_open())
|
||||
{
|
||||
window_cancel_textbox();
|
||||
console_toggle();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else if (gConsoleOpen)
|
||||
else if (console_is_open())
|
||||
{
|
||||
input_handle_console(key);
|
||||
continue;
|
||||
|
||||
@@ -66,20 +66,23 @@ private:
|
||||
static constexpr sint32 CONSOLE_EDGE_PADDING = 4;
|
||||
static constexpr sint32 CONSOLE_CARET_WIDTH = 6;
|
||||
|
||||
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;
|
||||
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;
|
||||
@@ -91,7 +94,7 @@ public:
|
||||
void Scroll(sint32 linesToScroll);
|
||||
|
||||
void Update();
|
||||
void Draw(rct_drawpixelinfo * dpi);
|
||||
void Draw(rct_drawpixelinfo * dpi) const;
|
||||
|
||||
private:
|
||||
void ClearInput();
|
||||
@@ -99,8 +102,8 @@ private:
|
||||
void HistoryAdd(const utf8 * src);
|
||||
void WritePrompt();
|
||||
void ScrollToEnd();
|
||||
void Invalidate();
|
||||
sint32 GetNumVisibleLines();
|
||||
void Invalidate() const;
|
||||
sint32 GetNumVisibleLines() const;
|
||||
};
|
||||
|
||||
class StdInOutConsole : public InteractiveConsole
|
||||
@@ -118,8 +121,7 @@ public:
|
||||
};
|
||||
|
||||
// Old pass-through functions for in-game console
|
||||
extern bool gConsoleOpen;
|
||||
|
||||
bool console_is_open();
|
||||
void console_open();
|
||||
void console_close();
|
||||
void console_toggle();
|
||||
|
||||
@@ -9,8 +9,6 @@
|
||||
#include "../localisation/Language.h"
|
||||
#include "../Version.h"
|
||||
|
||||
bool gConsoleOpen = false;
|
||||
|
||||
static InGameConsole _inGameConsole;
|
||||
|
||||
InGameConsole::InGameConsole()
|
||||
@@ -84,7 +82,7 @@ void InGameConsole::Input(CONSOLE_INPUT input)
|
||||
void InGameConsole::ClearInput()
|
||||
{
|
||||
_consoleCurrentLine[0] = 0;
|
||||
if (gConsoleOpen) {
|
||||
if (_isOpen) {
|
||||
context_start_text_input(_consoleCurrentLine, sizeof(_consoleCurrentLine));
|
||||
}
|
||||
}
|
||||
@@ -135,7 +133,7 @@ void InGameConsole::ClearLine()
|
||||
|
||||
void InGameConsole::Open()
|
||||
{
|
||||
gConsoleOpen = true;
|
||||
_isOpen = true;
|
||||
ScrollToEnd();
|
||||
RefreshCaret();
|
||||
_consoleTextInputSession = context_start_text_input(_consoleCurrentLine, sizeof(_consoleCurrentLine));
|
||||
@@ -144,17 +142,21 @@ void InGameConsole::Open()
|
||||
void InGameConsole::Close()
|
||||
{
|
||||
_consoleTextInputSession = nullptr;
|
||||
gConsoleOpen = false;
|
||||
_isOpen = false;
|
||||
Invalidate();
|
||||
context_stop_text_input();
|
||||
}
|
||||
|
||||
void InGameConsole::Toggle()
|
||||
{
|
||||
if (gConsoleOpen)
|
||||
console_close();
|
||||
if (_isOpen)
|
||||
{
|
||||
Close();
|
||||
}
|
||||
else
|
||||
console_open();
|
||||
{
|
||||
Open();
|
||||
}
|
||||
}
|
||||
|
||||
void InGameConsole::WriteLine(const std::string &input, uint32 colourFormat)
|
||||
@@ -183,7 +185,7 @@ void InGameConsole::WriteLine(const std::string &input, uint32 colourFormat)
|
||||
}
|
||||
}
|
||||
|
||||
void InGameConsole::Invalidate()
|
||||
void InGameConsole::Invalidate() const
|
||||
{
|
||||
gfx_set_dirty_blocks(_consoleLeft, _consoleTop, _consoleRight, _consoleBottom);
|
||||
}
|
||||
@@ -195,7 +197,7 @@ void InGameConsole::Update()
|
||||
_consoleRight = context_get_width();
|
||||
_consoleBottom = 322;
|
||||
|
||||
if (gConsoleOpen) {
|
||||
if (_isOpen) {
|
||||
// When scrolling the map, the console pixels get copied... therefore invalidate the screen
|
||||
rct_window *mainWindow = window_get_main();
|
||||
if (mainWindow != nullptr) {
|
||||
@@ -218,9 +220,9 @@ void InGameConsole::Update()
|
||||
_consoleCaretTicks = (_consoleCaretTicks + 1) % 30;
|
||||
}
|
||||
|
||||
void InGameConsole::Draw(rct_drawpixelinfo * dpi)
|
||||
void InGameConsole::Draw(rct_drawpixelinfo * dpi) const
|
||||
{
|
||||
if (!gConsoleOpen)
|
||||
if (!_isOpen)
|
||||
return;
|
||||
|
||||
// Set font
|
||||
@@ -300,7 +302,7 @@ void InGameConsole::Draw(rct_drawpixelinfo * dpi)
|
||||
}
|
||||
|
||||
// Calculates the amount of visible lines, based on the console size, excluding the input line.
|
||||
sint32 InGameConsole::GetNumVisibleLines()
|
||||
sint32 InGameConsole::GetNumVisibleLines() const
|
||||
{
|
||||
const sint32 lineHeight = font_get_line_height(gCurrentFontSpriteBase);
|
||||
const sint32 consoleHeight = _consoleBottom - _consoleTop;
|
||||
@@ -310,6 +312,11 @@ sint32 InGameConsole::GetNumVisibleLines()
|
||||
|
||||
// Old pass-through functions
|
||||
|
||||
bool console_is_open()
|
||||
{
|
||||
return _inGameConsole.IsOpen();
|
||||
}
|
||||
|
||||
void console_open()
|
||||
{
|
||||
_inGameConsole.Open();
|
||||
|
||||
Reference in New Issue
Block a user