Merge commit '13.0-RC1~2'

This commit is contained in:
2023-02-25 04:49:57 +00:00
603 changed files with 26913 additions and 18390 deletions

View File

@@ -33,12 +33,14 @@
#include "stringfilter_type.h"
#include "widgets/dropdown_func.h"
#include "town_kdtree.h"
#include "town_cmd.h"
#include "widgets/town_widget.h"
#include "table/strings.h"
#include "safeguards.h"
#include "zoom_func.h"
TownKdtree _town_local_authority_kdtree(&Kdtree_TownXYFunc);
@@ -48,16 +50,13 @@ static const NWidgetPart _nested_town_authority_widgets[] = {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
NWidget(WWT_CAPTION, COLOUR_BROWN, WID_TA_CAPTION), SetDataTip(STR_LOCAL_AUTHORITY_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TA_ZONE_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM + 2), SetDataTip(STR_LOCAL_AUTHORITY_ZONE, STR_LOCAL_AUTHORITY_ZONE_TOOLTIP),
NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TA_ZONE_BUTTON), SetMinimalSize(50, 0), SetMinimalTextLines(1, WidgetDimensions::unscaled.framerect.Vertical() + 2), SetDataTip(STR_LOCAL_AUTHORITY_ZONE, STR_LOCAL_AUTHORITY_ZONE_TOOLTIP),
NWidget(WWT_SHADEBOX, COLOUR_BROWN),
NWidget(WWT_DEFSIZEBOX, COLOUR_BROWN),
NWidget(WWT_STICKYBOX, COLOUR_BROWN),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_TA_RATING_INFO), SetMinimalSize(317, 92), SetResize(1, 1), SetFill(1, 1), EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_TA_COMMAND_LIST), SetMinimalSize(305, 52), SetResize(1, 0), SetDataTip(0x0, STR_LOCAL_AUTHORITY_ACTIONS_TOOLTIP), SetScrollbar(WID_TA_SCROLLBAR), EndContainer(),
NWidget(NWID_VSCROLLBAR, COLOUR_BROWN, WID_TA_SCROLLBAR),
EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_TA_COMMAND_LIST), SetMinimalSize(317, 52), SetResize(1, 0), SetDataTip(0x0, STR_LOCAL_AUTHORITY_ACTIONS_TOOLTIP), EndContainer(),
NWidget(WWT_PANEL, COLOUR_BROWN, WID_TA_ACTION_INFO), SetMinimalSize(317, 52), SetResize(1, 1), SetFill(1, 1), EndContainer(),
NWidget(NWID_HORIZONTAL),
NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_TA_EXECUTE), SetMinimalSize(317, 12), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_LOCAL_AUTHORITY_DO_IT_BUTTON, STR_LOCAL_AUTHORITY_DO_IT_TOOLTIP),
@@ -70,23 +69,26 @@ struct TownAuthorityWindow : Window {
private:
Town *town; ///< Town being displayed.
int sel_index; ///< Currently selected town action, \c 0 to \c TACT_COUNT-1, \c -1 means no action selected.
Scrollbar *vscroll;
uint actions_step;
uint displayed_actions_on_previous_painting; ///< Actions that were available on the previous call to OnPaint()
TownActions enabled_actions; ///< Actions that are enabled in settings.
TownActions available_actions; ///< Actions that are available to execute for the current company.
Dimension icon_size; ///< Dimensions of company icon
Dimension exclusive_size; ///< Dimensions of exlusive icon
/**
* Get the position of the Nth set bit.
*
* If there is no Nth bit set return -1
*
* @param bits The value to search in
* @param n The Nth set bit from which we want to know the position
* @return The position of the Nth set bit
* @return The position of the Nth set bit, or -1 if no Nth bit set.
*/
static int GetNthSetBit(uint32 bits, int n)
int GetNthSetBit(int n)
{
if (n >= 0) {
for (uint i : SetBitIterator(bits)) {
for (uint i : SetBitIterator(this->enabled_actions)) {
n--;
if (n < 0) return i;
}
@@ -94,94 +96,126 @@ private:
return -1;
}
/**
* Gets all town authority actions enabled in settings.
*
* @return Bitmask of actions enabled in the settings.
*/
static TownActions GetEnabledActions()
{
TownActions enabled = TACT_ALL;
if (!_settings_game.economy.fund_roads) CLRBITS(enabled, TACT_ROAD_REBUILD);
if (!_settings_game.economy.fund_buildings) CLRBITS(enabled, TACT_FUND_BUILDINGS);
if (!_settings_game.economy.exclusive_rights) CLRBITS(enabled, TACT_BUY_RIGHTS);
if (!_settings_game.economy.bribe) CLRBITS(enabled, TACT_BRIBE);
return enabled;
}
public:
TownAuthorityWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc), sel_index(-1), displayed_actions_on_previous_painting(0)
TownAuthorityWindow(WindowDesc *desc, WindowNumber window_number) : Window(desc), sel_index(-1), displayed_actions_on_previous_painting(0), available_actions(TACT_NONE)
{
this->town = Town::Get(window_number);
this->enabled_actions = GetEnabledActions();
this->InitNested(window_number);
this->vscroll = this->GetScrollbar(WID_TA_SCROLLBAR);
this->actions_step = GetMinButtonSize(FONT_HEIGHT_NORMAL);
this->vscroll->SetCapacity((this->GetWidget<NWidgetBase>(WID_TA_COMMAND_LIST)->current_y - WD_FRAMERECT_TOP - WD_FRAMERECT_BOTTOM) / this->actions_step);
}
void OnInit() override
{
this->icon_size = GetSpriteSize(SPR_COMPANY_ICON);
this->exclusive_size = GetSpriteSize(SPR_EXCLUSIVE_TRANSPORT);
}
void OnPaint() override
{
int numact;
uint buttons = GetMaskOfTownActions(&numact, _local_company, this->town);
if (buttons != displayed_actions_on_previous_painting) this->SetDirty();
displayed_actions_on_previous_painting = buttons;
this->vscroll->SetCount(numact + 1);
if (this->sel_index != -1 && !HasBit(buttons, this->sel_index)) {
this->sel_index = -1;
}
this->available_actions = GetMaskOfTownActions(_local_company, this->town);
if (this->available_actions != displayed_actions_on_previous_painting) this->SetDirty();
displayed_actions_on_previous_painting = this->available_actions;
this->SetWidgetLoweredState(WID_TA_ZONE_BUTTON, this->town->show_zone);
this->SetWidgetDisabledState(WID_TA_EXECUTE, this->sel_index == -1);
this->SetWidgetDisabledState(WID_TA_EXECUTE, (this->sel_index == -1) || !HasBit(this->available_actions, this->sel_index));
this->DrawWidgets();
if (!this->IsShaded()) this->DrawRatings();
if (!this->IsShaded())
{
this->DrawRatings();
this->DrawActions();
}
}
/** Draw the contents of the ratings panel. May request a resize of the window if the contents does not fit. */
void DrawRatings()
{
NWidgetBase *nwid = this->GetWidget<NWidgetBase>(WID_TA_RATING_INFO);
uint left = nwid->pos_x + WD_FRAMERECT_LEFT;
uint right = nwid->pos_x + nwid->current_x - 1 - WD_FRAMERECT_RIGHT;
Rect r = this->GetWidget<NWidgetBase>(WID_TA_RATING_INFO)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
uint y = nwid->pos_y + WD_FRAMERECT_TOP;
int text_y_offset = (this->resize.step_height - FONT_HEIGHT_NORMAL) / 2;
int icon_y_offset = (this->resize.step_height - this->icon_size.height) / 2;
int exclusive_y_offset = (this->resize.step_height - this->exclusive_size.height) / 2;
DrawString(left, right, y, STR_LOCAL_AUTHORITY_COMPANY_RATINGS);
y += FONT_HEIGHT_NORMAL;
Dimension icon_size = GetSpriteSize(SPR_COMPANY_ICON);
int icon_width = icon_size.width;
int icon_y_offset = (FONT_HEIGHT_NORMAL - icon_size.height) / 2;
Dimension exclusive_size = GetSpriteSize(SPR_EXCLUSIVE_TRANSPORT);
int exclusive_width = exclusive_size.width;
int exclusive_y_offset = (FONT_HEIGHT_NORMAL - exclusive_size.height) / 2;
DrawString(r.left, r.right, r.top + text_y_offset, STR_LOCAL_AUTHORITY_COMPANY_RATINGS);
r.top += this->resize.step_height;
bool rtl = _current_text_dir == TD_RTL;
uint text_left = left + (rtl ? 0 : icon_width + exclusive_width + 4);
uint text_right = right - (rtl ? icon_width + exclusive_width + 4 : 0);
uint icon_left = rtl ? right - icon_width : left;
uint exclusive_left = rtl ? right - icon_width - exclusive_width - 2 : left + icon_width + 2;
Rect icon = r.WithWidth(this->icon_size.width, rtl);
Rect exclusive = r.Indent(this->icon_size.width + WidgetDimensions::scaled.hsep_normal, rtl).WithWidth(this->exclusive_size.width, rtl);
Rect text = r.Indent(this->icon_size.width + WidgetDimensions::scaled.hsep_normal + this->exclusive_size.width + WidgetDimensions::scaled.hsep_normal, rtl);
/* Draw list of companies */
for (const Company *c : Company::Iterate()) {
if ((HasBit(this->town->have_ratings, c->index) || this->town->exclusivity == c->index)) {
DrawCompanyIcon(c->index, icon_left, y + icon_y_offset);
DrawCompanyIcon(c->index, icon.left, text.top + icon_y_offset);
SetDParam(0, c->index);
SetDParam(1, c->index);
int r = this->town->ratings[c->index];
int rating = this->town->ratings[c->index];
StringID str = STR_CARGO_RATING_APPALLING;
if (r > RATING_APPALLING) str++;
if (r > RATING_VERYPOOR) str++;
if (r > RATING_POOR) str++;
if (r > RATING_MEDIOCRE) str++;
if (r > RATING_GOOD) str++;
if (r > RATING_VERYGOOD) str++;
if (r > RATING_EXCELLENT) str++;
if (rating > RATING_APPALLING) str++;
if (rating > RATING_VERYPOOR) str++;
if (rating > RATING_POOR) str++;
if (rating > RATING_MEDIOCRE) str++;
if (rating > RATING_GOOD) str++;
if (rating > RATING_VERYGOOD) str++;
if (rating > RATING_EXCELLENT) str++;
SetDParam(2, str);
if (this->town->exclusivity == c->index) {
DrawSprite(SPR_EXCLUSIVE_TRANSPORT, COMPANY_SPRITE_COLOUR(c->index), exclusive_left, y + exclusive_y_offset);
DrawSprite(SPR_EXCLUSIVE_TRANSPORT, COMPANY_SPRITE_COLOUR(c->index), exclusive.left, text.top + exclusive_y_offset);
}
DrawString(text_left, text_right, y, STR_LOCAL_AUTHORITY_COMPANY_RATING);
y += FONT_HEIGHT_NORMAL;
DrawString(text.left, text.right, text.top + text_y_offset, STR_LOCAL_AUTHORITY_COMPANY_RATING);
text.top += this->resize.step_height;
}
}
y = y + WD_FRAMERECT_BOTTOM - nwid->pos_y; // Compute needed size of the widget.
if (y > nwid->current_y) {
text.bottom = text.top - 1;
if (text.bottom > r.bottom) {
/* If the company list is too big to fit, mark ourself dirty and draw again. */
ResizeWindow(this, 0, y - nwid->current_y, false);
ResizeWindow(this, 0, text.bottom - r.bottom, false);
}
}
/** Draws the contents of the actions panel. May re-initialise window to resize panel, if the list does not fit. */
void DrawActions()
{
Rect r = this->GetWidget<NWidgetBase>(WID_TA_COMMAND_LIST)->GetCurrentRect().Shrink(WidgetDimensions::scaled.framerect);
DrawString(r, STR_LOCAL_AUTHORITY_ACTIONS_TITLE);
r.top += FONT_HEIGHT_NORMAL;
/* Draw list of actions */
for (int i = 0; i < TACT_COUNT; i++) {
/* Don't show actions if disabled in settings. */
if (!HasBit(this->enabled_actions, i)) continue;
/* Set colour of action based on ability to execute and if selected. */
TextColour action_colour = TC_GREY | TC_NO_SHADE;
if (HasBit(this->available_actions, i)) action_colour = TC_ORANGE;
if (this->sel_index == i) action_colour = TC_WHITE;
DrawString(r, STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i, action_colour);
r.top += FONT_HEIGHT_NORMAL;
}
}
@@ -195,33 +229,15 @@ public:
switch (widget) {
case WID_TA_ACTION_INFO:
if (this->sel_index != -1) {
SetDParam(0, _price[PR_TOWN_ACTION] * _town_action_costs[this->sel_index] >> 8);
DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM,
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING + this->sel_index);
Money action_cost = _price[PR_TOWN_ACTION] * _town_action_costs[this->sel_index] >> 8;
bool affordable = action_cost < Company::GetIfValid(_local_company)->money;
SetDParam(0, action_cost);
DrawStringMultiLine(r.Shrink(WidgetDimensions::scaled.framerect),
STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING + this->sel_index,
affordable ? TC_YELLOW : TC_RED);
}
break;
case WID_TA_COMMAND_LIST: {
int numact;
uint buttons = GetMaskOfTownActions(&numact, _local_company, this->town);
int y = Center(r.top, this->actions_step);
int pos = this->vscroll->GetPosition();
if (--pos < 0) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y, STR_LOCAL_AUTHORITY_ACTIONS_TITLE);
y += this->actions_step;
}
for (int i = 0; buttons; i++, buttons >>= 1) {
if (pos <= -5) break; ///< Draw only the 5 fitting lines
if ((buttons & 1) && --pos < 0) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y,
STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i, this->sel_index == i ? TC_WHITE : TC_ORANGE);
y += this->actions_step;
}
}
break;
}
}
}
@@ -230,32 +246,29 @@ public:
switch (widget) {
case WID_TA_ACTION_INFO: {
assert(size->width > padding.width && size->height > padding.height);
size->width -= WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
size->height -= WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
Dimension d = {0, 0};
for (int i = 0; i < TACT_COUNT; i++) {
SetDParam(0, _price[PR_TOWN_ACTION] * _town_action_costs[i] >> 8);
d = maxdim(d, GetStringMultiLineBoundingBox(STR_LOCAL_AUTHORITY_ACTION_TOOLTIP_SMALL_ADVERTISING + i, *size));
}
d.width += padding.width;
d.height += padding.height;
*size = maxdim(*size, d);
size->width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
size->height += WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
break;
}
case WID_TA_COMMAND_LIST:
resize->height = GetMinButtonSize(FONT_HEIGHT_NORMAL);
size->height = WD_FRAMERECT_TOP + 3 * resize->height + WD_FRAMERECT_BOTTOM;
size->height = (TACT_COUNT + 1) * FONT_HEIGHT_NORMAL + padding.height;
size->width = GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTIONS_TITLE).width;
for (uint i = 0; i < TACT_COUNT; i++ ) {
size->width = std::max(size->width, GetStringBoundingBox(STR_LOCAL_AUTHORITY_ACTION_SMALL_ADVERTISING_CAMPAIGN + i).width);
}
size->width += WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
size->width += padding.width;
break;
case WID_TA_RATING_INFO:
resize->height = FONT_HEIGHT_NORMAL;
size->height = WD_FRAMERECT_TOP + 9 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_BOTTOM;
resize->height = std::max({this->icon_size.height + WidgetDimensions::scaled.vsep_normal, this->exclusive_size.height + WidgetDimensions::scaled.vsep_normal, (uint)FONT_HEIGHT_NORMAL});
size->height = 9 * resize->height + padding.height;
break;
}
}
@@ -276,21 +289,21 @@ public:
}
case WID_TA_COMMAND_LIST: {
int y = this->GetRowFromWidget(pt.y, WID_TA_COMMAND_LIST, 1, this->actions_step);
if (!IsInsideMM(y, 0, 5)) return;
int y = this->GetRowFromWidget(pt.y, WID_TA_COMMAND_LIST, 1, FONT_HEIGHT_NORMAL) - 1;
y = GetNthSetBit(GetMaskOfTownActions(nullptr, _local_company, this->town), y + this->vscroll->GetPosition() - 1);
y = GetNthSetBit(y);
if (y >= 0) {
this->sel_index = y;
this->SetDirty();
}
/* When double-clicking, continue */
if (click_count == 1 || y < 0) break;
FALLTHROUGH;
}
case WID_TA_EXECUTE:
DoCommandP(this->town->xy, this->window_number, this->sel_index, CMD_DO_TOWN_ACTION | CMD_MSG(STR_ERROR_CAN_T_DO_THIS));
Command<CMD_DO_TOWN_ACTION>::Post(STR_ERROR_CAN_T_DO_THIS, this->town->xy, this->window_number, this->sel_index);
break;
}
}
@@ -299,6 +312,16 @@ public:
{
this->SetDirty();
}
void OnInvalidateData(int data = 0, bool gui_scope = true) override
{
if (!gui_scope) return;
this->enabled_actions = this->GetEnabledActions();
if (!HasBit(this->enabled_actions, this->sel_index)) {
this->sel_index = -1;
}
}
};
static WindowDesc _town_authority_desc(
@@ -333,7 +356,7 @@ public:
this->flags |= WF_DISABLE_VP_SCROLL;
NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_TV_VIEWPORT);
nvp->InitializeViewport(this, this->town->xy, ZOOM_LVL_NEWS);
nvp->InitializeViewport(this, this->town->xy, ScaleZoomGUI(ZOOM_LVL_TOWN));
/* disable renaming town in network games if you are not the server */
this->SetWidgetDisabledState(WID_TV_CHANGE_NAME, _networking && !_network_server);
@@ -362,21 +385,24 @@ public:
{
if (widget != WID_TV_INFO) return;
uint y = r.top + WD_FRAMERECT_TOP;
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
SetDParam(0, this->town->cache.population);
SetDParam(1, this->town->cache.num_houses);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y, STR_TOWN_VIEW_POPULATION_HOUSES);
DrawString(tr, STR_TOWN_VIEW_POPULATION_HOUSES);
tr.top += FONT_HEIGHT_NORMAL;
SetDParam(0, 1 << CT_PASSENGERS);
SetDParam(1, this->town->supplied[CT_PASSENGERS].old_act);
SetDParam(2, this->town->supplied[CT_PASSENGERS].old_max);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, STR_TOWN_VIEW_CARGO_LAST_MONTH_MAX);
DrawString(tr, STR_TOWN_VIEW_CARGO_LAST_MONTH_MAX);
tr.top += FONT_HEIGHT_NORMAL;
SetDParam(0, 1 << CT_MAIL);
SetDParam(1, this->town->supplied[CT_MAIL].old_act);
SetDParam(2, this->town->supplied[CT_MAIL].old_max);
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, STR_TOWN_VIEW_CARGO_LAST_MONTH_MAX);
DrawString(tr, STR_TOWN_VIEW_CARGO_LAST_MONTH_MAX);
tr.top += FONT_HEIGHT_NORMAL;
bool first = true;
for (int i = TE_BEGIN; i < TE_END; i++) {
@@ -385,13 +411,12 @@ public:
if (this->town->goal[i] == TOWN_GROWTH_DESERT && (GetTropicZone(this->town->xy) != TROPICZONE_DESERT || this->town->cache.population <= 60)) continue;
if (first) {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH);
DrawString(tr, STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH);
tr.top += FONT_HEIGHT_NORMAL;
first = false;
}
bool rtl = _current_text_dir == TD_RTL;
uint cargo_text_left = r.left + WD_FRAMERECT_LEFT + (rtl ? 0 : 20);
uint cargo_text_right = r.right - WD_FRAMERECT_RIGHT - (rtl ? 20 : 0);
const CargoSpec *cargo = FindFirstCargoWithTownEffect((TownEffect)i);
assert(cargo != nullptr);
@@ -421,26 +446,30 @@ public:
SetDParam(2, cargo->Index());
SetDParam(3, this->town->goal[i]);
}
DrawString(cargo_text_left, cargo_text_right, y += FONT_HEIGHT_NORMAL, string);
DrawString(tr.Indent(20, rtl), string);
tr.top += FONT_HEIGHT_NORMAL;
}
if (HasBit(this->town->flags, TOWN_IS_GROWING)) {
SetDParam(0, RoundDivSU(this->town->growth_rate + 1, DAY_TICKS));
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, this->town->fund_buildings_months == 0 ? STR_TOWN_VIEW_TOWN_GROWS_EVERY : STR_TOWN_VIEW_TOWN_GROWS_EVERY_FUNDED);
DrawString(tr, this->town->fund_buildings_months == 0 ? STR_TOWN_VIEW_TOWN_GROWS_EVERY : STR_TOWN_VIEW_TOWN_GROWS_EVERY_FUNDED);
tr.top += FONT_HEIGHT_NORMAL;
} else {
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, STR_TOWN_VIEW_TOWN_GROW_STOPPED);
DrawString(tr, STR_TOWN_VIEW_TOWN_GROW_STOPPED);
tr.top += FONT_HEIGHT_NORMAL;
}
/* only show the town noise, if the noise option is activated. */
if (_settings_game.economy.station_noise_level) {
SetDParam(0, this->town->noise_reached);
SetDParam(1, this->town->MaxTownNoise());
DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, y += FONT_HEIGHT_NORMAL, STR_TOWN_VIEW_NOISE_IN_TOWN);
DrawString(tr, STR_TOWN_VIEW_NOISE_IN_TOWN);
tr.top += FONT_HEIGHT_NORMAL;
}
if (!this->town->text.empty()) {
SetDParamStr(0, this->town->text);
DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, y += FONT_HEIGHT_NORMAL, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
tr.top = DrawStringMultiLine(tr, STR_JUST_RAW_STRING, TC_BLACK);
}
}
@@ -477,12 +506,12 @@ public:
_warn_town_no_roads = true;
}
DoCommandP(0, this->window_number, 0, CMD_EXPAND_TOWN | CMD_MSG(STR_ERROR_CAN_T_EXPAND_TOWN));
Command<CMD_EXPAND_TOWN>::Post(STR_ERROR_CAN_T_EXPAND_TOWN, this->window_number, 0);
break;
}
case WID_TV_DELETE: // delete town - only available on Scenario editor
DoCommandP(0, this->window_number, 0, CMD_DELETE_TOWN | CMD_MSG(STR_ERROR_TOWN_CAN_T_DELETE));
Command<CMD_DELETE_TOWN>::Post(STR_ERROR_TOWN_CAN_T_DELETE, this->window_number);
break;
}
}
@@ -491,7 +520,7 @@ public:
{
switch (widget) {
case WID_TV_INFO:
size->height = GetDesiredInfoHeight(size->width);
size->height = GetDesiredInfoHeight(size->width) + padding.height;
break;
}
}
@@ -502,7 +531,7 @@ public:
*/
uint GetDesiredInfoHeight(int width) const
{
uint aimed_height = 3 * FONT_HEIGHT_NORMAL + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
uint aimed_height = 3 * FONT_HEIGHT_NORMAL;
bool first = true;
for (int i = TE_BEGIN; i < TE_END; i++) {
@@ -522,7 +551,7 @@ public:
if (!this->town->text.empty()) {
SetDParamStr(0, this->town->text);
aimed_height += GetStringHeight(STR_JUST_RAW_STRING, width - WD_FRAMERECT_LEFT - WD_FRAMERECT_RIGHT);
aimed_height += GetStringHeight(STR_JUST_RAW_STRING, width - WidgetDimensions::scaled.framerect.Horizontal());
}
return aimed_height;
@@ -564,7 +593,7 @@ public:
{
if (str == nullptr) return;
DoCommandP(0, this->window_number, 0, CMD_RENAME_TOWN | CMD_MSG(STR_ERROR_CAN_T_RENAME_TOWN), nullptr, str);
Command<CMD_RENAME_TOWN>::Post(STR_ERROR_CAN_T_RENAME_TOWN, this->window_number, str);
}
};
@@ -796,18 +825,17 @@ public:
case WID_TD_LIST: {
int n = 0;
int y = r.top + WD_FRAMERECT_TOP;
Rect tr = r.Shrink(WidgetDimensions::scaled.framerect);
if (this->towns.size() == 0) { // No towns available.
DrawString(r.left + WD_FRAMERECT_LEFT, r.right, y, STR_TOWN_DIRECTORY_NONE);
DrawString(tr, STR_TOWN_DIRECTORY_NONE);
break;
}
/* At least one town available. */
bool rtl = _current_text_dir == TD_RTL;
Dimension icon_size = GetSpriteSize(SPR_TOWN_RATING_GOOD);
int text_left = r.left + WD_FRAMERECT_LEFT + (rtl ? 0 : icon_size.width + 2);
int text_right = r.right - WD_FRAMERECT_RIGHT - (rtl ? icon_size.width + 2 : 0);
int icon_x = rtl ? r.right - WD_FRAMERECT_RIGHT - icon_size.width : r.left + WD_FRAMERECT_LEFT;
int icon_x = tr.WithWidth(icon_size.width, rtl).left;
tr = tr.Indent(icon_size.width + WidgetDimensions::scaled.hsep_normal, rtl);
for (uint i = this->vscroll->GetPosition(); i < this->towns.size(); i++) {
const Town *t = this->towns[i];
@@ -815,19 +843,19 @@ public:
/* Draw rating icon. */
if (_game_mode == GM_EDITOR || !HasBit(t->have_ratings, _local_company)) {
DrawSprite(SPR_TOWN_RATING_NA, PAL_NONE, icon_x, y + (this->resize.step_height - icon_size.height) / 2);
DrawSprite(SPR_TOWN_RATING_NA, PAL_NONE, icon_x, tr.top + (this->resize.step_height - icon_size.height) / 2);
} else {
SpriteID icon = SPR_TOWN_RATING_APALLING;
if (t->ratings[_local_company] > RATING_VERYPOOR) icon = SPR_TOWN_RATING_MEDIOCRE;
if (t->ratings[_local_company] > RATING_GOOD) icon = SPR_TOWN_RATING_GOOD;
DrawSprite(icon, PAL_NONE, icon_x, y + (this->resize.step_height - icon_size.height) / 2);
DrawSprite(icon, PAL_NONE, icon_x, tr.top + (this->resize.step_height - icon_size.height) / 2);
}
SetDParam(0, t->index);
SetDParam(1, t->cache.population);
DrawString(text_left, text_right, y + (this->resize.step_height - FONT_HEIGHT_NORMAL) / 2, GetTownString(t));
DrawString(tr.left, tr.right, tr.top + (this->resize.step_height - FONT_HEIGHT_NORMAL) / 2, GetTownString(t));
y += this->resize.step_height;
tr.top += this->resize.step_height;
if (++n == this->vscroll->GetCapacity()) break; // max number of towns in 1 window
}
break;
@@ -872,8 +900,8 @@ public:
d.height = GetMinButtonSize(d.height);
resize->height = d.height;
d.height *= 5;
d.width += padding.width + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT;
d.height += padding.height + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM;
d.width += padding.width;
d.height += padding.height;
*size = maxdim(*size, d);
break;
}
@@ -910,7 +938,7 @@ public:
break;
case WID_TD_LIST: { // Click on Town Matrix
uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_TD_LIST, WD_FRAMERECT_TOP);
uint id_v = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_TD_LIST, WidgetDimensions::scaled.framerect.top);
if (id_v >= this->towns.size()) return; // click out of town bounds
const Town *t = this->towns[id_v];
@@ -1014,7 +1042,7 @@ void ShowTownDirectory()
new TownDirectoryWindow(&_town_directory_desc);
}
void CcFoundTown(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
void CcFoundTown(Commands cmd, const CommandCost &result, TileIndex tile)
{
if (result.Failed()) return;
@@ -1022,9 +1050,9 @@ void CcFoundTown(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2
if (!_settings_client.gui.persistent_buildingtools) ResetObjectToPlace();
}
void CcFoundRandomTown(const CommandCost &result, TileIndex tile, uint32 p1, uint32 p2, uint32 cmd)
void CcFoundRandomTown(Commands cmd, const CommandCost &result, Money, TownID town_id)
{
if (result.Succeeded()) ScrollMainWindowToTile(Town::Get(_new_town_id)->xy);
if (result.Succeeded()) ScrollMainWindowToTile(Town::Get(town_id)->xy);
}
static const NWidgetPart _nested_found_town_widgets[] = {
@@ -1043,7 +1071,9 @@ static const NWidgetPart _nested_found_town_widgets[] = {
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TF_RANDOM_TOWN), SetMinimalSize(156, 12), SetFill(1, 0),
SetDataTip(STR_FOUND_TOWN_RANDOM_TOWN_BUTTON, STR_FOUND_TOWN_RANDOM_TOWN_TOOLTIP), SetPadding(0, 2, 1, 2),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TF_MANY_RANDOM_TOWNS), SetMinimalSize(156, 12), SetFill(1, 0),
SetDataTip(STR_FOUND_TOWN_MANY_RANDOM_TOWNS, STR_FOUND_TOWN_RANDOM_TOWNS_TOOLTIP), SetPadding(0, 2, 0, 2),
SetDataTip(STR_FOUND_TOWN_MANY_RANDOM_TOWNS, STR_FOUND_TOWN_RANDOM_TOWNS_TOOLTIP), SetPadding(0, 2, 1, 2),
NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_TF_EXPAND_ALL_TOWNS), SetMinimalSize(156, 12), SetFill(1, 0),
SetDataTip(STR_FOUND_TOWN_EXPAND_ALL_TOWNS, STR_FOUND_TOWN_EXPAND_ALL_TOWNS_TOOLTIP), SetPadding(0, 2, 0, 2),
/* Town name selection. */
NWidget(WWT_LABEL, COLOUR_DARK_GREEN), SetMinimalSize(156, 14), SetPadding(0, 2, 0, 2), SetDataTip(STR_FOUND_TOWN_NAME_TITLE, STR_NULL),
NWidget(WWT_EDITBOX, COLOUR_GREY, WID_TF_TOWN_NAME_EDITBOX), SetMinimalSize(156, 12), SetPadding(0, 2, 3, 2),
@@ -1144,7 +1174,7 @@ public:
void UpdateButtons(bool check_availability)
{
if (check_availability && _game_mode != GM_EDITOR) {
this->SetWidgetsDisabledState(true, WID_TF_RANDOM_TOWN, WID_TF_MANY_RANDOM_TOWNS, WID_TF_SIZE_LARGE, WIDGET_LIST_END);
this->SetWidgetsDisabledState(true, WID_TF_RANDOM_TOWN, WID_TF_MANY_RANDOM_TOWNS, WID_TF_EXPAND_ALL_TOWNS, WID_TF_SIZE_LARGE, WIDGET_LIST_END);
this->SetWidgetsDisabledState(_settings_game.economy.found_town != TF_CUSTOM_LAYOUT,
WID_TF_LAYOUT_ORIGINAL, WID_TF_LAYOUT_BETTER, WID_TF_LAYOUT_GRID2, WID_TF_LAYOUT_GRID3, WID_TF_LAYOUT_RANDOM, WIDGET_LIST_END);
if (_settings_game.economy.found_town != TF_CUSTOM_LAYOUT) town_layout = _settings_game.economy.town_layout;
@@ -1163,7 +1193,8 @@ public:
this->SetDirty();
}
void ExecuteFoundTownCommand(TileIndex tile, bool random, StringID errstr, CommandCallback cc)
template <typename Tcallback>
void ExecuteFoundTownCommand(TileIndex tile, bool random, StringID errstr, Tcallback cc)
{
std::string name;
@@ -1176,8 +1207,8 @@ public:
if (strcmp(buf, this->townname_editbox.text.buf) != 0) name = this->townname_editbox.text.buf;
}
bool success = DoCommandP(tile, this->town_size | this->city << 2 | this->town_layout << 3 | random << 6,
townnameparts, CMD_FOUND_TOWN | CMD_MSG(errstr), cc, name);
bool success = Command<CMD_FOUND_TOWN>::Post(errstr, cc,
tile, this->town_size, this->city, this->town_layout, random, townnameparts, name);
/* Rerandomise name, if success and no cost-estimation. */
if (success && !_shift_pressed) this->RandomTownName();
@@ -1210,6 +1241,12 @@ public:
break;
}
case WID_TF_EXPAND_ALL_TOWNS:
for (Town *t : Town::Iterate()) {
Command<CMD_EXPAND_TOWN>::Do(DC_EXEC, t->index, 0);
}
break;
case WID_TF_SIZE_SMALL: case WID_TF_SIZE_MEDIUM: case WID_TF_SIZE_LARGE: case WID_TF_SIZE_RANDOM:
this->town_size = (TownSize)(widget - WID_TF_SIZE_SMALL);
this->UpdateButtons(false);