summaryrefslogtreecommitdiff
path: root/src/toolbar_gui.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/toolbar_gui.cpp')
-rw-r--r--src/toolbar_gui.cpp124
1 files changed, 93 insertions, 31 deletions
diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp
index 7cd5facf1..23c10fb72 100644
--- a/src/toolbar_gui.cpp
+++ b/src/toolbar_gui.cpp
@@ -17,6 +17,7 @@
#include "command_func.h"
#include "vehicle_gui.h"
#include "rail_gui.h"
+#include "road.h"
#include "road_gui.h"
#include "date_func.h"
#include "vehicle_func.h"
@@ -64,6 +65,7 @@ uint _toolbar_width = 0;
RailType _last_built_railtype;
RoadType _last_built_roadtype;
+RoadType _last_built_tramtype;
static ScreenshotType _confirmed_screenshot_type; ///< Screenshot type the current query is about to confirm.
@@ -893,22 +895,7 @@ static CallBackFunction MenuClickBuildRail(int index)
static CallBackFunction ToolbarBuildRoadClick(Window *w)
{
- const Company *c = Company::Get(_local_company);
- DropDownList list;
-
- /* Road is always visible and available. */
- list.emplace_back(new DropDownListIconItem(SPR_IMG_ROAD_X_DIR, PAL_NONE, STR_ROAD_MENU_ROAD_CONSTRUCTION, ROADTYPE_ROAD, false));
-
- /* Tram is only visible when there will be a tram, and available when that has been introduced. */
- Engine *e;
- FOR_ALL_ENGINES_OF_TYPE(e, VEH_ROAD) {
- if (!HasBit(e->info.climates, _settings_game.game_creation.landscape)) continue;
- if (!HasBit(e->info.misc_flags, EF_ROAD_TRAM)) continue;
-
- list.emplace_back(new DropDownListIconItem(SPR_IMG_TRAMWAY_X_DIR, PAL_NONE, STR_ROAD_MENU_TRAM_CONSTRUCTION, ROADTYPE_TRAM, !HasBit(c->avail_roadtypes, ROADTYPE_TRAM)));
- break;
- }
- ShowDropDownList(w, std::move(list), _last_built_roadtype, WID_TN_ROADS, 140, true, true);
+ ShowDropDownList(w, GetRoadTypeDropDownList(RTTB_ROAD), _last_built_roadtype, WID_TN_ROADS, 140, true, true);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
return CBF_NONE;
}
@@ -926,6 +913,28 @@ static CallBackFunction MenuClickBuildRoad(int index)
return CBF_NONE;
}
+/* --- Tram button menu --- */
+
+static CallBackFunction ToolbarBuildTramClick(Window *w)
+{
+ ShowDropDownList(w, GetRoadTypeDropDownList(RTTB_TRAM), _last_built_tramtype, WID_TN_TRAMS, 140, true, true);
+ if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
+ return CBF_NONE;
+}
+
+/**
+ * Handle click on the entry in the Build Tram menu.
+ *
+ * @param index RoadType to show the build toolbar for.
+ * @return #CBF_NONE
+ */
+static CallBackFunction MenuClickBuildTram(int index)
+{
+ _last_built_tramtype = (RoadType)index;
+ ShowBuildRoadToolbar(_last_built_tramtype);
+ return CBF_NONE;
+}
+
/* --- Water button menu --- */
static CallBackFunction ToolbarBuildWaterClick(Window *w)
@@ -1251,9 +1260,41 @@ static CallBackFunction ToolbarScenGenIndustry(Window *w)
static CallBackFunction ToolbarScenBuildRoadClick(Window *w)
{
- w->HandleButtonClick(WID_TE_ROADS);
+ ShowDropDownList(w, GetScenRoadTypeDropDownList(RTTB_ROAD), _last_built_roadtype, WID_TE_ROADS, 140, true, true);
if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
- ShowBuildRoadScenToolbar();
+ return CBF_NONE;
+}
+
+/**
+ * Handle click on the entry in the Build Road menu.
+ *
+ * @param index RoadType to show the build toolbar for.
+ * @return #CBF_NONE
+ */
+static CallBackFunction ToolbarScenBuildRoad(int index)
+{
+ _last_built_roadtype = (RoadType)index;
+ ShowBuildRoadScenToolbar(_last_built_roadtype);
+ return CBF_NONE;
+}
+
+static CallBackFunction ToolbarScenBuildTramClick(Window *w)
+{
+ ShowDropDownList(w, GetScenRoadTypeDropDownList(RTTB_TRAM), _last_built_tramtype, WID_TE_TRAMS, 140, true, true);
+ if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP);
+ return CBF_NONE;
+}
+
+/**
+ * Handle click on the entry in the Build Tram menu.
+ *
+ * @param index RoadType to show the build toolbar for.
+ * @return #CBF_NONE
+ */
+static CallBackFunction ToolbarScenBuildTram(int index)
+{
+ _last_built_tramtype = (RoadType)index;
+ ShowBuildRoadScenToolbar(_last_built_tramtype);
return CBF_NONE;
}
@@ -1311,12 +1352,13 @@ static MenuClickedProc * const _menu_clicked_procs[] = {
nullptr, // 20
MenuClickBuildRail, // 21
MenuClickBuildRoad, // 22
- MenuClickBuildWater, // 23
- MenuClickBuildAir, // 24
- MenuClickForest, // 25
- MenuClickMusicWindow, // 26
- MenuClickNewspaper, // 27
- MenuClickHelp, // 28
+ MenuClickBuildTram, // 23
+ MenuClickBuildWater, // 24
+ MenuClickBuildAir, // 25
+ MenuClickForest, // 26
+ MenuClickMusicWindow, // 27
+ MenuClickNewspaper, // 28
+ MenuClickHelp, // 29
};
/** Full blown container to make it behave exactly as we want :) */
@@ -1772,6 +1814,7 @@ class NWidgetMainToolbarContainer : public NWidgetToolbarContainer {
WID_TN_ZOOM_OUT,
WID_TN_RAILS,
WID_TN_ROADS,
+ WID_TN_TRAMS,
WID_TN_WATER,
WID_TN_AIR,
WID_TN_LANDSCAPE,
@@ -1832,6 +1875,7 @@ class NWidgetScenarioToolbarContainer : public NWidgetToolbarContainer {
WID_TE_TOWN_GENERATE,
WID_TE_INDUSTRY,
WID_TE_ROADS,
+ WID_TE_TRAMS,
WID_TE_WATER,
WID_TE_TREES,
WID_TE_SIGNS,
@@ -1851,6 +1895,7 @@ class NWidgetScenarioToolbarContainer : public NWidgetToolbarContainer {
WID_TE_TOWN_GENERATE,
WID_TE_INDUSTRY,
WID_TE_ROADS,
+ WID_TE_TRAMS,
WID_TE_WATER,
WID_TE_TREES,
WID_TE_SIGNS,
@@ -1864,6 +1909,7 @@ class NWidgetScenarioToolbarContainer : public NWidgetToolbarContainer {
WID_TE_TOWN_GENERATE,
WID_TE_INDUSTRY,
WID_TE_ROADS,
+ WID_TE_TRAMS,
WID_TE_WATER,
WID_TE_TREES,
WID_TE_SIGNS,
@@ -1939,6 +1985,7 @@ static ToolbarButtonProc * const _toolbar_button_procs[] = {
ToolbarZoomOutClick,
ToolbarBuildRailClick,
ToolbarBuildRoadClick,
+ ToolbarBuildTramClick,
ToolbarBuildWaterClick,
ToolbarBuildAirClick,
ToolbarForestClick,
@@ -1973,6 +2020,7 @@ enum MainToolbarHotkeys {
MTHK_ZOOM_OUT,
MTHK_BUILD_RAIL,
MTHK_BUILD_ROAD,
+ MTHK_BUILD_TRAM,
MTHK_BUILD_DOCKS,
MTHK_BUILD_AIRPORT,
MTHK_BUILD_TREES,
@@ -2017,7 +2065,7 @@ struct MainToolbarWindow : Window {
/* If spectator, disable all construction buttons
* ie : Build road, rail, ships, airports and landscaping
* Since enabled state is the default, just disable when needed */
- this->SetWidgetsDisabledState(_local_company == COMPANY_SPECTATOR, WID_TN_RAILS, WID_TN_ROADS, WID_TN_WATER, WID_TN_AIR, WID_TN_LANDSCAPE, WIDGET_LIST_END);
+ this->SetWidgetsDisabledState(_local_company == COMPANY_SPECTATOR, WID_TN_RAILS, WID_TN_ROADS, WID_TN_TRAMS, WID_TN_WATER, WID_TN_AIR, WID_TN_LANDSCAPE, WIDGET_LIST_END);
/* disable company list drop downs, if there are no companies */
this->SetWidgetsDisabledState(Company::GetNumItems() == 0, WID_TN_STATIONS, WID_TN_FINANCES, WID_TN_TRAINS, WID_TN_ROADVEHS, WID_TN_SHIPS, WID_TN_AIRCRAFT, WIDGET_LIST_END);
@@ -2025,6 +2073,8 @@ struct MainToolbarWindow : Window {
this->SetWidgetDisabledState(WID_TN_STORY, StoryPage::GetNumItems() == 0);
this->SetWidgetDisabledState(WID_TN_RAILS, !CanBuildVehicleInfrastructure(VEH_TRAIN));
+ this->SetWidgetDisabledState(WID_TN_ROADS, !CanBuildVehicleInfrastructure(VEH_ROAD, RTT_ROAD));
+ this->SetWidgetDisabledState(WID_TN_TRAMS, !CanBuildVehicleInfrastructure(VEH_ROAD, RTT_TRAM));
this->SetWidgetDisabledState(WID_TN_AIR, !CanBuildVehicleInfrastructure(VEH_AIRCRAFT));
this->DrawWidgets();
@@ -2068,6 +2118,7 @@ struct MainToolbarWindow : Window {
case MTHK_ZOOM_OUT: ToolbarZoomOutClick(this); break;
case MTHK_BUILD_RAIL: if (CanBuildVehicleInfrastructure(VEH_TRAIN)) ShowBuildRailToolbar(_last_built_railtype); break;
case MTHK_BUILD_ROAD: ShowBuildRoadToolbar(_last_built_roadtype); break;
+ case MTHK_BUILD_TRAM: if (CanBuildVehicleInfrastructure(VEH_ROAD, RTT_TRAM)) ShowBuildRoadToolbar(_last_built_tramtype); break;
case MTHK_BUILD_DOCKS: ShowBuildDocksToolbar(); break;
case MTHK_BUILD_AIRPORT: if (CanBuildVehicleInfrastructure(VEH_AIRCRAFT)) ShowBuildAirToolbar(); break;
case MTHK_BUILD_TREES: ShowBuildTreesToolbar(); break;
@@ -2179,6 +2230,7 @@ static Hotkey maintoolbar_hotkeys[] = {
Hotkey(_maintoolbar_zoomout_keys, "zoomout", MTHK_ZOOM_OUT),
Hotkey(WKC_SHIFT | WKC_F7, "build_rail", MTHK_BUILD_RAIL),
Hotkey(WKC_SHIFT | WKC_F8, "build_road", MTHK_BUILD_ROAD),
+ Hotkey((uint16)0, "build_tram", MTHK_BUILD_TRAM),
Hotkey(WKC_SHIFT | WKC_F9, "build_docks", MTHK_BUILD_DOCKS),
Hotkey(WKC_SHIFT | WKC_F10, "build_airport", MTHK_BUILD_AIRPORT),
Hotkey(WKC_SHIFT | WKC_F11, "build_trees", MTHK_BUILD_TREES),
@@ -2224,6 +2276,7 @@ static NWidgetBase *MakeMainToolbar(int *biggest_index)
SPR_IMG_ZOOMOUT, // WID_TN_ZOOMOUT
SPR_IMG_BUILDRAIL, // WID_TN_RAILS
SPR_IMG_BUILDROAD, // WID_TN_ROADS
+ SPR_IMG_BUILDTRAMS, // WID_TN_TRAMS
SPR_IMG_BUILDWATER, // WID_TN_WATER
SPR_IMG_BUILDAIR, // WID_TN_AIR
SPR_IMG_LANDSCAPING, // WID_TN_LANDSCAPE
@@ -2282,14 +2335,15 @@ static MenuClickedProc * const _scen_toolbar_dropdown_procs[] = {
nullptr, // 11
nullptr, // 12
nullptr, // 13
- nullptr, // 14
- nullptr, // 15
+ ToolbarScenBuildRoad, // 14
+ ToolbarScenBuildTram, // 15
nullptr, // 16
nullptr, // 17
nullptr, // 18
- MenuClickMusicWindow, // 19
- MenuClickHelp, // 20
- nullptr, // 21
+ nullptr, // 19
+ MenuClickMusicWindow, // 20
+ MenuClickHelp, // 21
+ nullptr, // 22
};
static ToolbarButtonProc * const _scen_toolbar_button_procs[] = {
@@ -2308,6 +2362,7 @@ static ToolbarButtonProc * const _scen_toolbar_button_procs[] = {
ToolbarScenGenTown,
ToolbarScenGenIndustry,
ToolbarScenBuildRoadClick,
+ ToolbarScenBuildTramClick,
ToolbarScenBuildDocks,
ToolbarScenPlantTrees,
ToolbarScenPlaceSign,
@@ -2326,6 +2381,7 @@ enum MainToolbarEditorHotkeys {
MTEHK_GENTOWN,
MTEHK_GENINDUSTRY,
MTEHK_BUILD_ROAD,
+ MTEHK_BUILD_TRAM,
MTEHK_BUILD_DOCKS,
MTEHK_BUILD_TREES,
MTEHK_SIGN,
@@ -2366,6 +2422,8 @@ struct ScenarioEditorToolbarWindow : Window {
{
this->SetWidgetDisabledState(WID_TE_DATE_BACKWARD, _settings_game.game_creation.starting_year <= MIN_YEAR);
this->SetWidgetDisabledState(WID_TE_DATE_FORWARD, _settings_game.game_creation.starting_year >= MAX_YEAR);
+ this->SetWidgetDisabledState(WID_TE_ROADS, (GetRoadTypes(true) & ~_roadtypes_type) == ROADTYPES_NONE);
+ this->SetWidgetDisabledState(WID_TE_TRAMS, (GetRoadTypes(true) & _roadtypes_type) == ROADTYPES_NONE);
this->DrawWidgets();
}
@@ -2432,6 +2490,7 @@ struct ScenarioEditorToolbarWindow : Window {
case MTEHK_GENTOWN: ToolbarScenGenTown(this); break;
case MTEHK_GENINDUSTRY: ToolbarScenGenIndustry(this); break;
case MTEHK_BUILD_ROAD: ToolbarScenBuildRoadClick(this); break;
+ case MTEHK_BUILD_TRAM: ToolbarScenBuildTramClick(this); break;
case MTEHK_BUILD_DOCKS: ToolbarScenBuildDocks(this); break;
case MTEHK_BUILD_TREES: ToolbarScenPlantTrees(this); break;
case MTEHK_SIGN: cbf = ToolbarScenPlaceSign(this); break;
@@ -2535,6 +2594,7 @@ static Hotkey scenedit_maintoolbar_hotkeys[] = {
Hotkey(WKC_F5, "gen_town", MTEHK_GENTOWN),
Hotkey(WKC_F6, "gen_industry", MTEHK_GENINDUSTRY),
Hotkey(WKC_F7, "build_road", MTEHK_BUILD_ROAD),
+ Hotkey((uint16)0, "build_tram", MTEHK_BUILD_TRAM),
Hotkey(WKC_F8, "build_docks", MTEHK_BUILD_DOCKS),
Hotkey(WKC_F9, "build_trees", MTEHK_BUILD_TREES),
Hotkey(WKC_F10, "build_sign", MTEHK_SIGN),
@@ -2577,7 +2637,8 @@ static const NWidgetPart _nested_toolb_scen_inner_widgets[] = {
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_LAND_GENERATE), SetDataTip(SPR_IMG_LANDSCAPING, STR_SCENEDIT_TOOLBAR_LANDSCAPE_GENERATION),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_TOWN_GENERATE), SetDataTip(SPR_IMG_TOWN, STR_SCENEDIT_TOOLBAR_TOWN_GENERATION),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_INDUSTRY), SetDataTip(SPR_IMG_INDUSTRY, STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION),
- NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_ROADS), SetDataTip(SPR_IMG_BUILDROAD, STR_SCENEDIT_TOOLBAR_ROAD_CONSTRUCTION),
+ NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_ROADS), SetDataTip(SPR_IMG_BUILDROAD, STR_SCENEDIT_TOOLBAR_ROAD_CONSTRUCTION),
+ NWidget(WWT_IMGBTN, COLOUR_GREY, WID_TE_TRAMS), SetDataTip(SPR_IMG_BUILDTRAMS, STR_SCENEDIT_TOOLBAR_TRAM_CONSTRUCTION),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_WATER), SetDataTip(SPR_IMG_BUILDWATER, STR_TOOLBAR_TOOLTIP_BUILD_SHIP_DOCKS),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_TREES), SetDataTip(SPR_IMG_PLANTTREES, STR_SCENEDIT_TOOLBAR_PLANT_TREES),
NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_TE_SIGNS), SetDataTip(SPR_IMG_SIGN, STR_SCENEDIT_TOOLBAR_PLACE_SIGN),
@@ -2609,6 +2670,7 @@ void AllocateToolbar()
{
/* Clean old GUI values; railtype is (re)set by rail_gui.cpp */
_last_built_roadtype = ROADTYPE_ROAD;
+ _last_built_tramtype = ROADTYPE_TRAM;
if (_game_mode == GM_EDITOR) {
new ScenarioEditorToolbarWindow(&_toolb_scen_desc);