diff -r 8adfbd8b2cc3 src/lang/english.txt --- src/lang/english.txt Thu Jan 15 07:48:00 2009 +0100 +++ src/lang/english.txt Thu Jan 15 08:22:45 2009 +0100 @@ -3234,6 +3234,7 @@ STR_NEWGRF_TIP :{BLACK}A list of all the Newgrf sets that you have installed. Click a set to change the settings STR_NEWGRF_NO_FILES_INSTALLED :{BLACK}There are currently no newgrf files installed! Please refer to the manual for instructions on installing new graphics STR_NEWGRF_FILENAME :{BLACK}Filename: {SILVER}{RAW_STRING} +STR_NEWGRF_NAME :{BLACK}Name: {SILVER}{RAW_STRING} STR_NEWGRF_PALETTE :{BLACK}Palette: {SILVER}{RAW_STRING} STR_NEWGRF_GRF_ID :{BLACK}GRF ID: {SILVER}{RAW_STRING} STR_NEWGRF_MD5SUM :{BLACK}MD5sum: {SILVER}{RAW_STRING} @@ -3269,19 +3270,23 @@ STR_NEWGRF_ADD_TIP :{BLACK}Add a NewGRF file to the list STR_NEWGRF_REMOVE :{BLACK}Remove STR_NEWGRF_REMOVE_TIP :{BLACK}Remove the selected NewGRF file from the list -STR_NEWGRF_MOVEUP :{BLACK}Move Up +STR_NEWGRF_JOINT_ADD :{BLACK}>> +STR_NEWGRF_JOINT_REMOVE :{BLACK}<< +STR_NEWGRF_TOGGLE_SHOW :{BLACK}Disp. Mode +STR_NEWGRF_TOGGLE_SHOW_TIP :{BLACK}Toggles filtering of already selected grfs in the left list. Ctrl-click toggles show file names in stead of grf names. STR_NEWGRF_MOVEUP_TIP :{BLACK}Move the selected NewGRF file up the list -STR_NEWGRF_MOVEDOWN :{BLACK}Move Down +STR_NEWGRF_MOVEUP :{BLACK}Up +STR_NEWGRF_MOVEDOWN :{BLACK}Down STR_NEWGRF_MOVEDOWN_TIP :{BLACK}Move the selected NewGRF file down the list STR_NEWGRF_FILE_TIP :{BLACK}A list of the NewGRF files that are installed. Click a file to change its parameters STR_NEWGRF_PARAMETER :{BLACK}Parameters: {SILVER}{STRING1} STR_NEWGRF_PARAMETER_QUERY :{BLACK}Enter NewGRF parameters STR_NEWGRF_NO_INFO :{BLACK}No information available -STR_NEWGRF_ADD_CAPTION :{WHITE}Available NewGRF files +STR_NEWGRF_ADD_CAPTION :{WHITE}Available NewGRFs STR_NEWGRF_ADD_FILE :{BLACK}Add to selection STR_NEWGRF_ADD_FILE_TIP :{BLACK}Add the selected NewGRF file to your configuration -STR_NEWGRF_RESCAN_FILES :{BLACK}Rescan files +STR_NEWGRF_RESCAN_FILES :{BLACK}Rescan STR_NEWGRF_RESCAN_FILES_TIP :{BLACK}Update the list of available NewGRF files STR_NEWGRF_DUPLICATE_GRFID :{WHITE}Can't add file: duplicate GRF ID diff -r 8adfbd8b2cc3 src/newgrf_gui.cpp --- src/newgrf_gui.cpp Thu Jan 15 07:48:00 2009 +0100 +++ src/newgrf_gui.cpp Thu Jan 15 08:22:45 2009 +0100 @@ -15,6 +15,7 @@ #include "core/alloc_func.hpp" #include "string_func.h" #include "gfx_func.h" +#include "tilehighlight_func.h" #include "gamelog.h" #include "settings_func.h" #include "widgets/dropdown_type.h" @@ -47,7 +48,7 @@ } -static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint w, uint bottom, bool show_params) +static void ShowNewGRFInfo(const GRFConfig *c, uint x, uint y, uint w, uint bottom, bool show_params, bool show_filenames) { char buff[256]; @@ -74,8 +75,8 @@ /* Draw filename or not if it is not known (GRF sent over internet) */ if (c->filename != NULL) { - SetDParamStr(0, c->filename); - y += DrawStringMultiLine(x, y, STR_NEWGRF_FILENAME, w, bottom - y); + SetDParamStr(0, (show_filenames) ? c->name : c->filename); + y += DrawStringMultiLine(x, y, (show_filenames) ? STR_NEWGRF_NAME : STR_NEWGRF_FILENAME, w, bottom - y); } /* Prepare and draw GRF ID */ @@ -119,150 +120,6 @@ } } - -/** - * Window for adding NewGRF files - */ -struct NewGRFAddWindow : public Window { - /* Names of the add a newgrf window widgets */ - enum AddNewGRFWindowWidgets { - ANGRFW_CLOSEBOX = 0, - ANGRFW_CAPTION, - ANGRFW_BACKGROUND, - ANGRFW_GRF_LIST, - ANGRFW_SCROLLBAR, - ANGRFW_GRF_INFO, - ANGRFW_ADD, - ANGRFW_RESCAN, - ANGRFW_RESIZE, - }; - - GRFConfig **list; - const GRFConfig *sel; - - 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 Widget *wl = &this->widget[ANGRFW_GRF_LIST]; - int n = 0; - - /* Count the number of GRFs */ - for (c = _all_grfs; c != NULL; c = c->next) n++; - - this->vscroll.cap = (wl->bottom - wl->top) / 10; - SetVScrollCount(this, n); - - this->SetWidgetDisabledState(ANGRFW_ADD, this->sel == NULL || this->sel->IsOpenTTDBaseGRF()); - this->DrawWidgets(); - - GfxFillRect(wl->left + 1, wl->top + 1, wl->right, wl->bottom, 0xD7); - - uint y = wl->top + 1; - for (c = _all_grfs, n = 0; c != NULL && n < (this->vscroll.pos + this->vscroll.cap); c = c->next, n++) { - if (n >= this->vscroll.pos) { - bool h = c == this->sel; - const char *text = (c->name != NULL && !StrEmpty(c->name)) ? c->name : c->filename; - - /* Draw selection background */ - if (h) GfxFillRect(3, y, this->width - 15, y + 9, 156); - DoDrawStringTruncated(text, 4, y, h ? TC_WHITE : TC_ORANGE, this->width - 18); - y += 10; - } - } - - if (this->sel != NULL) { - const Widget *wi = &this->widget[ANGRFW_GRF_INFO]; - ShowNewGRFInfo(this->sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, false); - } - } - - virtual void OnDoubleClick(Point pt, int widget) - { - if (widget == ANGRFW_GRF_LIST) this->OnClick(pt, ANGRFW_ADD); - } - - virtual void OnClick(Point pt, int widget) - { - switch (widget) { - case ANGRFW_GRF_LIST: { - /* Get row... */ - const GRFConfig *c; - 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--) {} - this->sel = c; - this->SetDirty(); - break; - } - - case ANGRFW_ADD: // Add selection to list - if (this->sel != NULL) { - const GRFConfig *src = this->sel; - GRFConfig **list; - - /* Find last entry in the list, checking for duplicate grfid on the way */ - for (list = this->list; *list != NULL; list = &(*list)->next) { - if ((*list)->grfid == src->grfid) { - ShowErrorMessage(INVALID_STRING_ID, STR_NEWGRF_DUPLICATE_GRFID, 0, 0); - return; - } - } - - /* Copy GRF details from scanned list */ - GRFConfig *c = CallocT(1); - *c = *src; - c->filename = strdup(src->filename); - if (src->name != NULL) c->name = strdup(src->name); - if (src->info != NULL) c->info = strdup(src->info); - c->next = NULL; - - /* Append GRF config to configuration list */ - *list = c; - - DeleteWindowByClass(WC_SAVELOAD); - InvalidateWindowData(WC_GAME_OPTIONS, 0); - } - break; - - case ANGRFW_RESCAN: // Rescan list - this->sel = NULL; - ScanNewGRFFiles(); - this->SetDirty(); - break; - } - } -}; - -/* Widget definition for the add a newgrf window */ -static const Widget _newgrf_add_dlg_widgets[] = { -{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_GREY, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, // ANGRFW_CLOSEBOX -{ WWT_CAPTION, RESIZE_RIGHT, COLOUR_GREY, 11, 306, 0, 13, STR_NEWGRF_ADD_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS }, // ANGRFW_CAPTION -{ WWT_PANEL, RESIZE_RB, COLOUR_GREY, 0, 294, 14, 121, 0x0, STR_NULL }, // ANGRFW_BACKGROUND -{ WWT_INSET, RESIZE_RB, COLOUR_GREY, 2, 292, 16, 119, 0x0, STR_NULL }, // ANGRFW_GRF_LIST -{ WWT_SCROLLBAR, RESIZE_LRB, COLOUR_GREY, 295, 306, 14, 121, 0x0, STR_NULL }, // ANGRFW_SCROLLBAR -{ WWT_PANEL, RESIZE_RTB, COLOUR_GREY, 0, 306, 122, 224, 0x0, STR_NULL }, // ANGRFW_GRF_INFO -{ WWT_PUSHTXTBTN, RESIZE_RTB, COLOUR_GREY, 0, 146, 225, 236, STR_NEWGRF_ADD_FILE, STR_NEWGRF_ADD_FILE_TIP }, // ANGRFW_ADD -{ WWT_PUSHTXTBTN, RESIZE_LRTB, COLOUR_GREY, 147, 294, 225, 236, STR_NEWGRF_RESCAN_FILES, STR_NEWGRF_RESCAN_FILES_TIP }, // ANGRFW_RESCAN -{ WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_GREY, 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, -}; - static GRFPresetList _grf_preset_list; class DropDownListPresetItem : public DropDownListItem { @@ -285,44 +142,60 @@ static void NewGRFConfirmationCallback(Window *w, bool confirmed); /** - * Window for showing NewGRF files + * Combined NewGrf Window */ struct NewGRFWindow : public Window { - /* Names of the manage newgrfs window widgets */ - enum ShowNewGRFStateWidgets { - SNGRFS_CLOSEBOX = 0, + + /* Names of the window widgets */ + enum NewGRFListWindowWidgets { + SNGRFS_CLOSE = 0, SNGRFS_CAPTION, - SNGRFS_BACKGROUND1, + SNGRFS_EMPTY_PRESET, SNGRFS_PRESET_LIST, SNGRFS_PRESET_SAVE, SNGRFS_PRESET_DELETE, - SNGRFS_BACKGROUND2, - SNGRFS_ADD, + SNGRFS_AVAILABLE_GRF_CAPTION, + SNGRFS_EMPTY_GRF_LIST, + SNGRFS_AVAILABLE_GRF_LIST, + SNGRFS_AVAILABLE_GRF_LIST_SCROLLBAR, + SNGRFS_NEWGRF_INFO_LEFT, + SNGRFS_RESCAN_FILES, + SNGRFS_TOGGLE_SHOW_MODE, + SNGRFS_EMPTY_MIDDLE, + SNGRFS_EMPTY_BOTTOM_MIDDLE, + SNGRFS_EMPTY_TOP_RIGHT, + SNGRFS_ADD_FILE, SNGRFS_REMOVE, SNGRFS_MOVE_UP, SNGRFS_MOVE_DOWN, SNGRFS_FILE_LIST, - SNGRFS_SCROLLBAR, - SNGRFS_NEWGRF_INFO, + SNGRFS_FILE_LIST_SCROLLBAR, + SNGRFS_NEWGRF_INFO_RIGHT, + SNGRFS_TOGGLE_PALETTE, SNGRFS_SET_PARAMETERS, - SNGRFS_TOGGLE_PALETTE, SNGRFS_APPLY_CHANGES, - SNGRFS_RESIZE, }; - - 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 - int query_widget; ///< widget that opened a query - int preset; ///< selected preset + + const GRFConfig *sel_l; + GRFConfig **orig_list; ///< grf list the window is shown with + GRFConfig *list; ///< temporary grf list to which changes are made + GRFConfig *sel_r; ///< 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 + bool show_all; + bool show_file_names; + int query_widget; ///< widget that opened a query + int preset; ///< selected preset NewGRFWindow(const WindowDesc *desc, bool editable, bool show_params, bool exec_changes, GRFConfig **config) : Window(desc, 0) { - this->resize.step_height = 14; - this->sel = NULL; + this->resize.step_height = 13; + this->resize.step_width = 8; + this->resize.height = this->height - 78; + this->resize.width = this->width / 2 - 64; + + this->sel_r = NULL; this->list = NULL; this->orig_list = config; this->editable = editable; @@ -337,6 +210,7 @@ this->SetupNewGRFWindow(); } + ~NewGRFWindow() { if (!this->execute) { @@ -350,28 +224,14 @@ _grf_preset_list.Clear(); } - void SetupNewGRFWindow() + virtual void OnPaint() { const GRFConfig *c; - int i; - for (c = this->list, i = 0; c != NULL; c = c->next, i++) {} + int i, y; + int n = 0; - this->vscroll.cap = (this->widget[SNGRFS_FILE_LIST].bottom - this->widget[SNGRFS_FILE_LIST].top) / 14 + 1; - SetVScrollCount(this, i); - - this->SetWidgetsDisabledState(!this->editable, - SNGRFS_PRESET_LIST, - SNGRFS_ADD, - SNGRFS_APPLY_CHANGES, - SNGRFS_TOGGLE_PALETTE, - WIDGET_LIST_END - ); - } - - virtual void OnPaint() - { - bool disable_all = this->sel == NULL || !this->editable; + bool disable_all = this->sel_r == NULL || !this->editable; this->SetWidgetsDisabledState(disable_all, SNGRFS_REMOVE, @@ -379,14 +239,24 @@ SNGRFS_MOVE_DOWN, WIDGET_LIST_END ); + + this->SetWidgetsDisabledState(!this->editable, + SNGRFS_RESCAN_FILES, + SNGRFS_NEWGRF_INFO_LEFT, + SNGRFS_AVAILABLE_GRF_LIST, + SNGRFS_APPLY_CHANGES, + WIDGET_LIST_END + ); + + this->SetWidgetDisabledState(SNGRFS_ADD_FILE, !this->editable || this->sel_l == NULL || this->sel_l->IsOpenTTDBaseGRF()); this->SetWidgetDisabledState(SNGRFS_SET_PARAMETERS, !this->show_params || disable_all); this->SetWidgetDisabledState(SNGRFS_TOGGLE_PALETTE, disable_all); if (!disable_all) { /* All widgets are now enabled, so disable widgets we can't use */ - if (this->sel == this->list) this->DisableWidget(SNGRFS_MOVE_UP); - if (this->sel->next == NULL) this->DisableWidget(SNGRFS_MOVE_DOWN); - if (this->sel->IsOpenTTDBaseGRF()) this->DisableWidget(SNGRFS_REMOVE); + if (this->sel_r == this->list) this->DisableWidget(SNGRFS_MOVE_UP); + if (this->sel_r->next == NULL) this->DisableWidget(SNGRFS_MOVE_DOWN); + if (this->sel_r->IsOpenTTDBaseGRF()) this->DisableWidget(SNGRFS_REMOVE); } if (this->preset == -1) { @@ -398,12 +268,32 @@ this->DrawWidgets(); + DrawStringCentered((this->widget[SNGRFS_AVAILABLE_GRF_CAPTION].right - this->widget[SNGRFS_AVAILABLE_GRF_CAPTION].left) / 2, 34, STR_NEWGRF_ADD_CAPTION, TC_WHITE); + GfxFillRect(this->widget[SNGRFS_AVAILABLE_GRF_LIST].left + 1, this->widget[SNGRFS_AVAILABLE_GRF_LIST].top + 1, this->widget[SNGRFS_AVAILABLE_GRF_LIST].right, this->widget[SNGRFS_AVAILABLE_GRF_LIST].bottom, 0xD7); + + n = 0; + y = this->widget[SNGRFS_AVAILABLE_GRF_LIST].top + 2; + for (c = _all_grfs; c != NULL; c = c->next) { + + if (IsInSelectedList(c->grfid)) continue; + + if (n >= this->vscroll.pos && n < this->vscroll.pos + this->vscroll.cap) { + bool h = (c == this->sel_l); + const char *text = (c->name != NULL && !StrEmpty(c->name) && !this->show_file_names) ? c->name : c->filename; + + /* Draw selection background */ + if (h) GfxFillRect(3, y, this->widget[SNGRFS_AVAILABLE_GRF_LIST].right - 4, y + 9, 156); + DoDrawStringTruncated(text, 4, y, h ? TC_WHITE : TC_ORANGE, this->widget[SNGRFS_AVAILABLE_GRF_LIST].right - 7); + y += 10; + } + n++; + } + /* Draw NewGRF list */ - int y = this->widget[SNGRFS_FILE_LIST].top; - int i = 0; - 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; + y = this->widget[SNGRFS_FILE_LIST].top; + for (c = this->list, i = 0; c != NULL; c = c->next, i++) { + if (i >= this->vscroll2.pos && i < this->vscroll2.pos + this->vscroll2.cap) { + const char *text = (c->name != NULL && !StrEmpty(c->name) && !this->show_file_names) ? c->name : c->filename; SpriteID pal; byte txtoffset; @@ -430,19 +320,79 @@ } } - DrawSprite(SPR_SQUARE, pal, 5, y + 2); - if (c->error != NULL) DrawSprite(SPR_WARNING_SIGN, 0, 20, y + 2); + DrawSprite(SPR_SQUARE, pal, this->widget[SNGRFS_FILE_LIST].left + 9, y + 1); + if (c->error != NULL) DrawSprite(SPR_WARNING_SIGN, 0, this->widget[SNGRFS_FILE_LIST].left + 21, y + 1); txtoffset = c->error != NULL ? 35 : 25; - DoDrawStringTruncated(text, txtoffset, y + 3, this->sel == c ? TC_WHITE : TC_BLACK, this->width - txtoffset - 10); - y += 14; + DoDrawStringTruncated(text, + this->widget[SNGRFS_FILE_LIST].left + txtoffset, y + 2, + this->sel_r == c ? TC_WHITE : TC_BLACK, + this->widget[SNGRFS_FILE_LIST].right - this->widget[SNGRFS_FILE_LIST].left - txtoffset); + y += 13; } } - if (this->sel != NULL) { + if (this->sel_r != NULL) { /* Draw NewGRF file info */ - const Widget *wi = &this->widget[SNGRFS_NEWGRF_INFO]; - ShowNewGRFInfo(this->sel, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, this->show_params); + const Widget *wi = &this->widget[SNGRFS_NEWGRF_INFO_RIGHT]; + ShowNewGRFInfo(this->sel_r, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, this->show_params, this->show_file_names); } + + if (this->sel_l != NULL) { + const Widget *wi = &this->widget[SNGRFS_NEWGRF_INFO_LEFT]; + ShowNewGRFInfo(this->sel_l, wi->left + 2, wi->top + 2, wi->right - wi->left - 2, wi->bottom, false, this->show_file_names); + } + + } + + virtual void OnInvalidateData(int data = 0) + { + this->preset = -1; + this->SetupNewGRFWindow(); + } + + virtual void OnDragMove(Point pt, int widget) + { + if (widget != SNGRFS_FILE_LIST) return; + + GRFConfig **pc, *c, *source, *target; + + if ((source = this->sel_r) == NULL) return; + + uint i = (pt.y - this->widget[SNGRFS_FILE_LIST].top) / 13 + this->vscroll2.pos; + for (c = this->list; c != NULL && i > 0; c = c->next, i--) + if (c == source) i += 1; + target = c; + + if (target == source) return; + + for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) { + if (c == source) + *pc = c->next; + else if (c->next == source) { + c->next = c->next->next; + } + } + + for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) { + if (c == target) { + *pc = source; + source->next = target; + } + else if (c->next == target) { + c->next = source; + source->next = target; + } + } + + this->SetDirty(); + } + + virtual void OnDoubleClick(Point pt, int widget) + { + if (widget == SNGRFS_AVAILABLE_GRF_LIST) + this->OnClick(pt, SNGRFS_ADD_FILE); + if (widget == SNGRFS_FILE_LIST && this->sel_r) + this->OnClick(pt, SNGRFS_REMOVE); } virtual void OnClick(Point pt, int widget) @@ -478,30 +428,96 @@ this->SetDirty(); break; - case SNGRFS_ADD: // Add GRF - DeleteWindowByClass(WC_SAVELOAD); - new NewGRFAddWindow(&_newgrf_add_dlg_desc, &this->list); + case SNGRFS_AVAILABLE_GRF_LIST: { + /* Get row... */ + const GRFConfig *c; + uint i = ((pt.y) - this->widget[SNGRFS_AVAILABLE_GRF_LIST].top) / 10 + this->vscroll.pos; + + c = _all_grfs; + while (c && IsInSelectedList(c->grfid) && c->next) { + c = c->next; + } + while (c != NULL && i > 0) + { + c = c->next; + while (c != NULL && IsInSelectedList(c->grfid) && c->next) { + c = c->next; + } + --i; + } + if (c && IsInSelectedList(c->grfid)) c = NULL; + this->sel_l = c; + this->SetDirty(); + break; + } + + case SNGRFS_ADD_FILE: // Add selection to list + if (this->sel_l != NULL && this->editable) { + const GRFConfig *src = this->sel_l; + GRFConfig **list; + + /* Find last entry in the list, checking for duplicate grfid on the way */ + for (list = &this->list; *list != NULL; list = &(*list)->next) { + if ((*list)->grfid == src->grfid) { + ShowErrorMessage(INVALID_STRING_ID, STR_NEWGRF_DUPLICATE_GRFID, 0, 0); + return; + } + } + + /* Copy GRF details from scanned list */ + GRFConfig *c = CallocT(1); + *c = *src; + c->filename = strdup(src->filename); + if (src->name != NULL) c->name = strdup(src->name); + if (src->info != NULL) c->info = strdup(src->info); + c->next = NULL; + + /* Append GRF config to configuration list */ + *list = c; + this->sel_l = NULL; + this->preset = -1; + this->SetupNewGRFWindow(); + this->SetDirty(); + } + break; + + case SNGRFS_RESCAN_FILES: // Rescan list + this->sel_l = NULL; + ScanNewGRFFiles(); + this->SetDirty(); + break; + + case SNGRFS_TOGGLE_SHOW_MODE: // Toggle show mode + if (_ctrl_pressed) { + this->show_file_names = !this->show_file_names; + } + else { + this->show_all = !this->show_all; + } + + this->SetupNewGRFWindow(); // Adjust scroll bars + this->SetDirty(); break; case SNGRFS_REMOVE: { // Remove GRF GRFConfig **pc, *c, *newsel; /* Choose the next GRF file to be the selected file */ - newsel = this->sel->next; + newsel = this->sel_r->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 * in the list, pick the file just before the selected file */ - if (newsel == NULL && c->next == this->sel) newsel = c; + if (newsel == NULL && c->next == this->sel_r) newsel = c; - if (c == this->sel) { + if (c == this->sel_r) { *pc = c->next; free(c); break; } } - this->sel = newsel; + this->sel_r = newsel; this->preset = -1; this->SetupNewGRFWindow(); this->SetDirty(); @@ -510,13 +526,13 @@ case SNGRFS_MOVE_UP: { // Move GRF up GRFConfig **pc, *c; - if (this->sel == NULL) break; + if (this->sel_r == NULL) break; for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) { - if (c->next == this->sel) { - c->next = this->sel->next; - this->sel->next = c; - *pc = this->sel; + if (c->next == this->sel_r) { + c->next = this->sel_r->next; + this->sel_r->next = c; + *pc = this->sel_r; break; } } @@ -527,10 +543,10 @@ case SNGRFS_MOVE_DOWN: { // Move GRF down GRFConfig **pc, *c; - if (this->sel == NULL) break; + if (this->sel_r == NULL) break; for (pc = &this->list; (c = *pc) != NULL; pc = &c->next) { - if (c == this->sel) { + if (c == this->sel_r) { *pc = c->next; c->next = c->next->next; (*pc)->next = c; @@ -544,11 +560,14 @@ case SNGRFS_FILE_LIST: { // Select a GRF GRFConfig *c; - uint i = (pt.y - this->widget[SNGRFS_FILE_LIST].top) / 14 + this->vscroll.pos; + uint i = (pt.y - this->widget[SNGRFS_FILE_LIST].top) / 13 + this->vscroll2.pos; - for (c = this->list; c != NULL && i > 0; c = c->next, i--) {} - this->sel = c; + for (c = this->list; c != NULL && i > 0; c = c->next, i--); + this->sel_r = c; + /* Activate drag and drop */ + SetObjectToPlaceWnd(SPR_CURSOR_MOUSE, PAL_NONE, VHM_DRAG, this); + this->SetDirty(); break; } @@ -569,19 +588,19 @@ break; case SNGRFS_SET_PARAMETERS: { // Edit parameters - if (this->sel == NULL) break; + if (this->sel_r == NULL) break; this->query_widget = widget; static char buff[512]; - GRFBuildParamList(buff, this->sel, lastof(buff)); + GRFBuildParamList(buff, this->sel_r, lastof(buff)); SetDParamStr(0, buff); ShowQueryString(STR_JUST_RAW_STRING, STR_NEWGRF_PARAMETER_QUERY, 63, 250, this, CS_ALPHANUMERAL, QSF_NONE); break; } case SNGRFS_TOGGLE_PALETTE: { - if (this->sel != NULL) { - this->sel->windows_paletted ^= true; + if (this->sel_r != NULL) { + this->sel_r->windows_paletted ^= true; this->SetDirty(); } break; @@ -598,14 +617,14 @@ GRFConfig *c = LoadGRFPresetFromConfig(_grf_preset_list[index]); if (c != NULL) { - this->sel = NULL; + this->sel_r = NULL; ClearGRFConfigList(&this->list); this->list = c; this->preset = index; } } - this->sel = NULL; + this->sel_r = NULL; this->SetupNewGRFWindow(); this->SetDirty(); } @@ -632,7 +651,7 @@ case SNGRFS_SET_PARAMETERS: { /* Parse our new "int list" */ - GRFConfig *c = this->sel; + GRFConfig *c = this->sel_r; c->num_params = parse_intlist(str, (int*)c->param, lengthof(c->param)); /* parse_intlist returns -1 on error */ @@ -647,53 +666,123 @@ virtual void OnResize(Point new_size, Point delta) { - if (delta.x != 0) { - ResizeButtons(this, SNGRFS_ADD, SNGRFS_MOVE_DOWN); - ResizeButtons(this, SNGRFS_SET_PARAMETERS, SNGRFS_APPLY_CHANGES); + /* ASSUME: this->width, this->height already contains the new window size */ + + int left_column_width = (this->width - 31) / 2 + 4; + int right_column_width = left_column_width - 7; + + Widget *w = this->widget; + + w[SNGRFS_RESCAN_FILES].right = + (left_column_width / 2) - 1; + + w[SNGRFS_TOGGLE_SHOW_MODE].left = + (left_column_width / 2); + + w[SNGRFS_AVAILABLE_GRF_LIST].right = + left_column_width - 14; + + w[SNGRFS_AVAILABLE_GRF_LIST_SCROLLBAR].left = + left_column_width - 12; + + w[SNGRFS_AVAILABLE_GRF_CAPTION].right = + w[SNGRFS_EMPTY_GRF_LIST].right = + w[SNGRFS_AVAILABLE_GRF_LIST_SCROLLBAR].right = + w[SNGRFS_TOGGLE_SHOW_MODE].right = + w[SNGRFS_NEWGRF_INFO_LEFT].right = + left_column_width - 1; + + w[SNGRFS_EMPTY_MIDDLE].left = + w[SNGRFS_EMPTY_BOTTOM_MIDDLE].left = + left_column_width; + + w[SNGRFS_ADD_FILE].left = + w[SNGRFS_REMOVE].left = + left_column_width + 5; + + w[SNGRFS_ADD_FILE].right = + w[SNGRFS_REMOVE].right = + left_column_width + 25; + + w[SNGRFS_EMPTY_MIDDLE].right = + w[SNGRFS_EMPTY_BOTTOM_MIDDLE].right = + left_column_width + 29; + + int rightwin_start = left_column_width + 30; + + w[SNGRFS_EMPTY_TOP_RIGHT].left = + w[SNGRFS_FILE_LIST].left = + w[SNGRFS_NEWGRF_INFO_RIGHT].left = + w[SNGRFS_TOGGLE_PALETTE].left = + rightwin_start; + + int spacing = (right_column_width - 72) / 3; + int pos = rightwin_start + spacing; + + w[SNGRFS_MOVE_UP].left = pos; pos += 36; + w[SNGRFS_MOVE_UP].right = pos; pos += spacing; + w[SNGRFS_MOVE_DOWN].left = pos; pos += 36; + w[SNGRFS_MOVE_DOWN].right = pos; + + spacing = (right_column_width - 12) / 3; + w[SNGRFS_TOGGLE_PALETTE].right = rightwin_start + spacing - 1; + w[SNGRFS_SET_PARAMETERS].left = rightwin_start + spacing; + w[SNGRFS_SET_PARAMETERS].right = rightwin_start + 2 * spacing - 1; + w[SNGRFS_APPLY_CHANGES].left = rightwin_start + 2 * spacing; + + int list_bottom; + + if (this->height < 224) { + list_bottom = 111; + } else { + list_bottom = this->height - 113; } - this->vscroll.cap += delta.y / 14; - this->widget[SNGRFS_FILE_LIST].data = (this->vscroll.cap << 8) + 1; + w[SNGRFS_EMPTY_GRF_LIST].bottom = + w[SNGRFS_AVAILABLE_GRF_LIST].bottom = + w[SNGRFS_AVAILABLE_GRF_LIST_SCROLLBAR].bottom = + w[SNGRFS_FILE_LIST].bottom = + w[SNGRFS_FILE_LIST_SCROLLBAR].bottom = + list_bottom; + + w[SNGRFS_NEWGRF_INFO_LEFT].top = + w[SNGRFS_NEWGRF_INFO_RIGHT].top = + list_bottom + 1; this->SetupNewGRFWindow(); } + + bool IsInSelectedList(uint32 grfid) { + if (this->show_all) return false; + const GRFConfig *ctemp; + for (ctemp = this->list; ctemp != NULL; ctemp = ctemp->next) { + if (grfid == ctemp->grfid) return true; + } + return false; + } - virtual void OnInvalidateData(int data = 0) + void SetupNewGRFWindow() { - this->preset = -1; - this->SetupNewGRFWindow(); + const GRFConfig *c; + uint8 n; + + for (c = this->list, n = 0; c != NULL; c = c->next, n++); + + this->vscroll2.cap = (this->widget[SNGRFS_FILE_LIST].bottom - this->widget[SNGRFS_FILE_LIST].top) / 13; + + this->widget[SNGRFS_FILE_LIST].data = (this->vscroll2.cap << 8) + 1; + SetVScroll2Count(this, n); + this->SetWidgetDisabledState(SNGRFS_APPLY_CHANGES, !this->editable); + + /* Count the number of GRFs */ + for (c = _all_grfs, n = 0; c != NULL; c = c->next) + { + if (this->show_all || !IsInSelectedList(c->grfid)) n++; + } + + this->vscroll.cap = (this->widget[SNGRFS_AVAILABLE_GRF_LIST].bottom - this->widget[SNGRFS_AVAILABLE_GRF_LIST].top) / 10; + SetVScrollCount(this, n); } -}; - -/* Widget definition of the manage newgrfs window */ -static const Widget _newgrf_widgets[] = { -{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_MAUVE, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, // SNGRFS_CLOSEBOX -{ WWT_CAPTION, RESIZE_RIGHT, COLOUR_MAUVE, 11, 299, 0, 13, STR_NEWGRF_SETTINGS_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS }, // SNGRFS_CAPTION -{ WWT_PANEL, RESIZE_RIGHT, COLOUR_MAUVE, 0, 299, 14, 41, STR_NULL, STR_NULL }, // SNGRFS_BACKGROUND1 -{ WWT_DROPDOWN, RESIZE_RIGHT, COLOUR_YELLOW, 10, 103, 16, 27, STR_EMPTY, STR_NEWGRF_PRESET_LIST_TIP }, // SNGRFS_PRESET_LIST -{ WWT_PUSHTXTBTN, RESIZE_LR, COLOUR_YELLOW, 104, 196, 16, 27, STR_NEWGRF_PRESET_SAVE, STR_NEWGRF_PRESET_SAVE_TIP }, // SNGRFS_PRESET_SAVE -{ WWT_PUSHTXTBTN, RESIZE_LR, COLOUR_YELLOW, 197, 289, 16, 27, STR_NEWGRF_PRESET_DELETE, STR_NEWGRF_PRESET_DELETE_TIP }, // SNGRFS_PRESET_DELETE -{ WWT_PANEL, RESIZE_RIGHT, COLOUR_MAUVE, 0, 299, 30, 45, STR_NULL, STR_NULL }, // SNGRFS_BACKGROUND -{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_YELLOW, 10, 79, 32, 43, STR_NEWGRF_ADD, STR_NEWGRF_ADD_TIP }, // SNGRFS_ADD -{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_YELLOW, 80, 149, 32, 43, STR_NEWGRF_REMOVE, STR_NEWGRF_REMOVE_TIP }, // SNGRFS_REMOVE -{ WWT_PUSHTXTBTN, RESIZE_NONE, COLOUR_YELLOW, 150, 219, 32, 43, STR_NEWGRF_MOVEUP, STR_NEWGRF_MOVEUP_TIP }, // SNGRFS_MOVE_UP -{ WWT_PUSHTXTBTN, RESIZE_RIGHT, COLOUR_YELLOW, 220, 289, 32, 43, STR_NEWGRF_MOVEDOWN, STR_NEWGRF_MOVEDOWN_TIP }, // SNGRFS_MOVE_DOWN -{ WWT_MATRIX, RESIZE_RB, COLOUR_MAUVE, 0, 287, 46, 115, 0x501, STR_NEWGRF_FILE_TIP }, // SNGRFS_FILE_LIST -{ WWT_SCROLLBAR, RESIZE_LRB, COLOUR_MAUVE, 288, 299, 46, 115, 0x0, STR_0190_SCROLL_BAR_SCROLLS_LIST }, // SNGRFS_SCROLLBAR -{ WWT_PANEL, RESIZE_RTB, COLOUR_MAUVE, 0, 299, 116, 238, STR_NULL, STR_NULL }, // SNGRFS_NEWGRF_INFO -{ WWT_PUSHTXTBTN, RESIZE_TB, COLOUR_MAUVE, 0, 95, 239, 250, STR_NEWGRF_SET_PARAMETERS, STR_NULL }, // SNGRFS_SET_PARAMETERS -{ WWT_PUSHTXTBTN, RESIZE_RTB, COLOUR_MAUVE, 96, 191, 239, 250, STR_NEWGRF_TOGGLE_PALETTE, STR_NEWGRF_TOGGLE_PALETTE_TIP }, // SNGRFS_TOGGLE_PALETTE -{ WWT_PUSHTXTBTN, RESIZE_RTB, COLOUR_MAUVE, 192, 287, 239, 250, STR_NEWGRF_APPLY_CHANGES, STR_NULL }, // SNGRFS_APPLY_CHANGES -{ WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_MAUVE, 288, 299, 239, 250, 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, 251, 300, 251, - WC_GAME_OPTIONS, WC_NONE, - WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, - _newgrf_widgets, }; /** Callback function for the newgrf 'apply changes' confirmation window @@ -707,23 +796,64 @@ GRFConfig *c; int i = 0; - GamelogStartAction(GLAT_GRF); - GamelogGRFUpdate(_grfconfig, nw->list); // log GRF changes CopyGRFConfigList(nw->orig_list, nw->list, false); ReloadNewGRFData(); - GamelogStopAction(); /* Show new, updated list */ - for (c = nw->list; c != NULL && c != nw->sel; c = c->next, i++) {} + for (c = nw->list; c != NULL && c != nw->sel_r; 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; + for (c = nw->list; c != NULL && i > 0; c = c->next, i--); + nw->sel_r = c; w->SetDirty(); } } +static const Widget _newgrf_widgets[] = { +{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_MAUVE, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW }, // SNGRFS_CLOSE +{ WWT_CAPTION, RESIZE_RIGHT, COLOUR_MAUVE, 11, 599, 0, 13, STR_NEWGRF_SETTINGS_CAPTION, STR_018C_WINDOW_TITLE_DRAG_THIS }, // SNGRFS_CAPTION +/* NewGRF Presets */ +{ WWT_PANEL, RESIZE_RIGHT, COLOUR_MAUVE, 0, 599, 14, 29, STR_NULL, STR_NULL }, // SNGRFS_EMPTY_PRESET +{ WWT_DROPDOWN, RESIZE_RIGHT, COLOUR_YELLOW, 10, 403, 16, 27, STR_EMPTY, STR_NEWGRF_PRESET_LIST_TIP }, // SNGRFS_PRESET_LIST +{ WWT_PUSHTXTBTN, RESIZE_LR, COLOUR_YELLOW, 404, 496, 16, 27, STR_NEWGRF_PRESET_SAVE, STR_NEWGRF_PRESET_SAVE_TIP }, // SNGRFS_PRESET_SAVE +{ WWT_PUSHTXTBTN, RESIZE_LR, COLOUR_YELLOW, 497, 587, 16, 27, STR_NEWGRF_PRESET_DELETE, STR_NEWGRF_PRESET_DELETE_TIP }, // SNGRFS_PRESET_DELETE +/* List of files */ +{ WWT_PANEL, RESIZE_RIGHT, COLOUR_MAUVE, 0, 291, 30, 45, STR_NULL, STR_NULL }, // SNGRFS_AVAILABLE_GRF_CAPTION +{ WWT_PANEL, RESIZE_RB, COLOUR_MAUVE, 0, 279, 46, 137, STR_NULL, STR_NULL }, // SNGRFS_EMPTY_GRF_LIST +{ WWT_INSET, RESIZE_RB, COLOUR_MAUVE, 2, 277, 46, 137, STR_NULL, STR_NULL }, // SNGRFS_AVAILABLE_GRF_LIST +{ WWT_SCROLLBAR, RESIZE_LRB, COLOUR_MAUVE, 280, 291, 46, 137, STR_NULL, STR_NULL }, // SNGRFS_AVAILABLE_GRF_LIST_SCROLLBAR +/* NewGRF file info */ +{ WWT_PANEL, RESIZE_RTB, COLOUR_MAUVE, 0, 291, 138, 237, STR_NULL, STR_NULL }, // SNGRFS_NEWGRF_INFO_LEFT +{ WWT_PUSHTXTBTN, RESIZE_RTB, COLOUR_MAUVE, 0, 136, 238, 249, STR_NEWGRF_RESCAN_FILES, STR_NEWGRF_RESCAN_FILES_TIP }, // SNGRFS_RESCAN_FILES +{ WWT_PUSHTXTBTN, RESIZE_LRTB, COLOUR_MAUVE, 137, 291, 238, 249, STR_NEWGRF_TOGGLE_SHOW, STR_NEWGRF_TOGGLE_SHOW_TIP }, // SNGRFS_TOGGLE_SHOW_MODE +/* Middle Panel */ +{ WWT_PANEL, RESIZE_LRB, COLOUR_MAUVE, 292, 321, 30, 237, STR_NULL, STR_NULL }, // SNGRFS_EMPTY_MIDDLE +{ WWT_PANEL, RESIZE_LRTB, COLOUR_MAUVE, 292, 321, 238, 249, STR_NULL, STR_NULL }, // SNGRFS_EMPTY_BOTTOM_MIDDLE +/* NewGRF file Add, Remove, Move up, Move down */ +{ WWT_PANEL, RESIZE_LR, COLOUR_MAUVE, 322, 599, 30, 45, STR_NULL, STR_NULL }, // SNGRFS_EMPTY_TOP_RIGHT +{ WWT_PUSHTXTBTN, RESIZE_LR, COLOUR_YELLOW, 297, 316, 36, 58, STR_NEWGRF_JOINT_ADD, STR_NEWGRF_ADD_TIP }, // SNGRFS_ADD_FILE +{ WWT_PUSHTXTBTN, RESIZE_LR, COLOUR_YELLOW, 297, 316, 66, 88, STR_NEWGRF_JOINT_REMOVE, STR_NEWGRF_REMOVE_TIP }, // SNGRFS_REMOVE +{ WWT_PUSHTXTBTN, RESIZE_LR, COLOUR_YELLOW, 394, 430, 32, 43, STR_NEWGRF_MOVEUP, STR_NEWGRF_MOVEUP_TIP }, // SNGRFS_MOVE_UP +{ WWT_PUSHTXTBTN, RESIZE_LR, COLOUR_YELLOW, 499, 535, 32, 43, STR_NEWGRF_MOVEDOWN, STR_NEWGRF_MOVEDOWN_TIP }, // SNGRFS_MOVE_DOWN +/* NewGRF file list */ +{ WWT_MATRIX, RESIZE_LRB, COLOUR_MAUVE, 322, 588, 46, 137, 0x501, STR_NEWGRF_FILE_TIP }, // SNGRFS_FILE_LIST +{ WWT_SCROLL2BAR, RESIZE_LRB, COLOUR_MAUVE, 588, 599, 46, 137, STR_NULL, STR_0190_SCROLL_BAR_SCROLLS_LIST },// SNGRFS_FILE_LIST_SCROLLBAR +/* NewGRF file info */ +{ WWT_PANEL, RESIZE_LRTB, COLOUR_MAUVE, 322, 599, 138, 237, STR_NULL, STR_NULL }, // SNGRFS_NEWGRF_INFO_RIGHT +/* Edit parameter and apply changes button... */ +{ WWT_PUSHTXTBTN, RESIZE_LRTB, COLOUR_MAUVE, 322, 410, 238, 249, STR_NEWGRF_SET_PARAMETERS, STR_NULL }, // SNGRFS_SET_PARAMETERS +{ WWT_PUSHTXTBTN, RESIZE_LRTB, COLOUR_MAUVE, 411, 499, 238, 249, STR_NEWGRF_TOGGLE_PALETTE, STR_NEWGRF_TOGGLE_PALETTE_TIP }, // SNGRFS_TOGGLE_PALETTE +{ WWT_PUSHTXTBTN, RESIZE_LRTB, COLOUR_MAUVE, 500, 587, 238, 249, STR_NEWGRF_APPLY_CHANGES, STR_NULL }, // SNGRFS_APPLY_CHANGES +{ WWT_RESIZEBOX, RESIZE_LRTB, COLOUR_MAUVE, 588, 599, 238, 249, STR_NULL, STR_RESIZE_BUTTON }, +{ WIDGETS_END }, +}; +static const WindowDesc _newgrf_desc = { + WDP_CENTER, WDP_CENTER, 600, 250, 600, 250, + WC_GAME_OPTIONS, WC_NONE, + WDF_STD_TOOLTIPS | WDF_DEF_WIDGET | WDF_STD_BTN | WDF_UNCLICK_BUTTONS | WDF_RESIZABLE, + _newgrf_widgets, +}; /** Setup the NewGRF gui * @param editable allow the user to make changes to the grfconfig in the window @@ -734,5 +864,7 @@ void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfig **config) { DeleteWindowByClass(WC_GAME_OPTIONS); + new NewGRFWindow(&_newgrf_desc, editable, show_params, exec_changes, config); } + diff -r 8adfbd8b2cc3 src/window.cpp --- src/window.cpp Thu Jan 15 07:48:00 2009 +0100 +++ src/window.cpp Thu Jan 15 08:22:45 2009 +0100 @@ -1149,7 +1149,6 @@ static bool HandleDragDrop() { if (_special_mouse_mode != WSM_DRAGDROP) return true; - if (_left_button_down) return false; Window *w = GetCallbackWnd(); @@ -1158,7 +1157,13 @@ Point pt; pt.x = _cursor.pos.x - w->left; pt.y = _cursor.pos.y - w->top; - w->OnDragDrop(pt, GetWidgetFromPos(w, pt.x, pt.y)); + + if (_left_button_down) { + w->OnDragMove(pt, GetWidgetFromPos(w, pt.x, pt.y)); + return false; + } else { + w->OnDragDrop(pt, GetWidgetFromPos(w, pt.x, pt.y)); + } } ResetObjectToPlace(); diff -r 8adfbd8b2cc3 src/window_gui.h --- src/window_gui.h Thu Jan 15 07:48:00 2009 +0100 +++ src/window_gui.h Thu Jan 15 08:22:45 2009 +0100 @@ -315,6 +315,13 @@ virtual void OnDragDrop(Point pt, int widget) {} /** + * An 'object' is being dragged. + * @param pt the point inside the window where the cursor points to. + * @param widget the widget where the cursor points to. + */ + virtual void OnDragMove(Point pt, int widget) {} + + /** * Handle the request for (viewport) scrolling. * @param delta the amount the viewport must be scrolled. */