Changeset - r10538:b47d533c4a04
[Not reviewed]
master
0 1 0
rubidium - 15 years ago 2009-01-03 10:53:49
rubidium@openttd.org
(svn r14795) -Codechange: replace a magic number with a constant (Alberth)
1 file changed with 7 insertions and 5 deletions:
0 comments (0 inline, 0 general)
src/settings_gui.cpp
Show inline comments
 
@@ -562,48 +562,50 @@ public:
 
			}
 

	
 
			case GDW_CANCEL: // Cancel button - close window, abandon changes
 
				delete this;
 
				break;
 
		}
 
	}
 

	
 
	virtual void OnTick()
 
	{
 
		if (this->timeout != 0) {
 
			this->timeout--;
 
			if (this->timeout == 0) this->clicked_button = NO_SETTINGS_BUTTON;
 
			this->SetDirty();
 
		}
 
	}
 
};
 

	
 
void ShowGameDifficulty()
 
{
 
	DeleteWindowById(WC_GAME_OPTIONS, 0);
 
	new GameDifficultyWindow();
 
}
 

	
 
static const int SETTING_HEIGHT = 11;         ///< Height of a single patch setting in the tree view
 

	
 
static const char *_patches_ui[] = {
 
	"gui.vehicle_speed",
 
	"gui.status_long_date",
 
	"gui.date_format_in_default_names",
 
	"gui.show_finances",
 
	"gui.autoscroll",
 
	"gui.reverse_scroll",
 
	"gui.smooth_scroll",
 
	"gui.errmsg_duration",
 
	"gui.toolbar_pos",
 
	"gui.measure_tooltip",
 
	"gui.window_snap_radius",
 
	"gui.population_in_label",
 
	"gui.link_terraform_toolbar",
 
	"gui.liveries",
 
	"gui.prefer_teamchat",
 
	/* While the horizontal scrollwheel scrolling is written as general code, only
 
	 *  the cocoa (OSX) driver generates input for it.
 
	 *  Since it's also able to completely disable the scrollwheel will we display it on all platforms anyway */
 
	"gui.scrollwheel_scrolling",
 
	"gui.scrollwheel_multiplier",
 
#ifdef __APPLE__
 
	/* We might need to emulate a right mouse button on mac */
 
	"gui.right_mouse_btn_emulation",
 
@@ -764,52 +766,52 @@ struct PatchesSelectionWindow : Window {
 
		patches_ptr = (_game_mode == GM_MENU) ? &_settings_newgame : &_settings_game;
 

	
 
		/* Build up the dynamic settings-array only once per OpenTTD session */
 
		if (first_time) {
 
			PatchPage *page;
 
			for (page = &_patches_page[0]; page != endof(_patches_page); page++) {
 
				uint i;
 

	
 
				if (patches_max < page->num) patches_max = page->num;
 

	
 
				page->entries = MallocT<PatchEntry>(page->num);
 
				for (i = 0; i != page->num; i++) {
 
					uint index;
 
					const SettingDesc *sd = GetPatchFromName(page->names[i], &index);
 
					assert(sd != NULL);
 

	
 
					page->entries[i].setting = sd;
 
					page->entries[i].index = index;
 
				}
 
			}
 
			first_time = false;
 
		}
 

	
 
		/* Resize the window to fit the largest patch tab */
 
		ResizeWindowForWidget(this, PATCHSEL_OPTIONSPANEL, 0, patches_max * 11);
 
		ResizeWindowForWidget(this, PATCHSEL_OPTIONSPANEL, 0, patches_max * SETTING_HEIGHT);
 

	
 
		/* Recentre the window for the new size */
 
		this->top = this->top - (patches_max * 11) / 2;
 
		this->top = this->top - (patches_max * SETTING_HEIGHT) / 2;
 

	
 
		this->LowerWidget(PATCHSEL_INTERFACE);
 

	
 
		this->FindWindowPlacementAndResize(desc);
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		int x, y;
 
		const PatchPage *page = &_patches_page[this->page];
 
		uint i;
 

	
 
		/* Set up selected category */
 
		this->DrawWidgets();
 

	
 
		x = 5;
 
		y = 47;
 
		for (i = 0; i != page->num; i++) {
 
			const SettingDesc *sd = page->entries[i].setting;
 
			const SettingDescBase *sdb = &sd->desc;
 
			const void *var = GetVariableAddress(patches_ptr, &sd->save);
 
			bool editable = true;
 
			bool disabled = false;
 

	
 
@@ -827,71 +829,71 @@ struct PatchesSelectionWindow : Window {
 
				SetDParam(0, on ? STR_CONFIG_PATCHES_ON : STR_CONFIG_PATCHES_OFF);
 
			} else {
 
				int32 value;
 

	
 
				value = (int32)ReadValue(var, sd->save.conv);
 

	
 
				/* Draw [<][>] boxes for settings of an integer-type */
 
				DrawArrowButtons(x, y, COLOUR_YELLOW, this->click - (i * 2), (editable && value != sdb->min), (editable && value != sdb->max));
 

	
 
				disabled = (value == 0) && (sdb->flags & SGF_0ISDISABLED);
 
				if (disabled) {
 
					SetDParam(0, STR_CONFIG_PATCHES_DISABLED);
 
				} else {
 
					if (sdb->flags & SGF_CURRENCY) {
 
						SetDParam(0, STR_CONFIG_PATCHES_CURRENCY);
 
					} else if (sdb->flags & SGF_MULTISTRING) {
 
						SetDParam(0, sdb->str + value + 1);
 
					} else {
 
						SetDParam(0, (sdb->flags & SGF_NOCOMMA) ? STR_CONFIG_PATCHES_INT32 : STR_7024);
 
					}
 
					SetDParam(1, value);
 
				}
 
			}
 
			DrawString(30, y, (sdb->str) + disabled, TC_FROMSTRING);
 
			y += 11;
 
			y += SETTING_HEIGHT;
 
		}
 
	}
 

	
 
	virtual void OnClick(Point pt, int widget)
 
	{
 
		switch (widget) {
 
			case PATCHSEL_OPTIONSPANEL: {
 
				const PatchPage *page = &_patches_page[this->page];
 
				const SettingDesc *sd;
 
				void *var;
 
				int32 value;
 
				int x, y;
 
				byte btn;
 

	
 
				y = pt.y - 46 - 1;  // Shift y coordinate
 
				if (y < 0) return;  // Clicked above first entry
 

	
 
				x = pt.x - 5;  // Shift x coordinate
 
				if (x < 0) return;  // Clicked left of the entry
 

	
 
				btn = y / 11;  // Compute which setting is selected
 
				if (y % 11 > 9) return;  // Clicked too low at the setting
 
				btn = y / SETTING_HEIGHT;  // Compute which setting is selected
 
				if (y % SETTING_HEIGHT > SETTING_HEIGHT - 2) return;  // Clicked too low at the setting
 
				if (btn >= page->num) return;  // Clicked below the last setting of the page
 

	
 
				sd = page->entries[btn].setting;
 

	
 
				/* return if action is only active in network, or only settable by server */
 
				if (!(sd->save.conv & SLF_NETWORK_NO) && _networking && !_network_server) return;
 
				if ((sd->desc.flags & SGF_NETWORK_ONLY) && !_networking) return;
 
				if ((sd->desc.flags & SGF_NO_NETWORK) && _networking) return;
 

	
 
				var = GetVariableAddress(patches_ptr, &sd->save);
 
				value = (int32)ReadValue(var, sd->save.conv);
 

	
 
				/* clicked on the icon on the left side. Either scroller or bool on/off */
 
				if (x < 21) {
 
					const SettingDescBase *sdb = &sd->desc;
 
					int32 oldvalue = value;
 

	
 
					switch (sdb->cmd) {
 
					case SDT_BOOLX: value ^= 1; break;
 
					case SDT_ONEOFMANY:
 
					case SDT_NUMX: {
 
						/* Add a dynamic step-size to the scroller. In a maximum of
 
							* 50-steps you should be able to get from min to max,
 
							* unless specified otherwise in the 'interval' variable
0 comments (0 inline, 0 general)