Changeset - r24347:03930c1a73e8
[Not reviewed]
master
0 5 0
dP - 4 years ago 2020-07-05 18:18:35
dp@dpointer.org
Feature: Make news and errors close hotkeys configurable
5 files changed with 40 insertions and 18 deletions:
0 comments (0 inline, 0 general)
src/error.h
Show inline comments
 
@@ -55,6 +55,8 @@ public:
 
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);
 
bool HideActiveErrorMessage();
 

	
 
void ClearErrorMessages();
 
void ShowFirstError();
 
void UnshowCriticalError();
src/error_gui.cpp
Show inline comments
 
@@ -315,13 +315,6 @@ public:
 
		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.
 
	 * @return True iff the message was critical.
 
@@ -424,6 +417,18 @@ void ShowErrorMessage(StringID summary_m
 
	}
 
}
 

	
 

	
 
/**
 
 * 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.
 
 * Note: This does not try to display the error now. This is useful if the window system is not yet running.
src/main_gui.cpp
Show inline comments
 
@@ -31,6 +31,8 @@
 
#include "tilehighlight_func.h"
 
#include "hotkeys.h"
 
#include "guitimer_func.h"
 
#include "error.h"
 
#include "news_gui.h"
 

	
 
#include "saveload/saveload.h"
 

	
 
@@ -235,6 +237,8 @@ enum {
 
	GHK_CHAT_ALL,
 
	GHK_CHAT_COMPANY,
 
	GHK_CHAT_SERVER,
 
	GHK_CLOSE_NEWS,
 
	GHK_CLOSE_ERROR,
 
};
 

	
 
struct MainWindow : Window
 
@@ -427,6 +431,14 @@ struct MainWindow : Window
 
				}
 
				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;
 
		}
 
		return ES_HANDLED;
 
@@ -520,6 +532,8 @@ static Hotkey global_hotkeys[] = {
 
	Hotkey(_ghk_chat_all_keys, "chat_all", GHK_CHAT_ALL),
 
	Hotkey(_ghk_chat_company_keys, "chat_company", GHK_CHAT_COMPANY),
 
	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
 
};
 
HotkeyList MainWindow::hotkeys("global", global_hotkeys);
src/news_gui.cpp
Show inline comments
 
@@ -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.
 
	 * @param data Information about the changed data.
 
@@ -603,7 +593,6 @@ private:
 

	
 
/* static */ int NewsWindow::duration = 0; // Instance creation.
 

	
 

	
 
/** Open up an own newspaper window for the news item */
 
static void ShowNewspaper(const NewsItem *ni)
 
{
 
@@ -1033,6 +1022,17 @@ static void ShowNewsMessage(const NewsIt
 
	}
 
}
 

	
 
/**
 
 * 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 */
 
void ShowLastNewsMessage()
 
{
src/news_gui.h
Show inline comments
 
@@ -14,6 +14,7 @@
 

	
 
void ShowLastNewsMessage();
 
void ShowMessageHistory();
 
bool HideActiveNewsMessage();
 

	
 
extern NewsItem *_latest_news;
 

	
0 comments (0 inline, 0 general)