mirror of https://github.com/OpenTTD/OpenTTD.git
Feature: Make news and errors close hotkeys configurable
This commit is contained in:
parent
8f3d1ec970
commit
0110fa12da
|
@ -55,6 +55,8 @@ public:
|
||||||
void ScheduleErrorMessage(const ErrorMessageData &data);
|
void ScheduleErrorMessage(const ErrorMessageData &data);
|
||||||
|
|
||||||
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x = 0, int y = 0, const GRFFile *textref_stack_grffile = nullptr, uint textref_stack_size = 0, const uint32 *textref_stack = nullptr);
|
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x = 0, int y = 0, const GRFFile *textref_stack_grffile = nullptr, uint textref_stack_size = 0, const uint32 *textref_stack = nullptr);
|
||||||
|
bool HideActiveErrorMessage();
|
||||||
|
|
||||||
void ClearErrorMessages();
|
void ClearErrorMessages();
|
||||||
void ShowFirstError();
|
void ShowFirstError();
|
||||||
void UnshowCriticalError();
|
void UnshowCriticalError();
|
||||||
|
|
|
@ -315,13 +315,6 @@ public:
|
||||||
if (_window_system_initialized) ShowFirstError();
|
if (_window_system_initialized) ShowFirstError();
|
||||||
}
|
}
|
||||||
|
|
||||||
EventState OnKeyPress(WChar key, uint16 keycode) override
|
|
||||||
{
|
|
||||||
if (keycode != WKC_SPACE) return ES_NOT_HANDLED;
|
|
||||||
delete this;
|
|
||||||
return ES_HANDLED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether the currently shown error message was critical or not.
|
* Check whether the currently shown error message was critical or not.
|
||||||
* @return True iff the message was critical.
|
* @return True iff the message was critical.
|
||||||
|
@ -424,6 +417,18 @@ void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close active error message window
|
||||||
|
* @return true if a window was closed.
|
||||||
|
*/
|
||||||
|
bool HideActiveErrorMessage() {
|
||||||
|
ErrmsgWindow *w = (ErrmsgWindow*)FindWindowById(WC_ERRMSG, 0);
|
||||||
|
if (w == nullptr) return false;
|
||||||
|
delete w;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Schedule a list of errors.
|
* Schedule a list of errors.
|
||||||
* Note: This does not try to display the error now. This is useful if the window system is not yet running.
|
* Note: This does not try to display the error now. This is useful if the window system is not yet running.
|
||||||
|
|
|
@ -31,6 +31,8 @@
|
||||||
#include "tilehighlight_func.h"
|
#include "tilehighlight_func.h"
|
||||||
#include "hotkeys.h"
|
#include "hotkeys.h"
|
||||||
#include "guitimer_func.h"
|
#include "guitimer_func.h"
|
||||||
|
#include "error.h"
|
||||||
|
#include "news_gui.h"
|
||||||
|
|
||||||
#include "saveload/saveload.h"
|
#include "saveload/saveload.h"
|
||||||
|
|
||||||
|
@ -235,6 +237,8 @@ enum {
|
||||||
GHK_CHAT_ALL,
|
GHK_CHAT_ALL,
|
||||||
GHK_CHAT_COMPANY,
|
GHK_CHAT_COMPANY,
|
||||||
GHK_CHAT_SERVER,
|
GHK_CHAT_SERVER,
|
||||||
|
GHK_CLOSE_NEWS,
|
||||||
|
GHK_CLOSE_ERROR,
|
||||||
};
|
};
|
||||||
|
|
||||||
struct MainWindow : Window
|
struct MainWindow : Window
|
||||||
|
@ -427,6 +431,14 @@ struct MainWindow : Window
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case GHK_CLOSE_NEWS: // close active news window
|
||||||
|
if (!HideActiveNewsMessage()) return ES_NOT_HANDLED;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case GHK_CLOSE_ERROR: // close active error window
|
||||||
|
if (!HideActiveErrorMessage()) return ES_NOT_HANDLED;
|
||||||
|
break;
|
||||||
|
|
||||||
default: return ES_NOT_HANDLED;
|
default: return ES_NOT_HANDLED;
|
||||||
}
|
}
|
||||||
return ES_HANDLED;
|
return ES_HANDLED;
|
||||||
|
@ -520,6 +532,8 @@ static Hotkey global_hotkeys[] = {
|
||||||
Hotkey(_ghk_chat_all_keys, "chat_all", GHK_CHAT_ALL),
|
Hotkey(_ghk_chat_all_keys, "chat_all", GHK_CHAT_ALL),
|
||||||
Hotkey(_ghk_chat_company_keys, "chat_company", GHK_CHAT_COMPANY),
|
Hotkey(_ghk_chat_company_keys, "chat_company", GHK_CHAT_COMPANY),
|
||||||
Hotkey(_ghk_chat_server_keys, "chat_server", GHK_CHAT_SERVER),
|
Hotkey(_ghk_chat_server_keys, "chat_server", GHK_CHAT_SERVER),
|
||||||
|
Hotkey(WKC_SPACE, "close_news", GHK_CLOSE_NEWS),
|
||||||
|
Hotkey(WKC_SPACE, "close_error", GHK_CLOSE_ERROR),
|
||||||
HOTKEY_LIST_END
|
HOTKEY_LIST_END
|
||||||
};
|
};
|
||||||
HotkeyList MainWindow::hotkeys("global", global_hotkeys);
|
HotkeyList MainWindow::hotkeys("global", global_hotkeys);
|
||||||
|
|
|
@ -519,16 +519,6 @@ struct NewsWindow : Window {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
EventState OnKeyPress(WChar key, uint16 keycode) override
|
|
||||||
{
|
|
||||||
if (keycode == WKC_SPACE) {
|
|
||||||
/* Don't continue. */
|
|
||||||
delete this;
|
|
||||||
return ES_HANDLED;
|
|
||||||
}
|
|
||||||
return ES_NOT_HANDLED;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Some data on this window has become invalid.
|
* Some data on this window has become invalid.
|
||||||
* @param data Information about the changed data.
|
* @param data Information about the changed data.
|
||||||
|
@ -603,7 +593,6 @@ private:
|
||||||
|
|
||||||
/* static */ int NewsWindow::duration = 0; // Instance creation.
|
/* static */ int NewsWindow::duration = 0; // Instance creation.
|
||||||
|
|
||||||
|
|
||||||
/** Open up an own newspaper window for the news item */
|
/** Open up an own newspaper window for the news item */
|
||||||
static void ShowNewspaper(const NewsItem *ni)
|
static void ShowNewspaper(const NewsItem *ni)
|
||||||
{
|
{
|
||||||
|
@ -1033,6 +1022,17 @@ static void ShowNewsMessage(const NewsItem *ni)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Close active news message window
|
||||||
|
* @return true if a window was closed.
|
||||||
|
*/
|
||||||
|
bool HideActiveNewsMessage() {
|
||||||
|
NewsWindow *w = (NewsWindow*)FindWindowById(WC_NEWS_WINDOW, 0);
|
||||||
|
if (w == nullptr) return false;
|
||||||
|
delete w;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/** Show previous news item */
|
/** Show previous news item */
|
||||||
void ShowLastNewsMessage()
|
void ShowLastNewsMessage()
|
||||||
{
|
{
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
void ShowLastNewsMessage();
|
void ShowLastNewsMessage();
|
||||||
void ShowMessageHistory();
|
void ShowMessageHistory();
|
||||||
|
bool HideActiveNewsMessage();
|
||||||
|
|
||||||
extern NewsItem *_latest_news;
|
extern NewsItem *_latest_news;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue