build_vehicle_gui.c
author KUDr
Sun, 31 Dec 2006 02:53:23 +0000
branchcustombridgeheads
changeset 5611 11da6bafbfb9
parent 5274 8bb2b6d99ce7
child 5623 ef2a8a524a95
permissions -rw-r--r--
(svn r7687) [cbh] - Fix: trains can now enter the bridge from side. They still can't leave it from side (pathfinder will need to be invoked when the other ramp is entered). Also the code is not very clear and needs review. It is more proof of concept than final solution. I hope that somebody smarter (Celestar) can do it better.
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     1
/* $Id$ */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     2
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     3
#include "stdafx.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     4
#include "openttd.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     5
#include "aircraft.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     6
#include "debug.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     7
#include "functions.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     8
#include "table/sprites.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
     9
#include "table/strings.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    10
#include "window.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    11
#include "gui.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    12
#include "vehicle.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    13
#include "gfx.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    14
#include "station.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    15
#include "command.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    16
#include "engine.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    17
#include "player.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    18
#include "depot.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    19
#include "airport.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    20
#include "vehicle_gui.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    21
#include "newgrf_engine.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    22
#include "date.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    23
#include "strings.h"
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    24
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    25
5273
5fde4b8c94c4 (svn r7415) -Codechange: Don't use typedef enum for simple widget enumerators when we will never use
Darkvater
parents: 5215
diff changeset
    26
enum BuildVehicleWidgets {
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    27
	BUILD_VEHICLE_WIDGET_CLOSEBOX = 0,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    28
	BUILD_VEHICLE_WIDGET_CAPTION,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    29
	BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    30
	BUILD_VEHICLE_WIDGET_SORT_TEXT,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    31
	BUILD_VEHICLE_WIDGET_SORT_DROPDOWN,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    32
	BUILD_VEHICLE_WIDGET_LIST,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    33
	BUILD_VEHICLE_WIDGET_SCROLLBAR,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    34
	BUILD_VEHICLE_WIDGET_PANEL,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    35
	BUILD_VEHICLE_WIDGET_BUILD,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    36
	BUILD_VEHICLE_WIDGET_RENAME,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    37
	BUILD_VEHICLE_WIDGET_RESIZE,
5273
5fde4b8c94c4 (svn r7415) -Codechange: Don't use typedef enum for simple widget enumerators when we will never use
Darkvater
parents: 5215
diff changeset
    38
};
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    39
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    40
static const Widget _build_vehicle_widgets[] = {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    41
	{   WWT_CLOSEBOX,   RESIZE_NONE,    14,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW },
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    42
	{    WWT_CAPTION,   RESIZE_NONE,    14,    11,   239,     0,    13, STR_A005_NEW_AIRCRAFT,   STR_018C_WINDOW_TITLE_DRAG_THIS },
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    43
	{ WWT_PUSHTXTBTN,   RESIZE_NONE,    14,     0,    80,    14,    25, STR_SORT_BY,             STR_SORT_ORDER_TIP},
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    44
	{      WWT_PANEL,   RESIZE_NONE,    14,    81,   227,    14,    25, 0x0,                     STR_SORT_CRITERIA_TIP},
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    45
	{    WWT_TEXTBTN,   RESIZE_NONE,    14,   228,   239,    14,    25, STR_0225,                STR_SORT_CRITERIA_TIP},
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    46
	{     WWT_MATRIX, RESIZE_BOTTOM,    14,     0,   227,    26,   121, 0x401,                   STR_A025_AIRCRAFT_SELECTION_LIST },
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    47
	{  WWT_SCROLLBAR, RESIZE_BOTTOM,    14,   228,   239,    26,   121, 0x0,                     STR_0190_SCROLL_BAR_SCROLLS_LIST },
4931
6e09e884257d (svn r6911) - Codechange: Add extra space to all purchase windows (and the replace window) to allow room for more text. (mart3p)
peter1138
parents: 4930
diff changeset
    48
	{      WWT_PANEL,     RESIZE_TB,    14,     0,   239,   122,   213, 0x0,                     STR_NULL },
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    49
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
    50
	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,     0,   114,   214,   225, STR_A006_BUILD_AIRCRAFT, STR_A026_BUILD_THE_HIGHLIGHTED_AIRCRAFT },
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
    51
	{ WWT_PUSHTXTBTN,     RESIZE_TB,    14,   115,   227,   214,   225, STR_A037_RENAME,         STR_A038_RENAME_AIRCRAFT_TYPE },
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
    52
	{  WWT_RESIZEBOX,     RESIZE_TB,    14,   228,   239,   214,   225, 0x0,                     STR_RESIZE_BUTTON },
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    53
	{   WIDGETS_END},
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    54
};
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    55
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    56
static bool _internal_sort_order; // descending/ascending
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    57
static byte _last_sort_criteria = 0;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    58
static bool _last_sort_order = false;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    59
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    60
static int CDECL EngineNumberSorter(const void *a, const void *b)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    61
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    62
	const EngineID va = *(const EngineID*)a;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    63
	const EngineID vb = *(const EngineID*)b;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    64
	int r = va - vb;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    65
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    66
	return _internal_sort_order ? -r : r;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    67
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    68
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    69
static int CDECL EngineIntroDateSorter(const void *a, const void *b)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    70
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    71
	const int va = GetEngine(*(const EngineID*)a)->intro_date;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    72
	const int vb = GetEngine(*(const EngineID*)b)->intro_date;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    73
	const int r = va - vb;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    74
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    75
	if (r == 0) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    76
		/* Use EngineID to sort instead since we want consistent sorting */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    77
		return EngineNumberSorter(a, b);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    78
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    79
	return _internal_sort_order ? -r : r;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    80
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    81
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    82
static int CDECL EngineNameSorter(const void *a, const void *b)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    83
{
4804
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
    84
	static EngineID last_engine[2] = { INVALID_ENGINE, INVALID_ENGINE };
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
    85
	static char     last_name[2][64] = { "\0", "\0" };
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
    86
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    87
	const EngineID va = *(const EngineID*)a;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    88
	const EngineID vb = *(const EngineID*)b;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    89
	int r;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    90
4804
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
    91
	if (va != last_engine[0]) {
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
    92
		last_engine[0] = va;
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4896
diff changeset
    93
		GetString(last_name[0], GetCustomEngineName(va), lastof(last_name[0]));
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    94
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
    95
4804
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
    96
	if (vb != last_engine[1]) {
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
    97
		last_engine[1] = vb;
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4896
diff changeset
    98
		GetString(last_name[1], GetCustomEngineName(vb), lastof(last_name[1]));
4804
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
    99
	}
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   100
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   101
	r = strcmp(last_name[0], last_name[1]); // sort by name
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   102
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   103
	if (r == 0) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   104
		/* Use EngineID to sort instead since we want consistent sorting */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   105
		return EngineNumberSorter(a, b);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   106
	}
4804
74d2003d6f9b (svn r6726) -Codechange: [vehicle build window] cleaned up the name sorter (mainly by peter1138)
bjarni
parents: 4800
diff changeset
   107
	return _internal_sort_order ? -r : r;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   108
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   109
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   110
static int CDECL EngineReliabilitySorter(const void *a, const void *b)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   111
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   112
	const int va = GetEngine(*(const EngineID*)a)->reliability;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   113
	const int vb = GetEngine(*(const EngineID*)b)->reliability;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   114
	const int r = va - vb;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   115
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   116
	if (r == 0) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   117
		/* Use EngineID to sort instead since we want consistent sorting */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   118
		return EngineNumberSorter(a, b);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   119
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   120
	return _internal_sort_order ? -r : r;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   121
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   122
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   123
/* Aircraft sorting functions */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   124
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   125
static int CDECL AircraftEngineCostSorter(const void *a, const void *b)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   126
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   127
	const int va = AircraftVehInfo(*(const EngineID*)a)->base_cost;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   128
	const int vb = AircraftVehInfo(*(const EngineID*)b)->base_cost;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   129
	int r = va - vb;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   130
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   131
	return _internal_sort_order ? -r : r;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   132
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   133
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   134
static int CDECL AircraftEngineSpeedSorter(const void *a, const void *b)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   135
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   136
	const int va = AircraftVehInfo(*(const EngineID*)a)->max_speed;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   137
	const int vb = AircraftVehInfo(*(const EngineID*)b)->max_speed;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   138
	const int r = va - vb;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   139
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   140
	if (r == 0) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   141
		/* Use EngineID to sort instead since we want consistent sorting */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   142
		return EngineNumberSorter(a, b);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   143
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   144
	return _internal_sort_order ? -r : r;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   145
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   146
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   147
static int CDECL AircraftEngineRunningCostSorter(const void *a, const void *b)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   148
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   149
	const int va = AircraftVehInfo(*(const EngineID*)a)->running_cost;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   150
	const int vb = AircraftVehInfo(*(const EngineID*)b)->running_cost;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   151
	const int r = va - vb;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   152
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   153
	if (r == 0) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   154
		/* Use EngineID to sort instead since we want consistent sorting */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   155
		return EngineNumberSorter(a, b);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   156
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   157
	return _internal_sort_order ? -r : r;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   158
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   159
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   160
static int CDECL AircraftEngineCargoSorter(const void *a, const void *b)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   161
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   162
	const int va = AircraftVehInfo(*(const EngineID*)a)->passenger_capacity;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   163
	const int vb = AircraftVehInfo(*(const EngineID*)b)->passenger_capacity;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   164
	const int r = va - vb;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   165
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   166
	if (r == 0) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   167
		/* Use EngineID to sort instead since we want consistent sorting */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   168
		return EngineNumberSorter(a, b);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   169
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   170
	return _internal_sort_order ? -r : r;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   171
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   172
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   173
static EngList_SortTypeFunction * const _aircraft_sorter[] = {
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   174
	&EngineNumberSorter,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   175
	&AircraftEngineCostSorter,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   176
	&AircraftEngineSpeedSorter,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   177
	&EngineIntroDateSorter,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   178
	&EngineNameSorter,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   179
	&AircraftEngineRunningCostSorter,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   180
	&EngineReliabilitySorter,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   181
	&AircraftEngineCargoSorter,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   182
};
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   183
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   184
static const StringID _aircraft_sort_listing[] = {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   185
	STR_ENGINE_SORT_ENGINE_ID,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   186
	STR_ENGINE_SORT_COST,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   187
	STR_SORT_BY_MAX_SPEED,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   188
	STR_ENGINE_SORT_INTRO_DATE,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   189
	STR_SORT_BY_DROPDOWN_NAME,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   190
	STR_ENGINE_SORT_RUNNING_COST,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   191
	STR_SORT_BY_RELIABILITY,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   192
	STR_ENGINE_SORT_CARGO_CAPACITY,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   193
	INVALID_STRING_ID
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   194
};
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   195
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   196
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   197
/**
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   198
* Draw the purchase info details of an aircraft at a given location.
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   199
 * @param x,y location where to draw the info
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   200
 * @param engine_number the engine of which to draw the info of
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   201
 */
4930
fd91a88d6ef6 (svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
peter1138
parents: 4912
diff changeset
   202
void DrawAircraftPurchaseInfo(int x, int y, uint w, EngineID engine_number)
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   203
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   204
	const AircraftVehicleInfo *avi = AircraftVehInfo(engine_number);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   205
	const Engine *e = GetEngine(engine_number);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   206
	CargoID cargo;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   207
	YearMonthDay ymd;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   208
	ConvertDateToYMD(e->intro_date, &ymd);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   209
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   210
	/* Purchase cost - Max speed */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   211
	SetDParam(0, avi->base_cost * (_price.aircraft_base>>3)>>5);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   212
	SetDParam(1, avi->max_speed * 128 / 10);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   213
	DrawString(x, y, STR_PURCHASE_INFO_COST_SPEED, 0);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   214
	y += 10;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   215
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   216
	/* Cargo capacity */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   217
	cargo = FindFirstRefittableCargo(engine_number);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   218
	if (cargo == CT_INVALID || cargo == CT_PASSENGERS) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   219
		SetDParam(0, avi->passenger_capacity);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   220
		SetDParam(1, avi->mail_capacity);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   221
		DrawString(x, y, STR_PURCHASE_INFO_AIRCRAFT_CAPACITY, 0);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   222
	} else {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   223
		/* Note, if the default capacity is selected by the refit capacity
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   224
		* callback, then the capacity shown is likely to be incorrect. */
4896
72d7a8614580 (svn r6855) - Codechange: When displaying a "quantity of cargo" string, use the {CARGO} command and supply the cargo type and quantity, instead of manually looking up the cargo type's string.
peter1138
parents: 4807
diff changeset
   225
		SetDParam(0, cargo);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   226
		SetDParam(1, AircraftDefaultCargoCapacity(cargo, engine_number));
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   227
		SetDParam(2, STR_9842_REFITTABLE);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   228
		DrawString(x, y, STR_PURCHASE_INFO_CAPACITY, 0);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   229
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   230
	y += 10;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   231
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   232
	/* Running cost */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   233
	SetDParam(0, avi->running_cost * _price.aircraft_running >> 8);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   234
	DrawString(x, y, STR_PURCHASE_INFO_RUNNINGCOST, 0);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   235
	y += 10;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   236
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   237
	/* Design date - Life length */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   238
	SetDParam(0, ymd.year);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   239
	SetDParam(1, e->lifelength);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   240
	DrawString(x, y, STR_PURCHASE_INFO_DESIGNED_LIFE, 0);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   241
	y += 10;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   242
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   243
	/* Reliability */
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   244
	SetDParam(0, e->reliability * 100 >> 16);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   245
	DrawString(x, y, STR_PURCHASE_INFO_RELIABILITY, 0);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   246
	y += 10;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   247
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   248
	/* Additional text from NewGRF */
4930
fd91a88d6ef6 (svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
peter1138
parents: 4912
diff changeset
   249
	y += ShowAdditionalText(x, y, w, engine_number);
4932
3567a3ec9d80 (svn r6912) - Feature: Show a list of cargo types that a vehicle is refittable to in the purchase information window. (mart3p)
peter1138
parents: 4931
diff changeset
   250
	y += ShowRefitOptionsList(x, y, w, engine_number);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   251
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   252
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   253
void DrawAircraftImage(const Vehicle *v, int x, int y, VehicleID selection)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   254
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   255
	PalSpriteID pal = (v->vehstatus & VS_CRASHED) ? PALETTE_CRASH : GetVehiclePalette(v);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   256
	DrawSprite(GetAircraftImage(v, DIR_W) | pal, x + 25, y + 10);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   257
	if (v->subtype == 0) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   258
		SpriteID rotor_sprite = GetCustomRotorSprite(v, true);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   259
		if (rotor_sprite == 0) rotor_sprite = SPR_ROTOR_STOPPED;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   260
		DrawSprite(rotor_sprite, x + 25, y + 5);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   261
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   262
	if (v->index == selection) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   263
		DrawFrameRect(x - 1, y - 1, x + 58, y + 21, 0xF, FR_BORDERONLY);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   264
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   265
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   266
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   267
void CcBuildAircraft(bool success, TileIndex tile, uint32 p1, uint32 p2)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   268
{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   269
	if (success) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   270
		const Vehicle *v = GetVehicle(_new_vehicle_id);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   271
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   272
		if (v->tile == _backup_orders_tile) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   273
			_backup_orders_tile = 0;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   274
			RestoreVehicleOrders(v, _backup_orders_data);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   275
		}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   276
		ShowAircraftViewWindow(v);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   277
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   278
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   279
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   280
static void GenerateBuildAircraftList(Window *w)
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   281
{
5200
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   282
	EngineID eid, sel_id;
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   283
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   284
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   285
	EngList_RemoveAll(&bv->eng_list);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   286
5200
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   287
	/* Make list of all available planes.
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   288
	 * Also check to see if the previously selected plane is still available,
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   289
	 * and if not, reset selection to INVALID_ENGINE. This could be the case
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   290
	 * when planes become obsolete and are removed */
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   291
	sel_id = INVALID_ENGINE;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   292
	for (eid = AIRCRAFT_ENGINES_INDEX; eid < AIRCRAFT_ENGINES_INDEX + NUM_AIRCRAFT_ENGINES; eid++) {
5215
439d5ca71311 (svn r7330) -Fix (r7304): Data invalidation doesn't always happen as the local
peter1138
parents: 5201
diff changeset
   293
		if (IsEngineBuildable(eid, VEH_Aircraft, _local_player)) {
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   294
			const AircraftVehicleInfo *avi = AircraftVehInfo(eid);
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   295
			switch (bv->filter.acc_planes) {
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   296
				case HELICOPTERS_ONLY:
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   297
					if (avi->subtype != 0) continue; // if not helicopter
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   298
					break;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   299
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   300
				case AIRCRAFT_ONLY:
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   301
					if (avi->subtype == 0) continue; // if helicopter
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   302
					break;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   303
5199
523e7025d979 (svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents: 5198
diff changeset
   304
				case ALL: break;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   305
			}
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   306
			EngList_Add(&bv->eng_list, eid);
5200
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   307
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   308
			if (eid == bv->sel_engine) sel_id = eid;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   309
		}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   310
	}
5200
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   311
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   312
	bv->sel_engine = sel_id;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   313
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   314
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   315
static void GenerateBuildList(Window *w)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   316
{
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   317
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   318
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   319
	switch (bv->vehicle_type) {
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   320
		case VEH_Aircraft:
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   321
			GenerateBuildAircraftList(w);
5199
523e7025d979 (svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents: 5198
diff changeset
   322
			_internal_sort_order = bv->descending_sort_order;
523e7025d979 (svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents: 5198
diff changeset
   323
			EngList_Sort(&bv->eng_list, _aircraft_sorter[bv->sort_criteria]);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   324
			break;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   325
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   326
		default: NOT_REACHED();
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   327
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   328
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   329
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   330
static void DrawBuildAircraftWindow(Window *w)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   331
{
5200
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   332
	const buildvehicle_d *bv = &WP(w, buildvehicle_d);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   333
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   334
	SetWindowWidgetDisabledState(w, BUILD_VEHICLE_WIDGET_BUILD, w->window_number == 0);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   335
5201
db204cf84e2d (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   336
	SetVScrollCount(w, EngList_Count(&bv->eng_list));
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   337
	DrawWindowWidgets(w);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   338
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   339
	{
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   340
		int x = 2;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   341
		int y = 27;
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   342
		EngineID selected_id = bv->sel_engine;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   343
		EngineID eid = w->vscroll.pos;
5201
db204cf84e2d (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   344
		uint16 max = min(w->vscroll.pos + w->vscroll.cap, EngList_Count(&bv->eng_list));
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   345
5199
523e7025d979 (svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents: 5198
diff changeset
   346
		for (; eid < max; eid++) {
5201
db204cf84e2d (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   347
			const EngineID engine = bv->eng_list[eid];
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   348
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   349
			DrawString(x + 62, y + 7, GetCustomEngineName(engine), engine == selected_id ? 0xC : 0x10);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   350
			DrawAircraftEngine(x + 29, y + 10, engine, GetEnginePalette(engine, _local_player));
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   351
			y += 24;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   352
		}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   353
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   354
		if (selected_id != INVALID_ENGINE) {
4930
fd91a88d6ef6 (svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
peter1138
parents: 4912
diff changeset
   355
			const Widget *wi = &w->widget[BUILD_VEHICLE_WIDGET_PANEL];
fd91a88d6ef6 (svn r6910) - Codechange: Supply width of area when drawing purchase info instead of using hardcoded values. (mart3p)
peter1138
parents: 4912
diff changeset
   356
			DrawAircraftPurchaseInfo(x, wi->top + 1, wi->right - wi->left - 2, selected_id);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   357
		}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   358
	}
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   359
	DrawString(85, 15, _aircraft_sort_listing[bv->sort_criteria], 0x10);
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   360
	DoDrawString(bv->descending_sort_order ? DOWNARROW : UPARROW, 69, 15, 0x10);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   361
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   362
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   363
static void BuildAircraftClickEvent(Window *w, WindowEvent *e)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   364
{
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   365
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   366
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   367
	switch (e->we.click.widget) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   368
		case BUILD_VEHICLE_WIDGET_SORT_ASSENDING_DESCENDING:
5199
523e7025d979 (svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents: 5198
diff changeset
   369
			bv->descending_sort_order ^= true;
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   370
			_last_sort_order = bv->descending_sort_order;
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   371
			GenerateBuildList(w);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   372
			SetWindowDirty(w);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   373
			break;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   374
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   375
		case BUILD_VEHICLE_WIDGET_LIST: {
5201
db204cf84e2d (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   376
			uint i = (e->we.click.pt.y - 26) / 24 + w->vscroll.pos;
db204cf84e2d (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   377
			uint num_items = EngList_Count(&bv->eng_list);
db204cf84e2d (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   378
			bv->sel_engine = (i < num_items) ? bv->eng_list[i] : INVALID_ENGINE;
db204cf84e2d (svn r7316) -Codechange: Make train-build-gui and aircraft-build-gui (unified) look more alike.
Darkvater
parents: 5200
diff changeset
   379
			SetWindowDirty(w);
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   380
			break;
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   381
		}
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   382
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   383
		case BUILD_VEHICLE_WIDGET_SORT_TEXT: case BUILD_VEHICLE_WIDGET_SORT_DROPDOWN:/* Select sorting criteria dropdown menu */
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   384
			ShowDropDownMenu(w, _aircraft_sort_listing, bv->sort_criteria, BUILD_VEHICLE_WIDGET_SORT_DROPDOWN, 0, 0);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   385
			return;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   386
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   387
		case BUILD_VEHICLE_WIDGET_BUILD: {
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   388
			EngineID sel_eng = bv->sel_engine;
5192
add11dd769f5 (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
   389
			if (sel_eng != INVALID_ENGINE) {
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   390
				DoCommandP(w->window_number, sel_eng, 0, CcBuildAircraft, CMD_BUILD_AIRCRAFT | CMD_MSG(STR_A008_CAN_T_BUILD_AIRCRAFT));
5192
add11dd769f5 (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
   391
			}
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   392
			break;
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   393
		}
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   394
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   395
		case BUILD_VEHICLE_WIDGET_RENAME: {
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   396
			EngineID sel_eng = bv->sel_engine;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   397
			if (sel_eng != INVALID_ENGINE) {
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   398
				bv->rename_engine = sel_eng;
5192
add11dd769f5 (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
   399
				ShowQueryString(GetCustomEngineName(sel_eng), STR_A039_RENAME_AIRCRAFT_TYPE, 31, 160, w->window_class, w->window_number, CS_ALPHANUMERAL);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   400
			}
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   401
			break;
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   402
		}
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   403
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   404
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   405
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   406
static void NewAircraftWndProc(Window *w, WindowEvent *e)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   407
{
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   408
	buildvehicle_d *bv = &WP(w, buildvehicle_d);
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   409
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   410
	switch (e->event) {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   411
		case WE_INVALIDATE_DATA:
5194
f471a618864f (svn r7308) -Codechange: call GenerateBuildList() only when needed instead of on each redraw (peter1138)
KUDr
parents: 5193
diff changeset
   412
			GenerateBuildList(w);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   413
			break;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   414
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   415
		case WE_DESTROY:
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   416
			EngList_Destroy(&bv->eng_list);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   417
			break;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   418
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   419
		case WE_PAINT:
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   420
			DrawBuildAircraftWindow(w);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   421
			break;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   422
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   423
		case WE_CLICK:
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   424
			BuildAircraftClickEvent(w, e);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   425
			break;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   426
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   427
		case WE_ON_EDIT_TEXT: {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   428
			if (e->we.edittext.str[0] != '\0') {
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   429
				_cmd_text = e->we.edittext.str;
5192
add11dd769f5 (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
   430
				DoCommandP(0, bv->rename_engine, 0, NULL, CMD_RENAME_ENGINE | CMD_MSG(STR_A03A_CAN_T_RENAME_AIRCRAFT_TYPE));
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   431
			}
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   432
			break;
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   433
		}
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   434
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   435
		case WE_DROPDOWN_SELECT: /* we have selected a dropdown item in the list */
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   436
			if (bv->sort_criteria != e->we.dropdown.index) {
5199
523e7025d979 (svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents: 5198
diff changeset
   437
				bv->sort_criteria = _last_sort_criteria = e->we.dropdown.index;
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   438
				GenerateBuildList(w);
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   439
			}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   440
			SetWindowDirty(w);
5192
add11dd769f5 (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
   441
			break;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   442
5192
add11dd769f5 (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
   443
		case WE_RESIZE:
add11dd769f5 (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
   444
			w->vscroll.cap += e->we.sizing.diff.y / 24;
add11dd769f5 (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
   445
			w->widget[BUILD_VEHICLE_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
add11dd769f5 (svn r7305) -Codestyle: Indentation fixes
peter1138
parents: 5187
diff changeset
   446
			break;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   447
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   448
}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   449
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   450
static const WindowDesc _build_vehicle_desc = {
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   451
	WDP_AUTO, WDP_AUTO, 240, 226,
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   452
	WC_BUILD_VEHICLE,0,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   453
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   454
	_build_vehicle_widgets,
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   455
	NewAircraftWndProc
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   456
};
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   457
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   458
void ShowBuildVehicleWindow(TileIndex tile, byte type)
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   459
{
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   460
	buildvehicle_d *bv;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   461
	Window *w;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   462
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   463
	DeleteWindowById(WC_BUILD_VEHICLE, tile);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   464
	w = AllocateWindowDescFront(&_build_vehicle_desc, tile);
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   465
	if (w == NULL) return;
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   466
5199
523e7025d979 (svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents: 5198
diff changeset
   467
	w->caption_color = (tile != 0) ? GetTileOwner(tile) : _local_player;
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   468
	w->resize.step_height = GetVehicleListHeight(type);
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   469
	w->vscroll.cap = 4;
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   470
	w->widget[BUILD_VEHICLE_WIDGET_LIST].data = (w->vscroll.cap << 8) + 1;
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   471
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   472
	bv = &WP(w, buildvehicle_d);
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   473
	EngList_Create(&bv->eng_list);
5199
523e7025d979 (svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents: 5198
diff changeset
   474
	bv->sel_engine            = INVALID_ENGINE;
523e7025d979 (svn r7314) -Cleanup: const, whitespace, coding style and variable usage.
Darkvater
parents: 5198
diff changeset
   475
	bv->sort_criteria         = _last_sort_criteria;
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   476
	bv->descending_sort_order = _last_sort_order;
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   477
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   478
	bv->vehicle_type = type;
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   479
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   480
	switch (type) {
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   481
		case VEH_Aircraft: {
5274
8bb2b6d99ce7 (svn r7418) -Codechange/Feature: Put back the 'New Vehicles' button in the vehicle list window. As
Darkvater
parents: 5273
diff changeset
   482
			byte acc_planes = (tile == 0) ? ALL : GetAirport(GetStationByTile(tile)->airport_type)->acc_planes;
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   483
			bv->filter.acc_planes = acc_planes;
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   484
			break;
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   485
		}
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   486
		default: NOT_REACHED();
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   487
	}
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   488
5187
d1f4e447a7eb (svn r7299) -CodeChange: Train and Aircraft Build window GUI code simplified a bit:
KUDr
parents: 5070
diff changeset
   489
	GenerateBuildList(w);
5200
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   490
	/* Select the first plane in the list as default when opening the window */
603e30641448 (svn r7315) -Fix: Have the first engine in the list be selected once again when the window is opened
Darkvater
parents: 5199
diff changeset
   491
	if (EngList_Count(&bv->eng_list) > 0) bv->sel_engine = bv->eng_list[0];
4800
009e3c6cea8a (svn r6722) -Codechange: [aircraft build window] moved aircraft build window to a file of it's own
bjarni
parents:
diff changeset
   492
}