Adds console toggle hotkeys to the console welcome message.

Patch By: nwtour
Differential Revision: https://code.wildfiregames.com/D4347
This was SVN commit r26035.
This commit is contained in:
vladislavbelov
2021-12-07 20:09:46 +00:00
parent 5ceeac3dd5
commit 90f27d4909
2 changed files with 26 additions and 3 deletions
+24 -3
View File
@@ -80,7 +80,9 @@ CConsole::CConsole()
m_bCursorVisState = true;
m_cursorBlinkRate = 0.5;
InsertMessage("[ 0 A.D. Console v0.14 ]");
m_QuitHotkeyWasShown = false;
InsertMessage("[ 0 A.D. Console v0.15 ]");
InsertMessage("");
}
@@ -121,6 +123,22 @@ void CConsole::UpdateScreenSize(int w, int h)
m_fHeight = height / g_VideoMode.GetScale();
}
void CConsole::ShowQuitHotkeys()
{
if (m_QuitHotkeyWasShown)
return;
std::string str;
for (const std::pair<const SDL_Scancode_, KeyMapping>& key : g_HotkeyMap)
if (key.second.front().name == "console.toggle")
str += (str.empty() ? "Press " : " / ") + FindScancodeName(static_cast<SDL_Scancode>(key.first));
if (!str.empty())
InsertMessage(str + " to quit.");
m_QuitHotkeyWasShown = true;
}
void CConsole::ToggleVisible()
{
m_bToggle = true;
@@ -128,9 +146,12 @@ void CConsole::ToggleVisible()
// TODO: this should be based on input focus, not visibility
if (m_bVisible)
{
ShowQuitHotkeys();
SDL_StartTextInput();
else
SDL_StopTextInput();
return;
}
SDL_StopTextInput();
}
void CConsole::SetVisible(bool visible)
+2
View File
@@ -110,6 +110,7 @@ private:
bool m_bToggle; // show/hide animation is currently active
double m_prevTime; // the previous time the cursor draw state changed (used for blinking cursor)
bool m_bCursorVisState; // if the cursor should be drawn or not
bool m_QuitHotkeyWasShown; // show console.toggle hotkey values at first time
double m_cursorBlinkRate; // cursor blink rate in seconds, if greater than 0.0
void DrawWindow(CCanvas2D& canvas);
@@ -128,6 +129,7 @@ private:
void LoadHistory();
void SaveHistory();
void ShowQuitHotkeys();
};
extern CConsole* g_Console;