Skip to content

Commit

Permalink
Feature: Colourblind-friendly linkgraph colour scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
2TallTyler committed Aug 27, 2021
1 parent 56d4749 commit ec4d4e0
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 11 deletions.
5 changes: 5 additions & 0 deletions src/lang/english.txt
Expand Up @@ -1739,6 +1739,11 @@ STR_CONFIG_SETTING_DEMAND_SIZE_HELPTEXT :Setting this to
STR_CONFIG_SETTING_SHORT_PATH_SATURATION :Saturation of short paths before using high-capacity paths: {STRING2}
STR_CONFIG_SETTING_SHORT_PATH_SATURATION_HELPTEXT :Frequently there are multiple paths between two given stations. Cargodist will saturate the shortest path first, then use the second shortest path until that is saturated and so on. Saturation is determined by an estimation of capacity and planned usage. Once it has saturated all paths, if there is still demand left, it will overload all paths, prefering the ones with high capacity. Most of the time the algorithm will not estimate the capacity accurately, though. This setting allows you to specify up to which percentage a shorter path must be saturated in the first pass before choosing the next longer one. Set it to less than 100% to avoid overcrowded stations in case of overestimated capacity.

STR_CONFIG_SETTING_LINKGRAPH_COLOURS :Cargo flow overlay colours: {STRING2}
STR_CONFIG_SETTING_LINKGRAPH_COLOURS_HELPTEXT :Set the colour scheme used for the cargo flow overlay.
STR_CONFIG_SETTING_LINKGRAPH_COLOURS_GREEN_TO_RED :Green to red (original)
STR_CONFIG_SETTING_LINKGRAPH_COLOURS_BLUE_TO_RED :Blue to red

STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY :Speed units: {STRING2}
STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_HELPTEXT :Whenever a speed is shown in the user interface, show it in the selected units
STR_CONFIG_SETTING_LOCALISATION_UNITS_VELOCITY_IMPERIAL :Imperial (mph)
Expand Down
28 changes: 19 additions & 9 deletions src/linkgraph/linkgraph_gui.cpp
Expand Up @@ -26,10 +26,17 @@
* Colours for the various "load" states of links. Ordered from "unused" to
* "overloaded".
*/
const uint8 LinkGraphOverlay::LINK_COLOURS[] = {
0x0f, 0xd1, 0xd0, 0x57,
0x55, 0x53, 0xbf, 0xbd,
0xba, 0xb9, 0xb7, 0xb5
const uint8 LinkGraphOverlay::LINK_COLOURS[][12] = {
{
0x0f, 0xd1, 0xd0, 0x57,
0x55, 0x53, 0xbf, 0xbd,
0xba, 0xb9, 0xb7, 0xb5
},
{
0x07, 0xc6, 0xc9, 0xcb,
0xcd, 0x99, 0x44, 0xbe,
0xbb, 0xb9, 0xb7, 0xb5
}
};

/**
Expand Down Expand Up @@ -271,7 +278,7 @@ void LinkGraphOverlay::DrawLinks(const DrawPixelInfo *dpi) const
void LinkGraphOverlay::DrawContent(Point pta, Point ptb, const LinkProperties &cargo) const
{
uint usage_or_plan = std::min(cargo.capacity * 2 + 1, std::max(cargo.usage, cargo.planned));
int colour = LinkGraphOverlay::LINK_COLOURS[usage_or_plan * lengthof(LinkGraphOverlay::LINK_COLOURS) / (cargo.capacity * 2 + 2)];
int colour = LinkGraphOverlay::LINK_COLOURS[_settings_client.gui.linkgraph_colours][usage_or_plan * lengthof(LinkGraphOverlay::LINK_COLOURS[0]) / (cargo.capacity * 2 + 2)];
int dash = cargo.shared ? this->scale * 4 : 0;

/* Move line a bit 90° against its dominant direction to prevent it from
Expand Down Expand Up @@ -379,7 +386,7 @@ NWidgetBase *MakeCompanyButtonRowsLinkGraphGUI(int *biggest_index)
NWidgetBase *MakeSaturationLegendLinkGraphGUI(int *biggest_index)
{
NWidgetVertical *panel = new NWidgetVertical(NC_EQUALSIZE);
for (uint i = 0; i < lengthof(LinkGraphOverlay::LINK_COLOURS); ++i) {
for (uint i = 0; i < lengthof(LinkGraphOverlay::LINK_COLOURS[0]); ++i) {
NWidgetBackground * wid = new NWidgetBackground(WWT_PANEL, COLOUR_DARK_GREEN, i + WID_LGL_SATURATION_FIRST);
wid->SetMinimalSize(50, 0);
wid->SetMinimalTextLines(1, 0, FS_SMALL);
Expand Down Expand Up @@ -456,7 +463,7 @@ static const NWidgetPart _nested_linkgraph_legend_widgets[] = {
};

static_assert(WID_LGL_SATURATION_LAST - WID_LGL_SATURATION_FIRST ==
lengthof(LinkGraphOverlay::LINK_COLOURS) - 1);
lengthof(LinkGraphOverlay::LINK_COLOURS[0]) - 1);

static WindowDesc _linkgraph_legend_desc(
WDP_AUTO, "toolbar_linkgraph", 0, 0,
Expand Down Expand Up @@ -538,7 +545,8 @@ void LinkGraphLegendWindow::DrawWidget(const Rect &r, int widget) const
DrawCompanyIcon(cid, (r.left + r.right + 1 - sprite_size.width) / 2, (r.top + r.bottom + 1 - sprite_size.height) / 2);
}
if (IsInsideMM(widget, WID_LGL_SATURATION_FIRST, WID_LGL_SATURATION_LAST + 1)) {
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, LinkGraphOverlay::LINK_COLOURS[widget - WID_LGL_SATURATION_FIRST]);
uint8 colour = LinkGraphOverlay::LINK_COLOURS[_settings_client.gui.linkgraph_colours][widget - WID_LGL_SATURATION_FIRST];
GfxFillRect(r.left + 1, r.top + 1, r.right - 1, r.bottom - 1, colour);
StringID str = STR_NULL;
if (widget == WID_LGL_SATURATION_FIRST) {
str = STR_LINKGRAPH_LEGEND_UNUSED;
Expand All @@ -547,7 +555,9 @@ void LinkGraphLegendWindow::DrawWidget(const Rect &r, int widget) const
} else if (widget == (WID_LGL_SATURATION_LAST + WID_LGL_SATURATION_FIRST) / 2) {
str = STR_LINKGRAPH_LEGEND_SATURATED;
}
if (str != STR_NULL) DrawString(r.left, r.right, (r.top + r.bottom + 1 - FONT_HEIGHT_SMALL) / 2, str, TC_FROMSTRING, SA_HOR_CENTER);
if (str != STR_NULL) {
DrawString(r.left, r.right, (r.top + r.bottom + 1 - FONT_HEIGHT_SMALL) / 2, str, GetContrastColour(colour) | TC_FORCED, SA_HOR_CENTER);
}
}
if (IsInsideMM(widget, WID_LGL_CARGO_FIRST, WID_LGL_CARGO_LAST + 1)) {
if (this->IsWidgetDisabled(widget)) return;
Expand Down
2 changes: 1 addition & 1 deletion src/linkgraph/linkgraph_gui.h
Expand Up @@ -40,7 +40,7 @@ class LinkGraphOverlay {
typedef std::map<StationID, StationLinkMap> LinkMap;
typedef std::vector<std::pair<StationID, uint> > StationSupplyList;

static const uint8 LINK_COLOURS[];
static const uint8 LINK_COLOURS[][12];

/**
* Create a link graph overlay for the specified window.
Expand Down
1 change: 1 addition & 0 deletions src/settings_gui.cpp
Expand Up @@ -1570,6 +1570,7 @@ static SettingsContainer &GetSettingsTree()
graphics->Add(new SettingEntry("gui.zoom_max"));
graphics->Add(new SettingEntry("gui.sprite_zoom_min"));
graphics->Add(new SettingEntry("gui.smallmap_land_colour"));
graphics->Add(new SettingEntry("gui.linkgraph_colours"));
graphics->Add(new SettingEntry("gui.graph_line_thickness"));
}

Expand Down
10 changes: 10 additions & 0 deletions src/settings_table.cpp
Expand Up @@ -103,6 +103,16 @@ static void RedrawSmallmap(int32 new_value)
SetWindowClassesDirty(WC_SMALLMAP);
}

/**
* Redraw the linkgraph after a colour scheme change.
* @param new_value Callback parameter.
*/
static void UpdateLinkgraphColours(int32 new_value)
{
BuildLinkStatsLegend();
MarkWholeScreenDirty();
}

static void StationSpreadChanged(int32 p1)
{
InvalidateWindowData(WC_SELECT_STATION, 0);
Expand Down
1 change: 1 addition & 0 deletions src/settings_type.h
Expand Up @@ -114,6 +114,7 @@ struct GUISettings {
uint16 hover_delay_ms; ///< time required to activate a hover event, in milliseconds
bool link_terraform_toolbar; ///< display terraform toolbar when displaying rail, road, water and airport toolbars
uint8 smallmap_land_colour; ///< colour used for land and heightmap at the smallmap
uint8 linkgraph_colours; ///< Colour scheme used in the linkgraph overlay.
uint8 scroll_mode; ///< viewport scroll mode
bool smooth_scroll; ///< smooth scroll viewports
bool measure_tooltip; ///< show a permanent tooltip when dragging tools
Expand Down
2 changes: 1 addition & 1 deletion src/smallmap_gui.cpp
Expand Up @@ -216,7 +216,7 @@ void BuildLinkStatsLegend()

for (; i < _smallmap_cargo_count + lengthof(_linkstat_colours_in_legenda); ++i) {
_legend_linkstats[i].legend = STR_EMPTY;
_legend_linkstats[i].colour = LinkGraphOverlay::LINK_COLOURS[_linkstat_colours_in_legenda[i - _smallmap_cargo_count]];
_legend_linkstats[i].colour = LinkGraphOverlay::LINK_COLOURS[_settings_client.gui.linkgraph_colours][_linkstat_colours_in_legenda[i - _smallmap_cargo_count]];
_legend_linkstats[i].show_on_map = true;
}

Expand Down
14 changes: 14 additions & 0 deletions src/table/settings/gui_settings.ini
Expand Up @@ -15,6 +15,7 @@ static void InvalidateCompanyLiveryWindow(int32 new_value);
static void InvalidateNewGRFChangeWindows(int32 new_value);
static void ZoomMinMaxChanged(int32 new_value);
static void SpriteZoomMinChanged(int32 new_value);
static void UpdateLinkgraphColours(int32 new_value);

static std::initializer_list<const char*> _autosave_interval{"off", "monthly", "quarterly", "half year", "yearly"};
static std::initializer_list<const char*> _osk_activation{"disabled", "double", "single", "immediately"};
Expand Down Expand Up @@ -313,6 +314,19 @@ strhelp = STR_CONFIG_SETTING_SMALLMAP_LAND_COLOUR_HELPTEXT
strval = STR_CONFIG_SETTING_SMALLMAP_LAND_COLOUR_GREEN
post_cb = RedrawSmallmap

[SDTC_VAR]
var = gui.linkgraph_colours
type = SLE_UINT8
flags = SF_NOT_IN_SAVE | SF_NO_NETWORK_SYNC | SF_GUI_DROPDOWN
def = 1
min = 0
max = 1
str = STR_CONFIG_SETTING_LINKGRAPH_COLOURS
strhelp = STR_CONFIG_SETTING_LINKGRAPH_COLOURS_HELPTEXT
strval = STR_CONFIG_SETTING_LINKGRAPH_COLOURS_GREEN_TO_RED
post_cb = UpdateLinkgraphColours
cat = SC_BASIC

[SDTC_VAR]
var = gui.liveries
type = SLE_UINT8
Expand Down

0 comments on commit ec4d4e0

Please sign in to comment.