Add optional descriptions to settings

This commit is contained in:
Alexander Nell 2020-05-19 22:07:18 +02:00
parent 9b46a6e7f7
commit 7c04504e6a
4 changed files with 73 additions and 29 deletions

View File

@ -97,7 +97,7 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
$pagerSize = 9.; $pagerSize = 9.;
$settingHeight = 5.; $settingHeight = 5.;
$labelTextSize = 2; $labelTextSize = 2;
$pageMaxCount = 11; $pageMaxCount = 10;
// Pagers // Pagers
$pagerPrev = new Quad_Icons64x64_1(); $pagerPrev = new Quad_Icons64x64_1();
@ -127,8 +127,9 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
$backLabel = new Label_Button(); $backLabel = new Label_Button();
$frame->addChild($backLabel); $frame->addChild($backLabel);
$backLabel->setStyle($backLabel::STYLE_CardMain_Quit); $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->setHorizontalAlign($backLabel::LEFT);
$backLabel->setScale(0.5);
$backLabel->setTextSize(2); $backLabel->setTextSize(2);
$backLabel->setText('Back'); $backLabel->setText('Back');
$backLabel->setAction(self::ACTION_SETTINGCLASS_BACK); $backLabel->setAction(self::ACTION_SETTINGCLASS_BACK);
@ -168,6 +169,15 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
$nameLabel->setText($setting->setting); $nameLabel->setText($setting->setting);
$nameLabel->setTextColor('fff'); $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; $settingName = self::ACTION_PREFIX_SETTING . $setting->index;
if ($setting->type === Setting::TYPE_BOOL) { if ($setting->type === Setting::TYPE_BOOL) {
// Boolean checkbox // Boolean checkbox

View File

@ -256,7 +256,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
// TODO: centralize menu code to use by mc settings and plugin settings // TODO: centralize menu code to use by mc settings and plugin settings
$settings = $this->maniaControl->getSettingManager()->getSettingsByClass($settingClass); $settings = $this->maniaControl->getSettingManager()->getSettingsByClass($settingClass);
$pageSettingsMaxCount = 11; $pageSettingsMaxCount = 10;
$posY = 0; $posY = 0;
$index = 0; $index = 0;
$settingHeight = 5.; $settingHeight = 5.;
@ -295,6 +295,15 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$nameLabel->setText($setting->setting); $nameLabel->setText($setting->setting);
$nameLabel->setTextColor('fff'); $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) { if ($setting->type === Setting::TYPE_BOOL) {
// Boolean checkbox // Boolean checkbox
$quad = new Quad(); $quad = new Quad();
@ -332,9 +341,9 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$frame->addChild($backButton); $frame->addChild($backButton);
$backButton->setStyle($backButton::STYLE_CardMain_Quit); $backButton->setStyle($backButton::STYLE_CardMain_Quit);
$backButton->setHorizontalAlign($backButton::LEFT); $backButton->setHorizontalAlign($backButton::LEFT);
$backButton->setScale(0.75); $backButton->setScale(0.5);
$backButton->setText('Back'); $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); $backButton->setAction(self::ACTION_BACK_TO_PLUGINS);
return $frame; return $frame;

View File

@ -38,6 +38,7 @@ class Setting implements UsageInformationAble {
public $default = null; public $default = null;
public $set = null; public $set = null;
public $fetchTime = null; public $fetchTime = null;
public $description = null;
/** /**
* Construct a new setting instance * Construct a new setting instance
@ -45,8 +46,9 @@ class Setting implements UsageInformationAble {
* @param mixed $object * @param mixed $object
* @param string $settingName * @param string $settingName
* @param mixed $defaultValue * @param mixed $defaultValue
* @param string|null $description
*/ */
public function __construct($object, $settingName, $defaultValue) { public function __construct($object, $settingName, $defaultValue, $description = null) {
if ($object === false) { if ($object === false) {
// Fetched from Database // Fetched from Database
$this->value = $this->castValue($this->value); $this->value = $this->castValue($this->value);
@ -68,6 +70,7 @@ class Setting implements UsageInformationAble {
$this->value = $defaultValue; $this->value = $defaultValue;
} }
$this->default = $this->value; $this->default = $this->value;
$this->description = $description;
} }
} }

View File

@ -70,6 +70,15 @@ class SettingManager implements CallbackListener, UsageInformationAble {
if ($mysqli->error) { if ($mysqli->error) {
trigger_error($mysqli->error, E_USER_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; return $result;
} }
@ -175,9 +184,10 @@ class SettingManager implements CallbackListener, UsageInformationAble {
* @param mixed $object * @param mixed $object
* @param string $settingName * @param string $settingName
* @param mixed $value * @param mixed $value
* @param string|null $description
* @return bool * @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? //TODO nowhere used, everywhere saveSettings used, is it depreciated?
$setting = $this->getSettingObject($object, $settingName); $setting = $this->getSettingObject($object, $settingName);
if ($setting) { if ($setting) {
@ -187,7 +197,7 @@ class SettingManager implements CallbackListener, UsageInformationAble {
return false; return false;
} }
} else { } else {
$saved = $this->initSetting($object, $settingName, $value); $saved = $this->initSetting($object, $settingName, $value, $description);
if (!$saved) { if (!$saved) {
return false; return false;
} }
@ -269,10 +279,11 @@ class SettingManager implements CallbackListener, UsageInformationAble {
* @param mixed $object * @param mixed $object
* @param string $settingName * @param string $settingName
* @param mixed $defaultValue * @param mixed $defaultValue
* @param string|null $description
* @return bool * @return bool
*/ */
public function initSetting($object, $settingName, $defaultValue) { public function initSetting($object, $settingName, $defaultValue, $description = null) {
$setting = new Setting($object, $settingName, $defaultValue); $setting = new Setting($object, $settingName, $defaultValue, $description);
return $this->saveSetting($setting, true); return $this->saveSetting($setting, true);
} }
@ -296,17 +307,19 @@ class SettingManager implements CallbackListener, UsageInformationAble {
`class`, `class`,
`setting`, `setting`,
`type`, `type`,
`description`,
`value`, `value`,
`default`, `default`,
`set` `set`
) VALUES ( ) VALUES (
?, ?, ?, ?, ?, ? ?, ?, ?, ?, ?, ?, ?
) ON DUPLICATE KEY UPDATE ) ON DUPLICATE KEY UPDATE
`index` = LAST_INSERT_ID(`index`), `index` = LAST_INSERT_ID(`index`),
`type` = VALUES(`type`), `type` = VALUES(`type`),
{$valueUpdateString}, {$valueUpdateString},
`default` = VALUES(`default`), `default` = VALUES(`default`),
`set` = VALUES(`set`), `set` = VALUES(`set`),
`description` = VALUES(`description`),
`changed` = NOW();"; `changed` = NOW();";
$settingStatement = $mysqli->prepare($settingQuery); $settingStatement = $mysqli->prepare($settingQuery);
if ($mysqli->error) { if ($mysqli->error) {
@ -316,7 +329,16 @@ class SettingManager implements CallbackListener, UsageInformationAble {
$formattedValue = $setting->getFormattedValue(); $formattedValue = $setting->getFormattedValue();
$formattedDefault = $setting->getFormattedDefault(); $formattedDefault = $setting->getFormattedDefault();
$formattedSet = $setting->getFormattedSet(); $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(); $settingStatement->execute();
if ($settingStatement->error) { if ($settingStatement->error) {
trigger_error($settingStatement->error); trigger_error($settingStatement->error);