Changeset - r21811:1abd5b674a60
[Not reviewed]
master
0 1 0
peter1138 - 10 years ago 2014-10-04 19:52:23
peter1138@openttd.org
(svn r26956) -Codechange: GUI-scale for cheat window.
1 file changed with 29 insertions and 19 deletions:
0 comments (0 inline, 0 general)
src/cheat_gui.cpp
Show inline comments
 
@@ -211,9 +211,12 @@ struct CheatWindow : Window {
 
	int clicked;
 
	int header_height;
 
	int clicked_widget;
 
	uint line_height;
 
	int box_width;
 

	
 
	CheatWindow(WindowDesc *desc) : Window(desc)
 
	{
 
		this->box_width = GetSpriteSize(SPR_BOX_EMPTY).width;
 
		this->InitNested();
 
	}
 

	
 
@@ -225,21 +228,24 @@ struct CheatWindow : Window {
 
		DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_LEFT, r.top + WD_FRAMERECT_TOP, y, STR_CHEATS_WARNING, TC_FROMSTRING, SA_CENTER);
 

	
 
		bool rtl = _current_text_dir == TD_RTL;
 
		uint box_left    = rtl ? r.right - 12 : r.left + 5;
 
		uint button_left = rtl ? r.right - 20 - SETTING_BUTTON_WIDTH : r.left + 20;
 
		uint text_left   = r.left + (rtl ? WD_FRAMERECT_LEFT : 30 + SETTING_BUTTON_WIDTH);
 
		uint text_right  = r.right - (rtl ? 30 + SETTING_BUTTON_WIDTH : WD_FRAMERECT_RIGHT);
 
		uint box_left    = rtl ? r.right - this->box_width - 5 : r.left + 5;
 
		uint button_left = rtl ? r.right - this->box_width - 10 - SETTING_BUTTON_WIDTH : r.left + this->box_width + 10;
 
		uint text_left   = r.left + (rtl ? WD_FRAMERECT_LEFT : 20 + this->box_width + SETTING_BUTTON_WIDTH);
 
		uint text_right  = r.right - (rtl ? 20 + this->box_width + SETTING_BUTTON_WIDTH : WD_FRAMERECT_RIGHT);
 

	
 
		int text_y_offset = (this->line_height - FONT_HEIGHT_NORMAL) / 2;
 
		int icon_y_offset = (this->line_height - SETTING_BUTTON_HEIGHT) / 2;
 

	
 
		for (int i = 0; i != lengthof(_cheats_ui); i++) {
 
			const CheatEntry *ce = &_cheats_ui[i];
 

	
 
			DrawSprite((*ce->been_used) ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, box_left, y + 2);
 
			DrawSprite((*ce->been_used) ? SPR_BOX_CHECKED : SPR_BOX_EMPTY, PAL_NONE, box_left, y + icon_y_offset + 2);
 

	
 
			switch (ce->type) {
 
				case SLE_BOOL: {
 
					bool on = (*(bool*)ce->variable);
 

	
 
					DrawBoolButton(button_left, y, on, true);
 
					DrawBoolButton(button_left, y + icon_y_offset, on, true);
 
					SetDParam(0, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
 
					break;
 
				}
 
@@ -249,7 +255,7 @@ struct CheatWindow : Window {
 
					char buf[512];
 

	
 
					/* Draw [<][>] boxes for settings of an integer-type */
 
					DrawArrowButtons(button_left, y, COLOUR_YELLOW, clicked - (i * 2), true, true);
 
					DrawArrowButtons(button_left, y + icon_y_offset, COLOUR_YELLOW, clicked - (i * 2), true, true);
 

	
 
					switch (ce->str) {
 
						/* Display date for change date cheat */
 
@@ -260,7 +266,7 @@ struct CheatWindow : Window {
 
							SetDParam(0, val + 1);
 
							GetString(buf, STR_CHEAT_CHANGE_COMPANY, lastof(buf));
 
							uint offset = 10 + GetStringBoundingBox(buf).width;
 
							DrawCompanyIcon(_local_company, rtl ? text_right - offset - 10 : text_left + offset, y + 2);
 
							DrawCompanyIcon(_local_company, rtl ? text_right - offset - 10 : text_left + offset, y + icon_y_offset + 2);
 
							break;
 
						}
 

	
 
@@ -270,9 +276,9 @@ struct CheatWindow : Window {
 
				}
 
			}
 

	
 
			DrawString(text_left, text_right, y + 1, ce->str);
 
			DrawString(text_left, text_right, y + text_y_offset, ce->str);
 

	
 
			y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
 
			y += this->line_height;
 
		}
 
	}
 

	
 
@@ -314,16 +320,20 @@ struct CheatWindow : Window {
 
			}
 
		}
 

	
 
		size->width = width + 50 /* stuff on the left */ + 10 /* extra spacing on right */;
 
		this->line_height = max(GetSpriteSize(SPR_BOX_CHECKED).height, GetSpriteSize(SPR_BOX_EMPTY).height);
 
		this->line_height = max<uint>(this->line_height, SETTING_BUTTON_HEIGHT);
 
		this->line_height = max<uint>(this->line_height, FONT_HEIGHT_NORMAL) + WD_PAR_VSEP_NORMAL;
 

	
 
		size->width = width + 20 + this->box_width + SETTING_BUTTON_WIDTH /* stuff on the left */ + 10 /* extra spacing on right */;
 
		this->header_height = GetStringHeight(STR_CHEATS_WARNING, size->width - WD_FRAMERECT_LEFT - WD_FRAMERECT_RIGHT) + WD_PAR_VSEP_WIDE;
 
		size->height = this->header_height + WD_FRAMERECT_TOP + WD_PAR_VSEP_NORMAL + WD_FRAMERECT_BOTTOM + (FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL) * lengthof(_cheats_ui);
 
		size->height = this->header_height + WD_FRAMERECT_TOP + WD_PAR_VSEP_NORMAL + WD_FRAMERECT_BOTTOM + this->line_height * lengthof(_cheats_ui);
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget, int click_count)
 
	{
 
		const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_C_PANEL);
 
		uint btn = (pt.y - wid->pos_y - WD_FRAMERECT_TOP - this->header_height) / (FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL);
 
		uint x = pt.x - wid->pos_x;
 
		uint btn = (pt.y - wid->pos_y - WD_FRAMERECT_TOP - this->header_height) / this->line_height;
 
		int x = pt.x - wid->pos_x;
 
		bool rtl = _current_text_dir == TD_RTL;
 
		if (rtl) x = wid->current_x - x;
 

	
 
@@ -333,13 +343,13 @@ struct CheatWindow : Window {
 
		int value = (int32)ReadValue(ce->variable, ce->type);
 
		int oldvalue = value;
 

	
 
		if (btn == CHT_CHANGE_DATE && x >= 20 + SETTING_BUTTON_WIDTH) {
 
		if (btn == CHT_CHANGE_DATE && x >= 20 + this->box_width + SETTING_BUTTON_WIDTH) {
 
			/* Click at the date text directly. */
 
			clicked_widget = CHT_CHANGE_DATE;
 
			SetDParam(0, value);
 
			ShowQueryString(STR_JUST_INT, STR_CHEAT_CHANGE_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
 
			return;
 
		} else if (btn == CHT_EDIT_MAX_HL && x >= 20 + SETTING_BUTTON_WIDTH) {
 
		} else if (btn == CHT_EDIT_MAX_HL && x >= 20 + this->box_width + SETTING_BUTTON_WIDTH) {
 
			clicked_widget = CHT_EDIT_MAX_HL;
 
			SetDParam(0, value);
 
			ShowQueryString(STR_JUST_INT, STR_CHEAT_EDIT_MAX_HL_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ACCEPT_UNCHANGED);
 
@@ -347,7 +357,7 @@ struct CheatWindow : Window {
 
		}
 

	
 
		/* Not clicking a button? */
 
		if (!IsInsideMM(x, 20, 20 + SETTING_BUTTON_WIDTH)) return;
 
		if (!IsInsideMM(x, 10 + this->box_width, 10 + this->box_width + SETTING_BUTTON_WIDTH)) return;
 

	
 
		*ce->been_used = true;
 

	
 
@@ -359,10 +369,10 @@ struct CheatWindow : Window {
 

	
 
			default:
 
				/* Take whatever the function returns */
 
				value = ce->proc(value + ((x >= 20 + SETTING_BUTTON_WIDTH / 2) ? 1 : -1), (x >= 20 + SETTING_BUTTON_WIDTH / 2) ? 1 : -1);
 
				value = ce->proc(value + ((x >= 20 + SETTING_BUTTON_WIDTH / 2) ? 1 : -1), (x >= 10 + this->box_width + SETTING_BUTTON_WIDTH / 2) ? 1 : -1);
 

	
 
				/* The first cheat (money), doesn't return a different value. */
 
				if (value != oldvalue || btn == CHT_MONEY) this->clicked = btn * 2 + 1 + ((x >= 20 + SETTING_BUTTON_WIDTH / 2) != rtl ? 1 : 0);
 
				if (value != oldvalue || btn == CHT_MONEY) this->clicked = btn * 2 + 1 + ((x >= 10 + this->box_width + SETTING_BUTTON_WIDTH / 2) != rtl ? 1 : 0);
 
				break;
 
		}
 

	
0 comments (0 inline, 0 general)