Changeset - r28172:b12b2de9deaf
[Not reviewed]
master
0 2 0
Peter Nelson - 12 months ago 2023-11-24 02:39:08
peter1138@openttd.org
Codechange: List toolbar menu items and dividers explicitly.

This makes it clearer what items will be shown in the list, allows for non-consecutive
string IDs, and means unused enum values are not necessary.
2 files changed with 52 insertions and 45 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -440,31 +440,25 @@ STR_SETTINGS_MENU_TRANSPARENT_BUILDINGS 
 
STR_SETTINGS_MENU_TRANSPARENT_SIGNS                             :Transparent signs
 

	
 
# File menu
 
###length 5
 
STR_FILE_MENU_SAVE_GAME                                         :Save game
 
STR_FILE_MENU_LOAD_GAME                                         :Load game
 
STR_FILE_MENU_QUIT_GAME                                         :Abandon game
 
STR_FILE_MENU_SEPARATOR                                         :
 
STR_FILE_MENU_EXIT                                              :Exit
 

	
 
# Map menu
 
###length 4
 
STR_MAP_MENU_MAP_OF_WORLD                                       :Map of world
 
STR_MAP_MENU_EXTRA_VIEWPORT                                     :Extra viewport
 
STR_MAP_MENU_LINGRAPH_LEGEND                                    :Cargo flow legend
 
STR_MAP_MENU_SIGN_LIST                                          :Sign list
 

	
 
# Town menu
 
###length 2
 
STR_TOWN_MENU_TOWN_DIRECTORY                                    :Town directory
 
STR_TOWN_MENU_FOUND_TOWN                                        :Found town
 

	
 
# Subsidies menu
 
###length 1
 
STR_SUBSIDIES_MENU_SUBSIDIES                                    :Subsidies
 

	
 
# Graph menu
 
###length 6
 
STR_GRAPH_MENU_OPERATING_PROFIT_GRAPH                           :Operating profit graph
 
STR_GRAPH_MENU_INCOME_GRAPH                                     :Income graph
 
STR_GRAPH_MENU_DELIVERED_CARGO_GRAPH                            :Delivered cargo graph
 
@@ -473,58 +467,47 @@ STR_GRAPH_MENU_COMPANY_VALUE_GRAPH      
 
STR_GRAPH_MENU_CARGO_PAYMENT_RATES                              :Cargo payment rates
 

	
 
# Company league menu
 
###length 3
 
STR_GRAPH_MENU_COMPANY_LEAGUE_TABLE                             :Company league table
 
STR_GRAPH_MENU_DETAILED_PERFORMANCE_RATING                      :Detailed performance rating
 
STR_GRAPH_MENU_HIGHSCORE                                        :Highscore table
 

	
 
# Industry menu
 
###length 3
 
STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY                            :Industry directory
 
STR_INDUSTRY_MENU_INDUSTRY_CHAIN                                :Industry chains
 
STR_INDUSTRY_MENU_FUND_NEW_INDUSTRY                             :Fund new industry
 

	
 
# URailway construction menu
 
###length 4
 
STR_RAIL_MENU_RAILROAD_CONSTRUCTION                             :Railway construction
 
STR_RAIL_MENU_ELRAIL_CONSTRUCTION                               :Electrified railway construction
 
STR_RAIL_MENU_MONORAIL_CONSTRUCTION                             :Monorail construction
 
STR_RAIL_MENU_MAGLEV_CONSTRUCTION                               :Maglev construction
 

	
 
# Road construction menu
 
###length 2
 
STR_ROAD_MENU_ROAD_CONSTRUCTION                                 :Road construction
 
STR_ROAD_MENU_TRAM_CONSTRUCTION                                 :Tramway construction
 

	
 
# Waterways construction menu
 
###length 1
 
STR_WATERWAYS_MENU_WATERWAYS_CONSTRUCTION                       :Waterways construction
 

	
 
# Aairport construction menu
 
###length 1
 
STR_AIRCRAFT_MENU_AIRPORT_CONSTRUCTION                          :Airport construction
 

	
 
# Landscaping menu
 
###length 3
 
STR_LANDSCAPING_MENU_LANDSCAPING                                :Landscaping
 
STR_LANDSCAPING_MENU_PLANT_TREES                                :Plant trees
 
STR_LANDSCAPING_MENU_PLACE_SIGN                                 :Place sign
 

	
 
# Music menu
 
###length 1
 
STR_TOOLBAR_SOUND_MUSIC                                         :Sound/music
 

	
 
# Message menu
 
###length 3
 
STR_NEWS_MENU_LAST_MESSAGE_NEWS_REPORT                          :Last message/news report
 
STR_NEWS_MENU_MESSAGE_HISTORY_MENU                              :Message history
 
STR_NEWS_MENU_DELETE_ALL_MESSAGES                               :Delete all messages
 

	
 
# About menu
 
###length 12
 
STR_ABOUT_MENU_LAND_BLOCK_INFO                                  :Land area information
 
STR_ABOUT_MENU_HELP                                             :Help & manuals
 
STR_ABOUT_MENU_SEPARATOR                                        :
 
STR_ABOUT_MENU_TOGGLE_CONSOLE                                   :Toggle console
 
STR_ABOUT_MENU_AI_DEBUG                                         :AI/Game script debug
 
STR_ABOUT_MENU_SCREENSHOT                                       :Screenshot
src/toolbar_gui.cpp
Show inline comments
 
@@ -200,14 +200,19 @@ static void PopupMainToolbMenu(Window *w
 
 * Pop up a generic text only menu.
 
 * @param w Toolbar
 
 * @param widget Toolbar button
 
 * @param string String for the first item in the menu
 
 * @param count Number of items in the menu
 
 * @param strings List of strings for each item in the menu
 
 */
 
static void PopupMainToolbMenu(Window *w, int widget, StringID string, int count)
 
static void PopupMainToolbMenu(Window *w, int widget, const std::initializer_list<StringID> &strings)
 
{
 
	DropDownList list;
 
	for (int i = 0; i < count; i++) {
 
		list.push_back(std::make_unique<DropDownListStringItem>(string + i, i, false));
 
	int i = 0;
 
	for (StringID string : strings) {
 
		if (string == STR_NULL) {
 
			list.push_back(std::make_unique<DropDownListItem>(-1, false));
 
		} else {
 
			list.push_back(std::make_unique<DropDownListStringItem>(string, i, false));
 
			i++;
 
		}
 
	}
 
	PopupMainToolbMenu(w, widget, std::move(list), 0);
 
}
 
@@ -389,24 +394,22 @@ static CallBackFunction MenuClickSetting
 
 * SaveLoad entries in scenario editor mode.
 
 */
 
enum SaveLoadEditorMenuEntries {
 
	SLEME_SAVE_SCENARIO   = 0,
 
	SLEME_SAVE_SCENARIO = 0,
 
	SLEME_LOAD_SCENARIO,
 
	SLEME_SAVE_HEIGHTMAP,
 
	SLEME_LOAD_HEIGHTMAP,
 
	SLEME_EXIT_TOINTRO,
 
	SLEME_EXIT_GAME       = 6,
 
	SLEME_MENUCOUNT,
 
	SLEME_EXIT_GAME,
 
};
 

	
 
/**
 
 * SaveLoad entries in normal game mode.
 
 */
 
enum SaveLoadNormalMenuEntries {
 
	SLNME_SAVE_GAME   = 0,
 
	SLNME_SAVE_GAME = 0,
 
	SLNME_LOAD_GAME,
 
	SLNME_EXIT_TOINTRO,
 
	SLNME_EXIT_GAME = 4,
 
	SLNME_MENUCOUNT,
 
	SLNME_EXIT_GAME,
 
};
 

	
 
/**
 
@@ -417,7 +420,8 @@ enum SaveLoadNormalMenuEntries {
 
 */
 
static CallBackFunction ToolbarSaveClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, WID_TN_SAVE, STR_FILE_MENU_SAVE_GAME, SLNME_MENUCOUNT);
 
	PopupMainToolbMenu(w, WID_TN_SAVE, {STR_FILE_MENU_SAVE_GAME, STR_FILE_MENU_LOAD_GAME, STR_FILE_MENU_QUIT_GAME,
 
			STR_NULL, STR_FILE_MENU_EXIT});
 
	return CBF_NONE;
 
}
 

	
 
@@ -429,7 +433,9 @@ static CallBackFunction ToolbarSaveClick
 
 */
 
static CallBackFunction ToolbarScenSaveOrLoad(Window *w)
 
{
 
	PopupMainToolbMenu(w, WID_TE_SAVE, STR_SCENEDIT_FILE_MENU_SAVE_SCENARIO, SLEME_MENUCOUNT);
 
	PopupMainToolbMenu(w, WID_TE_SAVE, {STR_SCENEDIT_FILE_MENU_SAVE_SCENARIO, STR_SCENEDIT_FILE_MENU_LOAD_SCENARIO,
 
			STR_SCENEDIT_FILE_MENU_SAVE_HEIGHTMAP, STR_SCENEDIT_FILE_MENU_LOAD_HEIGHTMAP,
 
			STR_SCENEDIT_FILE_MENU_QUIT_EDITOR, STR_NULL, STR_SCENEDIT_FILE_MENU_QUIT});
 
	return CBF_NONE;
 
}
 

	
 
@@ -518,7 +524,11 @@ static CallBackFunction MenuClickMap(int
 

	
 
static CallBackFunction ToolbarTownClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, WID_TN_TOWNS, STR_TOWN_MENU_TOWN_DIRECTORY, (_settings_game.economy.found_town == TF_FORBIDDEN) ? 1 : 2);
 
	if (_settings_game.economy.found_town == TF_FORBIDDEN) {
 
		PopupMainToolbMenu(w, WID_TN_TOWNS, {STR_TOWN_MENU_TOWN_DIRECTORY});
 
	} else {
 
		PopupMainToolbMenu(w, WID_TN_TOWNS, {STR_TOWN_MENU_TOWN_DIRECTORY, STR_TOWN_MENU_FOUND_TOWN});
 
	}
 
	return CBF_NONE;
 
}
 

	
 
@@ -543,7 +553,7 @@ static CallBackFunction MenuClickTown(in
 

	
 
static CallBackFunction ToolbarSubsidiesClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, WID_TN_SUBSIDIES, STR_SUBSIDIES_MENU_SUBSIDIES, 1);
 
	PopupMainToolbMenu(w, WID_TN_SUBSIDIES, {STR_SUBSIDIES_MENU_SUBSIDIES});
 
	return CBF_NONE;
 
}
 

	
 
@@ -771,7 +781,11 @@ static CallBackFunction MenuClickGraphsO
 
static CallBackFunction ToolbarIndustryClick(Window *w)
 
{
 
	/* Disable build-industry menu if we are a spectator */
 
	PopupMainToolbMenu(w, WID_TN_INDUSTRIES, STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, (_local_company == COMPANY_SPECTATOR) ? 2 : 3);
 
	if (_local_company == COMPANY_SPECTATOR) {
 
		PopupMainToolbMenu(w, WID_TN_INDUSTRIES, {STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, STR_INDUSTRY_MENU_INDUSTRY_CHAIN});
 
	} else {
 
		PopupMainToolbMenu(w, WID_TN_INDUSTRIES, {STR_INDUSTRY_MENU_INDUSTRY_DIRECTORY, STR_INDUSTRY_MENU_INDUSTRY_CHAIN, STR_INDUSTRY_MENU_FUND_NEW_INDUSTRY});
 
	}
 
	return CBF_NONE;
 
}
 

	
 
@@ -1047,7 +1061,7 @@ static CallBackFunction MenuClickForest(
 

	
 
static CallBackFunction ToolbarMusicClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, _game_mode == GM_EDITOR ? (int)WID_TE_MUSIC_SOUND : (int)WID_TN_MUSIC_SOUND, STR_TOOLBAR_SOUND_MUSIC, 1);
 
	PopupMainToolbMenu(w, _game_mode == GM_EDITOR ? (int)WID_TE_MUSIC_SOUND : (int)WID_TN_MUSIC_SOUND, {STR_TOOLBAR_SOUND_MUSIC});
 
	return CBF_NONE;
 
}
 

	
 
@@ -1066,7 +1080,7 @@ static CallBackFunction MenuClickMusicWi
 

	
 
static CallBackFunction ToolbarNewspaperClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, WID_TN_MESSAGES, STR_NEWS_MENU_LAST_MESSAGE_NEWS_REPORT, 3);
 
	PopupMainToolbMenu(w, WID_TN_MESSAGES, {STR_NEWS_MENU_LAST_MESSAGE_NEWS_REPORT, STR_NEWS_MENU_MESSAGE_HISTORY_MENU, STR_NEWS_MENU_DELETE_ALL_MESSAGES});
 
	return CBF_NONE;
 
}
 

	
 
@@ -1101,7 +1115,17 @@ static CallBackFunction PlaceLandBlockIn
 

	
 
static CallBackFunction ToolbarHelpClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, _game_mode == GM_EDITOR ? (int)WID_TE_HELP : (int)WID_TN_HELP, STR_ABOUT_MENU_LAND_BLOCK_INFO, _settings_client.gui.newgrf_developer_tools ? 12 : 8);
 
	if (_settings_client.gui.newgrf_developer_tools) {
 
		PopupMainToolbMenu(w, _game_mode == GM_EDITOR ? (int)WID_TE_HELP : (int)WID_TN_HELP, {STR_ABOUT_MENU_LAND_BLOCK_INFO,
 
				STR_ABOUT_MENU_HELP, STR_NULL, STR_ABOUT_MENU_TOGGLE_CONSOLE, STR_ABOUT_MENU_AI_DEBUG,
 
				STR_ABOUT_MENU_SCREENSHOT, STR_ABOUT_MENU_SHOW_FRAMERATE, STR_ABOUT_MENU_ABOUT_OPENTTD,
 
				STR_ABOUT_MENU_SPRITE_ALIGNER, STR_ABOUT_MENU_TOGGLE_BOUNDING_BOXES, STR_ABOUT_MENU_TOGGLE_DIRTY_BLOCKS,
 
				STR_ABOUT_MENU_TOGGLE_WIDGET_OUTLINES});
 
	} else {
 
		PopupMainToolbMenu(w, _game_mode == GM_EDITOR ? (int)WID_TE_HELP : (int)WID_TN_HELP, {STR_ABOUT_MENU_LAND_BLOCK_INFO,
 
				STR_ABOUT_MENU_HELP, STR_NULL, STR_ABOUT_MENU_TOGGLE_CONSOLE, STR_ABOUT_MENU_AI_DEBUG,
 
				STR_ABOUT_MENU_SCREENSHOT, STR_ABOUT_MENU_SHOW_FRAMERATE, STR_ABOUT_MENU_ABOUT_OPENTTD});
 
	}
 
	return CBF_NONE;
 
}
 

	
 
@@ -1176,15 +1200,15 @@ static CallBackFunction MenuClickHelp(in
 
	switch (index) {
 
		case  0: return PlaceLandBlockInfo();
 
		case  1: ShowHelpWindow();                 break;
 
		case  3: IConsoleSwitch();                 break;
 
		case  4: ShowScriptDebugWindow();          break;
 
		case  5: ShowScreenshotWindow();           break;
 
		case  6: ShowFramerateWindow();            break;
 
		case  7: ShowAboutWindow();                break;
 
		case  8: ShowSpriteAlignerWindow();        break;
 
		case  9: ToggleBoundingBoxes();            break;
 
		case 10: ToggleDirtyBlocks();              break;
 
		case 11: ToggleWidgetOutlines();           break;
 
		case  2: IConsoleSwitch();                 break;
 
		case  3: ShowScriptDebugWindow();          break;
 
		case  4: ShowScreenshotWindow();           break;
 
		case  5: ShowFramerateWindow();            break;
 
		case  6: ShowAboutWindow();                break;
 
		case  7: ShowSpriteAlignerWindow();        break;
 
		case  8: ToggleBoundingBoxes();            break;
 
		case  9: ToggleDirtyBlocks();              break;
 
		case 10: ToggleWidgetOutlines();           break;
 
	}
 
	return CBF_NONE;
 
}
0 comments (0 inline, 0 general)