mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-01-31 03:12:41 +00:00
Codechange: add and use SetSprite over directly accessing widget_data
This commit is contained in:
parent
9ac1bad480
commit
fb06ddafba
@ -612,36 +612,36 @@ struct DepotWindow : Window {
|
||||
this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->widget_data = STR_TRAIN;
|
||||
|
||||
/* Sprites */
|
||||
this->GetWidget<NWidgetCore>(WID_D_SELL)->widget_data = SPR_SELL_TRAIN;
|
||||
this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->widget_data = SPR_SELL_ALL_TRAIN;
|
||||
this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_TRAIN;
|
||||
this->GetWidget<NWidgetCore>(WID_D_SELL)->SetSprite(SPR_SELL_TRAIN);
|
||||
this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->SetSprite(SPR_SELL_ALL_TRAIN);
|
||||
this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->SetSprite(SPR_REPLACE_TRAIN);
|
||||
break;
|
||||
|
||||
case VEH_ROAD:
|
||||
this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->widget_data = STR_LORRY;
|
||||
|
||||
/* Sprites */
|
||||
this->GetWidget<NWidgetCore>(WID_D_SELL)->widget_data = SPR_SELL_ROADVEH;
|
||||
this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->widget_data = SPR_SELL_ALL_ROADVEH;
|
||||
this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_ROADVEH;
|
||||
this->GetWidget<NWidgetCore>(WID_D_SELL)->SetSprite(SPR_SELL_ROADVEH);
|
||||
this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->SetSprite(SPR_SELL_ALL_ROADVEH);
|
||||
this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->SetSprite(SPR_REPLACE_ROADVEH);
|
||||
break;
|
||||
|
||||
case VEH_SHIP:
|
||||
this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->widget_data = STR_SHIP;
|
||||
|
||||
/* Sprites */
|
||||
this->GetWidget<NWidgetCore>(WID_D_SELL)->widget_data = SPR_SELL_SHIP;
|
||||
this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->widget_data = SPR_SELL_ALL_SHIP;
|
||||
this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_SHIP;
|
||||
this->GetWidget<NWidgetCore>(WID_D_SELL)->SetSprite(SPR_SELL_SHIP);
|
||||
this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->SetSprite(SPR_SELL_ALL_SHIP);
|
||||
this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->SetSprite(SPR_REPLACE_SHIP);
|
||||
break;
|
||||
|
||||
case VEH_AIRCRAFT:
|
||||
this->GetWidget<NWidgetCore>(WID_D_VEHICLE_LIST)->widget_data = STR_PLANE;
|
||||
|
||||
/* Sprites */
|
||||
this->GetWidget<NWidgetCore>(WID_D_SELL)->widget_data = SPR_SELL_AIRCRAFT;
|
||||
this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->widget_data = SPR_SELL_ALL_AIRCRAFT;
|
||||
this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->widget_data = SPR_REPLACE_AIRCRAFT;
|
||||
this->GetWidget<NWidgetCore>(WID_D_SELL)->SetSprite(SPR_SELL_AIRCRAFT);
|
||||
this->GetWidget<NWidgetCore>(WID_D_SELL_ALL)->SetSprite(SPR_SELL_ALL_AIRCRAFT);
|
||||
this->GetWidget<NWidgetCore>(WID_D_AUTOREPLACE)->SetSprite(SPR_REPLACE_AIRCRAFT);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -585,7 +585,7 @@ public:
|
||||
/* If not a default group and the group has replace protection, show an enabled replace sprite. */
|
||||
uint16_t protect_sprite = SPR_GROUP_REPLACE_OFF_TRAIN;
|
||||
if (!IsDefaultGroupID(this->vli.index) && !IsAllGroupID(this->vli.index) && HasBit(Group::Get(this->vli.index)->flags, GroupFlags::GF_REPLACE_PROTECTION)) protect_sprite = SPR_GROUP_REPLACE_ON_TRAIN;
|
||||
this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->widget_data = protect_sprite + this->vli.vtype;
|
||||
this->GetWidget<NWidgetCore>(WID_GL_REPLACE_PROTECTION)->SetSprite(protect_sprite + this->vli.vtype);
|
||||
|
||||
/* Set text of "group by" dropdown widget. */
|
||||
this->GetWidget<NWidgetCore>(WID_GL_GROUP_BY_DROPDOWN)->widget_data = std::data(this->vehicle_group_by_names)[this->grouping];
|
||||
|
@ -736,9 +736,9 @@ struct MusicWindow : public Window {
|
||||
|
||||
/* Hack-ish: set the proper widget data; only needs to be done once
|
||||
* per (Re)Init as that's the only time the language changes. */
|
||||
case WID_M_PREV: this->GetWidget<NWidgetCore>(WID_M_PREV)->widget_data = _current_text_dir == TD_RTL ? SPR_IMG_SKIP_TO_NEXT : SPR_IMG_SKIP_TO_PREV; break;
|
||||
case WID_M_NEXT: this->GetWidget<NWidgetCore>(WID_M_NEXT)->widget_data = _current_text_dir == TD_RTL ? SPR_IMG_SKIP_TO_PREV : SPR_IMG_SKIP_TO_NEXT; break;
|
||||
case WID_M_PLAY: this->GetWidget<NWidgetCore>(WID_M_PLAY)->widget_data = _current_text_dir == TD_RTL ? SPR_IMG_PLAY_MUSIC_RTL : SPR_IMG_PLAY_MUSIC; break;
|
||||
case WID_M_PREV: this->GetWidget<NWidgetCore>(WID_M_PREV)->SetSprite(_current_text_dir == TD_RTL ? SPR_IMG_SKIP_TO_NEXT : SPR_IMG_SKIP_TO_PREV); break;
|
||||
case WID_M_NEXT: this->GetWidget<NWidgetCore>(WID_M_NEXT)->SetSprite(_current_text_dir == TD_RTL ? SPR_IMG_SKIP_TO_PREV : SPR_IMG_SKIP_TO_NEXT); break;
|
||||
case WID_M_PLAY: this->GetWidget<NWidgetCore>(WID_M_PLAY)->SetSprite(_current_text_dir == TD_RTL ? SPR_IMG_PLAY_MUSIC_RTL : SPR_IMG_PLAY_MUSIC); break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -500,14 +500,14 @@ struct BuildRailToolbarWindow : Window {
|
||||
{
|
||||
/* Configure the rail toolbar for the railtype. */
|
||||
const RailTypeInfo *rti = GetRailTypeInfo(this->railtype);
|
||||
this->GetWidget<NWidgetCore>(WID_RAT_BUILD_NS)->widget_data = rti->gui_sprites.build_ns_rail;
|
||||
this->GetWidget<NWidgetCore>(WID_RAT_BUILD_X)->widget_data = rti->gui_sprites.build_x_rail;
|
||||
this->GetWidget<NWidgetCore>(WID_RAT_BUILD_EW)->widget_data = rti->gui_sprites.build_ew_rail;
|
||||
this->GetWidget<NWidgetCore>(WID_RAT_BUILD_Y)->widget_data = rti->gui_sprites.build_y_rail;
|
||||
this->GetWidget<NWidgetCore>(WID_RAT_AUTORAIL)->widget_data = rti->gui_sprites.auto_rail;
|
||||
this->GetWidget<NWidgetCore>(WID_RAT_BUILD_DEPOT)->widget_data = rti->gui_sprites.build_depot;
|
||||
this->GetWidget<NWidgetCore>(WID_RAT_CONVERT_RAIL)->widget_data = rti->gui_sprites.convert_rail;
|
||||
this->GetWidget<NWidgetCore>(WID_RAT_BUILD_TUNNEL)->widget_data = rti->gui_sprites.build_tunnel;
|
||||
this->GetWidget<NWidgetCore>(WID_RAT_BUILD_NS)->SetSprite(rti->gui_sprites.build_ns_rail);
|
||||
this->GetWidget<NWidgetCore>(WID_RAT_BUILD_X)->SetSprite(rti->gui_sprites.build_x_rail);
|
||||
this->GetWidget<NWidgetCore>(WID_RAT_BUILD_EW)->SetSprite(rti->gui_sprites.build_ew_rail);
|
||||
this->GetWidget<NWidgetCore>(WID_RAT_BUILD_Y)->SetSprite(rti->gui_sprites.build_y_rail);
|
||||
this->GetWidget<NWidgetCore>(WID_RAT_AUTORAIL)->SetSprite(rti->gui_sprites.auto_rail);
|
||||
this->GetWidget<NWidgetCore>(WID_RAT_BUILD_DEPOT)->SetSprite(rti->gui_sprites.build_depot);
|
||||
this->GetWidget<NWidgetCore>(WID_RAT_CONVERT_RAIL)->SetSprite(rti->gui_sprites.convert_rail);
|
||||
this->GetWidget<NWidgetCore>(WID_RAT_BUILD_TUNNEL)->SetSprite(rti->gui_sprites.build_tunnel);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -419,14 +419,14 @@ struct BuildRoadToolbarWindow : Window {
|
||||
{
|
||||
/* Configure the road toolbar for the roadtype. */
|
||||
const RoadTypeInfo *rti = GetRoadTypeInfo(this->roadtype);
|
||||
this->GetWidget<NWidgetCore>(WID_ROT_ROAD_X)->widget_data = rti->gui_sprites.build_x_road;
|
||||
this->GetWidget<NWidgetCore>(WID_ROT_ROAD_Y)->widget_data = rti->gui_sprites.build_y_road;
|
||||
this->GetWidget<NWidgetCore>(WID_ROT_AUTOROAD)->widget_data = rti->gui_sprites.auto_road;
|
||||
this->GetWidget<NWidgetCore>(WID_ROT_ROAD_X)->SetSprite(rti->gui_sprites.build_x_road);
|
||||
this->GetWidget<NWidgetCore>(WID_ROT_ROAD_Y)->SetSprite(rti->gui_sprites.build_y_road);
|
||||
this->GetWidget<NWidgetCore>(WID_ROT_AUTOROAD)->SetSprite(rti->gui_sprites.auto_road);
|
||||
if (_game_mode != GM_EDITOR) {
|
||||
this->GetWidget<NWidgetCore>(WID_ROT_DEPOT)->widget_data = rti->gui_sprites.build_depot;
|
||||
this->GetWidget<NWidgetCore>(WID_ROT_DEPOT)->SetSprite(rti->gui_sprites.build_depot);
|
||||
}
|
||||
this->GetWidget<NWidgetCore>(WID_ROT_CONVERT_ROAD)->widget_data = rti->gui_sprites.convert_road;
|
||||
this->GetWidget<NWidgetCore>(WID_ROT_BUILD_TUNNEL)->widget_data = rti->gui_sprites.build_tunnel;
|
||||
this->GetWidget<NWidgetCore>(WID_ROT_CONVERT_ROAD)->SetSprite(rti->gui_sprites.convert_road);
|
||||
this->GetWidget<NWidgetCore>(WID_ROT_BUILD_TUNNEL)->SetSprite(rti->gui_sprites.build_tunnel);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -3069,7 +3069,7 @@ public:
|
||||
SPR_SEND_AIRCRAFT_TODEPOT,
|
||||
};
|
||||
const Vehicle *v = Vehicle::Get(window_number);
|
||||
this->GetWidget<NWidgetCore>(WID_VV_GOTO_DEPOT)->widget_data = vehicle_view_goto_depot_sprites[v->type];
|
||||
this->GetWidget<NWidgetCore>(WID_VV_GOTO_DEPOT)->SetSprite(vehicle_view_goto_depot_sprites[v->type]);
|
||||
|
||||
/* Sprites for the 'clone vehicle' button indexed by vehicle type. */
|
||||
static const SpriteID vehicle_view_clone_sprites[] = {
|
||||
@ -3078,7 +3078,7 @@ public:
|
||||
SPR_CLONE_SHIP,
|
||||
SPR_CLONE_AIRCRAFT,
|
||||
};
|
||||
this->GetWidget<NWidgetCore>(WID_VV_CLONE)->widget_data = vehicle_view_clone_sprites[v->type];
|
||||
this->GetWidget<NWidgetCore>(WID_VV_CLONE)->SetSprite(vehicle_view_clone_sprites[v->type]);
|
||||
|
||||
switch (v->type) {
|
||||
case VEH_TRAIN:
|
||||
|
@ -1134,6 +1134,15 @@ void NWidgetCore::SetDataTip(uint32_t widget_data, StringID tool_tip)
|
||||
this->tool_tip = tool_tip;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set sprite of the nested widget.
|
||||
* @param sprite The new sprite.
|
||||
*/
|
||||
void NWidgetCore::SetSprite(SpriteID sprite)
|
||||
{
|
||||
this->widget_data = sprite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the text style of the nested widget.
|
||||
* @param colour TextColour to use.
|
||||
|
@ -374,7 +374,8 @@ public:
|
||||
|
||||
void SetDataTip(uint32_t widget_data, StringID tool_tip);
|
||||
void SetStringTip(StringID string, StringID tool_tip) { this->SetDataTip(string, tool_tip); }
|
||||
void SetSpriteTip(SpriteID sprite, StringID tool_tip) { this->SetDataTip(sprite, tool_tip); }
|
||||
void SetSprite(SpriteID sprite);
|
||||
void SetSpriteTip(SpriteID sprite, StringID tool_tip) { this->SetSprite(sprite); this->SetToolTip(tool_tip); }
|
||||
void SetMatrixDataTip(uint8_t cols, uint8_t rows, StringID tip) { this->SetDataTip(static_cast<uint32_t>((rows << MAT_ROW_START) | (cols << MAT_COL_START)), tip); }
|
||||
void SetToolTip(StringID tool_tip);
|
||||
StringID GetToolTip() const;
|
||||
|
Loading…
Reference in New Issue
Block a user