1
0
Fork 0

(svn r13073) -Codechange: make classes of the NewGRF windows

release/0.7
peter1138 2008-05-13 20:26:48 +00:00
parent ad8057ab76
commit 153acec334
1 changed files with 394 additions and 401 deletions

View File

@ -109,15 +109,12 @@ static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint w, uint bott
} }
/* Dialogue for adding NewGRF files to the selection */ /**
struct newgrf_add_d { * Window for adding NewGRF files
GRFConfig **list; */
const GRFConfig *sel; struct NewGRFAddWindow : public Window {
}; /* Names of the add a newgrf window widgets */
assert_compile(WINDOW_CUSTOM_SIZE >= sizeof(newgrf_add_d)); enum AddNewGRFWindowWidgets {
/* Names of the add a newgrf window widgets */
enum AddNewGRFWindowWidgets {
ANGRFW_CLOSEBOX = 0, ANGRFW_CLOSEBOX = 0,
ANGRFW_CAPTION, ANGRFW_CAPTION,
ANGRFW_BACKGROUND, ANGRFW_BACKGROUND,
@ -127,72 +124,81 @@ enum AddNewGRFWindowWidgets {
ANGRFW_ADD, ANGRFW_ADD,
ANGRFW_RESCAN, ANGRFW_RESCAN,
ANGRFW_RESIZE, ANGRFW_RESIZE,
}; };
static void NewGRFAddDlgWndProc(Window *w, WindowEvent *e) GRFConfig **list;
{ const GRFConfig *sel;
switch (e->event) {
case WE_PAINT: { NewGRFAddWindow(const WindowDesc *desc, GRFConfig **list) : Window(desc, 0)
{
this->list = list;
this->resize.step_height = 10;
this->FindWindowPlacementAndResize(desc);
}
virtual void OnPaint()
{
const GRFConfig *c; const GRFConfig *c;
const Widget *wl = &w->widget[ANGRFW_GRF_LIST]; const Widget *wl = &this->widget[ANGRFW_GRF_LIST];
int n = 0; int n = 0;
/* Count the number of GRFs */ /* Count the number of GRFs */
for (c = _all_grfs; c != NULL; c = c->next) n++; for (c = _all_grfs; c != NULL; c = c->next) n++;
w->vscroll.cap = (wl->bottom - wl->top) / 10; this->vscroll.cap = (wl->bottom - wl->top) / 10;
SetVScrollCount(w, n); SetVScrollCount(this, n);
w->SetWidgetDisabledState(ANGRFW_ADD, WP(w, newgrf_add_d).sel == NULL || WP(w, newgrf_add_d).sel->IsOpenTTDBaseGRF()); this->SetWidgetDisabledState(ANGRFW_ADD, this->sel == NULL || this->sel->IsOpenTTDBaseGRF());
DrawWindowWidgets(w); DrawWindowWidgets(this);
GfxFillRect(wl->left + 1, wl->top + 1, wl->right, wl->bottom, 0xD7); GfxFillRect(wl->left + 1, wl->top + 1, wl->right, wl->bottom, 0xD7);
uint y = wl->top + 1; uint y = wl->top + 1;
for (c = _all_grfs, n = 0; c != NULL && n < (w->vscroll.pos + w->vscroll.cap); c = c->next, n++) { for (c = _all_grfs, n = 0; c != NULL && n < (this->vscroll.pos + this->vscroll.cap); c = c->next, n++) {
if (n >= w->vscroll.pos) { if (n >= this->vscroll.pos) {
bool h = c == WP(w, newgrf_add_d).sel; bool h = c == this->sel;
const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename; const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename;
/* Draw selection background */ /* Draw selection background */
if (h) GfxFillRect(3, y, w->width - 15, y + 9, 156); if (h) GfxFillRect(3, y, this->width - 15, y + 9, 156);
DoDrawStringTruncated(text, 4, y, h ? TC_WHITE : TC_ORANGE, w->width - 18); DoDrawStringTruncated(text, 4, y, h ? TC_WHITE : TC_ORANGE, this->width - 18);
y += 10; y += 10;
} }
} }
if (WP(w, newgrf_add_d).sel != NULL) { if (this->sel != NULL) {
const Widget *wi = &w->widget[ANGRFW_GRF_INFO]; const Widget *wi = &this->widget[ANGRFW_GRF_INFO];
ShowNewGRFInfo(WP(w, newgrf_add_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, false); ShowNewGRFInfo(this->sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, false);
} }
break;
} }
case WE_DOUBLE_CLICK: virtual void OnDoubleClick(Point pt, int widget)
if (e->we.click.widget != ANGRFW_GRF_LIST) break; {
e->we.click.widget = ANGRFW_ADD; if (widget == ANGRFW_GRF_LIST) this->OnClick(pt, ANGRFW_ADD);
/* Fall through */ }
case WE_CLICK: virtual void OnClick(Point pt, int widget)
switch (e->we.click.widget) { {
switch (widget) {
case ANGRFW_GRF_LIST: { case ANGRFW_GRF_LIST: {
/* Get row... */ /* Get row... */
const GRFConfig *c; const GRFConfig *c;
uint i = (e->we.click.pt.y - w->widget[ANGRFW_GRF_LIST].top) / 10 + w->vscroll.pos; uint i = (pt.y - this->widget[ANGRFW_GRF_LIST].top) / 10 + this->vscroll.pos;
for (c = _all_grfs; c != NULL && i > 0; c = c->next, i--) {} for (c = _all_grfs; c != NULL && i > 0; c = c->next, i--) {}
WP(w, newgrf_add_d).sel = c; this->sel = c;
w->SetDirty(); this->SetDirty();
break; break;
} }
case ANGRFW_ADD: // Add selection to list case ANGRFW_ADD: // Add selection to list
if (WP(w, newgrf_add_d).sel != NULL) { if (this->sel != NULL) {
const GRFConfig *src = WP(w, newgrf_add_d).sel; const GRFConfig *src = this->sel;
GRFConfig **list; GRFConfig **list;
/* Find last entry in the list, checking for duplicate grfid on the way */ /* Find last entry in the list, checking for duplicate grfid on the way */
for (list = WP(w, newgrf_add_d).list; *list != NULL; list = &(*list)->next) { for (list = this->list; *list != NULL; list = &(*list)->next) {
if ((*list)->grfid == src->grfid) { if ((*list)->grfid == src->grfid) {
ShowErrorMessage(INVALID_STRING_ID, STR_NEWGRF_DUPLICATE_GRFID, 0, 0); ShowErrorMessage(INVALID_STRING_ID, STR_NEWGRF_DUPLICATE_GRFID, 0, 0);
return; return;
@ -216,14 +222,13 @@ static void NewGRFAddDlgWndProc(Window *w, WindowEvent *e)
break; break;
case ANGRFW_RESCAN: // Rescan list case ANGRFW_RESCAN: // Rescan list
WP(w, newgrf_add_d).sel = NULL; this->sel = NULL;
ScanNewGRFFiles(); ScanNewGRFFiles();
w->SetDirty(); this->SetDirty();
break; break;
} }
break;
} }
} };
/* Widget definition for the add a newgrf window */ /* Widget definition for the add a newgrf window */
static const Widget _newgrf_add_dlg_widgets[] = { static const Widget _newgrf_add_dlg_widgets[] = {
@ -245,24 +250,18 @@ static const WindowDesc _newgrf_add_dlg_desc = {
WC_SAVELOAD, WC_NONE, WC_SAVELOAD, WC_NONE,
WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
_newgrf_add_dlg_widgets, _newgrf_add_dlg_widgets,
NewGRFAddDlgWndProc, NULL,
}; };
/* 'NewGRF Settings' dialogue */ static void NewGRFConfirmationCallback(Window *w, bool confirmed);
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 */ * Window for showing NewGRF files
enum ShowNewGRFStateWidgets { */
struct NewGRFWindow : public Window {
/* Names of the manage newgrfs window widgets */
enum ShowNewGRFStateWidgets {
SNGRFS_CLOSEBOX = 0, SNGRFS_CLOSEBOX = 0,
SNGRFS_CAPTION, SNGRFS_CAPTION,
SNGRFS_BACKGROUND, SNGRFS_BACKGROUND,
@ -276,83 +275,83 @@ enum ShowNewGRFStateWidgets {
SNGRFS_SET_PARAMETERS, SNGRFS_SET_PARAMETERS,
SNGRFS_APPLY_CHANGES, SNGRFS_APPLY_CHANGES,
SNGRFS_RESIZE, SNGRFS_RESIZE,
}; };
static void SetupNewGRFState(Window *w) GRFConfig **orig_list; ///< grf list the window is shown with
{ GRFConfig *list; ///< temporary grf list to which changes are made
bool disable_all = WP(w, newgrf_d).sel == NULL || !WP(w, newgrf_d).editable; 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
w->SetWidgetDisabledState(SNGRFS_ADD, !WP(w, newgrf_d).editable); NewGRFWindow(const WindowDesc *desc, bool editable, bool show_params, bool exec_changes, GRFConfig **config) : Window(desc, 0)
w->SetWidgetsDisabledState(disable_all, {
this->resize.step_height = 14;
this->sel = NULL;
this->list = NULL;
this->orig_list = config;
this->editable = editable;
this->execute = exec_changes;
this->show_params = show_params;
CopyGRFConfigList(&this->list, *config, false);
this->FindWindowPlacementAndResize(desc);
this->SetupNewGRFWindow();
}
~NewGRFWindow()
{
if (!this->execute) {
CopyGRFConfigList(this->orig_list, this->list, true);
ResetGRFConfig(false);
ReloadNewGRFData();
}
/* Remove the temporary copy of grf-list used in window */
ClearGRFConfigList(&this->list);
}
void SetupNewGRFWindow()
{
const GRFConfig *c;
int i;
for (c = this->list, i = 0; c != NULL; c = c->next, i++) {}
this->vscroll.cap = (this->widget[SNGRFS_FILE_LIST].bottom - this->widget[SNGRFS_FILE_LIST].top) / 14 + 1;
SetVScrollCount(this, i);
this->SetWidgetDisabledState(SNGRFS_ADD, !this->editable);
this->SetWidgetDisabledState(SNGRFS_APPLY_CHANGES, !this->editable);
}
virtual void OnPaint()
{
bool disable_all = this->sel == NULL || !this->editable;
this->SetWidgetsDisabledState(disable_all,
SNGRFS_REMOVE, SNGRFS_REMOVE,
SNGRFS_MOVE_UP, SNGRFS_MOVE_UP,
SNGRFS_MOVE_DOWN, SNGRFS_MOVE_DOWN,
WIDGET_LIST_END WIDGET_LIST_END
); );
w->SetWidgetDisabledState(SNGRFS_SET_PARAMETERS, !WP(w, newgrf_d).show_params || disable_all); this->SetWidgetDisabledState(SNGRFS_SET_PARAMETERS, !this->show_params || disable_all);
if (!disable_all) { if (!disable_all) {
/* All widgets are now enabled, so disable widgets we can't use */ /* 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 (this->sel == this->list) this->DisableWidget(SNGRFS_MOVE_UP);
if (WP(w, newgrf_d).sel->next == NULL) w->DisableWidget(SNGRFS_MOVE_DOWN); if (this->sel->next == NULL) this->DisableWidget(SNGRFS_MOVE_DOWN);
if (WP(w, newgrf_d).sel->IsOpenTTDBaseGRF()) w->DisableWidget(SNGRFS_REMOVE); if (this->sel->IsOpenTTDBaseGRF()) this->DisableWidget(SNGRFS_REMOVE);
} }
}
DrawWindowWidgets(this);
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--) {}
nd->sel = c;
w->SetDirty();
}
}
static void NewGRFWndProc(Window *w, WindowEvent *e)
{
switch (e->event) {
case WE_PAINT: {
const GRFConfig *c;
int i, y;
SetupNewGRFState(w);
DrawWindowWidgets(w);
/* Draw NewGRF list */ /* Draw NewGRF list */
y = w->widget[SNGRFS_FILE_LIST].top; int y = this->widget[SNGRFS_FILE_LIST].top;
for (c = *WP(w, newgrf_d).list, i = 0; c != NULL; c = c->next, i++) { int i = 0;
if (i >= w->vscroll.pos && i < w->vscroll.pos + w->vscroll.cap) { for (const GRFConfig *c = this->list; c != NULL; c = c->next, i++) {
if (i >= this->vscroll.pos && i < this->vscroll.pos + this->vscroll.cap) {
const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename; const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename;
SpriteID pal; SpriteID pal;
byte txtoffset; byte txtoffset;
@ -383,165 +382,151 @@ static void NewGRFWndProc(Window *w, WindowEvent *e)
DrawSprite(SPR_SQUARE, pal, 5, y + 2); DrawSprite(SPR_SQUARE, pal, 5, y + 2);
if (c->error != NULL) DrawSprite(SPR_WARNING_SIGN, 0, 20, y + 2); if (c->error != NULL) DrawSprite(SPR_WARNING_SIGN, 0, 20, y + 2);
txtoffset = c->error != NULL ? 35 : 25; txtoffset = c->error != NULL ? 35 : 25;
DoDrawStringTruncated(text, txtoffset, y + 3, WP(w, newgrf_d).sel == c ? TC_WHITE : TC_BLACK, w->width - txtoffset - 10); DoDrawStringTruncated(text, txtoffset, y + 3, this->sel == c ? TC_WHITE : TC_BLACK, this->width - txtoffset - 10);
y += 14; y += 14;
} }
} }
if (WP(w, newgrf_d).sel != NULL) { if (this->sel != NULL) {
/* Draw NewGRF file info */ /* Draw NewGRF file info */
const Widget *wi = &w->widget[SNGRFS_NEWGRF_INFO]; const Widget *wi = &this->widget[SNGRFS_NEWGRF_INFO];
ShowNewGRFInfo(WP(w, newgrf_d).sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, WP(w, newgrf_d).show_params); ShowNewGRFInfo(this->sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, this->show_params);
}
} }
break; virtual void OnClick(Point pt, int widget)
} {
switch (widget) {
case WE_INVALIDATE_DATA: case SNGRFS_ADD: // Add GRF
SetupNewGRFWindow(w);
break;
case WE_CLICK:
switch (e->we.click.widget) {
case SNGRFS_ADD: { // Add GRF
GRFConfig **list = WP(w, newgrf_d).list;
Window *w;
DeleteWindowByClass(WC_SAVELOAD); DeleteWindowByClass(WC_SAVELOAD);
w = new Window(&_newgrf_add_dlg_desc); new NewGRFAddWindow(&_newgrf_add_dlg_desc, &this->list);
w->resize.step_height = 10;
WP(w, newgrf_add_d).list = list;
break; break;
}
case SNGRFS_REMOVE: { // Remove GRF case SNGRFS_REMOVE: { // Remove GRF
GRFConfig **pc, *c, *newsel; GRFConfig **pc, *c, *newsel;
/* Choose the next GRF file to be the selected file */ /* Choose the next GRF file to be the selected file */
newsel = WP(w, newgrf_d).sel->next; newsel = this->sel->next;
for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) { for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) {
/* If the new selection is empty (i.e. we're deleting the last item /* If the new selection is empty (i.e. we're deleting the last item
* in the list, pick the file just before the selected file */ * in the list, pick the file just before the selected file */
if (newsel == NULL && c->next == WP(w, newgrf_d).sel) newsel = c; if (newsel == NULL && c->next == this->sel) newsel = c;
if (c == WP(w, newgrf_d).sel) { if (c == this->sel) {
*pc = c->next; *pc = c->next;
free(c); free(c);
break; break;
} }
} }
WP(w, newgrf_d).sel = newsel; this->sel = newsel;
SetupNewGRFWindow(w); this->SetupNewGRFWindow();
w->SetDirty(); this->SetDirty();
break; break;
} }
case SNGRFS_MOVE_UP: { // Move GRF up case SNGRFS_MOVE_UP: { // Move GRF up
GRFConfig **pc, *c; GRFConfig **pc, *c;
if (WP(w, newgrf_d).sel == NULL) break; if (this->sel == NULL) break;
for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) { for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) {
if (c->next == WP(w, newgrf_d).sel) { if (c->next == this->sel) {
c->next = WP(w, newgrf_d).sel->next; c->next = this->sel->next;
WP(w, newgrf_d).sel->next = c; this->sel->next = c;
*pc = WP(w, newgrf_d).sel; *pc = this->sel;
break; break;
} }
} }
w->SetDirty(); this->SetDirty();
break; break;
} }
case SNGRFS_MOVE_DOWN: { // Move GRF down case SNGRFS_MOVE_DOWN: { // Move GRF down
GRFConfig **pc, *c; GRFConfig **pc, *c;
if (WP(w, newgrf_d).sel == NULL) break; if (this->sel == NULL) break;
for (pc = WP(w, newgrf_d).list; (c = *pc) != NULL; pc = &c->next) { for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) {
if (c == WP(w, newgrf_d).sel) { if (c == this->sel) {
*pc = c->next; *pc = c->next;
c->next = c->next->next; c->next = c->next->next;
(*pc)->next = c; (*pc)->next = c;
break; break;
} }
} }
w->SetDirty(); this->SetDirty();
break; break;
} }
case SNGRFS_FILE_LIST: { // Select a GRF case SNGRFS_FILE_LIST: { // Select a GRF
GRFConfig *c; GRFConfig *c;
uint i = (e->we.click.pt.y - w->widget[SNGRFS_FILE_LIST].top) / 14 + w->vscroll.pos; uint i = (pt.y - this->widget[SNGRFS_FILE_LIST].top) / 14 + this->vscroll.pos;
for (c = *WP(w, newgrf_d).list; c != NULL && i > 0; c = c->next, i--) {} for (c = this->list; c != NULL && i > 0; c = c->next, i--) {}
WP(w, newgrf_d).sel = c; this->sel = c;
w->SetDirty(); this->SetDirty();
break; break;
} }
case SNGRFS_APPLY_CHANGES: // Apply changes made to GRF list case SNGRFS_APPLY_CHANGES: // Apply changes made to GRF list
if (WP(w, newgrf_d).execute) { if (this->execute) {
ShowQuery( ShowQuery(
STR_POPUP_CAUTION_CAPTION, STR_POPUP_CAUTION_CAPTION,
STR_NEWGRF_CONFIRMATION_TEXT, STR_NEWGRF_CONFIRMATION_TEXT,
w, this,
NewGRFConfirmationCallback NewGRFConfirmationCallback
); );
} else { } else {
CopyGRFConfigList(WP(w, newgrf_d).orig_list, *WP(w, newgrf_d).list, true); CopyGRFConfigList(this->orig_list, this->list, true);
ResetGRFConfig(false); ResetGRFConfig(false);
ReloadNewGRFData(); ReloadNewGRFData();
} }
break; break;
case SNGRFS_SET_PARAMETERS: { // Edit parameters case SNGRFS_SET_PARAMETERS: { // Edit parameters
if (this->sel == NULL) break;
char buff[512]; char buff[512];
if (WP(w, newgrf_d).sel == NULL) break; GRFBuildParamList(buff, this->sel, lastof(buff));
ShowQueryString(BindCString(buff), STR_NEWGRF_PARAMETER_QUERY, 63, 250, this, CS_ALPHANUMERAL);
GRFBuildParamList(buff, WP(w, newgrf_d).sel, lastof(buff));
ShowQueryString(BindCString(buff), STR_NEWGRF_PARAMETER_QUERY, 63, 250, w, CS_ALPHANUMERAL);
break; break;
} }
} }
break; }
virtual void OnQueryTextFinished(char *str)
{
if (str == NULL) return;
case WE_ON_EDIT_TEXT:
if (e->we.edittext.str != NULL) {
/* Parse our new "int list" */ /* Parse our new "int list" */
GRFConfig *c = WP(w, newgrf_d).sel; GRFConfig *c = this->sel;
c->num_params = parse_intlist(e->we.edittext.str, (int*)c->param, lengthof(c->param)); c->num_params = parse_intlist(str, (int*)c->param, lengthof(c->param));
/* parse_intlist returns -1 on error */ /* parse_intlist returns -1 on error */
if (c->num_params == (byte)-1) c->num_params = 0; if (c->num_params == (byte)-1) c->num_params = 0;
w->SetDirty(); this->SetDirty();
} }
break;
case WE_DESTROY: virtual void OnResize(Point new_size, Point delta)
if (!WP(w, newgrf_d).execute) { {
CopyGRFConfigList(WP(w, newgrf_d).orig_list, *WP(w, newgrf_d).list, true); if (delta.x != 0) {
ResetGRFConfig(false); ResizeButtons(this, SNGRFS_ADD, SNGRFS_MOVE_DOWN);
ReloadNewGRFData(); ResizeButtons(this, SNGRFS_SET_PARAMETERS, SNGRFS_APPLY_CHANGES);
} }
/* Remove the temporary copy of grf-list used in window */
ClearGRFConfigList(WP(w, newgrf_d).list);
break;
case WE_RESIZE: this->vscroll.cap += delta.y / 14;
if (e->we.sizing.diff.x != 0) { this->widget[SNGRFS_FILE_LIST].data = (this->vscroll.cap << 8) + 1;
ResizeButtons(w, SNGRFS_ADD, SNGRFS_MOVE_DOWN);
ResizeButtons(w, SNGRFS_SET_PARAMETERS, SNGRFS_APPLY_CHANGES); this->SetupNewGRFWindow();
} }
w->vscroll.cap += e->we.sizing.diff.y / 14;
w->widget[SNGRFS_FILE_LIST].data = (w->vscroll.cap << 8) + 1; virtual void OnInvalidateData(int data = 0)
SetupNewGRFWindow(w); {
break; this->SetupNewGRFWindow();
} }
} };
/* Widget definition of the manage newgrfs window */ /* Widget definition of the manage newgrfs window */
static const Widget _newgrf_widgets[] = { static const Widget _newgrf_widgets[] = {
@ -567,9 +552,34 @@ static const WindowDesc _newgrf_desc = {
WC_GAME_OPTIONS, WC_NONE, WC_GAME_OPTIONS, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE,
_newgrf_widgets, _newgrf_widgets,
NewGRFWndProc, NULL,
}; };
/** 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) {
NewGRFWindow *nw = dynamic_cast<NewGRFWindow*>(w);
GRFConfig *c;
int i = 0;
CopyGRFConfigList(nw->orig_list, nw->list, false);
ReloadNewGRFData();
/* Show new, updated list */
for (c = nw->list; c != NULL && c != nw->sel; c = c->next, i++) {}
CopyGRFConfigList(&nw->list, *nw->orig_list, false);
for (c = nw->list; c != NULL && i > 0; c = c->next, i--) {}
nw->sel = c;
w->SetDirty();
}
}
/** Setup the NewGRF gui /** Setup the NewGRF gui
* @param editable allow the user to make changes to the grfconfig in the window * @param editable allow the user to make changes to the grfconfig in the window
@ -579,23 +589,6 @@ static const WindowDesc _newgrf_desc = {
* @param config pointer to a linked-list of grfconfig's that will be shown */ * @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) void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config)
{ {
static GRFConfig *local = NULL;
Window *w;
DeleteWindowByClass(WC_GAME_OPTIONS); DeleteWindowByClass(WC_GAME_OPTIONS);
w = new Window(&_newgrf_desc); new NewGRFWindow(&_newgrf_desc, editable, show_params, exec_changes, config);
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);
} }