/** * Appends the static GRFs to a list of GRFs * @param dst the head of the list to add to */ void AppendStaticGRFConfigs(GRFConfig **dst) { GRFConfig **tail = dst; while (*tail != NULL) tail = &(*tail)->next; CopyGRFConfigList(tail, _grfconfig_static, false); RemoveDuplicatesFromGRFConfigList(*dst); }
~NewGRFWindow() { if (this->editable && !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); _grf_preset_list.Clear(); }
/** 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; 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++) {} CopyGRFConfigList(&nw->list, *nw->orig_list, false); for (c = nw->list; c != NULL && i > 0; c = c->next, i--) {} nw->sel = c; w->SetDirty(); } }
NewGRFWindow(const WindowDesc *desc, bool editable, bool show_params, bool exec_changes, GRFConfig **config) : Window() { this->sel = NULL; this->list = NULL; this->orig_list = config; this->editable = editable; this->execute = exec_changes; this->show_params = show_params; this->preset = -1; CopyGRFConfigList(&this->list, *config, false); GetGRFPresetList(&_grf_preset_list); this->InitNested(desc); this->OnInvalidateData(2); }
/** Reset the current GRF Config to either blank or newgame settings. */ void ResetGRFConfig(bool defaults) { CopyGRFConfigList(&_grfconfig, _grfconfig_newgame, !defaults); AppendStaticGRFConfigs(&_grfconfig); }
virtual void OnClick(Point pt, int widget, int click_count) { switch (widget) { case SNGRFS_PRESET_LIST: { DropDownList *list = new DropDownList(); /* Add 'None' option for clearing list */ list->push_back(new DropDownListStringItem(STR_NONE, -1, false)); for (uint i = 0; i < _grf_preset_list.Length(); i++) { if (_grf_preset_list[i] != NULL) { list->push_back(new DropDownListPresetItem(i)); } } ShowDropDownList(this, list, this->preset, SNGRFS_PRESET_LIST); break; } case SNGRFS_PRESET_SAVE: this->query_widget = widget; ShowQueryString(STR_EMPTY, STR_NEWGRF_SETTINGS_PRESET_SAVE_QUERY, 32, 100, this, CS_ALPHANUMERAL, QSF_NONE); break; case SNGRFS_PRESET_DELETE: if (this->preset == -1) return; DeleteGRFPresetFromConfig(_grf_preset_list[this->preset]); GetGRFPresetList(&_grf_preset_list); this->preset = -1; this->InvalidateData(); break; case SNGRFS_ADD: // Add GRF DeleteWindowByClass(WC_SAVELOAD); new NewGRFAddWindow(&_newgrf_add_dlg_desc, this, &this->list); break; case SNGRFS_REMOVE: { // Remove GRF GRFConfig **pc, *c, *newsel; /* Choose the next GRF file to be the selected file */ newsel = this->sel->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 (c == this->sel) { *pc = c->next; free(c); break; } } this->sel = newsel; this->preset = -1; this->InvalidateData(3); this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window break; } case SNGRFS_MOVE_UP: { // Move GRF up GRFConfig **pc, *c; if (this->sel == NULL) break; int pos = 0; for (pc = &this->list; (c = *pc) != NULL; pc = &c->next, pos++) { if (c->next == this->sel) { c->next = this->sel->next; this->sel->next = c; *pc = this->sel; break; } } this->vscroll.ScrollTowards(pos); this->preset = -1; this->InvalidateData(); break; } case SNGRFS_MOVE_DOWN: { // Move GRF down GRFConfig **pc, *c; if (this->sel == NULL) break; int pos = 1; // Start at 1 as we swap the selected newgrf with the next one for (pc = &this->list; (c = *pc) != NULL; pc = &c->next, pos++) { if (c == this->sel) { *pc = c->next; c->next = c->next->next; (*pc)->next = c; break; } } this->vscroll.ScrollTowards(pos); this->preset = -1; this->InvalidateData(); break; } case SNGRFS_FILE_LIST: { // Select a GRF GRFConfig *c; uint i = (pt.y - this->GetWidget<NWidgetBase>(SNGRFS_FILE_LIST)->pos_y) / this->resize.step_height + this->vscroll.GetPosition(); for (c = this->list; c != NULL && i > 0; c = c->next, i--) {} if (this->sel != c) this->DeleteChildWindows(WC_QUERY_STRING); // Remove the parameter query window this->sel = c; this->InvalidateData(); if (click_count > 1) this->OnClick(pt, SNGRFS_SET_PARAMETERS, 1); break; } case SNGRFS_APPLY_CHANGES: // Apply changes made to GRF list if (this->execute) { ShowQuery( STR_NEWGRF_POPUP_CAUTION_CAPTION, STR_NEWGRF_CONFIRMATION_TEXT, this, NewGRFConfirmationCallback ); } else { CopyGRFConfigList(this->orig_list, this->list, true); ResetGRFConfig(false); ReloadNewGRFData(); } break; case SNGRFS_SET_PARAMETERS: { // Edit parameters if (this->sel == NULL) break; this->query_widget = widget; static char buff[512]; GRFBuildParamList(buff, this->sel, lastof(buff)); SetDParamStr(0, buff); ShowQueryString(STR_JUST_RAW_STRING, STR_NEWGRF_SETTINGS_PARAMETER_QUERY, 63, 250, this, CS_NUMERAL_SPACE, QSF_NONE); break; } case SNGRFS_TOGGLE_PALETTE: if (this->sel != NULL) { this->sel->windows_paletted ^= true; this->SetDirty(); } break; case SNGRFS_CONTENT_DOWNLOAD: if (!_network_available) { ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, 0, 0); } else { #if defined(ENABLE_NETWORK) /* Only show the things in the current list, or everything when nothing's selected */ ContentVector cv; for (const GRFConfig *c = this->list; c != NULL; c = c->next) { if (c->status != GCS_NOT_FOUND && !HasBit(c->flags, GCF_COMPATIBLE)) continue; ContentInfo *ci = new ContentInfo(); ci->type = CONTENT_TYPE_NEWGRF; ci->state = ContentInfo::DOES_NOT_EXIST; ttd_strlcpy(ci->name, c->name != NULL ? c->name : c->filename, lengthof(ci->name)); ci->unique_id = BSWAP32(c->grfid); memcpy(ci->md5sum, c->md5sum, sizeof(ci->md5sum)); if (HasBit(c->flags, GCF_COMPATIBLE)) GamelogGetOriginalGRFMD5Checksum(c->grfid, ci->md5sum); *cv.Append() = ci; } ShowNetworkContentListWindow(cv.Length() == 0 ? NULL : &cv, CONTENT_TYPE_NEWGRF); #endif } break; } }