Changeset - r2216:ed8d0dd67dce
[Not reviewed]
master
0 3 0
celestar - 19 years ago 2005-07-28 08:49:29
celestar@openttd.org
(svn r2734) -Feature: The Main Toolbar Dropdown Menu can now display disabled items
3 files changed with 27 insertions and 21 deletions:
0 comments (0 inline, 0 general)
main_gui.c
Show inline comments
 
@@ -483,12 +483,13 @@ static void MenuWndProc(Window *w, Windo
 
		int count,sel;
 
		int x,y;
 
		uint16 chk;
 
		StringID string;
 
		int eo;
 
		int inc;
 
		byte color;
 

	
 
		DrawWindowWidgets(w);
 

	
 
		count = WP(w,menu_d).item_count;
 
		sel = WP(w,menu_d).sel_index;
 
		chk = WP(w,menu_d).checked_items;
 
@@ -500,13 +501,15 @@ static void MenuWndProc(Window *w, Windo
 
		eo = 157;
 

	
 
		inc = (chk != 0) ? 2 : 1;
 

	
 
		do {
 
			if (sel== 0) GfxFillRect(x, y, x + eo, y+9, 0);
 
			DrawString(x + 2, y, string + (chk & 1), sel == 0 ? 0xC : 0x10);
 
			color = sel == 0 ? 0xC : 0x10;
 
			if (HASBIT(WP(w,menu_d).disabled_items, (string - WP(w, menu_d).string_id))) color = 0xE;
 
			DrawString(x + 2, y, string + (chk & 1), color);
 
			y += 10;
 
			string += inc;
 
			chk >>= 1;
 
		} while (--sel,--count);
 
	} break;
 

	
 
@@ -708,13 +711,13 @@ static void PlayerMenuWndProc(Window *w,
 
		SetWindowDirty(w);
 
		return;
 
		}
 
	}
 
}
 

	
 
static Window *PopupMainToolbMenu(Window *w, int x, int main_button, StringID base_string, int item_count)
 
static Window *PopupMainToolbMenu(Window *w, int x, int main_button, StringID base_string, int item_count, byte disabled_mask)
 
{
 
	x += w->left;
 

	
 
	SETBIT(w->click_state, (byte)main_button);
 
	InvalidateWidget(w, (byte)main_button);
 

	
 
@@ -727,12 +730,13 @@ static Window *PopupMainToolbMenu(Window
 
	WP(w,menu_d).item_count = item_count;
 
	WP(w,menu_d).sel_index = 0;
 
	WP(w,menu_d).main_button = main_button;
 
	WP(w,menu_d).action_id = (main_button >> 8) ? (main_button >> 8) : main_button;
 
	WP(w,menu_d).string_id = base_string;
 
	WP(w,menu_d).checked_items = 0;
 
	WP(w,menu_d).disabled_items = disabled_mask;
 

	
 
	_popup_menu_active = true;
 

	
 
	SndPlayFx(SND_15_BEEP);
 

	
 
	return w;
 
@@ -757,35 +761,36 @@ static Window *PopupMainPlayerToolbMenu(
 
			/* Select client list by default for spectators */
 
			WP(w,menu_d).sel_index = 0;
 
	}
 
	WP(w,menu_d).action_id = main_button;
 
	WP(w,menu_d).main_button = main_button;
 
	WP(w,menu_d).checked_items = gray;
 
	WP(w,menu_d).disabled_items = 0;
 
	_popup_menu_active = true;
 
	SndPlayFx(SND_15_BEEP);
 
	return w;
 
}
 

	
 
static void ToolbarSaveClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, 66, 3, STR_015C_SAVE_GAME, 4);
 
	PopupMainToolbMenu(w, 66, 3, STR_015C_SAVE_GAME, 4, 0);
 
}
 

	
 
static void ToolbarMapClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, 96, 4, STR_02DE_MAP_OF_WORLD, 3);
 
	PopupMainToolbMenu(w, 96, 4, STR_02DE_MAP_OF_WORLD, 3, 0);
 
}
 

	
 
static void ToolbarTownClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, 118, 5, STR_02BB_TOWN_DIRECTORY, 1);
 
	PopupMainToolbMenu(w, 118, 5, STR_02BB_TOWN_DIRECTORY, 1, 0);
 
}
 

	
 
static void ToolbarSubsidiesClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, 140, 6, STR_02DD_SUBSIDIES, 1);
 
	PopupMainToolbMenu(w, 140, 6, STR_02DD_SUBSIDIES, 1, 0);
 
}
 

	
 
static void ToolbarStationsClick(Window *w)
 
{
 
	PopupMainPlayerToolbMenu(w, 162, 7, 0);
 
}
 
@@ -799,23 +804,23 @@ static void ToolbarPlayersClick(Window *
 
{
 
	PopupMainPlayerToolbMenu(w, 213, 9, 0);
 
}
 

	
 
static void ToolbarGraphsClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, 236, 10, STR_0154_OPERATING_PROFIT_GRAPH, 6);
 
	PopupMainToolbMenu(w, 236, 10, STR_0154_OPERATING_PROFIT_GRAPH, 6, 0);
 
}
 

	
 
static void ToolbarLeagueClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, 258, 11, STR_015A_COMPANY_LEAGUE_TABLE, 2);
 
	PopupMainToolbMenu(w, 258, 11, STR_015A_COMPANY_LEAGUE_TABLE, 2, 0);
 
}
 

	
 
static void ToolbarIndustryClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, 280, 12, STR_INDUSTRY_DIR, 2);
 
	PopupMainToolbMenu(w, 280, 12, STR_INDUSTRY_DIR, 2, 0);
 
}
 

	
 
static void ToolbarTrainClick(Window *w)
 
{
 
	Vehicle *v;
 
	int dis = -1;
 
@@ -938,56 +943,56 @@ static void ToolbarZoomOutClick(Window *
 
}
 

	
 
static void ToolbarBuildRailClick(Window *w)
 
{
 
	Player *p = GetPlayer(_local_player);
 
	Window *w2;
 
	w2 = PopupMainToolbMenu(w, 457, 19, STR_1015_RAILROAD_CONSTRUCTION, GetNumRailtypes(p));
 
	w2 = PopupMainToolbMenu(w, 457, 19, STR_1015_RAILROAD_CONSTRUCTION, RAILTYPE_END, ~p->avail_railtypes);
 
	WP(w2,menu_d).sel_index = _last_built_railtype;
 
}
 

	
 
static void ToolbarBuildRoadClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, 479, 20, STR_180A_ROAD_CONSTRUCTION, 1);
 
	PopupMainToolbMenu(w, 479, 20, STR_180A_ROAD_CONSTRUCTION, 1, 0);
 
}
 

	
 
static void ToolbarBuildWaterClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, 501, 21, STR_9800_DOCK_CONSTRUCTION, 1);
 
	PopupMainToolbMenu(w, 501, 21, STR_9800_DOCK_CONSTRUCTION, 1, 0);
 
}
 

	
 
static void ToolbarBuildAirClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, 0x1E0, 22, STR_A01D_AIRPORT_CONSTRUCTION, 1);
 
	PopupMainToolbMenu(w, 0x1E0, 22, STR_A01D_AIRPORT_CONSTRUCTION, 1, 0);
 
}
 

	
 
static void ToolbarForestClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, 0x1E0, 23, STR_LANDSCAPING, 3);
 
	PopupMainToolbMenu(w, 0x1E0, 23, STR_LANDSCAPING, 3, 0);
 
}
 

	
 
static void ToolbarMusicClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, 0x1E0, 24, STR_01D3_SOUND_MUSIC, 1);
 
	PopupMainToolbMenu(w, 0x1E0, 24, STR_01D3_SOUND_MUSIC, 1, 0);
 
}
 

	
 
static void ToolbarNewspaperClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, 0x1E0, 25, STR_0200_LAST_MESSAGE_NEWS_REPORT, 3);
 
	PopupMainToolbMenu(w, 0x1E0, 25, STR_0200_LAST_MESSAGE_NEWS_REPORT, 3, 0);
 
}
 

	
 
static void ToolbarHelpClick(Window *w)
 
{
 
	PopupMainToolbMenu(w, 0x1E0, 26, STR_02D5_LAND_BLOCK_INFO, 5);
 
	PopupMainToolbMenu(w, 0x1E0, 26, STR_02D5_LAND_BLOCK_INFO, 5, 0);
 
}
 

	
 
static void ToolbarOptionsClick(Window *w)
 
{
 
	uint16 x;
 

	
 
	w = PopupMainToolbMenu(w,  43, 2, STR_02C3_GAME_OPTIONS, 13);
 
	w = PopupMainToolbMenu(w,  43, 2, STR_02C3_GAME_OPTIONS, 13, 0);
 

	
 
	x = (uint16)-1;
 
	if (_display_opt & DO_SHOW_TOWN_NAMES) x &= ~(1<<5);
 
	if (_display_opt & DO_SHOW_STATION_NAMES) x &= ~(1<<6);
 
	if (_display_opt & DO_SHOW_SIGNS) x &= ~(1<<7);
 
	if (_display_opt & DO_WAYPOINTS) x &= ~(1<<8);
 
@@ -998,13 +1003,13 @@ static void ToolbarOptionsClick(Window *
 
	WP(w,menu_d).checked_items = x;
 
}
 

	
 

	
 
static void ToolbarScenSaveOrLoad(Window *w)
 
{
 
	PopupMainToolbMenu(w, 0x2C, 3, STR_0292_SAVE_SCENARIO, 5);
 
	PopupMainToolbMenu(w, 0x2C, 3, STR_0292_SAVE_SCENARIO, 5, 0);
 
}
 

	
 
static void ToolbarScenDateBackward(Window *w)
 
{
 
	// don't allow too fast scrolling
 
	if ((w->flags4 & WF_TIMEOUT_MASK) <= 2 << WF_TIMEOUT_SHL) {
 
@@ -1029,13 +1034,13 @@ static void ToolbarScenDateForward(Windo
 
	}
 
	_left_button_clicked = false;
 
}
 

	
 
static void ToolbarScenMapTownDir(Window *w)
 
{
 
	PopupMainToolbMenu(w, 0x16A, 8 | (17<<8), STR_02DE_MAP_OF_WORLD, 4);
 
	PopupMainToolbMenu(w, 0x16A, 8 | (17<<8), STR_02DE_MAP_OF_WORLD, 4, 0);
 
}
 

	
 
static void ToolbarScenZoomIn(Window *w)
 
{
 
	if (DoZoomInOutWindow(ZOOM_IN, FindWindowById(WC_MAIN_WINDOW, 0))) {
 
		HandleButtonClick(w, 9);
window.c
Show inline comments
 
@@ -1531,13 +1531,13 @@ void UpdateWindows(void)
 

	
 
int GetMenuItemIndex(Window *w, int x, int y)
 
{
 
	if ((x -= w->left) >= 0 && x < w->width && (y -= w->top + 1) >= 0) {
 
		y /= 10;
 

	
 
		if (y < WP(w,menu_d).item_count)
 
		if (y < WP(w,menu_d).item_count && !HASBIT(WP(w,menu_d).disabled_items, y))
 
			return y;
 
	}
 
	return -1;
 
}
 

	
 
void InvalidateWindow(byte cls, WindowNumber number)
window.h
Show inline comments
 
@@ -313,12 +313,13 @@ typedef struct {
 
	byte item_count; /* follow_vehicle */
 
	byte sel_index;		/* scrollpos_x */
 
	byte main_button; /* scrollpos_y */
 
	byte action_id;
 
	StringID string_id; /* unk30 */
 
	uint16 checked_items; /* unk32 */
 
	byte disabled_items;
 
} menu_d;
 
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(menu_d));
 

	
 
typedef struct {
 
	int16 data_1, data_2, data_3;
 
	int16 data_4, data_5;
0 comments (0 inline, 0 general)