Changeset - r19690:8d473afad5d8
[Not reviewed]
master
0 1 0
frosch - 12 years ago 2012-10-27 15:26:34
frosch@openttd.org
(svn r24633) -Add: Autoexpand the adv. settings tree, if a filter term is entered immediately after opening the window without any manual expanding/collapsing.
1 file changed with 11 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/settings_gui.cpp
Show inline comments
 
@@ -1887,46 +1887,48 @@ struct GameSettingsWindow : QueryStringB
 
	static const int SETTINGTREE_TOP_OFFSET    = 5; ///< Position of top edge of setting values
 
	static const int SETTINGTREE_BOTTOM_OFFSET = 5; ///< Position of bottom edge of setting values
 

	
 
	static GameSettings *settings_ptr; ///< Pointer to the game settings being displayed and modified.
 

	
 
	SettingEntry *valuewindow_entry;   ///< If non-NULL, pointer to setting for which a value-entering window has been opened.
 
	SettingEntry *clicked_entry;       ///< If non-NULL, pointer to a clicked numeric setting (with a depressed left or right button).
 
	SettingEntry *last_clicked;        ///< If non-NULL, pointer to the last clicked setting.
 
	SettingEntry *valuedropdown_entry; ///< If non-NULL, pointer to the value for which a dropdown window is currently opened.
 
	bool closing_dropdown;             ///< True, if the dropdown list is currently closing.
 

	
 
	StringFilter string_filter;        ///< Text filter for settings.
 
	bool manually_changed_folding;     ///< Whether the user expanded/collapsed something manually.
 

	
 
	Scrollbar *vscroll;
 

	
 
	GameSettingsWindow(const WindowDesc *desc) : QueryStringBaseWindow(50)
 
	{
 
		static bool first_time = true;
 

	
 
		settings_ptr = &GetGameSettings();
 

	
 
		/* Build up the dynamic settings-array only once per OpenTTD session */
 
		if (first_time) {
 
			_settings_main_page.Init();
 
			first_time = false;
 
		} else {
 
			_settings_main_page.FoldAll(); // Close all sub-pages
 
		}
 

	
 
		this->valuewindow_entry = NULL; // No setting entry for which a entry window is opened
 
		this->clicked_entry = NULL; // No numeric setting buttons are depressed
 
		this->last_clicked = NULL;
 
		this->valuedropdown_entry = NULL;
 
		this->closing_dropdown = false;
 
		this->manually_changed_folding = false;
 

	
 
		this->CreateNestedTree(desc);
 
		this->vscroll = this->GetScrollbar(WID_GS_SCROLLBAR);
 
		this->FinishInitNested(desc, WN_GAME_OPTIONS_GAME_SETTINGS);
 

	
 
		this->text.Initialize(this->edit_str_buf, this->edit_str_size);
 
		this->SetFocusedWidget(WID_GS_FILTER);
 

	
 
		this->InvalidateData();
 
	}
 

	
 
	virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
 
@@ -2013,51 +2015,55 @@ struct GameSettingsWindow : QueryStringB
 
	 * @param pe Setting to display help text of, use \c NULL to stop displaying help of the currently displayed setting.
 
	 */
 
	void SetDisplayedHelpText(SettingEntry *pe)
 
	{
 
		if (this->last_clicked != pe) this->SetDirty();
 
		this->last_clicked = pe;
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		switch (widget) {
 
			case WID_GS_EXPAND_ALL:
 
				this->manually_changed_folding = true;
 
				_settings_main_page.UnFoldAll();
 
				this->InvalidateData();
 
				break;
 

	
 
			case WID_GS_COLLAPSE_ALL:
 
				this->manually_changed_folding = true;
 
				_settings_main_page.FoldAll();
 
				this->InvalidateData();
 
				break;
 
		}
 

	
 
		if (widget != WID_GS_OPTIONSPANEL) return;
 

	
 
		uint btn = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GS_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET);
 
		if (btn == INT_MAX) return;
 

	
 
		uint cur_row = 0;
 
		SettingEntry *pe = _settings_main_page.FindEntry(btn, &cur_row);
 

	
 
		if (pe == NULL) return;  // Clicked below the last setting of the page
 

	
 
		int x = (_current_text_dir == TD_RTL ? this->width - 1 - pt.x : pt.x) - SETTINGTREE_LEFT_OFFSET - (pe->level + 1) * LEVEL_WIDTH;  // Shift x coordinate
 
		if (x < 0) return;  // Clicked left of the entry
 

	
 
		if ((pe->flags & SEF_KIND_MASK) == SEF_SUBTREE_KIND) {
 
			this->SetDisplayedHelpText(NULL);
 
			pe->d.sub.folded = !pe->d.sub.folded; // Flip 'folded'-ness of the sub-page
 

	
 
			this->manually_changed_folding = true;
 

	
 
			this->InvalidateData();
 
			return;
 
		}
 

	
 
		assert((pe->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
 
		const SettingDesc *sd = pe->d.entry.setting;
 

	
 
		/* return if action is only active in network, or only settable by server */
 
		if ((!(sd->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(sd->desc.flags & SGF_PER_COMPANY)) ||
 
				((sd->desc.flags & SGF_NETWORK_ONLY) && !_networking) || ((sd->desc.flags & SGF_NO_NETWORK) && _networking)) {
 
			this->SetDisplayedHelpText(pe);
 
			return;
 
@@ -2269,24 +2275,29 @@ struct GameSettingsWindow : QueryStringB
 
	{
 
		/* Handle editbox input */
 
		EventState state = ES_NOT_HANDLED;
 
		if (this->HandleEditBoxKey(WID_GS_FILTER, key, keycode, state) == HEBR_EDITING) {
 
			this->OnOSKInput(WID_GS_FILTER);
 
		}
 
		return state;
 
	}
 

	
 
	virtual void OnOSKInput(int wid)
 
	{
 
		string_filter.SetFilterTerm(this->edit_str_buf);
 
		if (!string_filter.IsEmpty() && !this->manually_changed_folding) {
 
			/* User never expanded/collapsed single pages and entered a filter term.
 
			 * Expand everything, to save weird expand clicks, */
 
			_settings_main_page.UnFoldAll();
 
		}
 
		this->InvalidateData();
 
	}
 

	
 
	virtual void OnResize()
 
	{
 
		this->vscroll->SetCapacityFromWidget(this, WID_GS_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET);
 
	}
 
};
 

	
 
GameSettings *GameSettingsWindow::settings_ptr = NULL;
 

	
 
static const NWidgetPart _nested_settings_selection_widgets[] = {
0 comments (0 inline, 0 general)