Esempio n. 1
0
	/**
	 * Empties the string buffer that is edited by the filter text edit widget.
	 * It also triggers the redraw of the widget so it become visible that the string has been made empty.
	 */
	void ClearFilterTextWidget()
	{
		this->edit_str_buf[0] = '\0';
		UpdateTextBufferSize(&this->text);

		this->SetWidgetDirty(WID_SIL_FILTER_TEXT);
	}
Esempio n. 2
0
/**
 * Navigate Up/Down in the history of typed commands
 * @param direction Go further back in history (+1), go to recently typed commands (-1)
 */
static void IConsoleHistoryNavigate(int direction)
{
	if (_iconsole_history[0] == NULL) return; // Empty history
	int i = _iconsole_historypos + direction;

	/* watch out for overflows, just wrap around */
	if (i < 0) i = ICON_HISTORY_SIZE - 1;
	if ((uint)i >= ICON_HISTORY_SIZE) i = 0;

	if (direction > 0) {
		if (_iconsole_history[i] == NULL) i = 0;
	}

	if (direction < 0) {
		while (i > 0 && _iconsole_history[i] == NULL) i--;
	}

	_iconsole_historypos = i;
	IConsoleClearCommand();
	/* copy history to 'command prompt / bash' */
	assert(_iconsole_history[i] != NULL && IsInsideMM(i, 0, ICON_HISTORY_SIZE));
	ttd_strlcpy(_iconsole_cmdline.buf, _iconsole_history[i], _iconsole_cmdline.max_bytes);
	UpdateTextBufferSize(&_iconsole_cmdline);
}
Esempio n. 3
0
    virtual void OnTimeout()
    {
        /* This test protects against using widgets 11 and 12 which are only available
         * in those two saveload mode */
        if (!(_saveload_mode == SLD_SAVE_GAME || _saveload_mode == SLD_SAVE_SCENARIO)) return;

        if (this->IsWidgetLowered(SLWW_DELETE_SELECTION)) { // Delete button clicked
            if (!FiosDelete(this->text.buf)) {
                ShowErrorMessage(STR_ERROR_UNABLE_TO_DELETE_FILE, INVALID_STRING_ID, WL_ERROR);
            } else {
                this->InvalidateData();
                /* Reset file name to current date on successful delete */
                if (_saveload_mode == SLD_SAVE_GAME) GenerateFileName();
            }

            UpdateTextBufferSize(&this->text);
        } else if (this->IsWidgetLowered(SLWW_SAVE_GAME)) { // Save button clicked
            _switch_mode = SM_SAVE;
            FiosMakeSavegameName(_file_to_saveload.name, this->text.buf, sizeof(_file_to_saveload.name));

            /* In the editor set up the vehicle engines correctly (date might have changed) */
            if (_game_mode == GM_EDITOR) StartupEngines();
        }
    }
	/**
	 * See if we can auto-complete the current text of the user.
	 */
	void ChatTabCompletion()
	{
		static char _chat_tab_completion_buf[NETWORK_CHAT_LENGTH];
		assert(this->edit_str_size == lengthof(_chat_tab_completion_buf));

		Textbuf *tb = &this->text;
		size_t len, tb_len;
		uint item;
		char *tb_buf, *pre_buf;
		const char *cur_name;
		bool second_scan = false;

		item = 0;

		/* Copy the buffer so we can modify it without damaging the real data */
		pre_buf = (_chat_tab_completion_active) ? strdup(_chat_tab_completion_buf) : strdup(tb->buf);

		tb_buf  = ChatTabCompletionFindText(pre_buf);
		tb_len  = strlen(tb_buf);

		while ((cur_name = ChatTabCompletionNextItem(&item)) != NULL) {
			item++;

			if (_chat_tab_completion_active) {
				/* We are pressing TAB again on the same name, is there another name
				 *  that starts with this? */
				if (!second_scan) {
					size_t offset;
					size_t length;

					/* If we are completing at the begin of the line, skip the ': ' we added */
					if (tb_buf == pre_buf) {
						offset = 0;
						length = (tb->bytes - 1) - 2;
					} else {
						/* Else, find the place we are completing at */
						offset = strlen(pre_buf) + 1;
						length = (tb->bytes - 1) - offset;
					}

					/* Compare if we have a match */
					if (strlen(cur_name) == length && strncmp(cur_name, tb->buf + offset, length) == 0) second_scan = true;

					continue;
				}

				/* Now any match we make on _chat_tab_completion_buf after this, is perfect */
			}

			len = strlen(cur_name);
			if (tb_len < len && strncasecmp(cur_name, tb_buf, tb_len) == 0) {
				/* Save the data it was before completion */
				if (!second_scan) snprintf(_chat_tab_completion_buf, lengthof(_chat_tab_completion_buf), "%s", tb->buf);
				_chat_tab_completion_active = true;

				/* Change to the found name. Add ': ' if we are at the start of the line (pretty) */
				if (pre_buf == tb_buf) {
					snprintf(tb->buf, this->edit_str_size, "%s: ", cur_name);
				} else {
					snprintf(tb->buf, this->edit_str_size, "%s %s", pre_buf, cur_name);
				}

				/* Update the textbuffer */
				UpdateTextBufferSize(&this->text);

				this->SetDirty();
				free(pre_buf);
				return;
			}
		}

		if (second_scan) {
			/* We walked all posibilities, and the user presses tab again.. revert to original text */
			strcpy(tb->buf, _chat_tab_completion_buf);
			_chat_tab_completion_active = false;

			/* Update the textbuffer */
			UpdateTextBufferSize(&this->text);

			this->SetDirty();
		}
		free(pre_buf);
	}
Esempio n. 5
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;
        }
    }