Changeset - r8593:c595ca6308fb
[Not reviewed]
master
0 1 0
peter1138 - 16 years ago 2008-02-18 12:36:10
peter1138@openttd.org
(svn r12174) -Codechange: Make the patches window dynamically resize to the largest patch tab, so adding patch options is simply a case of adding to the lists.
1 file changed with 9 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/settings_gui.cpp
Show inline comments
 
@@ -839,73 +839,80 @@ static PatchPage _patches_page[] = {
 
	{_patches_ui,           NULL, lengthof(_patches_ui)},
 
	{_patches_construction, NULL, lengthof(_patches_construction)},
 
	{_patches_vehicles,     NULL, lengthof(_patches_vehicles)},
 
	{_patches_stations,     NULL, lengthof(_patches_stations)},
 
	{_patches_economy,      NULL, lengthof(_patches_economy)},
 
	{_patches_ai,           NULL, lengthof(_patches_ai)},
 
};
 

	
 
enum PatchesSelectionWidgets {
 
	PATCHSEL_OPTIONSPANEL = 3,
 
	PATCHSEL_INTERFACE,
 
	PATCHSEL_CONSTRUCTION,
 
	PATCHSEL_VEHICLES,
 
	PATCHSEL_STATIONS,
 
	PATCHSEL_ECONOMY,
 
	PATCHSEL_COMPETITORS
 
};
 

	
 
/** The main patches window. Shows a number of categories on top and
 
 * a selection of patches in that category.
 
 * Uses WP(w, def_d) macro - data_1, data_2, data_3 */
 
static void PatchesSelectionWndProc(Window *w, WindowEvent *e)
 
{
 
	static Patches *patches_ptr;
 
	static int patches_max = 0;
 

	
 
	switch (e->event) {
 
		case WE_CREATE: {
 
			static bool first_time = true;
 

	
 
			patches_ptr = (_game_mode == GM_MENU) ? &_patches_newgame : &_patches;
 

	
 
			/* Build up the dynamic settings-array only once per OpenTTD session */
 
			if (first_time) {
 
				PatchPage *page;
 
				for (page = &_patches_page[0]; page != endof(_patches_page); page++) {
 
					uint i;
 

	
 
					if (patches_max < page->num) patches_max = page->num;
 

	
 
					page->entries = MallocT<PatchEntry>(page->num);
 
					for (i = 0; i != page->num; i++) {
 
						uint index;
 
						const SettingDesc *sd = GetPatchFromName(page->names[i], &index);
 
						assert(sd != NULL);
 

	
 
						page->entries[i].setting = sd;
 
						page->entries[i].index = index;
 
					}
 
				}
 
				first_time = false;
 
			}
 

	
 
			/* Resize the window to fit the largest patch tab */
 
			ResizeWindowForWidget(w, PATCHSEL_OPTIONSPANEL, 0, patches_max * 11);
 

	
 
			w->LowerWidget(4);
 
		} break;
 

	
 
		case WE_PAINT: {
 
			int x, y;
 
			const PatchPage *page = &_patches_page[WP(w, def_d).data_1];
 
			uint i;
 

	
 
			/* Set up selected category */
 
			DrawWindowWidgets(w);
 

	
 
			x = 5;
 
			y = 47;
 
			for (i = 0; i != page->num; i++) {
 
				const SettingDesc *sd = page->entries[i].setting;
 
				const SettingDescBase *sdb = &sd->desc;
 
				const void *var = GetVariableAddress(patches_ptr, &sd->save);
 
				bool editable = true;
 
				bool disabled = false;
 

	
 
				// We do not allow changes of some items when we are a client in a networkgame
 
				if (!(sd->save.conv & SLF_NETWORK_NO) && _networking && !_network_server) editable = false;
 
				if ((sdb->flags & SGF_NETWORK_ONLY) && !_networking) editable = false;
 
				if ((sdb->flags & SGF_NO_NETWORK) && _networking) editable = false;
 
@@ -1050,61 +1057,61 @@ static void PatchesSelectionWndProc(Wind
 
		case WE_ON_EDIT_TEXT:
 
			if (e->we.edittext.str != NULL) {
 
				const PatchEntry *pe = &_patches_page[WP(w, def_d).data_1].entries[WP(w,def_d).data_3];
 
				const SettingDesc *sd = pe->setting;
 
				int32 value = atoi(e->we.edittext.str);
 

	
 
				/* Save the correct currency-translated value */
 
				if (sd->desc.flags & SGF_CURRENCY) value /= _currency->rate;
 

	
 
				SetPatchValue(pe->index, patches_ptr, value);
 
				SetWindowDirty(w);
 
			}
 
			break;
 

	
 
		case WE_DESTROY:
 
			DeleteWindowById(WC_QUERY_STRING, 0);
 
			break;
 
	}
 
}
 

	
 
static const Widget _patches_selection_widgets[] = {
 
{   WWT_CLOSEBOX,   RESIZE_NONE,    10,     0,    10,     0,    13, STR_00C5,                        STR_018B_CLOSE_WINDOW},
 
{    WWT_CAPTION,   RESIZE_NONE,    10,    11,   369,     0,    13, STR_CONFIG_PATCHES_CAPTION,      STR_018C_WINDOW_TITLE_DRAG_THIS},
 
{      WWT_PANEL,   RESIZE_NONE,    10,     0,   369,    14,    41, 0x0,                             STR_NULL},
 
{      WWT_PANEL,   RESIZE_NONE,    10,     0,   369,    42,   380, 0x0,                             STR_NULL},
 
{      WWT_PANEL,   RESIZE_NONE,    10,     0,   369,    42,    50, 0x0,                             STR_NULL},
 

	
 
{    WWT_TEXTBTN,   RESIZE_NONE,     3,    10,    96,    16,    27, STR_CONFIG_PATCHES_GUI,          STR_NULL},
 
{    WWT_TEXTBTN,   RESIZE_NONE,     3,    97,   183,    16,    27, STR_CONFIG_PATCHES_CONSTRUCTION, STR_NULL},
 
{    WWT_TEXTBTN,   RESIZE_NONE,     3,   184,   270,    16,    27, STR_CONFIG_PATCHES_VEHICLES,     STR_NULL},
 
{    WWT_TEXTBTN,   RESIZE_NONE,     3,   271,   357,    16,    27, STR_CONFIG_PATCHES_STATIONS,     STR_NULL},
 
{    WWT_TEXTBTN,   RESIZE_NONE,     3,    10,    96,    28,    39, STR_CONFIG_PATCHES_ECONOMY,      STR_NULL},
 
{    WWT_TEXTBTN,   RESIZE_NONE,     3,    97,   183,    28,    39, STR_CONFIG_PATCHES_AI,           STR_NULL},
 
{   WIDGETS_END},
 
};
 

	
 
static const WindowDesc _patches_selection_desc = {
 
	WDP_CENTER, WDP_CENTER, 370, 381, 370, 381,
 
	WDP_CENTER, WDP_CENTER, 370, 51, 370, 51,
 
	WC_GAME_OPTIONS, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET,
 
	_patches_selection_widgets,
 
	PatchesSelectionWndProc,
 
};
 

	
 
void ShowPatchesSelection()
 
{
 
	DeleteWindowById(WC_GAME_OPTIONS, 0);
 
	AllocateWindowDesc(&_patches_selection_desc);
 
}
 

	
 

	
 
/**
 
 * Draw [<][>] boxes.
 
 * @param x the x position to draw
 
 * @param y the y position to draw
 
 * @param ctab the color of the buttons
 
 * @param state 0 = none clicked, 1 = first clicked, 2 = second clicked
 
 * @param clickable_left is the left button clickable?
 
 * @param clickable_right is the right button clickable?
 
 */
 
void DrawArrowButtons(int x, int y, int ctab, byte state, bool clickable_left, bool clickable_right)
 
{
0 comments (0 inline, 0 general)