|
@@ -1004,53 +1004,53 @@ struct SettingEntry {
|
|
|
|
|
|
SettingEntry(const char *nm);
|
|
|
SettingEntry(SettingsPage *sub, StringID title);
|
|
|
|
|
|
void Init(byte level, bool last_field);
|
|
|
void FoldAll();
|
|
|
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).
|
|
|
|
|
|
void Init(byte level = 0);
|
|
|
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 == */
|
|
|
|
|
|
/**
|
|
|
* Constructor for a single setting in the 'advanced settings' window
|
|
|
* @param nm Name of the setting in the setting table
|
|
|
*/
|
|
|
SettingEntry::SettingEntry(const char *nm)
|
|
|
{
|
|
|
this->flags = SEF_SETTING_KIND;
|
|
@@ -1194,27 +1194,28 @@ uint SettingEntry::GetMaxHelpHeight(int
|
|
|
* \endverbatim
|
|
|
* The left-most vertical line is not wanted. It is prevented by setting the
|
|
|
* appropiate bit in the \a parent_last parameter.
|
|
|
*
|
|
|
* @param settings_ptr Pointer to current values of all settings
|
|
|
* @param left Left-most position in window/panel to start drawing \a first_row
|
|
|
* @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;
|
|
|
|
|
|
int x = rtl ? right : left;
|
|
|
int y = base_y;
|
|
|
if (cur_row >= first_row) {
|
|
|
int colour = _colour_gradient[COLOUR_ORANGE][4];
|
|
|
y = base_y + (cur_row - first_row) * SETTING_HEIGHT; // Compute correct y start position
|
|
@@ -1227,41 +1228,42 @@ uint SettingEntry::Draw(GameSettings *se
|
|
|
/* draw own |- prefix */
|
|
|
int halfway_y = y + SETTING_HEIGHT / 2;
|
|
|
int bottom_y = (flags & SEF_LAST_FIELD) ? halfway_y : y + SETTING_HEIGHT - 1;
|
|
|
GfxDrawLine(x + offset, y, x + offset, bottom_y, colour);
|
|
|
/* Small horizontal line from the last vertical line */
|
|
|
GfxDrawLine(x + offset, halfway_y, x + level_width - offset, halfway_y, colour);
|
|
|
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);
|
|
|
DrawString(rtl ? left : x + 12, rtl ? x - 12 : right, y, this->d.sub.title);
|
|
|
}
|
|
|
cur_row++;
|
|
|
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;
|
|
|
}
|
|
|
|
|
|
static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd)
|
|
|
{
|
|
|
if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
|
|
|
if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
|
|
|
return GetVariableAddress(&Company::Get(_local_company)->settings, &sd->save);
|
|
@@ -1272,67 +1274,68 @@ static const void *ResolveVariableAddres
|
|
|
return GetVariableAddress(settings_ptr, &sd->save);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Private function to draw setting value (button + text + current value)
|
|
|
* @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;
|
|
|
uint buttons_left = rtl ? right - 19 : left;
|
|
|
uint text_left = left + (rtl ? 0 : 25);
|
|
|
uint text_right = right - (rtl ? 25 : 0);
|
|
|
uint button_y = y + (SETTING_HEIGHT - 11) / 2;
|
|
|
|
|
|
/* 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);
|
|
|
} else {
|
|
|
int32 value = (int32)ReadValue(var, sd->save.conv);
|
|
|
|
|
|
/* Draw [<][>] boxes for settings of an integer-type */
|
|
|
DrawArrowButtons(buttons_left, button_y, COLOUR_YELLOW, state,
|
|
|
editable && value != (sdb->flags & SGF_0ISDISABLED ? 0 : sdb->min), editable && (uint32)value != sdb->max);
|
|
|
|
|
|
if ((sdb->flags & SGF_MULTISTRING) != 0) {
|
|
|
SetDParam(1, sdb->str_val - sdb->min + value);
|
|
|
} else if ((sdb->flags & SGF_DISPLAY_ABS) != 0) {
|
|
|
SetDParam(1, sdb->str_val + ((value >= 0) ? 1 : 0));
|
|
|
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 == */
|
|
|
|
|
|
/**
|
|
|
* 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 SettingsPage::Init(byte level)
|
|
|
{
|
|
|
for (uint field = 0; field < this->num; field++) {
|
|
@@ -1397,32 +1400,33 @@ uint SettingsPage::GetMaxHelpHeight(int
|
|
|
* The scrollbar uses rows of the page, while the page data strucure is a tree of #SettingsPage and #SettingEntry objects.
|
|
|
* As a result, the drawing routing traverses the tree from top to bottom, counting rows in \a cur_row until it reaches \a first_row.
|
|
|
* Then it enables drawing rows while traversing until \a max_row is reached, at which point drawing is terminated.
|
|
|
*
|
|
|
* @param settings_ptr Pointer to current values of all settings
|
|
|
* @param left Left-most position in window/panel to start drawing of each setting row
|
|
|
* @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;
|
|
|
}
|
|
|
|
|
|
|
|
|
static SettingEntry _settings_ui_display[] = {
|
|
|
SettingEntry("gui.date_format_in_default_names"),
|
|
|
SettingEntry("gui.population_in_label"),
|
|
|
SettingEntry("gui.measure_tooltip"),
|
|
@@ -1725,25 +1729,25 @@ struct GameSettingsWindow : Window {
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
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);
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
}
|