mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r23757) -Codechange: Unify the drawing of toggle buttons for boolean settings.
This commit is contained in:
parent
2fb393fcd0
commit
69e197c87f
|
@ -384,7 +384,7 @@ struct AISettingsWindow : public Window {
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0) {
|
if ((config_item.flags & SCRIPTCONFIG_BOOLEAN) != 0) {
|
||||||
DrawFrameRect(buttons_left, y + 2, buttons_left + 19, y + 10, (current_value != 0) ? COLOUR_GREEN : COLOUR_RED, (current_value != 0) ? FR_LOWERED : FR_NONE);
|
DrawBoolButton(buttons_left, y + 2, current_value != 0, editable);
|
||||||
SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
|
SetDParam(idx++, current_value == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
|
||||||
} else {
|
} else {
|
||||||
DrawArrowButtons(buttons_left, y + 2, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value);
|
DrawArrowButtons(buttons_left, y + 2, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, editable && current_value > config_item.min_value, editable && current_value < config_item.max_value);
|
||||||
|
|
|
@ -197,7 +197,7 @@ struct CheatWindow : Window {
|
||||||
case SLE_BOOL: {
|
case SLE_BOOL: {
|
||||||
bool on = (*(bool*)ce->variable);
|
bool on = (*(bool*)ce->variable);
|
||||||
|
|
||||||
DrawFrameRect(button_left, y + 1, button_left + 20 - 1, y + FONT_HEIGHT_NORMAL - 1, on ? COLOUR_GREEN : COLOUR_RED, on ? FR_LOWERED : FR_NONE);
|
DrawBoolButton(button_left, y, on, true);
|
||||||
SetDParam(0, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
|
SetDParam(0, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@ void ShowGameOptions();
|
||||||
void ShowGameDifficulty();
|
void ShowGameDifficulty();
|
||||||
void ShowGameSettings();
|
void ShowGameSettings();
|
||||||
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right);
|
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right);
|
||||||
|
void DrawBoolButton(int x, int y, bool state, bool clickable);
|
||||||
|
|
||||||
/* train_gui.cpp */
|
/* train_gui.cpp */
|
||||||
void ShowOrdersWindow(const Vehicle *v);
|
void ShowOrdersWindow(const Vehicle *v);
|
||||||
|
|
|
@ -247,7 +247,7 @@ struct NewGRFParametersWindow : public Window {
|
||||||
bool selected = (i == this->clicked_row);
|
bool selected = (i == this->clicked_row);
|
||||||
|
|
||||||
if (par_info->type == PTYPE_BOOL) {
|
if (par_info->type == PTYPE_BOOL) {
|
||||||
DrawFrameRect(buttons_left, y + 2, buttons_left + 19, y + 10, (current_value != 0) ? COLOUR_GREEN : COLOUR_RED, (current_value != 0) ? FR_LOWERED : FR_NONE);
|
DrawBoolButton(buttons_left, y + 2, current_value != 0, true);
|
||||||
SetDParam(2, par_info->GetValue(this->grf_config) == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
|
SetDParam(2, par_info->GetValue(this->grf_config) == 0 ? STR_CONFIG_SETTING_OFF : STR_CONFIG_SETTING_ON);
|
||||||
} else if (par_info->type == PTYPE_UINT_ENUM) {
|
} else if (par_info->type == PTYPE_UINT_ENUM) {
|
||||||
DrawArrowButtons(buttons_left, y + 2, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, current_value > par_info->min_value, current_value < par_info->max_value);
|
DrawArrowButtons(buttons_left, y + 2, COLOUR_YELLOW, (this->clicked_button == i) ? 1 + (this->clicked_increase != rtl) : 0, current_value > par_info->min_value, current_value < par_info->max_value);
|
||||||
|
|
|
@ -1197,11 +1197,10 @@ void SettingEntry::DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd
|
||||||
if ((sdb->flags & SGF_NO_NETWORK) && _networking) editable = false;
|
if ((sdb->flags & SGF_NO_NETWORK) && _networking) editable = false;
|
||||||
|
|
||||||
if (sdb->cmd == SDT_BOOLX) {
|
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 */
|
/* Draw checkbox for boolean-value either on/off */
|
||||||
bool on = ReadValue(var, sd->save.conv) != 0;
|
bool on = ReadValue(var, sd->save.conv) != 0;
|
||||||
|
|
||||||
DrawFrameRect(buttons_left, button_y, buttons_left + 19, button_y + 8, _bool_ctabs[!!on][!!editable], on ? FR_LOWERED : FR_NONE);
|
DrawBoolButton(buttons_left, button_y, on, editable);
|
||||||
SetDParam(0, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
|
SetDParam(0, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
|
||||||
} else {
|
} else {
|
||||||
int32 value;
|
int32 value;
|
||||||
|
@ -1822,6 +1821,19 @@ void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clic
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Draw a toggle button.
|
||||||
|
* @param x the x position to draw
|
||||||
|
* @param y the y position to draw
|
||||||
|
* @param state true = lowered
|
||||||
|
* @param clickable is the button clickable?
|
||||||
|
*/
|
||||||
|
void DrawBoolButton(int x, int y, bool state, bool clickable)
|
||||||
|
{
|
||||||
|
static const Colours _bool_ctabs[2][2] = {{COLOUR_CREAM, COLOUR_RED}, {COLOUR_DARK_GREEN, COLOUR_GREEN}};
|
||||||
|
DrawFrameRect(x, y + 1, x + 19, y + 9, _bool_ctabs[state][clickable], state ? FR_LOWERED : FR_NONE);
|
||||||
|
}
|
||||||
|
|
||||||
struct CustomCurrencyWindow : Window {
|
struct CustomCurrencyWindow : Window {
|
||||||
int query_widget;
|
int query_widget;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue