Changeset - r8591:b9b5c1c437ed
[Not reviewed]
master
0 1 0
peter1138 - 16 years ago 2008-02-18 09:16:02
peter1138@openttd.org
(svn r12172) -Codechange: Allow buttons to resize in NewGRF settings window
1 file changed with 6 insertions and 2 deletions:
0 comments (0 inline, 0 general)
src/newgrf_gui.cpp
Show inline comments
 
@@ -236,97 +236,97 @@ static const Widget _newgrf_add_dlg_widg
 
{ WWT_PUSHTXTBTN,    RESIZE_LRTB, 14, 147, 294, 225, 236, STR_NEWGRF_RESCAN_FILES, STR_NEWGRF_RESCAN_FILES_TIP },     // ANGRFW_RESCAN
 
{  WWT_RESIZEBOX,    RESIZE_LRTB, 14, 295, 306, 225, 236, 0x0,                     STR_RESIZE_BUTTON },               // ANGRFW_RESIZE
 
{   WIDGETS_END },
 
};
 

	
 
/* Window definition for the add a newgrf window */
 
static const WindowDesc _newgrf_add_dlg_desc = {
 
	WDP_CENTER, WDP_CENTER, 307, 237, 307, 337,
 
	WC_SAVELOAD, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
 
	_newgrf_add_dlg_widgets,
 
	NewGRFAddDlgWndProc,
 
};
 

	
 

	
 
/* 'NewGRF Settings' dialogue */
 
struct newgrf_d {
 
	GRFConfig **orig_list; ///< grf list the window is shown with
 
	GRFConfig **list;      ///< temporary grf list to which changes are made
 
	GRFConfig *sel;        ///< selected grf item
 
	bool editable;         ///< is the window editable
 
	bool show_params;      ///< are the grf-parameters shown in the info-panel
 
	bool execute;          ///< on pressing 'apply changes' are grf changes applied immediately, or only list is updated
 
};
 
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(newgrf_d));
 

	
 

	
 
/* Names of the manage newgrfs window widgets */
 
enum ShowNewGRFStateWidgets {
 
	SNGRFS_CLOSEBOX = 0,
 
	SNGRFS_CAPTION,
 
	SNGRFS_BACKGROUND,
 
	SNGRFS_ADD,
 
	SNGRFS_REMOVE,
 
	SNGRFS_MOVE_UP,
 
	SNGRFS_MOVE_DOWN,
 
	SNGRFS_FILE_LIST,
 
	SNGRFS_SCROLLBAR,
 
	SNGRFS_NEWGRF_INFO,
 
	SNGRFS_SET_PARAMETERS,
 
	SNGRFS_APPLY_CHANGES,
 
	SNGRFS_RESIZE,
 
};
 

	
 
static void SetupNewGRFState(Window *w)
 
{
 
	bool disable_all = WP(w, newgrf_d).sel == NULL || !WP(w, newgrf_d).editable;
 

	
 
	w->SetWidgetDisabledState(3, !WP(w, newgrf_d).editable);
 
	w->SetWidgetDisabledState(SNGRFS_ADD, !WP(w, newgrf_d).editable);
 
	w->SetWidgetsDisabledState(disable_all,
 
		SNGRFS_REMOVE,
 
		SNGRFS_MOVE_UP,
 
		SNGRFS_MOVE_DOWN,
 
		WIDGET_LIST_END
 
	);
 
	w->SetWidgetDisabledState(SNGRFS_SET_PARAMETERS, !WP(w, newgrf_d).show_params || disable_all);
 

	
 
	if (!disable_all) {
 
		/* All widgets are now enabled, so disable widgets we can't use */
 
		if (WP(w, newgrf_d).sel == *WP(w, newgrf_d).list) w->DisableWidget(SNGRFS_MOVE_UP);
 
		if (WP(w, newgrf_d).sel->next == NULL) w->DisableWidget(SNGRFS_MOVE_DOWN);
 
		if (WP(w, newgrf_d).sel->IsOpenTTDBaseGRF()) w->DisableWidget(SNGRFS_REMOVE);
 
	}
 
}
 

	
 

	
 
static void SetupNewGRFWindow(Window *w)
 
{
 
	const GRFConfig *c;
 
	int i;
 

	
 
	for (c = *WP(w, newgrf_d).list, i = 0; c != NULL; c = c->next, i++);
 

	
 
	w->vscroll.cap = (w->widget[SNGRFS_FILE_LIST].bottom - w->widget[SNGRFS_FILE_LIST].top) / 14 + 1;
 
	SetVScrollCount(w, i);
 
	w->SetWidgetDisabledState(SNGRFS_APPLY_CHANGES, !WP(w, newgrf_d).editable);
 
}
 

	
 

	
 
/** Callback function for the newgrf 'apply changes' confirmation window
 
 * @param w Window which is calling this callback
 
 * @param confirmed boolean value, true when yes was clicked, false otherwise
 
 */
 
static void NewGRFConfirmationCallback(Window *w, bool confirmed)
 
{
 
	if (confirmed) {
 
		newgrf_d *nd = &WP(w, newgrf_d);
 
		GRFConfig *c;
 
		int i = 0;
 

	
 
		CopyGRFConfigList(nd->orig_list, *nd->list, false);
 
		ReloadNewGRFData();
 

	
 
		/* Show new, updated list */
 
		for (c = *nd->list; c != NULL && c != nd->sel; c = c->next, i++);
 
		CopyGRFConfigList(nd->list, *nd->orig_list, false);
 
		for (c = *nd->list; c != NULL && i > 0; c = c->next, i--);
 
@@ -485,111 +485,115 @@ static void NewGRFWndProc(Window *w, Win
 
					if (WP(w, newgrf_d).execute) {
 
						ShowQuery(
 
							STR_POPUP_CAUTION_CAPTION,
 
							STR_NEWGRF_CONFIRMATION_TEXT,
 
							w,
 
							NewGRFConfirmationCallback
 
						);
 
					} else {
 
						CopyGRFConfigList(WP(w, newgrf_d).orig_list, *WP(w, newgrf_d).list, true);
 
						ResetGRFConfig(false);
 
						ReloadNewGRFData();
 
					}
 
					break;
 

	
 
				case SNGRFS_SET_PARAMETERS: { // Edit parameters
 
					char buff[512];
 
					if (WP(w, newgrf_d).sel == NULL) break;
 

	
 
					GRFBuildParamList(buff, WP(w, newgrf_d).sel, lastof(buff));
 
					ShowQueryString(BindCString(buff), STR_NEWGRF_PARAMETER_QUERY, 63, 250, w, CS_ALPHANUMERAL);
 
					break;
 
				}
 
			}
 
			break;
 

	
 
		case WE_ON_EDIT_TEXT:
 
			if (e->we.edittext.str != NULL) {
 
				/* Parse our new "int list" */
 
				GRFConfig *c = WP(w, newgrf_d).sel;
 
				c->num_params = parse_intlist(e->we.edittext.str, (int*)c->param, lengthof(c->param));
 

	
 
				/* parse_intlist returns -1 on error */
 
				if (c->num_params == (byte)-1) c->num_params = 0;
 
			}
 
			SetWindowDirty(w);
 
			break;
 

	
 
		case WE_DESTROY:
 
			if (!WP(w, newgrf_d).execute) {
 
				CopyGRFConfigList(WP(w, newgrf_d).orig_list, *WP(w, newgrf_d).list, true);
 
				ResetGRFConfig(false);
 
				ReloadNewGRFData();
 
			}
 
			/* Remove the temporary copy of grf-list used in window */
 
			ClearGRFConfigList(WP(w, newgrf_d).list);
 
			break;
 

	
 
		case WE_RESIZE:
 
			if (e->we.sizing.diff.x != 0) {
 
				ResizeButtons(w, SNGRFS_ADD, SNGRFS_MOVE_DOWN);
 
				ResizeButtons(w, SNGRFS_SET_PARAMETERS, SNGRFS_APPLY_CHANGES);
 
			}
 
			w->vscroll.cap += e->we.sizing.diff.y / 14;
 
			w->widget[SNGRFS_FILE_LIST].data = (w->vscroll.cap << 8) + 1;
 
			SetupNewGRFWindow(w);
 
			break;
 
	}
 
}
 

	
 
/* Widget definition of the manage newgrfs window */
 
static const Widget _newgrf_widgets[] = {
 
{   WWT_CLOSEBOX,  RESIZE_NONE, 10,   0,  10,   0,  13, STR_00C5,                    STR_018B_CLOSE_WINDOW },            // SNGRFS_CLOSEBOX
 
{    WWT_CAPTION, RESIZE_RIGHT, 10,  11, 299,   0,  13, STR_NEWGRF_SETTINGS_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS },  // SNGRFS_CAPTION
 
{      WWT_PANEL, RESIZE_RIGHT, 10,   0, 299,  14,  29, STR_NULL,                    STR_NULL },                         // SNGRFS_BACKGROUND
 
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  3,  10,  79,  16,  27, STR_NEWGRF_ADD,              STR_NEWGRF_ADD_TIP },               // SNGRFS_ADD
 
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  3,  80, 149,  16,  27, STR_NEWGRF_REMOVE,           STR_NEWGRF_REMOVE_TIP },            // SNGRFS_REMOVE
 
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  3, 150, 219,  16,  27, STR_NEWGRF_MOVEUP,           STR_NEWGRF_MOVEUP_TIP },            // SNGRFS_MOVE_UP
 
{ WWT_PUSHTXTBTN,  RESIZE_NONE,  3, 220, 289,  16,  27, STR_NEWGRF_MOVEDOWN,         STR_NEWGRF_MOVEDOWN_TIP },          // SNGRFS_MOVE_DOWN
 
{ WWT_PUSHTXTBTN, RESIZE_RIGHT,  3, 220, 289,  16,  27, STR_NEWGRF_MOVEDOWN,         STR_NEWGRF_MOVEDOWN_TIP },          // SNGRFS_MOVE_DOWN
 
{     WWT_MATRIX,    RESIZE_RB, 10,   0, 287,  30,  99, 0x501,                       STR_NEWGRF_FILE_TIP },              // SNGRFS_FILE_LIST
 
{  WWT_SCROLLBAR,   RESIZE_LRB, 10, 288, 299,  30,  99, 0x0,                         STR_0190_SCROLL_BAR_SCROLLS_LIST }, // SNGRFS_SCROLLBAR
 
{      WWT_PANEL,   RESIZE_RTB, 10,   0, 299, 100, 212, STR_NULL,                    STR_NULL },                         // SNGRFS_NEWGRF_INFO
 
{ WWT_PUSHTXTBTN,    RESIZE_TB, 10,   0, 143, 213, 224, STR_NEWGRF_SET_PARAMETERS,   STR_NULL },                         // SNGRFS_SET_PARAMETERS
 
{ WWT_PUSHTXTBTN,   RESIZE_RTB, 10, 144, 287, 213, 224, STR_NEWGRF_APPLY_CHANGES,    STR_NULL },                         // SNGRFS_APPLY_CHANGES
 
{  WWT_RESIZEBOX,  RESIZE_LRTB, 10, 288, 299, 213, 224, 0x0,                         STR_RESIZE_BUTTON },                // SNGRFS_RESIZE
 
{ WIDGETS_END },
 
};
 

	
 
/* Window definition of the manage newgrfs window */
 
static const WindowDesc _newgrf_desc = {
 
	WDP_CENTER, WDP_CENTER, 300, 225, 300, 225,
 
	WC_GAME_OPTIONS, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
 
	_newgrf_widgets,
 
	NewGRFWndProc,
 
};
 

	
 

	
 
/** Setup the NewGRF gui
 
 * @param editable allow the user to make changes to the grfconfig in the window
 
 * @param show_params show information about what parameters are set for the grf files
 
 * @param exec_changes if changes are made to the list (editable is true), apply these
 
 *        changes immediately or only update the list
 
 * @param config pointer to a linked-list of grfconfig's that will be shown */
 
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
 
{
 
	static GRFConfig *local = NULL;
 
	Window *w;
 

	
 
	DeleteWindowByClass(WC_GAME_OPTIONS);
 
	w = AllocateWindowDesc(&_newgrf_desc);
 
	if (w == NULL) return;
 

	
 
	w->resize.step_height = 14;
 
	CopyGRFConfigList(&local, *config, false);
 

	
 
	/* Clear selections */
 
	WP(w, newgrf_d).sel         = NULL;
 
	WP(w, newgrf_d).list        = &local;
 
	WP(w, newgrf_d).orig_list   = config;
 
	WP(w, newgrf_d).editable    = editable;
 
	WP(w, newgrf_d).execute     = exec_changes;
 
	WP(w, newgrf_d).show_params = show_params;
 

	
 
	SetupNewGRFWindow(w);
 
}
0 comments (0 inline, 0 general)