Files
@ r28769:123ae3cb0017
Branch filter:
Location: cpp/openttd-patchpack/source/src/subsidy_gui.cpp - annotation
r28769:123ae3cb0017
9.1 KiB
text/x-c
Codechange: Add support for number format and abbreviations pragmas/attributes to strgen
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 | r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r12768:980ae0491352 r9111:983de9c5a848 r6420:01087f989fd1 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r8106:01dbd10fde05 r8114:866ed489ed98 r27148:4e041ae27b9d r8224:194097dc7288 r9094:b8b4d5f9a3d8 r11992:e36dfa660636 r12287:e460d5b47431 r14248:a9050881acd7 r5584:545d748cc681 r18670:f122c356353c r8264:d493cb51fe8a r18670:f122c356353c r11682:de4530e142ab r21383:942c32fb8b0e r21383:942c32fb8b0e r9286:2a7d3fae4203 r15769:4a935f419828 r28752:a27b176a812f r15769:4a935f419828 r20280:ca1fc41725ff r9286:2a7d3fae4203 r20280:ca1fc41725ff r18689:162d0eb61e95 r20280:ca1fc41725ff r12854:adb7b59e6e99 r9286:2a7d3fae4203 r9286:2a7d3fae4203 r28752:a27b176a812f r28752:a27b176a812f r28752:a27b176a812f r28752:a27b176a812f r28752:a27b176a812f r28353:bfc4ab63f376 r9286:2a7d3fae4203 r18689:162d0eb61e95 r9286:2a7d3fae4203 r26575:d5725bf82346 r12854:adb7b59e6e99 r23972:7fe6caff6272 r12433:78c0a45f0d40 r12854:adb7b59e6e99 r12854:adb7b59e6e99 r9448:f26ee261b59c r9448:f26ee261b59c r9448:f26ee261b59c r9286:2a7d3fae4203 r9286:2a7d3fae4203 r9286:2a7d3fae4203 r5584:545d748cc681 r9286:2a7d3fae4203 r12854:adb7b59e6e99 r9286:2a7d3fae4203 r9286:2a7d3fae4203 r9286:2a7d3fae4203 r12854:adb7b59e6e99 r9286:2a7d3fae4203 r9286:2a7d3fae4203 r23972:7fe6caff6272 r12433:78c0a45f0d40 r12854:adb7b59e6e99 r12854:adb7b59e6e99 r9448:f26ee261b59c r9448:f26ee261b59c r9448:f26ee261b59c r9286:2a7d3fae4203 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r9286:2a7d3fae4203 r9286:2a7d3fae4203 r12642:9f166415b666 r9286:2a7d3fae4203 r12642:9f166415b666 r27106:2d95beb51290 r27106:2d95beb51290 r12642:9f166415b666 r5584:545d748cc681 r9094:b8b4d5f9a3d8 r9286:2a7d3fae4203 r24333:94ef0c6c84e2 r5584:545d748cc681 r12642:9f166415b666 r12642:9f166415b666 r27106:2d95beb51290 r27106:2d95beb51290 r12642:9f166415b666 r9286:2a7d3fae4203 r5584:545d748cc681 r9286:2a7d3fae4203 r24333:94ef0c6c84e2 r9286:2a7d3fae4203 r9286:2a7d3fae4203 r9286:2a7d3fae4203 r5584:545d748cc681 r5584:545d748cc681 r5584:545d748cc681 r12854:adb7b59e6e99 r12854:adb7b59e6e99 r12854:adb7b59e6e99 r12854:adb7b59e6e99 r12854:adb7b59e6e99 r12853:1fbbf0652bd6 r12853:1fbbf0652bd6 r12853:1fbbf0652bd6 r12853:1fbbf0652bd6 r23972:7fe6caff6272 r12853:1fbbf0652bd6 r12853:1fbbf0652bd6 r12853:1fbbf0652bd6 r12853:1fbbf0652bd6 r12853:1fbbf0652bd6 r12853:1fbbf0652bd6 r12853:1fbbf0652bd6 r12853:1fbbf0652bd6 r12853:1fbbf0652bd6 r12853:1fbbf0652bd6 r12853:1fbbf0652bd6 r12854:adb7b59e6e99 r12854:adb7b59e6e99 r12854:adb7b59e6e99 r12853:1fbbf0652bd6 r28353:bfc4ab63f376 r12854:adb7b59e6e99 r18689:162d0eb61e95 r12854:adb7b59e6e99 r12854:adb7b59e6e99 r28167:b14ea36d49e5 r12854:adb7b59e6e99 r12854:adb7b59e6e99 r26575:d5725bf82346 r26575:d5725bf82346 r12853:1fbbf0652bd6 r12853:1fbbf0652bd6 r12853:1fbbf0652bd6 r28752:a27b176a812f r28752:a27b176a812f r28752:a27b176a812f r28752:a27b176a812f r28752:a27b176a812f r28752:a27b176a812f r28752:a27b176a812f r28752:a27b176a812f r28752:a27b176a812f r28353:bfc4ab63f376 r12852:2b93198d4367 r18689:162d0eb61e95 r9286:2a7d3fae4203 r28549:6bc33bc6ee38 r9286:2a7d3fae4203 r26575:d5725bf82346 r28752:a27b176a812f r5584:545d748cc681 r15769:4a935f419828 r15769:4a935f419828 r12854:adb7b59e6e99 r19944:25a78576fb5e r28167:b14ea36d49e5 r12854:adb7b59e6e99 r12854:adb7b59e6e99 r9286:2a7d3fae4203 r23972:7fe6caff6272 r12433:78c0a45f0d40 r12871:50422c42a279 r12854:adb7b59e6e99 r25636:7c2fc0b1c9aa r28559:3924f7d56927 r28559:3924f7d56927 r28559:3924f7d56927 r28559:3924f7d56927 r28559:3924f7d56927 r28559:3924f7d56927 r28559:3924f7d56927 r28559:3924f7d56927 r28559:3924f7d56927 r28752:a27b176a812f r28752:a27b176a812f r12854:adb7b59e6e99 r12854:adb7b59e6e99 r9286:2a7d3fae4203 r9286:2a7d3fae4203 r9286:2a7d3fae4203 r5584:545d748cc681 r9286:2a7d3fae4203 r28167:b14ea36d49e5 r12854:adb7b59e6e99 r5584:545d748cc681 r9286:2a7d3fae4203 r19944:25a78576fb5e r12854:adb7b59e6e99 r28167:b14ea36d49e5 r12854:adb7b59e6e99 r9286:2a7d3fae4203 r5584:545d748cc681 r23972:7fe6caff6272 r12433:78c0a45f0d40 r12871:50422c42a279 r25636:7c2fc0b1c9aa r12854:adb7b59e6e99 r28559:3924f7d56927 r28559:3924f7d56927 r28559:3924f7d56927 r28559:3924f7d56927 r28559:3924f7d56927 r28559:3924f7d56927 r28559:3924f7d56927 r28559:3924f7d56927 r28559:3924f7d56927 r9286:2a7d3fae4203 r12854:adb7b59e6e99 r28752:a27b176a812f r28752:a27b176a812f r12854:adb7b59e6e99 r12854:adb7b59e6e99 r9286:2a7d3fae4203 r5584:545d748cc681 r9286:2a7d3fae4203 r9286:2a7d3fae4203 r12854:adb7b59e6e99 r28167:b14ea36d49e5 r12854:adb7b59e6e99 r12854:adb7b59e6e99 r12854:adb7b59e6e99 r12854:adb7b59e6e99 r23499:f9bf6ad58697 r12854:adb7b59e6e99 r18689:162d0eb61e95 r12854:adb7b59e6e99 r12854:adb7b59e6e99 r17476:d3b7a183536d r17476:d3b7a183536d r17476:d3b7a183536d r17476:d3b7a183536d r17476:d3b7a183536d r27942:f7389062d120 r12854:adb7b59e6e99 r17476:d3b7a183536d r15769:4a935f419828 r5584:545d748cc681 r9286:2a7d3fae4203 r5584:545d748cc681 r28487:2130fff7270c r11684:cacbcf699b81 r13742:180ad925befc r13742:180ad925befc r14035:4f06488d5a62 r20287:5b9a8691769e r13742:180ad925befc r11684:cacbcf699b81 r11684:cacbcf699b81 r18689:162d0eb61e95 r11684:cacbcf699b81 r18689:162d0eb61e95 r13742:180ad925befc r11684:cacbcf699b81 r11684:cacbcf699b81 r11684:cacbcf699b81 r11684:cacbcf699b81 r28078:5e5d6c0447b1 r20283:2a199c78224c r5893:6c4fd9987e0f r13739:747ed1f003e3 r27861:6269475166e0 r11368:058349c3a02c r5584:545d748cc681 r5584:545d748cc681 r6247:96e840dbefcc r5584:545d748cc681 r9286:2a7d3fae4203 r5584:545d748cc681 | /*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file subsidy_gui.cpp GUI for subsidies. */
#include "stdafx.h"
#include "industry.h"
#include "town.h"
#include "window_gui.h"
#include "strings_func.h"
#include "timer/timer_game_calendar.h"
#include "viewport_func.h"
#include "gui.h"
#include "subsidy_func.h"
#include "subsidy_base.h"
#include "core/geometry_func.hpp"
#include "widgets/subsidy_widget.h"
#include "table/strings.h"
#include "safeguards.h"
struct SubsidyListWindow : Window {
Scrollbar *vscroll;
Dimension cargo_icon_size;
SubsidyListWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc)
{
this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_SUL_SCROLLBAR);
this->FinishInitNested(window_number);
this->OnInvalidateData(0);
}
void OnInit() override
{
this->cargo_icon_size = GetLargestCargoIconSize();
}
void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
{
if (widget != WID_SUL_PANEL) return;
int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SUL_PANEL, WidgetDimensions::scaled.framerect.top);
int num = 0;
for (const Subsidy *s : Subsidy::Iterate()) {
if (!s->IsAwarded()) {
y--;
if (y == 0) {
this->HandleClick(s);
return;
}
num++;
}
}
if (num == 0) {
y--; // "None"
if (y < 0) return;
}
y -= 2; // "Services already subsidised:"
if (y < 0) return;
for (const Subsidy *s : Subsidy::Iterate()) {
if (s->IsAwarded()) {
y--;
if (y == 0) {
this->HandleClick(s);
return;
}
}
}
}
void HandleClick(const Subsidy *s)
{
/* determine src coordinate for subsidy and try to scroll to it */
TileIndex xy;
switch (s->src_type) {
case SourceType::Industry: xy = Industry::Get(s->src)->location.tile; break;
case SourceType::Town: xy = Town::Get(s->src)->xy; break;
default: NOT_REACHED();
}
if (_ctrl_pressed || !ScrollMainWindowToTile(xy)) {
if (_ctrl_pressed) ShowExtraViewportWindow(xy);
/* otherwise determine dst coordinate for subsidy and scroll to it */
switch (s->dst_type) {
case SourceType::Industry: xy = Industry::Get(s->dst)->location.tile; break;
case SourceType::Town: xy = Town::Get(s->dst)->xy; break;
default: NOT_REACHED();
}
if (_ctrl_pressed) {
ShowExtraViewportWindow(xy);
} else {
ScrollMainWindowToTile(xy);
}
}
}
/**
* Count the number of lines in this window.
* @return the number of lines
*/
uint CountLines()
{
/* Count number of (non) awarded subsidies */
uint num_awarded = 0;
uint num_not_awarded = 0;
for (const Subsidy *s : Subsidy::Iterate()) {
if (!s->IsAwarded()) {
num_not_awarded++;
} else {
num_awarded++;
}
}
/* Count the 'none' lines */
if (num_awarded == 0) num_awarded = 1;
if (num_not_awarded == 0) num_not_awarded = 1;
/* Offered, accepted and an empty line before the accepted ones. */
return 3 + num_awarded + num_not_awarded;
}
void UpdateWidgetSize(WidgetID widget, Dimension *size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension *fill, [[maybe_unused]] Dimension *resize) override
{
if (widget != WID_SUL_PANEL) return;
Dimension d = maxdim(GetStringBoundingBox(STR_SUBSIDIES_OFFERED_TITLE), GetStringBoundingBox(STR_SUBSIDIES_SUBSIDISED_TITLE));
resize->height = GetCharacterHeight(FS_NORMAL);
d.height *= 5;
d.width += WidgetDimensions::scaled.framerect.Horizontal();
d.height += WidgetDimensions::scaled.framerect.Vertical();
*size = maxdim(*size, d);
}
void DrawCargoIcon(const Rect &r, int y_offset, CargoID cid) const
{
bool rtl = _current_text_dir == TD_RTL;
SpriteID icon = CargoSpec::Get(cid)->GetCargoIcon();
Dimension d = GetSpriteSize(icon);
Rect ir = r.WithWidth(this->cargo_icon_size.width, rtl).WithHeight(GetCharacterHeight(FS_NORMAL));
DrawSprite(icon, PAL_NONE, CenterBounds(ir.left, ir.right, d.width), CenterBounds(ir.top, ir.bottom, this->cargo_icon_size.height) + y_offset);
}
void DrawWidget(const Rect &r, WidgetID widget) const override
{
if (widget != WID_SUL_PANEL) return;
TimerGameEconomy::YearMonthDay ymd = TimerGameEconomy::ConvertDateToYMD(TimerGameEconomy::date);
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
Rect sr = tr.Indent(this->cargo_icon_size.width + WidgetDimensions::scaled.hsep_normal, _current_text_dir == TD_RTL);
int pos = -this->vscroll->GetPosition();
const int cap = this->vscroll->GetCapacity();
/* Section for drawing the offered subsidies */
if (IsInsideMM(pos, 0, cap)) DrawString(tr.left, tr.right, tr.top + pos * GetCharacterHeight(FS_NORMAL), STR_SUBSIDIES_OFFERED_TITLE);
pos++;
uint num = 0;
for (const Subsidy *s : Subsidy::Iterate()) {
if (!s->IsAwarded()) {
if (IsInsideMM(pos, 0, cap)) {
/* Displays the two offered towns */
SetupSubsidyDecodeParam(s, SubsidyDecodeParamType::Gui);
/* If using wallclock units, show minutes remaining. Otherwise show the date when the subsidy ends. */
if (TimerGameEconomy::UsingWallclockUnits()) {
SetDParam(7, STR_SUBSIDIES_OFFERED_EXPIRY_TIME);
SetDParam(8, s->remaining + 1); // We get the rest of the current economy month for free, since the expiration is checked on each new month.
} else {
SetDParam(7, STR_SUBSIDIES_OFFERED_EXPIRY_DATE);
SetDParam(8, TimerGameEconomy::date - ymd.day + s->remaining * 32);
}
DrawCargoIcon(tr, pos * GetCharacterHeight(FS_NORMAL), s->cargo_type);
DrawString(sr.left, sr.right, sr.top + pos * GetCharacterHeight(FS_NORMAL), STR_SUBSIDIES_OFFERED_FROM_TO);
}
pos++;
num++;
}
}
if (num == 0) {
if (IsInsideMM(pos, 0, cap)) DrawString(tr.left, tr.right, tr.top + pos * GetCharacterHeight(FS_NORMAL), STR_SUBSIDIES_NONE);
pos++;
}
/* Section for drawing the already granted subsidies */
pos++;
if (IsInsideMM(pos, 0, cap)) DrawString(tr.left, tr.right, tr.top + pos * GetCharacterHeight(FS_NORMAL), STR_SUBSIDIES_SUBSIDISED_TITLE);
pos++;
num = 0;
for (const Subsidy *s : Subsidy::Iterate()) {
if (s->IsAwarded()) {
if (IsInsideMM(pos, 0, cap)) {
SetupSubsidyDecodeParam(s, SubsidyDecodeParamType::Gui);
SetDParam(7, s->awarded);
/* If using wallclock units, show minutes remaining. Otherwise show the date when the subsidy ends. */
if (TimerGameEconomy::UsingWallclockUnits()) {
SetDParam(8, STR_SUBSIDIES_SUBSIDISED_EXPIRY_TIME);
SetDParam(9, s->remaining);
}
else {
SetDParam(8, STR_SUBSIDIES_SUBSIDISED_EXPIRY_DATE);
SetDParam(9, TimerGameEconomy::date - ymd.day + s->remaining * 32);
}
/* Displays the two connected stations */
DrawCargoIcon(tr, pos * GetCharacterHeight(FS_NORMAL), s->cargo_type);
DrawString(sr.left, sr.right, sr.top + pos * GetCharacterHeight(FS_NORMAL), STR_SUBSIDIES_SUBSIDISED_FROM_TO);
}
pos++;
num++;
}
}
if (num == 0) {
if (IsInsideMM(pos, 0, cap)) DrawString(tr.left, tr.right, tr.top + pos * GetCharacterHeight(FS_NORMAL), STR_SUBSIDIES_NONE);
pos++;
}
}
void OnResize() override
{
this->vscroll->SetCapacityFromWidget(this, WID_SUL_PANEL);
}
/**
* Some data on this window has become invalid.
* @param data Information about the changed data.
* @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
*/
void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
{
if (!gui_scope) return;
this->vscroll->SetCount(this->CountLines());
}
};
static constexpr NWidgetPart _nested_subsidies_list_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_SUBSIDIES_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_SHADEBOX, COLOUR_BROWN),
NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_SUL_PANEL), SetDataTip(0x0, STR_SUBSIDIES_TOOLTIP_CLICK_ON_SERVICE_TO_CENTER), SetResize(1, 1), SetScrollbar(WID_SUL_SCROLLBAR), EndContainer(),
NWidget(NWID_VERTICAL),
NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_SUL_SCROLLBAR),
NWidget(WWT_RESIZEBOX, COLOUR_BROWN),
EndContainer(),
EndContainer(),
};
static WindowDesc _subsidies_list_desc(__FILE__, __LINE__,
WDP_AUTO, "list_subsidies", 500, 127,
WC_SUBSIDIES_LIST, WC_NONE,
0,
std::begin(_nested_subsidies_list_widgets), std::end(_nested_subsidies_list_widgets)
);
void ShowSubsidiesList()
{
AllocateWindowDescFront<SubsidyListWindow>(&_subsidies_list_desc, 0);
}
|