Add optional descriptions to settings
This commit is contained in:
		@@ -97,7 +97,7 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
 | 
			
		||||
		$pagerSize     = 9.;
 | 
			
		||||
		$settingHeight = 5.;
 | 
			
		||||
		$labelTextSize = 2;
 | 
			
		||||
		$pageMaxCount  = 11;
 | 
			
		||||
		$pageMaxCount  = 10;
 | 
			
		||||
 | 
			
		||||
		// Pagers
 | 
			
		||||
		$pagerPrev = new Quad_Icons64x64_1();
 | 
			
		||||
@@ -127,8 +127,9 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
 | 
			
		||||
		$backLabel = new Label_Button();
 | 
			
		||||
		$frame->addChild($backLabel);
 | 
			
		||||
		$backLabel->setStyle($backLabel::STYLE_CardMain_Quit);
 | 
			
		||||
		$backLabel->setPosition(-$width / 2 + 7, -$height / 2 + 7);
 | 
			
		||||
		$backLabel->setPosition(-$width / 2 + 5, -$height / 2 + 5);
 | 
			
		||||
		$backLabel->setHorizontalAlign($backLabel::LEFT);
 | 
			
		||||
		$backLabel->setScale(0.5);
 | 
			
		||||
		$backLabel->setTextSize(2);
 | 
			
		||||
		$backLabel->setText('Back');
 | 
			
		||||
		$backLabel->setAction(self::ACTION_SETTINGCLASS_BACK);
 | 
			
		||||
@@ -168,6 +169,15 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
 | 
			
		||||
			$nameLabel->setText($setting->setting);
 | 
			
		||||
			$nameLabel->setTextColor('fff');
 | 
			
		||||
 | 
			
		||||
			$descriptionLabel = new Label_Text();
 | 
			
		||||
			$pageFrame->addChild($descriptionLabel);
 | 
			
		||||
			$descriptionLabel->setHorizontalAlign($descriptionLabel::LEFT);
 | 
			
		||||
			$descriptionLabel->setPosition(-0.45 * $width, -0.35 * $height);
 | 
			
		||||
			$descriptionLabel->setSize(0.9 * $width, $settingHeight);
 | 
			
		||||
			$descriptionLabel->setTextSize($labelTextSize);
 | 
			
		||||
			$descriptionLabel->setTranslate(true);
 | 
			
		||||
			$nameLabel->addTooltipLabelFeature($descriptionLabel, $setting->description);
 | 
			
		||||
 | 
			
		||||
			$settingName = self::ACTION_PREFIX_SETTING . $setting->index;
 | 
			
		||||
			if ($setting->type === Setting::TYPE_BOOL) {
 | 
			
		||||
				// Boolean checkbox
 | 
			
		||||
 
 | 
			
		||||
@@ -256,7 +256,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
 | 
			
		||||
		// TODO: centralize menu code to use by mc settings and plugin settings
 | 
			
		||||
		$settings = $this->maniaControl->getSettingManager()->getSettingsByClass($settingClass);
 | 
			
		||||
 | 
			
		||||
		$pageSettingsMaxCount = 11;
 | 
			
		||||
		$pageSettingsMaxCount = 10;
 | 
			
		||||
		$posY                 = 0;
 | 
			
		||||
		$index                = 0;
 | 
			
		||||
		$settingHeight        = 5.;
 | 
			
		||||
@@ -295,6 +295,15 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
 | 
			
		||||
			$nameLabel->setText($setting->setting);
 | 
			
		||||
			$nameLabel->setTextColor('fff');
 | 
			
		||||
 | 
			
		||||
			$descriptionLabel = new Label_Text();
 | 
			
		||||
			$pageFrame->addChild($descriptionLabel);
 | 
			
		||||
			$descriptionLabel->setHorizontalAlign($descriptionLabel::LEFT);
 | 
			
		||||
			$descriptionLabel->setPosition(-0.45 * $width, -0.35 * $height);
 | 
			
		||||
			$descriptionLabel->setSize(0.9 * $width, $settingHeight);
 | 
			
		||||
			$descriptionLabel->setTextSize(2);
 | 
			
		||||
			$descriptionLabel->setTranslate(true);
 | 
			
		||||
			$nameLabel->addTooltipLabelFeature($descriptionLabel, $setting->description);
 | 
			
		||||
 | 
			
		||||
			if ($setting->type === Setting::TYPE_BOOL) {
 | 
			
		||||
				// Boolean checkbox
 | 
			
		||||
				$quad = new Quad();
 | 
			
		||||
@@ -332,9 +341,9 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
 | 
			
		||||
		$frame->addChild($backButton);
 | 
			
		||||
		$backButton->setStyle($backButton::STYLE_CardMain_Quit);
 | 
			
		||||
		$backButton->setHorizontalAlign($backButton::LEFT);
 | 
			
		||||
		$backButton->setScale(0.75);
 | 
			
		||||
		$backButton->setScale(0.5);
 | 
			
		||||
		$backButton->setText('Back');
 | 
			
		||||
		$backButton->setPosition(-$width / 2 + 7, -$height / 2 + 7);
 | 
			
		||||
		$backButton->setPosition(-$width / 2 + 5, -$height / 2 + 5);
 | 
			
		||||
		$backButton->setAction(self::ACTION_BACK_TO_PLUGINS);
 | 
			
		||||
 | 
			
		||||
		return $frame;
 | 
			
		||||
 
 | 
			
		||||
@@ -38,6 +38,7 @@ class Setting implements UsageInformationAble {
 | 
			
		||||
	public $default     = null;
 | 
			
		||||
	public $set         = null;
 | 
			
		||||
	public $fetchTime   = null;
 | 
			
		||||
	public $description = null;
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Construct a new setting instance
 | 
			
		||||
@@ -45,8 +46,9 @@ class Setting implements UsageInformationAble {
 | 
			
		||||
	 * @param mixed       $object
 | 
			
		||||
	 * @param string      $settingName
 | 
			
		||||
	 * @param mixed       $defaultValue
 | 
			
		||||
	 * @param string|null $description
 | 
			
		||||
	 */
 | 
			
		||||
	public function __construct($object, $settingName, $defaultValue) {
 | 
			
		||||
	public function __construct($object, $settingName, $defaultValue, $description = null) {
 | 
			
		||||
		if ($object === false) {
 | 
			
		||||
			// Fetched from Database
 | 
			
		||||
			$this->value   = $this->castValue($this->value);
 | 
			
		||||
@@ -68,6 +70,7 @@ class Setting implements UsageInformationAble {
 | 
			
		||||
				$this->value = $defaultValue;
 | 
			
		||||
			}
 | 
			
		||||
			$this->default = $this->value;
 | 
			
		||||
			$this->description = $description;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -70,6 +70,15 @@ class SettingManager implements CallbackListener, UsageInformationAble {
 | 
			
		||||
		if ($mysqli->error) {
 | 
			
		||||
			trigger_error($mysqli->error, E_USER_ERROR);
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		$mysqli->query("ALTER TABLE `" . self::TABLE_SETTINGS . "` ADD `description` VARCHAR(500) DEFAULT NULL;");
 | 
			
		||||
		if ($mysqli->error) {
 | 
			
		||||
			// If not Duplicate
 | 
			
		||||
			if ($mysqli->errno !== 1060) {
 | 
			
		||||
				trigger_error($mysqli->error, E_USER_ERROR);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		return $result;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -175,9 +184,10 @@ class SettingManager implements CallbackListener, UsageInformationAble {
 | 
			
		||||
	 * @param mixed       $object
 | 
			
		||||
	 * @param string      $settingName
 | 
			
		||||
	 * @param mixed       $value
 | 
			
		||||
	 * @param string|null $description
 | 
			
		||||
	 * @return bool
 | 
			
		||||
	 */
 | 
			
		||||
	public function setSetting($object, $settingName, $value) {
 | 
			
		||||
	public function setSetting($object, $settingName, $value, $description = null) {
 | 
			
		||||
		//TODO nowhere used, everywhere saveSettings used, is it depreciated?
 | 
			
		||||
		$setting = $this->getSettingObject($object, $settingName);
 | 
			
		||||
		if ($setting) {
 | 
			
		||||
@@ -187,7 +197,7 @@ class SettingManager implements CallbackListener, UsageInformationAble {
 | 
			
		||||
				return false;
 | 
			
		||||
			}
 | 
			
		||||
		} else {
 | 
			
		||||
			$saved = $this->initSetting($object, $settingName, $value);
 | 
			
		||||
			$saved = $this->initSetting($object, $settingName, $value, $description);
 | 
			
		||||
			if (!$saved) {
 | 
			
		||||
				return false;
 | 
			
		||||
			}
 | 
			
		||||
@@ -269,10 +279,11 @@ class SettingManager implements CallbackListener, UsageInformationAble {
 | 
			
		||||
	 * @param mixed       $object
 | 
			
		||||
	 * @param string      $settingName
 | 
			
		||||
	 * @param mixed       $defaultValue
 | 
			
		||||
	 * @param string|null $description
 | 
			
		||||
	 * @return bool
 | 
			
		||||
	 */
 | 
			
		||||
	public function initSetting($object, $settingName, $defaultValue) {
 | 
			
		||||
		$setting = new Setting($object, $settingName, $defaultValue);
 | 
			
		||||
	public function initSetting($object, $settingName, $defaultValue, $description = null) {
 | 
			
		||||
		$setting = new Setting($object, $settingName, $defaultValue, $description);
 | 
			
		||||
		return $this->saveSetting($setting, true);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
@@ -296,17 +307,19 @@ class SettingManager implements CallbackListener, UsageInformationAble {
 | 
			
		||||
				`class`,
 | 
			
		||||
				`setting`,
 | 
			
		||||
				`type`,
 | 
			
		||||
				`description`,
 | 
			
		||||
				`value`,
 | 
			
		||||
				`default`,
 | 
			
		||||
				`set`
 | 
			
		||||
				) VALUES (
 | 
			
		||||
				?, ?, ?, ?, ?, ?
 | 
			
		||||
				?, ?, ?, ?, ?, ?, ?
 | 
			
		||||
				) ON DUPLICATE KEY UPDATE
 | 
			
		||||
				`index` = LAST_INSERT_ID(`index`),
 | 
			
		||||
				`type` = VALUES(`type`),
 | 
			
		||||
				{$valueUpdateString},
 | 
			
		||||
				`default` = VALUES(`default`),
 | 
			
		||||
				`set` = VALUES(`set`),
 | 
			
		||||
				`description` = VALUES(`description`),
 | 
			
		||||
				`changed` = NOW();";
 | 
			
		||||
		$settingStatement = $mysqli->prepare($settingQuery);
 | 
			
		||||
		if ($mysqli->error) {
 | 
			
		||||
@@ -316,7 +329,16 @@ class SettingManager implements CallbackListener, UsageInformationAble {
 | 
			
		||||
		$formattedValue   = $setting->getFormattedValue();
 | 
			
		||||
		$formattedDefault = $setting->getFormattedDefault();
 | 
			
		||||
		$formattedSet     = $setting->getFormattedSet();
 | 
			
		||||
		$settingStatement->bind_param('ssssss', $setting->class, $setting->setting, $setting->type, $formattedValue, $formattedDefault, $formattedSet);
 | 
			
		||||
		$settingStatement->bind_param(
 | 
			
		||||
			'sssssss',
 | 
			
		||||
			$setting->class,
 | 
			
		||||
			$setting->setting,
 | 
			
		||||
			$setting->type,
 | 
			
		||||
			$setting->description,
 | 
			
		||||
			$formattedValue,
 | 
			
		||||
			$formattedDefault,
 | 
			
		||||
			$formattedSet
 | 
			
		||||
		);
 | 
			
		||||
		$settingStatement->execute();
 | 
			
		||||
		if ($settingStatement->error) {
 | 
			
		||||
			trigger_error($settingStatement->error);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user