1
0
Fork 0

Compare commits

...

4 Commits

Author SHA1 Message Date
Kuhnovic 1693e34e77
Merge 643dcefc8f into 7546c1acab 2025-07-14 08:01:53 +00:00
Peter Nelson 7546c1acab
Codefix f220ed179d: GetUnicodeGlyph takes a unicode character. (#14438)
Previous change erroneously changed type to GlyphID, based on naming. It should actually be char32_t.
2025-07-14 08:01:42 +00:00
Peter Nelson a6143eea21
Codechange: Include more relevant headers for script_storage. (#14437) 2025-07-14 07:49:50 +01:00
Koen Bussemaker 643dcefc8f Change: Error window colour changes based on severity 2025-03-14 20:05:54 +01:00
8 changed files with 47 additions and 40 deletions

View File

@ -134,7 +134,7 @@ bool DriverFactoryBase::SelectDriverImpl(const std::string &name, Driver::Type t
Debug(driver, 1, "Probing {} driver '{}' skipped due to earlier crash", GetDriverTypeName(type), d->name); Debug(driver, 1, "Probing {} driver '{}' skipped due to earlier crash", GetDriverTypeName(type), d->name);
_video_hw_accel = false; _video_hw_accel = false;
ErrorMessageData msg(GetEncodedString(STR_VIDEO_DRIVER_ERROR), GetEncodedString(STR_VIDEO_DRIVER_ERROR_HARDWARE_ACCELERATION_CRASH), true); ErrorMessageData msg(GetEncodedString(STR_VIDEO_DRIVER_ERROR), GetEncodedString(STR_VIDEO_DRIVER_ERROR_HARDWARE_ACCELERATION_CRASH), WL_CRITICAL);
ScheduleErrorMessage(std::move(msg)); ScheduleErrorMessage(std::move(msg));
continue; continue;
} }
@ -158,7 +158,7 @@ bool DriverFactoryBase::SelectDriverImpl(const std::string &name, Driver::Type t
if (type == Driver::DT_VIDEO && _video_hw_accel && d->UsesHardwareAcceleration()) { if (type == Driver::DT_VIDEO && _video_hw_accel && d->UsesHardwareAcceleration()) {
_video_hw_accel = false; _video_hw_accel = false;
ErrorMessageData msg(GetEncodedString(STR_VIDEO_DRIVER_ERROR), GetEncodedString(STR_VIDEO_DRIVER_ERROR_NO_HARDWARE_ACCELERATION), true); ErrorMessageData msg(GetEncodedString(STR_VIDEO_DRIVER_ERROR), GetEncodedString(STR_VIDEO_DRIVER_ERROR_NO_HARDWARE_ACCELERATION), WL_CRITICAL);
ScheduleErrorMessage(std::move(msg)); ScheduleErrorMessage(std::move(msg));
} }
} }

View File

@ -30,7 +30,7 @@ enum WarningLevel : uint8_t {
/** The data of the error message. */ /** The data of the error message. */
class ErrorMessageData { class ErrorMessageData {
protected: protected:
bool is_critical; ///< Whether the error message is critical. WarningLevel level; ///< Level of the error message (e.g. whether it's a critical error).
EncodedString summary_msg; ///< General error message showed in first line. Must be valid. EncodedString summary_msg; ///< General error message showed in first line. Must be valid.
EncodedString detailed_msg; ///< Detailed error message showed in second line. Can be #INVALID_STRING_ID. EncodedString detailed_msg; ///< Detailed error message showed in second line. Can be #INVALID_STRING_ID.
EncodedString extra_msg; ///< Extra error message shown in third line. Can be #INVALID_STRING_ID. EncodedString extra_msg; ///< Extra error message shown in third line. Can be #INVALID_STRING_ID.
@ -38,7 +38,7 @@ protected:
CompanyID company; ///< Company belonging to the face being shown. #CompanyID::Invalid() if no face present. CompanyID company; ///< Company belonging to the face being shown. #CompanyID::Invalid() if no face present.
public: public:
ErrorMessageData(EncodedString &&summary_msg, EncodedString &&detailed_msg, bool is_critical = false, int x = 0, int y = 0, EncodedString &&extra_msg = {}, CompanyID company = CompanyID::Invalid()); ErrorMessageData(EncodedString &&summary_msg, EncodedString &&detailed_msg, WarningLevel level = WL_ERROR, int x = 0, int y = 0, EncodedString &&extra_msg = {}, CompanyID company = CompanyID::Invalid());
/** Check whether error window shall display a company manager face */ /** Check whether error window shall display a company manager face */
bool HasFace() const { return company != CompanyID::Invalid(); } bool HasFace() const { return company != CompanyID::Invalid(); }

View File

@ -35,10 +35,10 @@
static constexpr NWidgetPart _nested_errmsg_widgets[] = { static constexpr NWidgetPart _nested_errmsg_widgets[] = {
NWidget(NWID_HORIZONTAL), NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_RED), NWidget(WWT_CLOSEBOX, COLOUR_RED, WID_EM_CLOSEBOX),
NWidget(WWT_CAPTION, COLOUR_RED, WID_EM_CAPTION), SetStringTip(STR_ERROR_MESSAGE_CAPTION), NWidget(WWT_CAPTION, COLOUR_RED, WID_EM_CAPTION), SetStringTip(STR_ERROR_MESSAGE_CAPTION),
EndContainer(), EndContainer(),
NWidget(WWT_PANEL, COLOUR_RED), NWidget(WWT_PANEL, COLOUR_RED, WID_EM_PANEL),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_EM_MESSAGE), SetPadding(WidgetDimensions::unscaled.modalpopup), SetFill(1, 0), SetMinimalSize(236, 0), NWidget(WWT_EMPTY, INVALID_COLOUR, WID_EM_MESSAGE), SetPadding(WidgetDimensions::unscaled.modalpopup), SetFill(1, 0), SetMinimalSize(236, 0),
EndContainer(), EndContainer(),
}; };
@ -52,10 +52,10 @@ static WindowDesc _errmsg_desc(
static constexpr NWidgetPart _nested_errmsg_face_widgets[] = { static constexpr NWidgetPart _nested_errmsg_face_widgets[] = {
NWidget(NWID_HORIZONTAL), NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_RED), NWidget(WWT_CLOSEBOX, COLOUR_RED, WID_EM_CLOSEBOX),
NWidget(WWT_CAPTION, COLOUR_RED, WID_EM_CAPTION), NWidget(WWT_CAPTION, COLOUR_RED, WID_EM_CAPTION),
EndContainer(), EndContainer(),
NWidget(WWT_PANEL, COLOUR_RED), NWidget(WWT_PANEL, COLOUR_RED, WID_EM_PANEL),
NWidget(NWID_HORIZONTAL), NWidget(NWID_HORIZONTAL),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_EM_FACE), SetPadding(2, 0, 2, 2), SetFill(0, 1), SetMinimalSize(92, 119), NWidget(WWT_EMPTY, INVALID_COLOUR, WID_EM_FACE), SetPadding(2, 0, 2, 2), SetFill(0, 1), SetMinimalSize(92, 119),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_EM_MESSAGE), SetPadding(WidgetDimensions::unscaled.modalpopup), SetFill(1, 1), SetMinimalSize(236, 0), NWidget(WWT_EMPTY, INVALID_COLOUR, WID_EM_MESSAGE), SetPadding(WidgetDimensions::unscaled.modalpopup), SetFill(1, 1), SetMinimalSize(236, 0),
@ -74,13 +74,13 @@ static WindowDesc _errmsg_face_desc(
* Display an error message in a window. * Display an error message in a window.
* @param summary_msg General error message showed in first line. Must be valid. * @param summary_msg General error message showed in first line. Must be valid.
* @param detailed_msg Detailed error message showed in second line. Can be empty. * @param detailed_msg Detailed error message showed in second line. Can be empty.
* @param is_critical Whether the error is critical. Critical messages never go away on their own. * @param level Warning/error level of the message. NOTE: critical messages never go away on their own.
* @param x World X position (TileVirtX) of the error location. Set both x and y to 0 to just center the message when there is no related error tile. * @param x World X position (TileVirtX) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
* @param y World Y position (TileVirtY) of the error location. Set both x and y to 0 to just center the message when there is no related error tile. * @param y World Y position (TileVirtY) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
* @param extra_msg Extra error message showed in third line. Can be empty. * @param extra_msg Extra error message showed in third line. Can be empty.
*/ */
ErrorMessageData::ErrorMessageData(EncodedString &&summary_msg, EncodedString &&detailed_msg, bool is_critical, int x, int y, EncodedString &&extra_msg, CompanyID company) : ErrorMessageData::ErrorMessageData(EncodedString &&summary_msg, EncodedString &&detailed_msg, WarningLevel level, int x, int y, EncodedString &&extra_msg, CompanyID company) :
is_critical(is_critical), level(level),
summary_msg(std::move(summary_msg)), summary_msg(std::move(summary_msg)),
detailed_msg(std::move(detailed_msg)), detailed_msg(std::move(detailed_msg)),
extra_msg(std::move(extra_msg)), extra_msg(std::move(extra_msg)),
@ -113,8 +113,15 @@ public:
{ {
this->InitNested(); this->InitNested();
Colours window_colour = COLOUR_RED;
if (level == WL_INFO) window_colour = COLOUR_GREEN;
if (level == WL_WARNING) window_colour = COLOUR_ORANGE;
this->GetWidget<NWidgetCore>(WID_EM_CAPTION)->colour = window_colour;
this->GetWidget<NWidgetCore>(WID_EM_CLOSEBOX)->colour = window_colour;
this->GetWidget<NWidgetCore>(WID_EM_PANEL)->colour = window_colour;
/* Only start the timeout if the message is not critical. */ /* Only start the timeout if the message is not critical. */
if (!this->is_critical) { if (this->level != WL_CRITICAL) {
this->display_timeout.Reset(); this->display_timeout.Reset();
} }
} }
@ -225,7 +232,7 @@ public:
void OnMouseLoop() override void OnMouseLoop() override
{ {
/* Disallow closing the window too easily, if timeout is disabled */ /* Disallow closing the window too easily, if timeout is disabled */
if (_right_button_down && !this->is_critical) this->Close(); if (_right_button_down && this->level != WL_CRITICAL) this->Close();
} }
void Close([[maybe_unused]] int data = 0) override void Close([[maybe_unused]] int data = 0) override
@ -241,7 +248,7 @@ public:
*/ */
bool IsCritical() bool IsCritical()
{ {
return this->is_critical; return this->level == WL_CRITICAL;
} }
}; };
@ -281,7 +288,7 @@ void UnshowCriticalError()
/** /**
* Display an error message in a window. * Display an error message in a window.
* Note: CommandCost errors are always severity level WL_INFO. * Note: CommandCost errors are always severity level WL_ERROR.
* @param summary_msg General error message showed in first line. Must be valid. * @param summary_msg General error message showed in first line. Must be valid.
* @param x World X position (TileVirtX) of the error location. Set both x and y to 0 to just center the message when there is no related error tile. * @param x World X position (TileVirtX) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
* @param y World Y position (TileVirtY) of the error location. Set both x and y to 0 to just center the message when there is no related error tile. * @param y World Y position (TileVirtY) of the error location. Set both x and y to 0 to just center the message when there is no related error tile.
@ -292,7 +299,7 @@ void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc
EncodedString error = std::move(cc.GetEncodedMessage()); EncodedString error = std::move(cc.GetEncodedMessage());
if (error.empty()) error = GetEncodedStringIfValid(cc.GetErrorMessage()); if (error.empty()) error = GetEncodedStringIfValid(cc.GetErrorMessage());
ShowErrorMessage(std::move(summary_msg), std::move(error), WL_INFO, x, y, ShowErrorMessage(std::move(summary_msg), std::move(error), WL_ERROR, x, y,
GetEncodedStringIfValid(cc.GetExtraErrorMessage()), cc.GetErrorOwner()); GetEncodedStringIfValid(cc.GetExtraErrorMessage()), cc.GetErrorOwner());
} }
@ -323,12 +330,10 @@ void ShowErrorMessage(EncodedString &&summary_msg, EncodedString &&detailed_msg,
IConsolePrint(wl == WL_WARNING ? CC_WARNING : CC_ERROR, message); IConsolePrint(wl == WL_WARNING ? CC_WARNING : CC_ERROR, message);
} }
bool is_critical = wl == WL_CRITICAL;
if (_game_mode == GM_BOOTSTRAP) return; if (_game_mode == GM_BOOTSTRAP) return;
if (_settings_client.gui.errmsg_duration == 0 && !is_critical) return; if (_settings_client.gui.errmsg_duration == 0 && wl != WL_CRITICAL) return;
ErrorMessageData data(std::move(summary_msg), std::move(detailed_msg), is_critical, x, y, std::move(extra_msg), company); ErrorMessageData data(std::move(summary_msg), std::move(detailed_msg), wl, x, y, std::move(extra_msg), company);
ErrmsgWindow *w = dynamic_cast<ErrmsgWindow *>(FindWindowById(WC_ERRMSG, 0)); ErrmsgWindow *w = dynamic_cast<ErrmsgWindow *>(FindWindowById(WC_ERRMSG, 0));
if (w != nullptr) { if (w != nullptr) {

View File

@ -43,26 +43,26 @@ SpriteFontCache::SpriteFontCache(FontSize fs) : FontCache(fs)
} }
/** /**
* Get SpriteID associated with a GlyphID. * Get SpriteID associated with a character.
* @param key Glyph to find. * @param key Character to find.
* @return SpriteID of glyph, or 0 if not present. * @return SpriteID for character, or 0 if not present.
*/ */
SpriteID SpriteFontCache::GetUnicodeGlyph(GlyphID key) SpriteID SpriteFontCache::GetUnicodeGlyph(char32_t key)
{ {
const auto found = this->glyph_to_spriteid_map.find(key & ~SPRITE_GLYPH); const auto found = this->char_map.find(key);
if (found == std::end(this->glyph_to_spriteid_map)) return 0; if (found == std::end(this->char_map)) return 0;
return found->second; return found->second;
} }
void SpriteFontCache::SetUnicodeGlyph(char32_t key, SpriteID sprite) void SpriteFontCache::SetUnicodeGlyph(char32_t key, SpriteID sprite)
{ {
this->glyph_to_spriteid_map[key] = sprite; this->char_map[key] = sprite;
} }
void SpriteFontCache::InitializeUnicodeGlyphMap() void SpriteFontCache::InitializeUnicodeGlyphMap()
{ {
/* Clear out existing glyph map if it exists */ /* Clear out existing glyph map if it exists */
this->glyph_to_spriteid_map.clear(); this->char_map.clear();
SpriteID base; SpriteID base;
switch (this->fs) { switch (this->fs) {

View File

@ -28,8 +28,8 @@ public:
bool IsBuiltInFont() override { return true; } bool IsBuiltInFont() override { return true; }
private: private:
std::unordered_map<GlyphID, SpriteID> glyph_to_spriteid_map{}; ///< Mapping of glyphs to sprite IDs. std::unordered_map<char32_t, SpriteID> char_map{}; ///< Mapping of characters to sprite IDs.
SpriteID GetUnicodeGlyph(GlyphID key); SpriteID GetUnicodeGlyph(char32_t key);
}; };
#endif /* SPRITEFONTCACHE_H */ #endif /* SPRITEFONTCACHE_H */

View File

@ -24,10 +24,12 @@
#include "api/script_event.hpp" #include "api/script_event.hpp"
#include "api/script_log.hpp" #include "api/script_log.hpp"
#include "../company_base.h" #include "../company_type.h"
#include "../company_func.h"
#include "../fileio_func.h" #include "../fileio_func.h"
#include "../goal_type.h"
#include "../league_type.h" #include "../league_type.h"
#include "../signs_type.h"
#include "../story_type.h"
#include "../misc/endian_buffer.hpp" #include "../misc/endian_buffer.hpp"
#include "../safeguards.h" #include "../safeguards.h"

View File

@ -12,12 +12,10 @@
#include <queue> #include <queue>
#include "../signs_func.h" #include "../command_type.h"
#include "../vehicle_func.h" #include "../company_type.h"
#include "../rail_type.h"
#include "../road_type.h" #include "../road_type.h"
#include "../group.h"
#include "../goal_type.h"
#include "../story_type.h"
#include "script_types.hpp" #include "script_types.hpp"
#include "script_log_types.hpp" #include "script_log_types.hpp"

View File

@ -12,9 +12,11 @@
/** Widgets of the #ErrmsgWindow class. */ /** Widgets of the #ErrmsgWindow class. */
enum ErrorMessageWidgets : WidgetID { enum ErrorMessageWidgets : WidgetID {
WID_EM_CAPTION, ///< Caption of the window. WID_EM_CAPTION, ///< Caption of the window.
WID_EM_FACE, ///< Error title. WID_EM_FACE, ///< Error title.
WID_EM_MESSAGE, ///< Error message. WID_EM_MESSAGE, ///< Error message.
WID_EM_CLOSEBOX, ///< Close box button.
WID_EM_PANEL, ///< Coloured background panel.
}; };
#endif /* WIDGETS_ERROR_WIDGET_H */ #endif /* WIDGETS_ERROR_WIDGET_H */