diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp index d20dd284a6..a1fad1be4c 100644 --- a/src/bridge_gui.cpp +++ b/src/bridge_gui.cpp @@ -126,7 +126,7 @@ private: this->bridges.Sort(); /* Display the current sort variant */ - this->GetWidget(WID_BBS_DROPDOWN_CRITERIA)->widget_data = BuildBridgeWindow::sorter_names[this->bridges.SortType()]; + this->GetWidget(WID_BBS_DROPDOWN_CRITERIA)->SetString(BuildBridgeWindow::sorter_names[this->bridges.SortType()]); /* Set the modified widgets dirty */ this->SetWidgetDirty(WID_BBS_DROPDOWN_CRITERIA); @@ -161,7 +161,7 @@ public: this->CreateNestedTree(); this->vscroll = this->GetScrollbar(WID_BBS_SCROLLBAR); /* Change the data, or the caption of the gui. Set it to road or rail, accordingly. */ - this->GetWidget(WID_BBS_CAPTION)->widget_data = (transport_type == TRANSPORT_ROAD) ? STR_SELECT_ROAD_BRIDGE_CAPTION : STR_SELECT_RAIL_BRIDGE_CAPTION; + this->GetWidget(WID_BBS_CAPTION)->SetString((transport_type == TRANSPORT_ROAD) ? STR_SELECT_ROAD_BRIDGE_CAPTION : STR_SELECT_RAIL_BRIDGE_CAPTION); this->FinishInitNested(transport_type); // Initializes 'this->icon_width'. this->parent = FindWindowById(WC_BUILD_TOOLBAR, transport_type); diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 6262ab3635..bb74419623 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -1365,9 +1365,9 @@ class SelectCompanyManagerFaceWindow : public Window this->is_female = HasBit(this->ge, GENDER_FEMALE); // get the gender: 0 == male and 1 == female this->is_moust_male = !is_female && GetCompanyManagerFaceBits(this->face, CMFV_HAS_MOUSTACHE, this->ge) != 0; // is a male face with moustache - this->GetWidget(WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT)->widget_data = this->is_female ? STR_FACE_EARRING : STR_FACE_MOUSTACHE; - this->GetWidget(WID_SCMF_TIE_EARRING_TEXT)->widget_data = this->is_female ? STR_FACE_EARRING : STR_FACE_TIE; - this->GetWidget(WID_SCMF_LIPS_MOUSTACHE_TEXT)->widget_data = this->is_moust_male ? STR_FACE_MOUSTACHE : STR_FACE_LIPS; + this->GetWidget(WID_SCMF_HAS_MOUSTACHE_EARRING_TEXT)->SetString(this->is_female ? STR_FACE_EARRING : STR_FACE_MOUSTACHE); + this->GetWidget(WID_SCMF_TIE_EARRING_TEXT)->SetString(this->is_female ? STR_FACE_EARRING : STR_FACE_TIE); + this->GetWidget(WID_SCMF_LIPS_MOUSTACHE_TEXT)->SetString(this->is_moust_male ? STR_FACE_MOUSTACHE : STR_FACE_LIPS); } public: @@ -1393,7 +1393,7 @@ public: this->GetWidget(WID_SCMF_SEL_LOADSAVE)->SetDisplayedPlane(advanced ? 0 : SZSP_NONE); this->GetWidget(WID_SCMF_SEL_PARTS)->SetDisplayedPlane(advanced ? 0 : SZSP_NONE); this->GetWidget(WID_SCMF_SEL_MALEFEMALE)->SetDisplayedPlane(advanced ? SZSP_NONE : 0); - this->GetWidget(WID_SCMF_RANDOM_NEW_FACE)->widget_data = advanced ? STR_FACE_RANDOM : STR_FACE_NEW_FACE_BUTTON; + this->GetWidget(WID_SCMF_RANDOM_NEW_FACE)->SetString(advanced ? STR_FACE_RANDOM : STR_FACE_NEW_FACE_BUTTON); NWidgetCore *wi = this->GetWidget(WID_SCMF_TOGGLE_LARGE_SMALL_BUTTON); if (advanced) { diff --git a/src/depot_gui.cpp b/src/depot_gui.cpp index 5225a58b35..7183038987 100644 --- a/src/depot_gui.cpp +++ b/src/depot_gui.cpp @@ -609,7 +609,7 @@ struct DepotWindow : Window { default: NOT_REACHED(); case VEH_TRAIN: - this->GetWidget(WID_D_VEHICLE_LIST)->widget_data = STR_TRAIN; + this->GetWidget(WID_D_VEHICLE_LIST)->SetString(STR_TRAIN); /* Sprites */ this->GetWidget(WID_D_SELL)->SetSprite(SPR_SELL_TRAIN); @@ -618,7 +618,7 @@ struct DepotWindow : Window { break; case VEH_ROAD: - this->GetWidget(WID_D_VEHICLE_LIST)->widget_data = STR_LORRY; + this->GetWidget(WID_D_VEHICLE_LIST)->SetString(STR_LORRY); /* Sprites */ this->GetWidget(WID_D_SELL)->SetSprite(SPR_SELL_ROADVEH); @@ -627,7 +627,7 @@ struct DepotWindow : Window { break; case VEH_SHIP: - this->GetWidget(WID_D_VEHICLE_LIST)->widget_data = STR_SHIP; + this->GetWidget(WID_D_VEHICLE_LIST)->SetString(STR_SHIP); /* Sprites */ this->GetWidget(WID_D_SELL)->SetSprite(SPR_SELL_SHIP); @@ -636,7 +636,7 @@ struct DepotWindow : Window { break; case VEH_AIRCRAFT: - this->GetWidget(WID_D_VEHICLE_LIST)->widget_data = STR_PLANE; + this->GetWidget(WID_D_VEHICLE_LIST)->SetString(STR_PLANE); /* Sprites */ this->GetWidget(WID_D_SELL)->SetSprite(SPR_SELL_AIRCRAFT); diff --git a/src/fios_gui.cpp b/src/fios_gui.cpp index 526acdb985..71becf935e 100644 --- a/src/fios_gui.cpp +++ b/src/fios_gui.cpp @@ -408,7 +408,7 @@ public: default: NOT_REACHED(); } - this->GetWidget(WID_SL_CAPTION)->widget_data = caption_string; + this->GetWidget(WID_SL_CAPTION)->SetString(caption_string); this->vscroll = this->GetScrollbar(WID_SL_SCROLLBAR); this->FinishInitNested(0); diff --git a/src/group_gui.cpp b/src/group_gui.cpp index 031d88ef46..b6e03adf1f 100644 --- a/src/group_gui.cpp +++ b/src/group_gui.cpp @@ -405,7 +405,7 @@ public: this->BuildGroupList(vli.company); this->group_sb->SetCount(this->groups.size()); - this->GetWidget(WID_GL_CAPTION)->widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this->vli.vtype; + this->GetWidget(WID_GL_CAPTION)->SetString(STR_VEHICLE_LIST_TRAIN_CAPTION + this->vli.vtype); this->GetWidget(WID_GL_LIST_VEHICLE)->SetToolTip(STR_VEHICLE_LIST_TRAIN_LIST_TOOLTIP + this->vli.vtype); this->GetWidget(WID_GL_CREATE_GROUP)->widget_data += this->vli.vtype; @@ -588,10 +588,10 @@ public: this->GetWidget(WID_GL_REPLACE_PROTECTION)->SetSprite(protect_sprite + this->vli.vtype); /* Set text of "group by" dropdown widget. */ - this->GetWidget(WID_GL_GROUP_BY_DROPDOWN)->widget_data = std::data(this->vehicle_group_by_names)[this->grouping]; + this->GetWidget(WID_GL_GROUP_BY_DROPDOWN)->SetString(std::data(this->vehicle_group_by_names)[this->grouping]); /* Set text of "sort by" dropdown widget. */ - this->GetWidget(WID_GL_SORT_BY_DROPDOWN)->widget_data = this->GetVehicleSorterNames()[this->vehgroups.SortType()]; + this->GetWidget(WID_GL_SORT_BY_DROPDOWN)->SetString(this->GetVehicleSorterNames()[this->vehgroups.SortType()]); this->DrawWidgets(); } diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index f1ece7f3e2..36fbb850f6 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -2827,7 +2827,7 @@ struct IndustryCargoesWindow : public Window { */ void ComputeIndustryDisplay(IndustryType displayed_it) { - this->GetWidget(WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION; + this->GetWidget(WID_IC_CAPTION)->SetString(STR_INDUSTRY_CARGOES_INDUSTRY_CAPTION); this->ind_cargo = displayed_it; _displayed_industries.reset(); _displayed_industries.set(displayed_it); @@ -2905,7 +2905,7 @@ struct IndustryCargoesWindow : public Window { */ void ComputeCargoDisplay(CargoID cid) { - this->GetWidget(WID_IC_CAPTION)->widget_data = STR_INDUSTRY_CARGOES_CARGO_CAPTION; + this->GetWidget(WID_IC_CAPTION)->SetString(STR_INDUSTRY_CARGOES_CARGO_CAPTION); this->ind_cargo = cid + NUM_INDUSTRYTYPES; _displayed_industries.reset(); diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp index a6688b2eb4..42dbcbb13c 100644 --- a/src/network/network_chat_gui.cpp +++ b/src/network/network_chat_gui.cpp @@ -327,7 +327,7 @@ struct NetworkChatWindow : public Window { assert((uint)this->dtype < lengthof(chat_captions)); this->CreateNestedTree(); - this->GetWidget(WID_NC_DESTINATION)->widget_data = chat_captions[this->dtype]; + this->GetWidget(WID_NC_DESTINATION)->SetString(chat_captions[this->dtype]); this->FinishInitNested(type); this->SetFocusedWidget(WID_NC_TEXTBOX); diff --git a/src/network/network_content_gui.cpp b/src/network/network_content_gui.cpp index 8bb6723bb0..876951431d 100644 --- a/src/network/network_content_gui.cpp +++ b/src/network/network_content_gui.cpp @@ -308,7 +308,7 @@ public: /* When downloading is finished change cancel in ok */ if (this->downloaded_bytes == this->total_bytes) { - this->GetWidget(WID_NCDS_CANCELOK)->widget_data = STR_BUTTON_OK; + this->GetWidget(WID_NCDS_CANCELOK)->SetString(STR_BUTTON_OK); } } }; @@ -1003,7 +1003,7 @@ public: this->SetWidgetDisabledState(WID_NCL_TEXTFILE + tft, this->selected == nullptr || this->selected->state != ContentInfo::ALREADY_HERE || !this->selected->GetTextfile(tft).has_value()); } - this->GetWidget(WID_NCL_CANCEL)->widget_data = this->filesize_sum == 0 ? STR_AI_SETTINGS_CLOSE : STR_AI_LIST_CANCEL; + this->GetWidget(WID_NCL_CANCEL)->SetString(this->filesize_sum == 0 ? STR_AI_SETTINGS_CLOSE : STR_AI_LIST_CANCEL); } }; diff --git a/src/news_gui.cpp b/src/news_gui.cpp index 543677593a..e040b33851 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -363,23 +363,23 @@ struct NewsWindow : Window { this->CreateNestedTree(); /* For company news with a face we have a separate headline in param[0] */ - if (&desc == &_company_news_desc) this->GetWidget(WID_N_TITLE)->widget_data = std::get(this->ni->params[0]); + if (&desc == &_company_news_desc) this->GetWidget(WID_N_TITLE)->SetString(static_cast(std::get(this->ni->params[0]))); NWidgetCore *nwid = this->GetWidget(WID_N_SHOW_GROUP); if (ni->reftype1 == NR_VEHICLE && nwid != nullptr) { const Vehicle *v = Vehicle::Get(ni->ref1); switch (v->type) { case VEH_TRAIN: - nwid->widget_data = STR_TRAIN; + nwid->SetString(STR_TRAIN); break; case VEH_ROAD: - nwid->widget_data = RoadVehicle::From(v)->IsBus() ? STR_BUS : STR_LORRY; + nwid->SetString(RoadVehicle::From(v)->IsBus() ? STR_BUS : STR_LORRY); break; case VEH_SHIP: - nwid->widget_data = STR_SHIP; + nwid->SetString(STR_SHIP); break; case VEH_AIRCRAFT: - nwid->widget_data = STR_PLANE; + nwid->SetString(STR_PLANE); break; default: break; // Do nothing diff --git a/src/order_gui.cpp b/src/order_gui.cpp index 43ed4c63de..f1f2b622b2 100644 --- a/src/order_gui.cpp +++ b/src/order_gui.cpp @@ -1070,8 +1070,8 @@ public: } OrderConditionVariable ocv = order->GetConditionVariable(); /* Set the strings for the dropdown boxes. */ - this->GetWidget(WID_O_COND_VARIABLE)->widget_data = STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + ocv; - this->GetWidget(WID_O_COND_COMPARATOR)->widget_data = _order_conditional_condition[order->GetConditionComparator()]; + this->GetWidget(WID_O_COND_VARIABLE)->SetString(STR_ORDER_CONDITIONAL_LOAD_PERCENTAGE + ocv); + this->GetWidget(WID_O_COND_COMPARATOR)->SetString(_order_conditional_condition[order->GetConditionComparator()]); this->SetWidgetDisabledState(WID_O_COND_COMPARATOR, ocv == OCV_UNCONDITIONALLY); this->SetWidgetDisabledState(WID_O_COND_VALUE, ocv == OCV_REQUIRES_SERVICE || ocv == OCV_UNCONDITIONALLY); break; diff --git a/src/road_gui.cpp b/src/road_gui.cpp index f4007856bb..5f2196fb05 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -1093,7 +1093,7 @@ struct BuildRoadDepotWindow : public PickerWindowBase { this->LowerWidget(WID_BROD_DEPOT_NE + _road_depot_orientation); if (RoadTypeIsTram(_cur_roadtype)) { - this->GetWidget(WID_BROD_CAPTION)->widget_data = STR_BUILD_DEPOT_TRAM_ORIENTATION_CAPTION; + this->GetWidget(WID_BROD_CAPTION)->SetString(STR_BUILD_DEPOT_TRAM_ORIENTATION_CAPTION); for (WidgetID i = WID_BROD_DEPOT_NE; i <= WID_BROD_DEPOT_NW; i++) { this->GetWidget(i)->SetToolTip(STR_BUILD_DEPOT_TRAM_ORIENTATION_SELECT_TOOLTIP); } @@ -1314,7 +1314,7 @@ public: this->ConstructWindow(); const RoadTypeInfo *rti = GetRoadTypeInfo(_cur_roadtype); - this->GetWidget(WID_BROS_CAPTION)->widget_data = rti->strings.picker_title[rs]; + this->GetWidget(WID_BROS_CAPTION)->SetString(rti->strings.picker_title[rs]); for (WidgetID i = RoadTypeIsTram(_cur_roadtype) ? WID_BROS_STATION_X : WID_BROS_STATION_NE; i < WID_BROS_LT_OFF; i++) { this->GetWidget(i)->SetToolTip(rti->strings.picker_tooltip[rs]); diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 00867ea20c..d5c2732435 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -441,7 +441,7 @@ public: if (HasBit(this->filter.facilities, i)) this->LowerWidget(i + WID_STL_TRAIN); } - this->GetWidget(WID_STL_SORTDROPBTN)->widget_data = CompanyStationsWindow::sorter_names[this->stations.SortType()]; + this->GetWidget(WID_STL_SORTDROPBTN)->SetString(CompanyStationsWindow::sorter_names[this->stations.SortType()]); } ~CompanyStationsWindow() @@ -682,7 +682,7 @@ public: this->stations.SetSortType(index); /* Display the current sort variant */ - this->GetWidget(WID_STL_SORTDROPBTN)->widget_data = CompanyStationsWindow::sorter_names[this->stations.SortType()]; + this->GetWidget(WID_STL_SORTDROPBTN)->SetString(CompanyStationsWindow::sorter_names[this->stations.SortType()]); this->SetDirty(); } @@ -2086,7 +2086,7 @@ struct StationViewWindow : public Window { NOT_REACHED(); } /* Display the current sort variant */ - this->GetWidget(WID_SV_SORT_BY)->widget_data = StationViewWindow::sort_names[index]; + this->GetWidget(WID_SV_SORT_BY)->SetString(StationViewWindow::sort_names[index]); this->SetDirty(); } @@ -2098,7 +2098,7 @@ struct StationViewWindow : public Window { { this->grouping_index = index; _settings_client.gui.station_gui_group_order = index; - this->GetWidget(WID_SV_GROUP_BY)->widget_data = StationViewWindow::group_names[index]; + this->GetWidget(WID_SV_GROUP_BY)->SetString(StationViewWindow::group_names[index]); switch (StationViewWindow::group_names[index]) { case STR_STATION_VIEW_GROUP_S_V_D: this->groupings[1] = GR_SOURCE; @@ -2321,7 +2321,7 @@ struct SelectStationWindow : Window { { this->CreateNestedTree(); this->vscroll = this->GetScrollbar(WID_JS_SCROLLBAR); - this->GetWidget(WID_JS_CAPTION)->widget_data = T::IsWaypoint() ? STR_JOIN_WAYPOINT_CAPTION : STR_JOIN_STATION_CAPTION; + this->GetWidget(WID_JS_CAPTION)->SetString(T::IsWaypoint() ? STR_JOIN_WAYPOINT_CAPTION : STR_JOIN_STATION_CAPTION); this->FinishInitNested(0); this->OnInvalidateData(0); diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 6293e16889..94573ac5d4 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -373,7 +373,7 @@ public: this->CreateNestedTree(); this->town = Town::Get(window_number); - if (this->town->larger_town) this->GetWidget(WID_TV_CAPTION)->widget_data = STR_TOWN_VIEW_CITY_CAPTION; + if (this->town->larger_town) this->GetWidget(WID_TV_CAPTION)->SetString(STR_TOWN_VIEW_CITY_CAPTION); this->FinishInitNested(window_number); diff --git a/src/vehicle_gui.cpp b/src/vehicle_gui.cpp index 7f62db7744..40c0a78144 100644 --- a/src/vehicle_gui.cpp +++ b/src/vehicle_gui.cpp @@ -1959,14 +1959,14 @@ public: NWidgetStacked *nwi = this->GetWidget(WID_VL_CAPTION_SELECTION); if (this->vli.type == VL_SHARED_ORDERS) { - this->GetWidget(WID_VL_CAPTION_SHARED_ORDERS)->widget_data = STR_VEHICLE_LIST_SHARED_ORDERS_LIST_CAPTION; + this->GetWidget(WID_VL_CAPTION_SHARED_ORDERS)->SetString(STR_VEHICLE_LIST_SHARED_ORDERS_LIST_CAPTION); /* If we are in the shared orders window, then disable the group-by dropdown menu. * Remove this when the group-by dropdown menu has another option apart from grouping by shared orders. */ this->SetWidgetDisabledState(WID_VL_GROUP_ORDER, true); this->SetWidgetDisabledState(WID_VL_GROUP_BY_PULLDOWN, true); nwi->SetDisplayedPlane(BP_SHARED_ORDERS); } else { - this->GetWidget(WID_VL_CAPTION)->widget_data = STR_VEHICLE_LIST_TRAIN_CAPTION + this->vli.vtype; + this->GetWidget(WID_VL_CAPTION)->SetString(STR_VEHICLE_LIST_TRAIN_CAPTION + this->vli.vtype); nwi->SetDisplayedPlane(BP_NORMAL); } @@ -2118,12 +2118,12 @@ public: } /* Set text of group by dropdown widget. */ - this->GetWidget(WID_VL_GROUP_BY_PULLDOWN)->widget_data = std::data(this->vehicle_group_by_names)[this->grouping]; + this->GetWidget(WID_VL_GROUP_BY_PULLDOWN)->SetString(std::data(this->vehicle_group_by_names)[this->grouping]); /* Set text of sort by dropdown widget. */ - this->GetWidget(WID_VL_SORT_BY_PULLDOWN)->widget_data = this->GetVehicleSorterNames()[this->vehgroups.SortType()]; + this->GetWidget(WID_VL_SORT_BY_PULLDOWN)->SetString(this->GetVehicleSorterNames()[this->vehgroups.SortType()]); - this->GetWidget(WID_VL_FILTER_BY_CARGO)->widget_data = this->GetCargoFilterLabel(this->cargo_filter_criteria); + this->GetWidget(WID_VL_FILTER_BY_CARGO)->SetString(this->GetCargoFilterLabel(this->cargo_filter_criteria)); this->DrawWidgets(); } @@ -2766,7 +2766,7 @@ struct VehicleDetailsWindow : Window { !v->ServiceIntervalIsCustom() ? STR_VEHICLE_DETAILS_DEFAULT : v->ServiceIntervalIsPercent() ? STR_VEHICLE_DETAILS_PERCENT : TimerGameEconomy::UsingWallclockUnits() ? STR_VEHICLE_DETAILS_MINUTES : STR_VEHICLE_DETAILS_DAYS; - this->GetWidget(WID_VD_SERVICE_INTERVAL_DROPDOWN)->widget_data = str; + this->GetWidget(WID_VD_SERVICE_INTERVAL_DROPDOWN)->SetString(str); this->DrawWidgets(); } diff --git a/src/widget.cpp b/src/widget.cpp index c0600798b8..7706f1c99b 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -1134,6 +1134,26 @@ void NWidgetCore::SetDataTip(uint32_t widget_data, StringID tool_tip) this->tool_tip = tool_tip; } +/** + * Set string of the nested widget. + * @param string The new string. + */ +void NWidgetCore::SetString(StringID string) +{ + this->widget_data = string; +} + +/** + * Set string and tool tip of the nested widget. + * @param stringThe new string. + * @param tool_tip The new tool_tip. + */ +void NWidgetCore::SetStringTip(StringID string, StringID tool_tip) +{ + this->SetString(string); + this->SetToolTip(tool_tip); +} + /** * Set sprite of the nested widget. * @param sprite The new sprite. @@ -1143,6 +1163,17 @@ void NWidgetCore::SetSprite(SpriteID sprite) this->widget_data = sprite; } +/** + * Set sprite and tool tip of the nested widget. + * @param sprite The new sprite. + * @param tool_tip The new tool_tip. + */ +void NWidgetCore::SetSpriteTip(SpriteID sprite, StringID tool_tip) +{ + this->SetSprite(sprite); + this->SetToolTip(tool_tip); +} + /** * Set the text style of the nested widget. * @param colour TextColour to use. diff --git a/src/widget_type.h b/src/widget_type.h index e5b37f1c85..7736d6d6b5 100644 --- a/src/widget_type.h +++ b/src/widget_type.h @@ -373,9 +373,10 @@ public: NWidgetCore(WidgetType tp, Colours colour, WidgetID index, uint fill_x, uint fill_y, uint32_t widget_data, StringID tool_tip); void SetDataTip(uint32_t widget_data, StringID tool_tip); - void SetStringTip(StringID string, StringID tool_tip) { this->SetDataTip(string, tool_tip); } + void SetString(StringID string); + void SetStringTip(StringID string, StringID tool_tip); void SetSprite(SpriteID sprite); - void SetSpriteTip(SpriteID sprite, StringID tool_tip) { this->SetSprite(sprite); this->SetToolTip(tool_tip); } + void SetSpriteTip(SpriteID sprite, StringID tool_tip); void SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip) { this->SetDataTip(static_cast((rows << MAT_ROW_START) | (cols << MAT_COL_START)), tip); } void SetToolTip(StringID tool_tip); StringID GetToolTip() const;