Changeset - r10670:141a072d4889
[Not reviewed]
master
0 1 0
rubidium - 15 years ago 2009-01-10 17:27:11
rubidium@openttd.org
(svn r14973) -Codechange: recursively fold subpages (Alberth)
1 file changed with 30 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/settings_gui.cpp
Show inline comments
 
@@ -624,41 +624,43 @@ struct PatchEntrySetting {
 
struct PatchEntry {
 
	byte flags; ///< Flags of the patch entry. @see PatchEntryFlags
 
	byte level; ///< Nesting level of this patch entry
 
	union {
 
		PatchEntrySetting entry; ///< Data fields if entry is a setting
 
		PatchEntrySubtree sub;   ///< Data fields if entry is a sub-page
 
	} d; ///< Data fields for each kind
 

	
 
	PatchEntry(const char *nm);
 
	PatchEntry(PatchPage *sub, StringID title);
 

	
 
	void Init(byte level, bool last_field);
 
	void FoldAll();
 
	void SetButtons(byte new_val);
 

	
 
	uint Length() const;
 
	PatchEntry *FindEntry(uint row, uint *cur_row);
 

	
 
	uint Draw(GameSettings *patches_ptr, int base_x, int base_y, uint first_row, uint max_row, uint cur_row, uint parent_last);
 

	
 
private:
 
	void DrawPatch(GameSettings *patches_ptr, const SettingDesc *sd, int x, int y, int state);
 
};
 

	
 
/** Data structure describing one page of patches in the patch settings window. */
 
struct PatchPage {
 
	PatchEntry *entries; ///< Array of patch entries of the page.
 
	byte num;            ///< Number of entries on the page (statically filled).
 

	
 
	void Init(byte level = 0);
 
	void FoldAll();
 

	
 
	uint Length() const;
 
	PatchEntry *FindEntry(uint row, uint *cur_row) const;
 

	
 
	uint Draw(GameSettings *patches_ptr, int base_x, int base_y, uint first_row, uint max_row, uint cur_row = 0, uint parent_last = 0) const;
 
};
 

	
 

	
 
/* == PatchEntry methods == */
 

	
 
/**
 
 * Constructor for a single setting in the 'advanced settings' window
 
@@ -700,24 +702,41 @@ void PatchEntry::Init(byte level, bool l
 
	switch (this->flags & PEF_KIND_MASK) {
 
		case PEF_SETTING_KIND:
 
			this->d.entry.setting = GetPatchFromName(this->d.entry.name, &this->d.entry.index);
 
			assert(this->d.entry.setting != NULL);
 
			break;
 
		case PEF_SUBTREE_KIND:
 
			this->d.sub.page->Init(level + 1);
 
			break;
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 
/** Recursively close all folds of sub-pages */
 
void PatchEntry::FoldAll()
 
{
 
	switch(this->flags & PEF_KIND_MASK) {
 
		case PEF_SETTING_KIND:
 
			break;
 

	
 
		case PEF_SUBTREE_KIND:
 
			this->d.sub.folded = true;
 
			this->d.sub.page->FoldAll();
 
			break;
 

	
 
		default: NOT_REACHED();
 
	}
 
}
 

	
 

	
 
/**
 
 * Set the button-depressed flags (#PEF_LEFT_DEPRESSED and #PEF_RIGHT_DEPRESSED) to a specified value
 
 * @param new_val New value for the button flags
 
 * @see PatchEntryFlags
 
 */
 
void PatchEntry::SetButtons(byte new_val)
 
{
 
	assert((new_val & ~PEF_BUTTONS_MASK) == 0); // Should not touch any flags outside the buttons
 
	this->flags = (this->flags & ~PEF_BUTTONS_MASK) | new_val;
 
}
 

	
 
/** Return numbers of rows needed to display the entry */
 
@@ -894,24 +913,32 @@ void PatchEntry::DrawPatch(GameSettings 
 

	
 
/**
 
 * Initialization of an entire setting page
 
 * @param level Nesting level of this page (internal variable, do not provide a value for it when calling)
 
 */
 
void PatchPage::Init(byte level)
 
{
 
	for (uint field = 0; field < this->num; field++) {
 
		this->entries[field].Init(level, field + 1 == num);
 
	}
 
}
 

	
 
/** Recursively close all folds of sub-pages */
 
void PatchPage::FoldAll()
 
{
 
	for (uint field = 0; field < this->num; field++) {
 
		this->entries[field].FoldAll();
 
	}
 
}
 

	
 
/** Return number of rows needed to display the whole page */
 
uint PatchPage::Length() const
 
{
 
	uint length = 0;
 
	for (uint field = 0; field < this->num; field++) {
 
		length += this->entries[field].Length();
 
	}
 
	return length;
 
}
 

	
 
/**
 
 * Find the patch entry at row number \a row_num
 
@@ -1140,24 +1167,26 @@ struct PatchesSelectionWindow : Window {
 
		 */
 
		assert(this->widget[PATCHSEL_OPTIONSPANEL].left + 5 == SETTINGTREE_LEFT_OFFSET);
 
		assert(this->widget[PATCHSEL_OPTIONSPANEL].top + 5 == SETTINGTREE_TOP_OFFSET);
 

	
 
		static bool first_time = true;
 

	
 
		patches_ptr = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game;
 

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

	
 
		this->valuewindow_entry = NULL; // No patch entry for which a entry window is opened
 
		this->clicked_entry = NULL; // No numeric patch setting buttons are depressed
 
		this->vscroll.pos = 0;
 
		this->vscroll.cap = (this->widget[PATCHSEL_OPTIONSPANEL].bottom - this->widget[PATCHSEL_OPTIONSPANEL].top - 8) / SETTING_HEIGHT;
 
		SetVScrollCount(this, _patches_main_page.Length());
 

	
 
		this->resize.step_height = SETTING_HEIGHT;
 
		this->resize.height = this->height;
 
		this->resize.step_width = 1;
 
		this->resize.width = this->width;
 
@@ -1311,25 +1340,25 @@ const int PatchesSelectionWindow::SETTIN
 
const int PatchesSelectionWindow::SETTINGTREE_TOP_OFFSET = 19;
 

	
 
static const Widget _patches_selection_widgets[] = {
 
{   WWT_CLOSEBOX,   RESIZE_NONE,  COLOUR_MAUVE,     0,    10,     0,    13, STR_00C5,                        STR_018B_CLOSE_WINDOW},
 
{    WWT_CAPTION,  RESIZE_RIGHT,  COLOUR_MAUVE,    11,   411,     0,    13, STR_CONFIG_PATCHES_CAPTION,      STR_018C_WINDOW_TITLE_DRAG_THIS},
 
{      WWT_PANEL,     RESIZE_RB,  COLOUR_MAUVE,     0,   399,    14,   187, 0x0,                             STR_NULL}, // PATCHSEL_OPTIONSPANEL
 
{  WWT_SCROLLBAR,    RESIZE_LRB,  COLOUR_MAUVE,   400,   411,    14,   175, 0x0,                             STR_0190_SCROLL_BAR_SCROLLS_LIST}, // PATCHSEL_SCROLLBAR
 
{  WWT_RESIZEBOX,   RESIZE_LRTB,  COLOUR_MAUVE,   400,   411,   176,   187, 0x0,                             STR_RESIZE_BUTTON}, // PATCHSEL_RESIZE
 
{   WIDGETS_END},
 
};
 

	
 
static const WindowDesc _patches_selection_desc = {
 
	WDP_CENTER, WDP_CENTER, 412, 188, 412, 397,
 
	WDP_CENTER, WDP_CENTER, 412, 188, 450, 397,
 
	WC_GAME_OPTIONS, WC_NONE,
 
	WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_RESIZABLE,
 
	_patches_selection_widgets,
 
};
 

	
 
void ShowPatchesSelection()
 
{
 
	DeleteWindowById(WC_GAME_OPTIONS, 0);
 
	new PatchesSelectionWindow(&_patches_selection_desc);
 
}
 

	
 

	
0 comments (0 inline, 0 general)