add and use new attribute for the length of the Entries

This commit is contained in:
Beu 2023-07-10 17:12:57 +02:00
parent 8c478084a2
commit 13965aef03
4 changed files with 51 additions and 44 deletions

View File

@ -4,7 +4,6 @@ namespace ManiaControl\Configurator;
use FML\Components\CheckBox;
use FML\Controls\Entry;
use FML\Controls\TextEdit;
use FML\Controls\Frame;
use FML\Controls\Label;
use FML\Controls\Labels\Label_Text;
@ -140,6 +139,20 @@ class GameModeSettings implements ConfiguratorMenu, CallbackListener, Communicat
}
$statement->close();
$query = "ALTER TABLE `" . self::TABLE_GAMEMODE_SETTINGS . "` MODIFY `settingValue` VARCHAR(1000);";
// Grow the size limit for plugins settings
$statement = $mysqli->prepare($query);
if ($mysqli->error) {
trigger_error($mysqli->error, E_USER_ERROR);
return false;
}
$statement->execute();
if ($statement->error) {
trigger_error($statement->error, E_USER_ERROR);
return false;
}
$statement->close();
return true;
}
@ -440,7 +453,7 @@ class GameModeSettings implements ConfiguratorMenu, CallbackListener, Communicat
$quad->setX(0.27 * $width);
$checkBox = new CheckBox(self::ACTION_PREFIX_SETTING . $settingName, $settingValue, $quad);
$settingFrame->addChild($checkBox);
} else if (is_numeric($settingValue)) {
} else {
// Value entry
$entry = new Entry();
$settingFrame->addChild($entry);
@ -449,20 +462,8 @@ class GameModeSettings implements ConfiguratorMenu, CallbackListener, Communicat
$entry->setSize(0.3 * $width, 0.9 * $settingHeight);
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
$entry->setTextSize(1);
$entry->setMaxLength(1000);
$entry->setX(0.275 * $width);
} else {
// Standard entry
$textedit = new TextEdit();
$settingFrame->addChild($textedit);
$textedit->setX(0.275 * $width);
$textedit->setSize(0.3 * $width, 0.9 * $settingHeight);
$textedit->setStyle(Label_Text::STYLE_TextValueSmall);
$textedit->setTextSize(1);
$textedit->setName(self::ACTION_PREFIX_SETTING . $settingName);
$textedit->setDefault($settingValue);
$textedit->setHorizontalAlign(TextEdit::CENTER);
$textedit->setVerticalAlign(TextEdit::CENTER);
$textedit->setMaxLines(1);
}
if ($isScriptMode) {

View File

@ -10,7 +10,6 @@ use FML\Controls\Labels\Label_Button;
use FML\Controls\Labels\Label_Text;
use FML\Controls\Quad;
use FML\Controls\Quads\Quad_Icons64x64_1;
use FML\Controls\TextEdit;
use FML\Script\Features\Paging;
use FML\Script\Script;
use ManiaControl\Admin\AuthenticationManager;
@ -219,7 +218,7 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
$label->setTextSize(1);
$valuePicker = new ValuePicker($settingName, $setting->set, $setting->value, $label);
$settingFrame->addChild($valuePicker);
} else if ($setting->type === Setting::TYPE_INT) {
} else {
// Standard entry
$entry = new Entry();
$settingFrame->addChild($entry);
@ -227,21 +226,9 @@ class ManiaControlSettings implements ConfiguratorMenu, CallbackListener {
$entry->setSize($width * 0.3, $settingHeight * 0.9);
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
$entry->setTextSize(1);
$entry->setMaxLength(1000);
$entry->setName($settingName);
$entry->setDefault($setting->value);
} else {
// Standard TextEdit
$textedit = new TextEdit();
$settingFrame->addChild($textedit);
$textedit->setX($width * 0.33);
$textedit->setSize($width * 0.3, $settingHeight * 0.9);
$textedit->setStyle(Label_Text::STYLE_TextValueSmall);
$textedit->setTextSize(1);
$textedit->setName(self::ACTION_PREFIX_SETTING . $setting->index);
$textedit->setDefault($setting->value);
$textedit->setHorizontalAlign(TextEdit::CENTER);
$textedit->setVerticalAlign(TextEdit::CENTER);
$textedit->setMaxLines(1);
}
$posY -= $settingHeight;

View File

@ -5,7 +5,6 @@ namespace ManiaControl\Plugins;
use FML\Components\CheckBox;
use FML\Components\ValuePicker;
use FML\Controls\Entry;
use FML\Controls\TextEdit;
use FML\Controls\Frame;
use FML\Controls\Label;
use FML\Controls\Labels\Label_Button;
@ -348,19 +347,6 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$label->setTextSize(1);
$valuePicker = new ValuePicker(self::ACTION_PREFIX_SETTING . $setting->index, $setting->set, $setting->value, $label);
$settingFrame->addChild($valuePicker);
} else if ($setting->type === Setting::TYPE_STRING) {
// Standard entry
$textedit = new TextEdit();
$settingFrame->addChild($textedit);
$textedit->setX($width * 0.33);
$textedit->setSize($width * 0.3, $settingHeight * 0.9);
$textedit->setStyle(Label_Text::STYLE_TextValueSmall);
$textedit->setTextSize(1);
$textedit->setName(self::ACTION_PREFIX_SETTING . $setting->index);
$textedit->setDefault($setting->value);
$textedit->setHorizontalAlign(TextEdit::CENTER);
$textedit->setVerticalAlign(TextEdit::CENTER);
$textedit->setMaxLines(1);
} else {
// Value entry
$entry = new Entry();
@ -368,6 +354,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
$entry->setX($width * 0.33);
$entry->setSize($width * 0.3, $settingHeight * 0.9);
$entry->setTextSize(1);
$entry->setMaxLength(1000);
$entry->setStyle(Label_Text::STYLE_TextValueSmall);
$entry->setName(self::ACTION_PREFIX_SETTING . $setting->index);
$entry->setDefault($setting->value);

View File

@ -48,6 +48,11 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF
*/
protected $autoNewLine = null;
/**
* @var string $maxLength Text format
*/
protected $maxLength = null;
/**
* @var string $textFormat Text format
*/
@ -192,6 +197,30 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF
return $this;
}
/**
* Get text format
*
* @api
* @return int
*/
public function getMaxLength()
{
return $this->maxLength;
}
/**
* Set text format
*
* @api
* @param int $maxLength Max Length
* @return static
*/
public function setMaxLength($maxLength)
{
$this->maxLength = $maxLength;
return $this;
}
/**
* Get text format
*
@ -443,6 +472,9 @@ class Entry extends Control implements NewLineable, Scriptable, Styleable, TextF
if ($this->selectText) {
$domElement->setAttribute("selecttext", 1);
}
if ($this->maxLength) {
$domElement->setAttribute("maxlen", $this->maxLength);
}
if ($this->autoNewLine) {
$domElement->setAttribute("autonewline", 1);
}