|
@@ -989,65 +989,69 @@ SettingEntry *SettingEntry::FindEntry(ui
|
|
|
* | |-- setting
|
|
|
* \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 base_x Left-most position in window/panel to start drawing \a first_row
|
|
|
* @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 max_x The maximum x position to draw strings add.
|
|
|
* @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)
|
|
|
* @return Row number of the next row to draw
|
|
|
*/
|
|
|
uint SettingEntry::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 SettingEntry::Draw(GameSettings *settings_ptr, int left, int right, int base_y, uint first_row, uint max_row, uint cur_row, uint parent_last)
|
|
|
{
|
|
|
if (cur_row >= max_row) return cur_row;
|
|
|
|
|
|
int x = base_x;
|
|
|
bool rtl = _dynlang.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
|
|
|
|
|
|
/* Draw vertical for parent nesting levels */
|
|
|
for (uint lvl = 0; lvl < this->level; lvl++) {
|
|
|
if (!HasBit(parent_last, lvl)) GfxDrawLine(x + 4, y, x + 4, y + SETTING_HEIGHT - 1, colour);
|
|
|
x += LEVEL_WIDTH;
|
|
|
if (!HasBit(parent_last, lvl)) GfxDrawLine(x + offset, y, x + offset, y + SETTING_HEIGHT - 1, colour);
|
|
|
x += level_width;
|
|
|
}
|
|
|
/* 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 + 4, y, x + 4, bottom_y, colour);
|
|
|
GfxDrawLine(x + offset, y, x + offset, bottom_y, colour);
|
|
|
/* Small horizontal line from the last vertical line */
|
|
|
GfxDrawLine(x + 4, halfway_y, x + LEVEL_WIDTH - 4, halfway_y, colour);
|
|
|
x += LEVEL_WIDTH;
|
|
|
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, x, y, max_x, this->flags & SEF_BUTTONS_MASK);
|
|
|
DrawSetting(settings_ptr, this->d.entry.setting, rtl ? left : x, rtl ? x : right, y, this->flags & SEF_BUTTONS_MASK);
|
|
|
}
|
|
|
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, x, y);
|
|
|
DrawString(x + 12, max_x, y, this->d.sub.title);
|
|
|
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, base_x, base_y, max_x, 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, cur_row, parent_last);
|
|
|
}
|
|
|
break;
|
|
|
default: NOT_REACHED();
|
|
|
}
|
|
|
return cur_row;
|
|
|
}
|
|
@@ -1066,43 +1070,49 @@ static const void *ResolveVariableAddres
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 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 x Left-most position in window/panel to start drawing
|
|
|
* @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 max_x The maximum x position to draw strings add.
|
|
|
* @param state State of the left + right arrow buttons to draw for the setting
|
|
|
*/
|
|
|
void SettingEntry::DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd, int x, int y, int max_x, int state)
|
|
|
void SettingEntry::DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd, int left, int right, int y, int state)
|
|
|
{
|
|
|
const SettingDescBase *sdb = &sd->desc;
|
|
|
const void *var = ResolveVariableAddress(settings_ptr, sd);
|
|
|
bool editable = true;
|
|
|
bool disabled = false;
|
|
|
|
|
|
bool rtl = _dynlang.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_NETWORK_NO) && _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;
|
|
|
|
|
|
if (sdb->cmd == SDT_BOOLX) {
|
|
|
static const Colours _bool_ctabs[2][2] = {{COLOUR_CREAM, COLOUR_RED}, {COLOUR_DARK_GREEN, COLOUR_GREEN}};
|
|
|
/* Draw checkbox for boolean-value either on/off */
|
|
|
bool on = (*(bool*)var);
|
|
|
|
|
|
DrawFrameRect(x, y, x + 19, y + 8, _bool_ctabs[!!on][!!editable], on ? FR_LOWERED : FR_NONE);
|
|
|
DrawFrameRect(buttons_left, button_y, buttons_left + 19, button_y + 8, _bool_ctabs[!!on][!!editable], on ? FR_LOWERED : FR_NONE);
|
|
|
SetDParam(0, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
|
|
|
} else {
|
|
|
int32 value;
|
|
|
|
|
|
value = (int32)ReadValue(var, sd->save.conv);
|
|
|
|
|
|
/* Draw [<][>] boxes for settings of an integer-type */
|
|
|
DrawArrowButtons(x, y, COLOUR_YELLOW, state, editable && value != (sdb->flags & SGF_0ISDISABLED ? 0 : sdb->min), editable && (uint32)value != sdb->max);
|
|
|
DrawArrowButtons(buttons_left, button_y, COLOUR_YELLOW, state, editable && value != (sdb->flags & SGF_0ISDISABLED ? 0 : sdb->min), editable && (uint32)value != sdb->max);
|
|
|
|
|
|
disabled = (value == 0) && (sdb->flags & SGF_0ISDISABLED);
|
|
|
if (disabled) {
|
|
|
SetDParam(0, STR_CONFIG_SETTING_DISABLED);
|
|
|
} else {
|
|
|
if (sdb->flags & SGF_CURRENCY) {
|
|
@@ -1112,13 +1122,13 @@ void SettingEntry::DrawSetting(GameSetti
|
|
|
} else {
|
|
|
SetDParam(0, (sdb->flags & SGF_NOCOMMA) ? STR_JUST_INT : STR_JUST_COMMA);
|
|
|
}
|
|
|
SetDParam(1, value);
|
|
|
}
|
|
|
}
|
|
|
DrawString(x + 25, max_x, y, (sdb->str) + disabled);
|
|
|
DrawString(text_left, text_right, y, (sdb->str) + disabled);
|
|
|
}
|
|
|
|
|
|
|
|
|
/* == SettingsPage methods == */
|
|
|
|
|
|
/**
|
|
@@ -1174,27 +1184,27 @@ SettingEntry *SettingsPage::FindEntry(ui
|
|
|
*
|
|
|
* 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 base_x Left-most position in window/panel to start drawing of each setting row
|
|
|
* @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 max_x The maximum x position to draw strings add.
|
|
|
* @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)
|
|
|
* @return Row number of the next row to draw
|
|
|
*/
|
|
|
uint SettingsPage::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) const
|
|
|
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
|
|
|
{
|
|
|
if (cur_row >= max_row) return cur_row;
|
|
|
|
|
|
for (uint i = 0; i < this->num; i++) {
|
|
|
cur_row = this->entries[i].Draw(settings_ptr, base_x, base_y, max_x, 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);
|
|
|
if (cur_row >= max_row) {
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
return cur_row;
|
|
|
}
|
|
@@ -1478,14 +1488,14 @@ struct GameSettingsWindow : Window {
|
|
|
}
|
|
|
|
|
|
virtual void DrawWidget(const Rect &r, int widget) const
|
|
|
{
|
|
|
if (widget != SETTINGSEL_OPTIONSPANEL) return;
|
|
|
|
|
|
_settings_main_page.Draw(settings_ptr, r.left + SETTINGTREE_LEFT_OFFSET, r.top + SETTINGTREE_TOP_OFFSET,
|
|
|
r.right - SETTINGTREE_RIGHT_OFFSET, this->vscroll.GetPosition(), this->vscroll.GetPosition() + this->vscroll.GetCapacity());
|
|
|
_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());
|
|
|
}
|
|
|
|
|
|
virtual void OnPaint()
|
|
|
{
|
|
|
this->DrawWidgets();
|
|
|
}
|
|
@@ -1502,13 +1512,13 @@ struct GameSettingsWindow : Window {
|
|
|
|
|
|
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 = pt.x - SETTINGTREE_LEFT_OFFSET - (pe->level + 1) * LEVEL_WIDTH; // Shift x coordinate
|
|
|
int x = (_dynlang.text_dir == TD_RTL ? this->width - 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) {
|
|
|
pe->d.sub.folded = !pe->d.sub.folded; // Flip 'folded'-ness of the sub-page
|
|
|
|
|
|
this->vscroll.SetCount(_settings_main_page.Length());
|
|
@@ -1567,13 +1577,13 @@ struct GameSettingsWindow : Window {
|
|
|
/* Set up scroller timeout for numeric values */
|
|
|
if (value != oldvalue && !(sd->desc.flags & SGF_MULTISTRING)) {
|
|
|
if (this->clicked_entry != NULL) { // Release previous buttons if any
|
|
|
this->clicked_entry->SetButtons(0);
|
|
|
}
|
|
|
this->clicked_entry = pe;
|
|
|
this->clicked_entry->SetButtons((x >= 10) ? SEF_RIGHT_DEPRESSED : SEF_LEFT_DEPRESSED);
|
|
|
this->clicked_entry->SetButtons((x >= 10) != (_dynlang.text_dir == TD_RTL) ? SEF_RIGHT_DEPRESSED : SEF_LEFT_DEPRESSED);
|
|
|
this->flags4 |= WF_TIMEOUT_BEGIN;
|
|
|
_left_button_clicked = false;
|
|
|
}
|
|
|
} break;
|
|
|
|
|
|
default: NOT_REACHED();
|
|
@@ -1681,16 +1691,17 @@ void DrawArrowButtons(int x, int y, Colo
|
|
|
DrawFrameRect(x, y + 1, x + 9, y + 9, button_colour, (state == 1) ? FR_LOWERED : FR_NONE);
|
|
|
DrawFrameRect(x + 10, y + 1, x + 19, y + 9, button_colour, (state == 2) ? FR_LOWERED : FR_NONE);
|
|
|
DrawSprite(SPR_ARROW_LEFT, PAL_NONE, x + WD_IMGBTN_LEFT, y + WD_IMGBTN_TOP);
|
|
|
DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, x + WD_IMGBTN_LEFT + 10, y + WD_IMGBTN_TOP);
|
|
|
|
|
|
/* Grey out the buttons that aren't clickable */
|
|
|
if (!clickable_left) {
|
|
|
bool rtl = _dynlang.text_dir == TD_RTL;
|
|
|
if (rtl ? !clickable_right : !clickable_left) {
|
|
|
GfxFillRect(x + 1, y + 1, x + 1 + 8, y + 8, colour, FILLRECT_CHECKER);
|
|
|
}
|
|
|
if (!clickable_right) {
|
|
|
if (rtl ? !clickable_left : !clickable_right) {
|
|
|
GfxFillRect(x + 11, y + 1, x + 11 + 8, y + 8, colour, FILLRECT_CHECKER);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/** Widget numbers of the custom currency window. */
|
|
|
enum CustomCurrencyWidgets {
|