src/player_gui.cpp
changeset 8835 4a8e24bfde22
parent 8805 7269d54ce5dc
child 8839 bd8a5bb77cd7
equal deleted inserted replaced
8834:ef15cacd6894 8835:4a8e24bfde22
   117 
   117 
   118 	SetDParam(0, p->player_money - p->current_loan);
   118 	SetDParam(0, p->player_money - p->current_loan);
   119 	DrawStringRightAligned(182, y, STR_7028, TC_FROMSTRING);
   119 	DrawStringRightAligned(182, y, STR_7028, TC_FROMSTRING);
   120 }
   120 }
   121 
   121 
       
   122 enum PlayerFinancesWindowWidgets {
       
   123 	PFW_WIDGET_TOGGLE_SIZE   = 2,
       
   124 	PFW_WIDGET_INCREASE_LOAN = 6,
       
   125 	PFW_WIDGET_REPAY_LOAN    = 7,
       
   126 };
       
   127 
   122 static const Widget _player_finances_widgets[] = {
   128 static const Widget _player_finances_widgets[] = {
   123 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,               STR_018B_CLOSE_WINDOW},
   129 {   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,               STR_018B_CLOSE_WINDOW},
   124 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   379,     0,    13, STR_700E_FINANCES,      STR_018C_WINDOW_TITLE_DRAG_THIS},
   130 {    WWT_CAPTION,   RESIZE_NONE,    14,    11,   379,     0,    13, STR_700E_FINANCES,      STR_018C_WINDOW_TITLE_DRAG_THIS},
   125 {     WWT_IMGBTN,   RESIZE_NONE,    14,   380,   394,     0,    13, SPR_LARGE_SMALL_WINDOW, STR_7075_TOGGLE_LARGE_SMALL_WINDOW},
   131 {     WWT_IMGBTN,   RESIZE_NONE,    14,   380,   394,     0,    13, SPR_LARGE_SMALL_WINDOW, STR_7075_TOGGLE_LARGE_SMALL_WINDOW},
   126 {  WWT_STICKYBOX,   RESIZE_NONE,    14,   395,   406,     0,    13, 0x0,                    STR_STICKY_BUTTON},
   132 {  WWT_STICKYBOX,   RESIZE_NONE,    14,   395,   406,     0,    13, 0x0,                    STR_STICKY_BUTTON},
   157 			/* Make window dirty before and after resizing */
   163 			/* Make window dirty before and after resizing */
   158 			SetWindowDirty(w);
   164 			SetWindowDirty(w);
   159 			w->height = new_height;
   165 			w->height = new_height;
   160 			SetWindowDirty(w);
   166 			SetWindowDirty(w);
   161 
   167 
   162 			w->SetWidgetHiddenState(6, player != _local_player);
   168 			w->SetWidgetHiddenState(PFW_WIDGET_INCREASE_LOAN, player != _local_player);
   163 			w->SetWidgetHiddenState(7, player != _local_player);
   169 			w->SetWidgetHiddenState(PFW_WIDGET_REPAY_LOAN,    player != _local_player);
   164 		}
   170 		}
   165 
   171 
   166 		/* Borrow button only shows when there is any more money to loan */
   172 		/* Borrow button only shows when there is any more money to loan */
   167 		w->SetWidgetDisabledState(6, p->current_loan == _economy.max_loan);
   173 		w->SetWidgetDisabledState(PFW_WIDGET_INCREASE_LOAN, p->current_loan == _economy.max_loan);
   168 
   174 
   169 		/* Repay button only shows when there is any more money to repay */
   175 		/* Repay button only shows when there is any more money to repay */
   170 		w->SetWidgetDisabledState(7, player != _local_player || p->current_loan == 0);
   176 		w->SetWidgetDisabledState(PFW_WIDGET_REPAY_LOAN, player != _local_player || p->current_loan == 0);
   171 
   177 
   172 		SetDParam(0, p->index);
   178 		SetDParam(0, p->index);
   173 		SetDParam(1, p->index);
   179 		SetDParam(1, p->index);
   174 		SetDParam(2, LOAN_INTERVAL);
   180 		SetDParam(2, LOAN_INTERVAL);
   175 		DrawWindowWidgets(w);
   181 		DrawWindowWidgets(w);
   177 		DrawPlayerEconomyStats(p, (byte)WP(w, def_d).data_1);
   183 		DrawPlayerEconomyStats(p, (byte)WP(w, def_d).data_1);
   178 	} break;
   184 	} break;
   179 
   185 
   180 	case WE_CLICK:
   186 	case WE_CLICK:
   181 		switch (e->we.click.widget) {
   187 		switch (e->we.click.widget) {
   182 		case 2: {/* toggle size */
   188 		case PFW_WIDGET_TOGGLE_SIZE: {/* toggle size */
   183 			byte mode = (byte)WP(w, def_d).data_1;
   189 			byte mode = (byte)WP(w, def_d).data_1;
   184 			bool stickied = !!(w->flags4 & WF_STICKY);
   190 			bool stickied = !!(w->flags4 & WF_STICKY);
   185 			PlayerID player = (PlayerID)w->window_number;
   191 			PlayerID player = (PlayerID)w->window_number;
   186 			DeleteWindow(w);
   192 			DeleteWindow(w);
   187 			DoShowPlayerFinances(player, !HasBit(mode, 0), stickied);
   193 			DoShowPlayerFinances(player, !HasBit(mode, 0), stickied);
   188 		} break;
   194 		} break;
   189 
   195 
   190 		case 6: /* increase loan */
   196 		case PFW_WIDGET_INCREASE_LOAN: /* increase loan */
   191 			DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_INCREASE_LOAN | CMD_MSG(STR_702C_CAN_T_BORROW_ANY_MORE_MONEY));
   197 			DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_INCREASE_LOAN | CMD_MSG(STR_702C_CAN_T_BORROW_ANY_MORE_MONEY));
   192 			break;
   198 			break;
   193 
   199 
   194 		case 7: /* repay loan */
   200 		case PFW_WIDGET_REPAY_LOAN: /* repay loan */
   195 			DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_DECREASE_LOAN | CMD_MSG(STR_702F_CAN_T_REPAY_LOAN));
   201 			DoCommandP(0, 0, _ctrl_pressed, NULL, CMD_DECREASE_LOAN | CMD_MSG(STR_702F_CAN_T_REPAY_LOAN));
   196 			break;
   202 			break;
   197 		}
   203 		}
   198 		break;
   204 		break;
   199 	}
   205 	}
   276 	uint32 sel;
   282 	uint32 sel;
   277 	LiveryClass livery_class;
   283 	LiveryClass livery_class;
   278 };
   284 };
   279 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(livery_d));
   285 assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(livery_d));
   280 
   286 
       
   287 
       
   288 enum PlayerLiveryWindowWidgets {
       
   289 	PLW_WIDGET_CLASS_GENERAL = 2,
       
   290 	PLW_WIDGET_CLASS_RAIL,
       
   291 	PLW_WIDGET_CLASS_ROAD,
       
   292 	PLW_WIDGET_CLASS_SHIP,
       
   293 	PLW_WIDGET_CLASS_AIRCRAFT,
       
   294 
       
   295 	PLW_WIDGET_PRI_COL_TEXT = 9,
       
   296 	PLW_WIDGET_PRI_COL_DROPDOWN,
       
   297 	PLW_WIDGET_SEC_COL_TEXT,
       
   298 	PLW_WIDGET_SEC_COL_DROPDOWN,
       
   299 	PLW_WIDGET_MATRIX,
       
   300 };
       
   301 
   281 static void ShowColourDropDownMenu(Window *w, uint32 widget)
   302 static void ShowColourDropDownMenu(Window *w, uint32 widget)
   282 {
   303 {
   283 	uint32 used_colours = 0;
   304 	uint32 used_colours = 0;
   284 	const Livery *livery;
   305 	const Livery *livery;
   285 	LiveryScheme scheme;
   306 	LiveryScheme scheme;
   286 
   307 
   287 	/* Disallow other player colours for the primary colour */
   308 	/* Disallow other player colours for the primary colour */
   288 	if (HasBit(WP(w, livery_d).sel, LS_DEFAULT) && widget == 10) {
   309 	if (HasBit(WP(w, livery_d).sel, LS_DEFAULT) && widget == PLW_WIDGET_PRI_COL_DROPDOWN) {
   289 		const Player *p;
   310 		const Player *p;
   290 		FOR_ALL_PLAYERS(p) {
   311 		FOR_ALL_PLAYERS(p) {
   291 			if (p->is_active && p->index != _local_player) SetBit(used_colours, p->player_color);
   312 			if (p->is_active && p->index != _local_player) SetBit(used_colours, p->player_color);
   292 		}
   313 		}
   293 	}
   314 	}
   297 		if (HasBit(WP(w, livery_d).sel, scheme)) break;
   318 		if (HasBit(WP(w, livery_d).sel, scheme)) break;
   298 	}
   319 	}
   299 	if (scheme == LS_END) scheme = LS_DEFAULT;
   320 	if (scheme == LS_END) scheme = LS_DEFAULT;
   300 	livery = &GetPlayer((PlayerID)w->window_number)->livery[scheme];
   321 	livery = &GetPlayer((PlayerID)w->window_number)->livery[scheme];
   301 
   322 
   302 	ShowDropDownMenu(w, _colour_dropdown, widget == 10 ? livery->colour1 : livery->colour2, widget, used_colours, 0);
   323 	ShowDropDownMenu(w, _colour_dropdown, widget == PLW_WIDGET_PRI_COL_DROPDOWN ? livery->colour1 : livery->colour2, widget, used_colours, 0);
   303 }
   324 }
   304 
   325 
   305 static void SelectPlayerLiveryWndProc(Window *w, WindowEvent *e)
   326 static void SelectPlayerLiveryWndProc(Window *w, WindowEvent *e)
   306 {
   327 {
   307 	switch (e->event) {
   328 	switch (e->event) {
   308 		case WE_CREATE:
   329 		case WE_CREATE:
   309 			w->LowerWidget(WP(w, livery_d).livery_class + 2);
   330 			w->LowerWidget(WP(w, livery_d).livery_class + PLW_WIDGET_CLASS_GENERAL);
   310 			if (!_loaded_newgrf_features.has_2CC) {
   331 			if (!_loaded_newgrf_features.has_2CC) {
   311 				w->HideWidget(11);
   332 				w->HideWidget(PLW_WIDGET_SEC_COL_TEXT);
   312 				w->HideWidget(12);
   333 				w->HideWidget(PLW_WIDGET_SEC_COL_DROPDOWN);
   313 			}
   334 			}
   314 			break;
   335 			break;
   315 
   336 
   316 		case WE_PAINT: {
   337 		case WE_PAINT: {
   317 			const Player *p = GetPlayer((PlayerID)w->window_number);
   338 			const Player *p = GetPlayer((PlayerID)w->window_number);
   318 			LiveryScheme scheme = LS_DEFAULT;
   339 			LiveryScheme scheme = LS_DEFAULT;
   319 			int y = 51;
   340 			int y = 51;
   320 
   341 
   321 			/* Disable dropdown controls if no scheme is selected */
   342 			/* Disable dropdown controls if no scheme is selected */
   322 			w->SetWidgetDisabledState( 9, (WP(w, livery_d).sel == 0));
   343 			w->SetWidgetDisabledState(PLW_WIDGET_PRI_COL_TEXT,     (WP(w, livery_d).sel == 0));
   323 			w->SetWidgetDisabledState(10, (WP(w, livery_d).sel == 0));
   344 			w->SetWidgetDisabledState(PLW_WIDGET_PRI_COL_DROPDOWN, (WP(w, livery_d).sel == 0));
   324 			w->SetWidgetDisabledState(11, (WP(w, livery_d).sel == 0));
   345 			w->SetWidgetDisabledState(PLW_WIDGET_SEC_COL_TEXT,     (WP(w, livery_d).sel == 0));
   325 			w->SetWidgetDisabledState(12, (WP(w, livery_d).sel == 0));
   346 			w->SetWidgetDisabledState(PLW_WIDGET_SEC_COL_DROPDOWN, (WP(w, livery_d).sel == 0));
   326 
   347 
   327 			if (!(WP(w, livery_d).sel == 0)) {
   348 			if (!(WP(w, livery_d).sel == 0)) {
   328 				for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
   349 				for (scheme = LS_BEGIN; scheme < LS_END; scheme++) {
   329 					if (HasBit(WP(w, livery_d).sel, scheme)) break;
   350 					if (HasBit(WP(w, livery_d).sel, scheme)) break;
   330 				}
   351 				}
   361 		}
   382 		}
   362 
   383 
   363 		case WE_CLICK: {
   384 		case WE_CLICK: {
   364 			switch (e->we.click.widget) {
   385 			switch (e->we.click.widget) {
   365 				/* Livery Class buttons */
   386 				/* Livery Class buttons */
   366 				case 2:
   387 				case PLW_WIDGET_CLASS_GENERAL:
   367 				case 3:
   388 				case PLW_WIDGET_CLASS_RAIL:
   368 				case 4:
   389 				case PLW_WIDGET_CLASS_ROAD:
   369 				case 5:
   390 				case PLW_WIDGET_CLASS_SHIP:
   370 				case 6: {
   391 				case PLW_WIDGET_CLASS_AIRCRAFT: {
   371 					LiveryScheme scheme;
   392 					LiveryScheme scheme;
   372 
   393 
   373 					w->RaiseWidget(WP(w, livery_d).livery_class + 2);
   394 					w->RaiseWidget(WP(w, livery_d).livery_class + PLW_WIDGET_CLASS_GENERAL);
   374 					WP(w, livery_d).livery_class = (LiveryClass)(e->we.click.widget - 2);
   395 					WP(w, livery_d).livery_class = (LiveryClass)(e->we.click.widget - PLW_WIDGET_CLASS_GENERAL);
   375 					WP(w, livery_d).sel = 0;
   396 					WP(w, livery_d).sel = 0;
   376 					w->LowerWidget(WP(w, livery_d).livery_class + 2);
   397 					w->LowerWidget(WP(w, livery_d).livery_class + PLW_WIDGET_CLASS_GENERAL);
   377 
   398 
   378 					/* Select the first item in the list */
   399 					/* Select the first item in the list */
   379 					for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
   400 					for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
   380 						if (livery_class[scheme] == WP(w, livery_d).livery_class) {
   401 						if (livery_class[scheme] == WP(w, livery_d).livery_class) {
   381 							WP(w, livery_d).sel = 1 << scheme;
   402 							WP(w, livery_d).sel = 1 << scheme;
   382 							break;
   403 							break;
   383 						}
   404 						}
   384 					}
   405 					}
   385 					w->height = 49 + livery_height[WP(w, livery_d).livery_class] * 14;
   406 					w->height = 49 + livery_height[WP(w, livery_d).livery_class] * 14;
   386 					w->widget[13].bottom = w->height - 1;
   407 					w->widget[PLW_WIDGET_MATRIX].bottom = w->height - 1;
   387 					w->widget[13].data = livery_height[WP(w, livery_d).livery_class] << 8 | 1;
   408 					w->widget[PLW_WIDGET_MATRIX].data = livery_height[WP(w, livery_d).livery_class] << 8 | 1;
   388 					MarkWholeScreenDirty();
   409 					MarkWholeScreenDirty();
   389 					break;
   410 					break;
   390 				}
   411 				}
   391 
   412 
   392 				case 9:
   413 				case PLW_WIDGET_PRI_COL_TEXT:
   393 				case 10: /* First colour dropdown */
   414 				case PLW_WIDGET_PRI_COL_DROPDOWN: /* First colour dropdown */
   394 					ShowColourDropDownMenu(w, 10);
   415 					ShowColourDropDownMenu(w, PLW_WIDGET_PRI_COL_DROPDOWN);
   395 					break;
   416 					break;
   396 
   417 
   397 				case 11:
   418 				case PLW_WIDGET_SEC_COL_TEXT:
   398 				case 12: /* Second colour dropdown */
   419 				case PLW_WIDGET_SEC_COL_DROPDOWN: /* Second colour dropdown */
   399 					ShowColourDropDownMenu(w, 12);
   420 					ShowColourDropDownMenu(w, PLW_WIDGET_SEC_COL_DROPDOWN);
   400 					break;
   421 					break;
   401 
   422 
   402 				case 13: {
   423 				case PLW_WIDGET_MATRIX: {
   403 					LiveryScheme scheme;
   424 					LiveryScheme scheme;
   404 					LiveryScheme j = (LiveryScheme)((e->we.click.pt.y - 48) / 14);
   425 					LiveryScheme j = (LiveryScheme)((e->we.click.pt.y - 48) / 14);
   405 
   426 
   406 					for (scheme = LS_BEGIN; scheme <= j; scheme++) {
   427 					for (scheme = LS_BEGIN; scheme <= j; scheme++) {
   407 						if (livery_class[scheme] != WP(w, livery_d).livery_class) j++;
   428 						if (livery_class[scheme] != WP(w, livery_d).livery_class) j++;
   429 		case WE_DROPDOWN_SELECT: {
   450 		case WE_DROPDOWN_SELECT: {
   430 			LiveryScheme scheme;
   451 			LiveryScheme scheme;
   431 
   452 
   432 			for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
   453 			for (scheme = LS_DEFAULT; scheme < LS_END; scheme++) {
   433 				if (HasBit(WP(w, livery_d).sel, scheme)) {
   454 				if (HasBit(WP(w, livery_d).sel, scheme)) {
   434 					DoCommandP(0, scheme | (e->we.dropdown.button == 10 ? 0 : 256), e->we.dropdown.index, NULL, CMD_SET_PLAYER_COLOR);
   455 					DoCommandP(0, scheme | (e->we.dropdown.button == PLW_WIDGET_PRI_COL_DROPDOWN ? 0 : 256), e->we.dropdown.index, NULL, CMD_SET_PLAYER_COLOR);
   435 				}
   456 				}
   436 			}
   457 			}
   437 			break;
   458 			break;
   438 		}
   459 		}
   439 	}
   460 	}