/** * Helper function to construct the dropdown. * @param widget the dropdown widget to create the dropdown for */ void ShowDateDropDown(int widget) { int selected; DropDownList *list = new DropDownList(); switch (widget) { default: NOT_REACHED(); case WID_SD_DAY: for (uint i = 0; i < 31; i++) { list->push_back(new DropDownListStringItem(STR_ORDINAL_NUMBER_1ST + i, i + 1, false)); } selected = this->date.day; break; case WID_SD_MONTH: for (uint i = 0; i < 12; i++) { list->push_back(new DropDownListStringItem(STR_MONTH_JAN + i, i, false)); } selected = this->date.month; break; case WID_SD_YEAR: for (Year i = this->min_year; i <= this->max_year; i++) { DropDownListParamStringItem *item = new DropDownListParamStringItem(STR_JUST_INT, i, false); item->SetParam(0, i); list->push_back(item); } selected = this->date.year; break; } ShowDropDownList(this, list, selected, widget); }
/** * Update/redraw the group action dropdown * @param w the window the dropdown belongs to * @param gid the currently selected group in the window */ static void ShowGroupActionDropdown(Window *w, GroupID gid) { DropDownList *list = new DropDownList(); list->push_back(new DropDownListStringItem(STR_VEHICLE_LIST_REPLACE_VEHICLES, GALF_REPLACE, false)); list->push_back(new DropDownListStringItem(STR_VEHICLE_LIST_SEND_FOR_SERVICING, GALF_SERVICE, false)); list->push_back(new DropDownListStringItem(STR_VEHICLE_LIST_SEND_TRAIN_TO_DEPOT, GALF_DEPOT, false)); if (Group::IsValidID(gid)) { list->push_back(new DropDownListStringItem(STR_GROUP_ADD_SHARED_VEHICLE, GALF_ADD_SHARED, false)); list->push_back(new DropDownListStringItem(STR_GROUP_REMOVE_ALL_VEHICLES, GALF_REMOVE_ALL, false)); } ShowDropDownList(w, list, 0, GRP_WIDGET_MANAGE_VEHICLES_DROPDOWN); }
/** Build a dropdown list of available airport classes */ static DropDownList *BuildAirportClassDropDown() { DropDownList *list = new DropDownList(); for (uint i = 0; i < AirportClass::GetCount(); i++) { list->push_back(new DropDownListStringItem(AirportClass::GetName((AirportClassID)i), i, false)); } return list; }
/** * Show a dropdown menu window near a widget of the parent window. * The result code of the items is their index in the #strings list. * @param w Parent window that wants the dropdown menu. * @param strings Menu list, end with #INVALID_STRING_ID * @param selected Index of initial selected item. * @param button Button widget number of the parent window #w that wants the dropdown menu. * @param disabled_mask Bitmask for diabled items (items with their bit set are not copied to the dropdown list). * @param hidden_mask Bitmask for hidden items (items with their bit set are displayed, but not selectable in the dropdown list). * @param width Width of the dropdown menu. If \c 0, use the width of parent widget #button. */ void ShowDropDownMenu(Window *w, const StringID *strings, int selected, int button, uint32 disabled_mask, uint32 hidden_mask, uint width) { DropDownList *list = new DropDownList(); for (uint i = 0; strings[i] != INVALID_STRING_ID; i++) { if (!HasBit(hidden_mask, i)) { list->push_back(new DropDownListStringItem(strings[i], i, HasBit(disabled_mask, i))); } } /* No entries in the list? */ if (list->size() == 0) { DeleteDropDownList(list); return; } ShowDropDownList(w, list, selected, button, width); }
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; } }