src/town_gui.cpp
branchNewGRF_ports
changeset 6878 7d1ff2f621c7
parent 6872 1c4a4a609f85
child 10184 fcf5fb2548eb
equal deleted inserted replaced
6877:889301acc299 6878:7d1ff2f621c7
   223 	} break;
   223 	} break;
   224 
   224 
   225 	case WE_DOUBLE_CLICK:
   225 	case WE_DOUBLE_CLICK:
   226 	case WE_CLICK:
   226 	case WE_CLICK:
   227 		switch (e->we.click.widget) {
   227 		switch (e->we.click.widget) {
   228 		case TWA_COMMAND_LIST: {
   228 			case TWA_COMMAND_LIST: {
   229 			const Town *t = GetTown(w->window_number);
   229 				const Town *t = GetTown(w->window_number);
   230 			int y = (e->we.click.pt.y - 0x6B) / 10;
   230 				int y = (e->we.click.pt.y - 0x6B) / 10;
   231 
   231 
   232 			if (!IsInsideMM(y, 0, 5)) return;
   232 				if (!IsInsideMM(y, 0, 5)) return;
   233 
   233 
   234 			y = GetNthSetBit(GetMaskOfTownActions(NULL, _local_player, t), y + w->vscroll.pos - 1);
   234 				y = GetNthSetBit(GetMaskOfTownActions(NULL, _local_player, t), y + w->vscroll.pos - 1);
   235 			if (y >= 0) {
   235 				if (y >= 0) {
   236 				WP(w, def_d).data_1 = y;
   236 					WP(w, def_d).data_1 = y;
   237 				SetWindowDirty(w);
   237 					SetWindowDirty(w);
   238 			}
   238 				}
   239 			/* Fall through to clicking in case we are double-clicked */
   239 				/* Fall through to clicking in case we are double-clicked */
   240 			if (e->event != WE_DOUBLE_CLICK || y < 0) break;
   240 				if (e->event != WE_DOUBLE_CLICK || y < 0) break;
   241 		}
   241 			}
   242 
   242 
   243 		case TWA_EXECUTE: {
   243 			case TWA_EXECUTE:
   244 			DoCommandP(GetTown(w->window_number)->xy, w->window_number, WP(w, def_d).data_1, NULL, CMD_DO_TOWN_ACTION | CMD_MSG(STR_00B4_CAN_T_DO_THIS));
   244 				DoCommandP(GetTown(w->window_number)->xy, w->window_number, WP(w, def_d).data_1, NULL, CMD_DO_TOWN_ACTION | CMD_MSG(STR_00B4_CAN_T_DO_THIS));
   245 			break;
   245 				break;
   246 		}
       
   247 		}
   246 		}
   248 		break;
   247 		break;
   249 
   248 
   250 	case WE_4:
   249 	case WE_4:
   251 		SetWindowDirty(w);
   250 		SetWindowDirty(w);
   318 				break;
   317 				break;
   319 
   318 
   320 			case 10: /* delete town */
   319 			case 10: /* delete town */
   321 				delete t;
   320 				delete t;
   322 				break;
   321 				break;
   323 		}
   322 		} break;
   324 		break;
       
   325 
   323 
   326 	case WE_ON_EDIT_TEXT:
   324 	case WE_ON_EDIT_TEXT:
   327 		if (e->we.edittext.str[0] != '\0') {
   325 		if (e->we.edittext.str[0] != '\0') {
   328 			_cmd_text = e->we.edittext.str;
   326 			_cmd_text = e->we.edittext.str;
   329 			DoCommandP(0, w->window_number, 0, NULL,
   327 			DoCommandP(0, w->window_number, 0, NULL,
   392 		w->flags4 |= WF_DISABLE_VP_SCROLL;
   390 		w->flags4 |= WF_DISABLE_VP_SCROLL;
   393 		AssignWindowViewport(w, 3, 17, 0xFE, 0x56, GetTown(town)->xy, ZOOM_LVL_TOWN);
   391 		AssignWindowViewport(w, 3, 17, 0xFE, 0x56, GetTown(town)->xy, ZOOM_LVL_TOWN);
   394 	}
   392 	}
   395 }
   393 }
   396 
   394 
       
   395 enum TownDirectoryWidget {
       
   396 	TDW_SORTNAME = 3,
       
   397 	TDW_SORTPOPULATION,
       
   398 	TDW_CENTERTOWN,
       
   399 };
   397 static const Widget _town_directory_widgets[] = {
   400 static const Widget _town_directory_widgets[] = {
   398 {   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,               STR_018B_CLOSE_WINDOW},
   401 {   WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,               STR_018B_CLOSE_WINDOW},
   399 {    WWT_CAPTION,   RESIZE_NONE,    13,    11,   195,     0,    13, STR_2000_TOWNS,         STR_018C_WINDOW_TITLE_DRAG_THIS},
   402 {    WWT_CAPTION,   RESIZE_NONE,    13,    11,   195,     0,    13, STR_2000_TOWNS,         STR_018C_WINDOW_TITLE_DRAG_THIS},
   400 {  WWT_STICKYBOX,   RESIZE_NONE,    13,   196,   207,     0,    13, 0x0,                    STR_STICKY_BUTTON},
   403 {  WWT_STICKYBOX,   RESIZE_NONE,    13,   196,   207,     0,    13, 0x0,                    STR_STICKY_BUTTON},
   401 { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,     0,    98,    14,    25, STR_SORT_BY_NAME,       STR_SORT_ORDER_TIP},
   404 { WWT_PUSHTXTBTN,   RESIZE_NONE,    13,     0,    98,    14,    25, STR_SORT_BY_NAME,       STR_SORT_ORDER_TIP},
   476 		}
   479 		}
   477 
   480 
   478 		SetVScrollCount(w, _num_town_sort);
   481 		SetVScrollCount(w, _num_town_sort);
   479 
   482 
   480 		DrawWindowWidgets(w);
   483 		DrawWindowWidgets(w);
   481 		DrawSortButtonState(w, (_town_sort_order <= 1) ? 3 : 4, _town_sort_order & 1 ? SBS_DOWN : SBS_UP);
   484 		DrawSortButtonState(w, (_town_sort_order <= 1) ? TDW_SORTNAME : TDW_SORTPOPULATION, _town_sort_order & 1 ? SBS_DOWN : SBS_UP);
   482 
   485 
   483 		{
   486 		{
   484 			int n = 0;
   487 			int n = 0;
   485 			uint16 i = w->vscroll.pos;
   488 			uint16 i = w->vscroll.pos;
   486 			int y = 28;
   489 			int y = 28;
   503 		}
   506 		}
   504 	} break;
   507 	} break;
   505 
   508 
   506 	case WE_CLICK:
   509 	case WE_CLICK:
   507 		switch (e->we.click.widget) {
   510 		switch (e->we.click.widget) {
   508 		case 3: { /* Sort by Name ascending/descending */
   511 			case TDW_SORTNAME: { /* Sort by Name ascending/descending */
   509 			_town_sort_order = (_town_sort_order == 0) ? 1 : 0;
   512 				_town_sort_order = (_town_sort_order == 0) ? 1 : 0;
   510 			_town_sort_dirty = true;
   513 				_town_sort_dirty = true;
   511 			SetWindowDirty(w);
   514 				SetWindowDirty(w);
   512 		} break;
   515 			} break;
   513 
   516 
   514 		case 4: { /* Sort by Population ascending/descending */
   517 			case TDW_SORTPOPULATION: { /* Sort by Population ascending/descending */
   515 			_town_sort_order = (_town_sort_order == 2) ? 3 : 2;
   518 				_town_sort_order = (_town_sort_order == 2) ? 3 : 2;
   516 			_town_sort_dirty = true;
   519 				_town_sort_dirty = true;
   517 			SetWindowDirty(w);
   520 				SetWindowDirty(w);
   518 		} break;
   521 			} break;
   519 
   522 
   520 		case 5: { /* Click on Town Matrix */
   523 			case TDW_CENTERTOWN: { /* Click on Town Matrix */
   521 			const Town* t;
   524 				const Town* t;
   522 
   525 
   523 			uint16 id_v = (e->we.click.pt.y - 28) / 10;
   526 				uint16 id_v = (e->we.click.pt.y - 28) / 10;
   524 
   527 
   525 			if (id_v >= w->vscroll.cap) return; // click out of bounds
   528 				if (id_v >= w->vscroll.cap) return; // click out of bounds
   526 
   529 
   527 			id_v += w->vscroll.pos;
   530 				id_v += w->vscroll.pos;
   528 
   531 
   529 			if (id_v >= _num_town_sort) return; // click out of town bounds
   532 				if (id_v >= _num_town_sort) return; // click out of town bounds
   530 
   533 
   531 			t = _town_sort[id_v];
   534 				t = _town_sort[id_v];
   532 			assert(t->xy);
   535 				assert(t->xy);
   533 			ScrollMainWindowToTile(t->xy);
   536 				ScrollMainWindowToTile(t->xy);
   534 			break;
   537 			} break;
   535 		}
       
   536 		}
   538 		}
   537 		break;
   539 		break;
   538 
   540 
   539 	case WE_4:
   541 	case WE_4:
   540 		SetWindowDirty(w);
   542 		SetWindowDirty(w);