Exemplo n.º 1
0
	/**
	 * Some data on this window has become invalid.
	 * @param data Information about the changed data.
	 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
	 */
	virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
	{
		switch (data) {
			case 0:
				/* Rescan files */
				this->selected = NULL;
				_load_check_data.Clear();
				if (!gui_scope) break;
				BuildFileList();
				/* FALL THROUGH */
			case 1:
				/* Selection changes */
				if (!gui_scope) break;
				if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) {
					this->SetWidgetDisabledState(WID_SL_LOAD_BUTTON,
							this->selected == NULL || _load_check_data.HasErrors() || !(_load_check_data.grf_compatibility != GLC_NOT_FOUND || _settings_client.gui.UserIsAllowedToChangeNewGRFs()));
					this->SetWidgetDisabledState(WID_SL_NEWGRF_INFO,
							!_load_check_data.HasNewGrfs());
					this->SetWidgetDisabledState(WID_SL_MISSING_NEWGRFS,
							!_load_check_data.HasNewGrfs() || _load_check_data.grf_compatibility == GLC_ALL_GOOD);
				}
				break;
			case 2:
				/* _fios_items changed */
				this->vscroll->SetCount(_fios_items.Length());
				this->selected = NULL;
				_load_check_data.Clear();
				break;
		}
	}
Exemplo n.º 2
0
 virtual void OnInvalidateData(int data)
 {
     switch (data) {
     case 0:
         /* Rescan files */
         this->selected = NULL;
         _load_check_data.Clear();
         BuildFileList();
     /* FALL THROUGH */
     case 1:
         /* Selection changes */
         if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) {
             this->SetWidgetDisabledState(SLWW_LOAD_BUTTON,
                                          this->selected == NULL || _load_check_data.HasErrors());
             this->SetWidgetDisabledState(SLWW_NEWGRF_INFO,
                                          !_load_check_data.HasNewGrfs());
         }
         break;
     }
 }
Exemplo n.º 3
0
    virtual void OnClick(Point pt, int widget, int click_count)
    {
        switch (widget) {
        case SLWW_SORT_BYNAME: // Sort save names by name
            _savegame_sort_order = (_savegame_sort_order == SORT_BY_NAME) ?
                                   SORT_BY_NAME | SORT_DESCENDING : SORT_BY_NAME;
            _savegame_sort_dirty = true;
            this->SetDirty();
            break;

        case SLWW_SORT_BYDATE: // Sort save names by date
            _savegame_sort_order = (_savegame_sort_order == SORT_BY_DATE) ?
                                   SORT_BY_DATE | SORT_DESCENDING : SORT_BY_DATE;
            _savegame_sort_dirty = true;
            this->SetDirty();
            break;

        case SLWW_HOME_BUTTON: // OpenTTD 'button', jumps to OpenTTD directory
            FiosBrowseTo(&o_dir);
            this->InvalidateData();
            break;

        case SLWW_LOAD_BUTTON:
            if (this->selected != NULL && !_load_check_data.HasErrors()) {
                _switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_SCENARIO : SM_LOAD;

                const char *name = FiosBrowseTo(this->selected);
                SetFiosType(this->selected->type);

                strecpy(_file_to_saveload.name, name, lastof(_file_to_saveload.name));
                strecpy(_file_to_saveload.title, this->selected->title, lastof(_file_to_saveload.title));

                delete this;
            }
            break;

        case SLWW_NEWGRF_INFO:
            if (_load_check_data.HasNewGrfs()) {
                ShowNewGRFSettings(false, false, false, &_load_check_data.grfconfig);
            }
            break;

        case SLWW_DRIVES_DIRECTORIES_LIST: { // Click the listbox
            int y = (pt.y - this->GetWidget<NWidgetBase>(SLWW_DRIVES_DIRECTORIES_LIST)->pos_y - WD_FRAMERECT_TOP) / this->resize.step_height;

            if (y < 0 || (y += this->vscroll.GetPosition()) >= this->vscroll.GetCount()) return;

            const FiosItem *file = _fios_items.Get(y);

            const char *name = FiosBrowseTo(file);
            if (name != NULL) {
                if (click_count == 1) {
                    if (this->selected != file) {
                        this->selected = file;
                        _load_check_data.Clear();

                        if (file->type == FIOS_TYPE_FILE || file->type == FIOS_TYPE_SCENARIO) {
                            SaveOrLoad(name, SL_LOAD_CHECK, NO_DIRECTORY, false);
                        }

                        this->InvalidateData(1);
                    }
                    if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO) {
                        /* Copy clicked name to editbox */
                        ttd_strlcpy(this->text.buf, file->title, this->text.maxsize);
                        UpdateTextBufferSize(&this->text);
                        this->SetWidgetDirty(SLWW_SAVE_OSK_TITLE);
                    }
                } else if (!_load_check_data.HasErrors()) {
                    this->selected = file;
                    if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) {
                        this->OnClick(pt, SLWW_LOAD_BUTTON, 1);
                    } else if (_saveload_mode == SLD_LOAD_HEIGHTMAP) {
                        SetFiosType(file->type);
                        strecpy(_file_to_saveload.name, name, lastof(_file_to_saveload.name));
                        strecpy(_file_to_saveload.title, file->title, lastof(_file_to_saveload.title));

                        delete this;
                        ShowHeightmapLoad();
                    }
                }
            } else {
                /* Changed directory, need refresh. */
                this->InvalidateData();
            }
            break;
        }

        case SLWW_CONTENT_DOWNLOAD:
            if (!_network_available) {
                ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
            } else {
#if defined(ENABLE_NETWORK)
                switch (_saveload_mode) {
                default:
                    NOT_REACHED();
                case SLD_LOAD_SCENARIO:
                    ShowNetworkContentListWindow(NULL, CONTENT_TYPE_SCENARIO);
                    break;
                case SLD_LOAD_HEIGHTMAP:
                    ShowNetworkContentListWindow(NULL, CONTENT_TYPE_HEIGHTMAP);
                    break;
                }
#endif
            }
            break;

        case SLWW_DELETE_SELECTION:
        case SLWW_SAVE_GAME: // Delete, Save game
            break;
        }
    }
Exemplo n.º 4
0
	virtual void OnClick(Point pt, int widget, int click_count)
	{
		switch (widget) {
			case WID_SL_SORT_BYNAME: // Sort save names by name
				_savegame_sort_order = (_savegame_sort_order == SORT_BY_NAME) ?
					SORT_BY_NAME | SORT_DESCENDING : SORT_BY_NAME;
				_savegame_sort_dirty = true;
				this->SetDirty();
				break;

			case WID_SL_SORT_BYDATE: // Sort save names by date
				_savegame_sort_order = (_savegame_sort_order == SORT_BY_DATE) ?
					SORT_BY_DATE | SORT_DESCENDING : SORT_BY_DATE;
				_savegame_sort_dirty = true;
				this->SetDirty();
				break;

			case WID_SL_HOME_BUTTON: // OpenTTD 'button', jumps to OpenTTD directory
				FiosBrowseTo(&o_dir);
				this->InvalidateData();
				break;

			case WID_SL_LOAD_BUTTON:
				if (this->selected != NULL && !_load_check_data.HasErrors() && (_load_check_data.grf_compatibility != GLC_NOT_FOUND || _settings_client.gui.UserIsAllowedToChangeNewGRFs())) {
					_switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_SCENARIO : SM_LOAD_GAME;

					const char *name = FiosBrowseTo(this->selected);
					SetFiosType(this->selected->type);

					strecpy(_file_to_saveload.name, name, lastof(_file_to_saveload.name));
					strecpy(_file_to_saveload.title, this->selected->title, lastof(_file_to_saveload.title));
					ClearErrorMessages();
					delete this;
				}
				break;

			case WID_SL_NEWGRF_INFO:
				if (_load_check_data.HasNewGrfs()) {
					ShowNewGRFSettings(false, false, false, &_load_check_data.grfconfig);
				}
				break;

			case WID_SL_MISSING_NEWGRFS:
				if (!_network_available) {
					ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
				} else {
#if defined(ENABLE_NETWORK)
					ShowMissingContentWindow(_load_check_data.grfconfig);
#endif
				}
				break;

			case WID_SL_DRIVES_DIRECTORIES_LIST: { // Click the listbox
				int y = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SL_DRIVES_DIRECTORIES_LIST, WD_FRAMERECT_TOP);
				if (y == INT_MAX) return;

				const FiosItem *file = _fios_items.Get(y);

				const char *name = FiosBrowseTo(file);
				if (name != NULL) {
					if (click_count == 1) {
						if (this->selected != file) {
							this->selected = file;
							_load_check_data.Clear();

							if (file->type == FIOS_TYPE_FILE || file->type == FIOS_TYPE_SCENARIO) {
								SaveOrLoad(name, SL_LOAD_CHECK, NO_DIRECTORY, false);
							}

							this->InvalidateData(1);
						}
						if (_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO || _saveload_mode == SLD_SAVE_HEIGHTMAP) {
							/* Copy clicked name to editbox */
							this->filename_editbox.text.Assign(file->title);
							this->SetWidgetDirty(WID_SL_SAVE_OSK_TITLE);
						}
					} else if (!_load_check_data.HasErrors()) {
						this->selected = file;
						if (_saveload_mode == SLD_LOAD_GAME || _saveload_mode == SLD_LOAD_SCENARIO) {
							this->OnClick(pt, WID_SL_LOAD_BUTTON, 1);
						} else if (_saveload_mode == SLD_LOAD_HEIGHTMAP) {
							SetFiosType(file->type);
							strecpy(_file_to_saveload.name, name, lastof(_file_to_saveload.name));
							strecpy(_file_to_saveload.title, file->title, lastof(_file_to_saveload.title));

							delete this;
							ShowHeightmapLoad();
						}
					}
				} else {
					/* Changed directory, need refresh. */
					this->InvalidateData();
				}
				break;
			}

			case WID_SL_CONTENT_DOWNLOAD:
				if (!_network_available) {
					ShowErrorMessage(STR_NETWORK_ERROR_NOTAVAILABLE, INVALID_STRING_ID, WL_ERROR);
				} else {
#if defined(ENABLE_NETWORK)
					switch (_saveload_mode) {
						default: NOT_REACHED();
						case SLD_LOAD_SCENARIO:  ShowNetworkContentListWindow(NULL, CONTENT_TYPE_SCENARIO);  break;
						case SLD_LOAD_HEIGHTMAP: ShowNetworkContentListWindow(NULL, CONTENT_TYPE_HEIGHTMAP); break;
					}
#endif
				}
				break;

			case WID_SL_DELETE_SELECTION: // Delete
				break;

			case WID_SL_SAVE_GAME: // Save game
				/* Note, this is also called via the OSK; and we need to lower the button. */
				this->HandleButtonClick(WID_SL_SAVE_GAME);
				break;
		}
	}
Exemplo n.º 5
0
	/**
	 * Some data on this window has become invalid.
	 * @param data Information about the changed data.
	 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
	 */
	virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
	{
		switch (data) {
			case SLIWD_RESCAN_FILES:
				/* Rescan files */
				this->selected = NULL;
				_load_check_data.Clear();
				if (!gui_scope) break;

				_fios_path_changed = true;
				this->fios_items.BuildFileList(this->abstract_filetype, this->fop);
				this->vscroll->SetCount(this->fios_items.Length());
				this->selected = NULL;
				_load_check_data.Clear();

				/* We reset the files filtered */
				this->OnInvalidateData(SLIWD_FILTER_CHANGES);

				FALLTHROUGH;

			case SLIWD_SELECTION_CHANGES:
				/* Selection changes */
				if (!gui_scope) break;

				if (this->fop != SLO_LOAD) break;

				switch (this->abstract_filetype) {
					case FT_HEIGHTMAP:
						this->SetWidgetDisabledState(WID_SL_LOAD_BUTTON, this->selected == NULL || _load_check_data.HasErrors());
						break;

					case FT_SAVEGAME:
					case FT_SCENARIO: {
						bool disabled = this->selected == NULL || _load_check_data.HasErrors();
						if (!_settings_client.gui.UserIsAllowedToChangeNewGRFs()) {
							disabled |= _load_check_data.HasNewGrfs() && _load_check_data.grf_compatibility == GLC_NOT_FOUND;
						}
						this->SetWidgetDisabledState(WID_SL_LOAD_BUTTON, disabled);
						this->SetWidgetDisabledState(WID_SL_NEWGRF_INFO, !_load_check_data.HasNewGrfs());
						this->SetWidgetDisabledState(WID_SL_MISSING_NEWGRFS,
								!_load_check_data.HasNewGrfs() || _load_check_data.grf_compatibility == GLC_ALL_GOOD);
						break;
					}

					default:
						NOT_REACHED();
				}
				break;

			case SLIWD_FILTER_CHANGES:
				/* Filter changes */
				this->fios_items_shown.Resize(this->fios_items.Length());
				uint items_shown_count = 0; ///< The number of items shown in the list
				/* We pass through every fios item */
				for (uint i = 0; i < this->fios_items.Length(); i++) {
					if (this->string_filter.IsEmpty()) {
						/* We don't filter anything out if the filter editbox is empty */
						this->fios_items_shown[i] = true;
						items_shown_count++;
					} else {
						this->string_filter.ResetState();
						this->string_filter.AddLine(this->fios_items[i].title);
						/* We set the vector to show this fios element as filtered depending on the result of the filter */
						this->fios_items_shown[i] = this->string_filter.GetState();
						if (this->fios_items_shown[i]) items_shown_count++;

						if (&(this->fios_items[i]) == this->selected && this->fios_items_shown[i] == false) {
							/* The selected element has been filtered out */
							this->selected = NULL;
							this->OnInvalidateData(SLIWD_SELECTION_CHANGES);
						}
					}
				}
				this->vscroll->SetCount(items_shown_count);
				break;
		}
	}