Changeset - r19328:ef1d4d5fdd4e
[Not reviewed]
master
0 1 0
alberth - 12 years ago 2012-05-12 10:17:20
alberth@openttd.org
(svn r24239) -Add: Highlight setting that has its help text displayed.
1 file changed with 16 insertions and 12 deletions:
0 comments (0 inline, 0 general)
src/settings_gui.cpp
Show inline comments
 
@@ -1010,26 +1010,26 @@ struct SettingEntry {
 
	void SetButtons(byte new_val);
 

	
 
	uint Length() const;
 
	SettingEntry *FindEntry(uint row, uint *cur_row);
 
	uint GetMaxHelpHeight(int maxw);
 

	
 
	uint Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, uint cur_row, uint parent_last);
 
	uint Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, uint cur_row, uint parent_last, SettingEntry *selected);
 

	
 
	/**
 
	 * Get the help text of a single setting.
 
	 * @return The requested help text.
 
	 */
 
	inline StringID GetHelpText()
 
	{
 
		assert((this->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
 
		return this->d.entry.setting->desc.str_help;
 
	}
 

	
 
private:
 
	void DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd, int x, int y, int max_x, int state);
 
	void DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd, int x, int y, int max_x, int state, bool highlight);
 
};
 

	
 
/** Data structure describing one page of settings in the settings window. */
 
struct SettingsPage {
 
	SettingEntry *entries; ///< Array of setting entries of the page.
 
	byte num;              ///< Number of entries on the page (statically filled).
 
@@ -1038,13 +1038,13 @@ struct SettingsPage {
 
	void FoldAll();
 

	
 
	uint Length() const;
 
	SettingEntry *FindEntry(uint row, uint *cur_row) const;
 
	uint GetMaxHelpHeight(int maxw);
 

	
 
	uint Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, uint cur_row = 0, uint parent_last = 0) const;
 
	uint Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, SettingEntry *selected, uint cur_row = 0, uint parent_last = 0) const;
 
};
 

	
 

	
 
/* == SettingEntry methods == */
 

	
 
/**
 
@@ -1200,15 +1200,16 @@ uint SettingEntry::GetMaxHelpHeight(int 
 
 * @param right        Right-most x position to draw strings at.
 
 * @param base_y       Upper-most position in window/panel to start drawing \a first_row
 
 * @param first_row    First row number to draw
 
 * @param max_row      Row-number to stop drawing (the row-number of the row below the last row to draw)
 
 * @param cur_row      Current row number (internal variable)
 
 * @param parent_last  Last-field booleans of parent page level (page level \e i sets bit \e i to 1 if it is its last field)
 
 * @param selected     Selected entry by the user.
 
 * @return Row number of the next row to draw
 
 */
 
uint SettingEntry::Draw(GameSettings *settings_ptr, int left, int right, int base_y, uint first_row, uint max_row, uint cur_row, uint parent_last)
 
uint SettingEntry::Draw(GameSettings *settings_ptr, int left, int right, int base_y, uint first_row, uint max_row, uint cur_row, uint parent_last, SettingEntry *selected)
 
{
 
	if (cur_row >= max_row) return cur_row;
 

	
 
	bool rtl = _current_text_dir == TD_RTL;
 
	int offset = rtl ? -4 : 4;
 
	int level_width = rtl ? -LEVEL_WIDTH : LEVEL_WIDTH;
 
@@ -1233,13 +1234,14 @@ uint SettingEntry::Draw(GameSettings *se
 
		x += level_width;
 
	}
 

	
 
	switch (this->flags & SEF_KIND_MASK) {
 
		case SEF_SETTING_KIND:
 
			if (cur_row >= first_row) {
 
				DrawSetting(settings_ptr, this->d.entry.setting, rtl ? left : x, rtl ? x : right, y, this->flags & SEF_BUTTONS_MASK);
 
				this->DrawSetting(settings_ptr, this->d.entry.setting, rtl ? left : x, rtl ? x : right, y, this->flags & SEF_BUTTONS_MASK,
 
						this == selected);
 
			}
 
			cur_row++;
 
			break;
 
		case SEF_SUBTREE_KIND:
 
			if (cur_row >= first_row) {
 
				DrawSprite((this->d.sub.folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED), PAL_NONE, rtl ? x - 8 : x, y + (SETTING_HEIGHT - 11) / 2);
 
@@ -1249,13 +1251,13 @@ uint SettingEntry::Draw(GameSettings *se
 
			if (!this->d.sub.folded) {
 
				if (this->flags & SEF_LAST_FIELD) {
 
					assert(this->level < sizeof(parent_last));
 
					SetBit(parent_last, this->level); // Add own last-field state
 
				}
 

	
 
				cur_row = this->d.sub.page->Draw(settings_ptr, left, right, base_y, first_row, max_row, cur_row, parent_last);
 
				cur_row = this->d.sub.page->Draw(settings_ptr, left, right, base_y, first_row, max_row, selected, cur_row, parent_last);
 
			}
 
			break;
 
		default: NOT_REACHED();
 
	}
 
	return cur_row;
 
}
 
@@ -1278,14 +1280,15 @@ static const void *ResolveVariableAddres
 
 * @param settings_ptr Pointer to current values of all settings
 
 * @param sd           Pointer to value description of setting to draw
 
 * @param left         Left-most position in window/panel to start drawing
 
 * @param right        Right-most position in window/panel to draw
 
 * @param y            Upper-most position in window/panel to start drawing
 
 * @param state        State of the left + right arrow buttons to draw for the setting
 
 * @param highlight    Highlight entry.
 
 */
 
void SettingEntry::DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd, int left, int right, int y, int state)
 
void SettingEntry::DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd, int left, int right, int y, int state, bool highlight)
 
{
 
	const SettingDescBase *sdb = &sd->desc;
 
	const void *var = ResolveVariableAddress(settings_ptr, sd);
 
	bool editable = true;
 

	
 
	bool rtl = _current_text_dir == TD_RTL;
 
@@ -1296,13 +1299,13 @@ void SettingEntry::DrawSetting(GameSetti
 

	
 
	/* We do not allow changes of some items when we are a client in a networkgame */
 
	if (!(sd->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(sdb->flags & SGF_PER_COMPANY)) editable = false;
 
	if ((sdb->flags & SGF_NETWORK_ONLY) && !_networking) editable = false;
 
	if ((sdb->flags & SGF_NO_NETWORK) && _networking) editable = false;
 

	
 
	SetDParam(0, STR_ORANGE_STRING1_LTBLUE);
 
	SetDParam(0, highlight ? STR_ORANGE_STRING1_WHITE : STR_ORANGE_STRING1_LTBLUE);
 
	if (sdb->cmd == SDT_BOOLX) {
 
		/* Draw checkbox for boolean-value either on/off */
 
		bool on = ReadValue(var, sd->save.conv) != 0;
 

	
 
		DrawBoolButton(buttons_left, button_y, on, editable);
 
		SetDParam(1, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
 
@@ -1320,13 +1323,13 @@ void SettingEntry::DrawSetting(GameSetti
 
			value = abs(value);
 
		} else {
 
			SetDParam(1, sdb->str_val + ((value == 0 && (sdb->flags & SGF_0ISDISABLED) != 0) ? 1 : 0));
 
		}
 
		SetDParam(2, value);
 
	}
 
	DrawString(text_left, text_right, y, sdb->str, TC_LIGHT_BLUE);
 
	DrawString(text_left, text_right, y, sdb->str, highlight ? TC_WHITE : TC_LIGHT_BLUE);
 
}
 

	
 

	
 
/* == SettingsPage methods == */
 

	
 
/**
 
@@ -1403,20 +1406,21 @@ uint SettingsPage::GetMaxHelpHeight(int 
 
 * @param right        Right-most position in window/panel to draw at
 
 * @param base_y       Upper-most position in window/panel to start drawing of row number \a first_row
 
 * @param first_row    Number of first row to draw
 
 * @param max_row      Row-number to stop drawing (the row-number of the row below the last row to draw)
 
 * @param cur_row      Current row number (internal variable)
 
 * @param parent_last  Last-field booleans of parent page level (page level \e i sets bit \e i to 1 if it is its last field)
 
 * @param selected     Selected entry by the user.
 
 * @return Row number of the next row to draw
 
 */
 
uint SettingsPage::Draw(GameSettings *settings_ptr, int left, int right, int base_y, uint first_row, uint max_row, uint cur_row, uint parent_last) const
 
uint SettingsPage::Draw(GameSettings *settings_ptr, int left, int right, int base_y, uint first_row, uint max_row, SettingEntry *selected, uint cur_row, uint parent_last) const
 
{
 
	if (cur_row >= max_row) return cur_row;
 

	
 
	for (uint i = 0; i < this->num; i++) {
 
		cur_row = this->entries[i].Draw(settings_ptr, left, right, base_y, first_row, max_row, cur_row, parent_last);
 
		cur_row = this->entries[i].Draw(settings_ptr, left, right, base_y, first_row, max_row, cur_row, parent_last, selected);
 
		if (cur_row >= max_row) {
 
			break;
 
		}
 
	}
 
	return cur_row;
 
}
 
@@ -1731,13 +1735,13 @@ struct GameSettingsWindow : Window {
 

	
 
	virtual void DrawWidget(const Rect &r, int widget) const
 
	{
 
		switch (widget) {
 
			case WID_GS_OPTIONSPANEL:
 
				_settings_main_page.Draw(settings_ptr, r.left + SETTINGTREE_LEFT_OFFSET, r.right - SETTINGTREE_RIGHT_OFFSET, r.top + SETTINGTREE_TOP_OFFSET,
 
						this->vscroll->GetPosition(), this->vscroll->GetPosition() + this->vscroll->GetCapacity());
 
						this->vscroll->GetPosition(), this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->last_clicked);
 
				break;
 

	
 
			case WID_GS_HELP_TEXT:
 
				if (this->last_clicked != NULL) {
 
					DrawStringMultiLine(r.left, r.right, r.top, r.bottom, this->last_clicked->GetHelpText(), TC_WHITE);
 
				}
0 comments (0 inline, 0 general)