Skip to content
Permalink
Browse files

0.66.1 Save speedo and roundtime settings

- Add button colors to config
  • Loading branch information...
brakerb committed May 11, 2019
1 parent 3803f16 commit 5422c9f70df689dff5e34792bec3f107dba3619b
@@ -17,6 +17,12 @@
"color": "38c",
"text" : "fff"
},
"btn" : {
"primary": "38c",
"default": "555",
"warning": "e90",
"danger" : "e33"
},
"text" : {
"primary" : "fff",
"highlight": "38c",
@@ -16,8 +16,6 @@ public function __construct()
Hook::add('PlayerConnect', [self::class, 'playerConnect']);
ChatCommand::add('/music', [self::class, 'searchMusic'], 'Open and search the music list.');
KeyBinds::add('reload_music_client', 'Reload music client.', [self::class, 'reload'], 'F2', 'ms');
}
/**
@@ -30,12 +28,6 @@ public static function playerConnect(Player $player)
Template::show($player, 'music-client.music-client');
}
public static function reload(Player $player)
{
TemplateController::loadTemplates();
self::playerConnect($player);
}
public static function searchMusic(Player $player, $cmd, ...$arguments)
{
$query = implode(' ', $arguments);
@@ -4,6 +4,7 @@
use esc\Classes\Hook;
use esc\Classes\ManiaLinkEvent;
use esc\Classes\Template;
use esc\Models\Player;
@@ -12,10 +13,25 @@ class RoundTime
public function __construct()
{
Hook::add('PlayerConnect', [self::class, 'show']);
ManiaLinkEvent::add('roundtime.save', [self::class, 'saveSettings']);
ManiaLinkEvent::add('roundtime.reset', [self::class, 'resetSettings']);
}
public static function show(Player $player)
{
Template::show($player, 'roundtime.meter');
$settings = $player->setting('speedo');
Template::show($player, 'roundtime.meter', compact('settings'));
}
public static function saveSettings(Player $player, ...$settingsJson)
{
$player->setSetting('roundtime', implode(',', $settingsJson));
}
public static function resetSettings(Player $player)
{
$player->settings()->where('name', 'roundtime')->delete();
}
}
@@ -9,9 +9,9 @@

<frame id="settings" pos="-20 7" hidden="1">
<quad id="handle" z-index="5" size="35 5" />
<quad z-index="-1" size="40 5" bgcolor="{config('colors.ui.window.header.color')}c" />
<quad z-index="-1" size="40 14" pos="0 -5" bgcolor="{config('colors.ui.window.bg.color')}c" />
<label class="close" pos="37.5 -2.5" size="5 5" halign="center" valign="center" textsize="0.5" text="" ScriptEvents="1" focusareacolor1="0000" focusareacolor2="0003" />
<quad z-index="-1" size="41 5" bgcolor="{config('colors.ui.window.header.color')}c" />
<quad z-index="-1" size="41 18" pos="0 -5" bgcolor="{config('colors.ui.window.bg.color')}c" />
<label class="close" pos="38.5 -2.5" size="5 5" halign="center" valign="center" textsize="0.5" text="" ScriptEvents="1" focusareacolor1="0000" focusareacolor2="0003" />
<label pos="1 -2.5" size="30 5" halign="left" valign="center" textsize="0.3" text=" RoundTime Settings" textfont="{config('colors.ui.font')|noescape}" />

<label pos="2 -7.5" size="30 5" halign="left" valign="center" textsize="0.3" text="Show label" textfont="{config('colors.ui.font')|noescape}" />
@@ -23,6 +23,9 @@

<label pos="2 -15.5" size="30 5" halign="left" valign="center" textsize="0.3" text="Position" textfont="{config('colors.ui.font')|noescape}" />
<label pos="14 -15.5" size="30 5" halign="left" valign="center" textsize="0.3" text="$iDrag the widget" textcolor="fffc" textfont="{config('colors.ui.font')|noescape}" />

<label class="save" pos="20 -20" size="12 3" halign="center" valign="center" textsize="0.5" text="Save" textcolor="{config('colors.ui.window.text.primary')}" textfont="{config('colors.ui.font')|noescape}" focusareacolor1="{config('colors.ui.window.header.color')}3" focusareacolor2="{config('colors.ui.window.header.color')}c" ScriptEvents="1" />
<label class="reset" pos="33 -20" size="12 3" halign="center" valign="center" textsize="0.5" text="Reset" textcolor="{config('colors.ui.window.text.primary')}" textfont="{config('colors.ui.font')|noescape}" focusareacolor1="{config('colors.ui.window.btn.warning')}3" focusareacolor2="{config('colors.ui.window.btn.warning')}6" ScriptEvents="1" />
</frame>

<script><!--
@@ -35,10 +38,22 @@
Real scale;
}
declare RoundTimeSettings settings;
{(new esc\Classes\ManiaLinkDrag())|noescape}
Void resetMeter(){
settings.showLabel = True;
settings.position = <80.0, -86.0>;
settings.scale = 1.0;
}
main(){
declare RoundTimeSettings settings_roundtime;
{if $settings}
settings.fromjson("""{$settings|noescape}""");
{else}
resetMeter();
{/if}
declare player <=> InputPlayer;
declare labelEnabled <=> (Page.MainFrame.GetFirstChild("label-enabled") as CMlLabel);
@@ -52,15 +67,9 @@
declare Boolean hidden = False;
declare Boolean settingsVisible = False;
if(settings_roundtime.scale == 0.0){
settings_roundtime.showLabel = True;
settings_roundtime.position = <80.0, -86.0>;
settings_roundtime.scale = 1.0;
}
speedometer.RelativeScale = settings_roundtime.scale;
labelLabel.Visible = settings_roundtime.showLabel;
speedometer.RelativePosition_V3 = settings_roundtime.position;
speedometer.RelativeScale = settings.scale;
labelLabel.Visible = settings.showLabel;
speedometer.RelativePosition_V3 = settings.position;
while(True){
yield;
@@ -87,19 +96,29 @@
if(event.Control.HasClass("label-disabled") && event.Type == CMlScriptEvent::Type::MouseClick){
labelEnabled.Show();
labelDisabled.Hide();
settings_roundtime.showLabel = True;
settings.showLabel = True;
labelLabel.Show();
}
if(event.Control.HasClass("label-enabled") && event.Type == CMlScriptEvent::Type::MouseClick){
labelEnabled.Hide();
labelDisabled.Show();
settings_roundtime.showLabel = False;
settings.showLabel = False;
labelLabel.Hide();
}
if(event.Control.HasClass("close") && event.Type == CMlScriptEvent::Type::MouseClick){
settingsFrame.Hide();
settingsVisible = False;
}
if(event.Control.HasClass("reset") && event.Type == CMlScriptEvent::Type::MouseClick){
resetMeter();
speedometer.RelativeScale = settings.scale;
labelLabel.Visible = settings.showLabel;
speedometer.RelativePosition_V3 = settings.position;
TriggerPageAction("roundtime.reset");
}
if(event.Control.HasClass("save") && event.Type == CMlScriptEvent::Type::MouseClick){
TriggerPageAction("roundtime.save," ^ settings.tojson());
}
if(event.Control.HasClass("action") && event.Type == CMlScriptEvent::Type::MouseClick){
if(settingsVisible){
declare startPos = speedometer.RelativePosition_V3;
@@ -113,20 +132,20 @@
declare newPosY = startPos[1] + (MouseY - startY);
speedometer.RelativePosition_V3 = <newPosX, newPosY>;
settings_roundtime.position = speedometer.RelativePosition_V3;
settings.position = speedometer.RelativePosition_V3;
}
continue;
}
if(settings_roundtime.showLabel){
if(settings.showLabel){
labelEnabled.Show();
labelDisabled.Hide();
}else{
labelEnabled.Hide();
labelDisabled.Show();
}
scaleEntry.SetText(settings_roundtime.scale ^ "", False);
scaleEntry.SetText(settings.scale ^ "", False);
settingsFrame.Show();
settingsVisible = True;
}
@@ -137,17 +156,17 @@
wrench.Hide();
}
if(event.Control.HasClass("entry") && event.Type == CMlScriptEvent::Type::EntrySubmit){
settings_roundtime.scale = TL::ToReal(scaleEntry.Value);
settings.scale = TL::ToReal(scaleEntry.Value);
if(settings_roundtime.scale < 0){
settings_roundtime.scale = -settings_roundtime.scale;
if(settings.scale < 0){
settings.scale = -settings.scale;
}
if(settings_roundtime.scale < 0.4){
settings_roundtime.scale = 0.4;
if(settings.scale < 0.4){
settings.scale = 0.4;
}
scaleEntry.SetText(settings_roundtime.scale ^ "", False);
speedometer.RelativeScale = settings_roundtime.scale;
scaleEntry.SetText(settings.scale ^ "", False);
speedometer.RelativeScale = settings.scale;
}
}
@@ -4,6 +4,7 @@
use esc\Classes\Hook;
use esc\Classes\ManiaLinkEvent;
use esc\Classes\Template;
use esc\Controllers\TemplateController;
use esc\Models\Player;
@@ -13,10 +14,33 @@ class Speedometer
public function __construct()
{
Hook::add('PlayerConnect', [self::class, 'show']);
ManiaLinkEvent::add('speedo.save', [self::class, 'saveSettings']);
ManiaLinkEvent::add('speedo.reset', [self::class, 'resetSettings']);
KeyBinds::add('reload_music_client', 'Reload speedo.', [self::class, 'reload'], 'F2', 'ms');
}
public static function show(Player $player)
{
Template::show($player, 'speedometer.meter');
$settings = $player->setting('speedo');
Template::show($player, 'speedometer.meter', compact('settings'));
}
public static function saveSettings(Player $player, ...$settingsJson)
{
$player->setSetting('speedo', implode(',', $settingsJson));
}
public static function resetSettings(Player $player)
{
$player->settings()->where('name', 'speedo')->delete();
}
public static function reload(Player $player)
{
TemplateController::loadTemplates();
self::show($player);
}
}
@@ -9,8 +9,8 @@

<frame id="settings" pos="-20 7" hidden="1">
<quad id="handle" z-index="5" size="35 5" />
<quad z-index="-1" size="40 5" bgcolor="{config('colors.ui.window.header.color')}c" />
<quad z-index="-1" size="40 14" pos="0 -5" bgcolor="{config('colors.ui.window.bg.color')}c" />
<quad z-index="-1" size="41 5" bgcolor="{config('colors.ui.window.header.color')}c" />
<quad z-index="-1" size="41 18" pos="0 -5" bgcolor="{config('colors.ui.window.bg.color')}c" />
<label class="close" pos="37.5 -2.5" size="5 5" halign="center" valign="center" textsize="0.5" text="" ScriptEvents="1" focusareacolor1="0000" focusareacolor2="0003" />
<label pos="1 -2.5" size="30 5" halign="left" valign="center" textsize="0.3" text=" Speedometer Settings" textfont="{config('colors.ui.font')|noescape}" />

@@ -23,6 +23,9 @@

<label pos="2 -15.5" size="30 5" halign="left" valign="center" textsize="0.3" text="Position" textfont="{config('colors.ui.font')|noescape}" />
<label pos="14 -15.5" size="30 5" halign="left" valign="center" textsize="0.3" text="$iDrag the widget" textcolor="fffc" textfont="{config('colors.ui.font')|noescape}" />

<label class="save" pos="20 -20" size="12 3" halign="center" valign="center" textsize="0.5" text="Save" textcolor="{config('colors.ui.window.text.primary')}" textfont="{config('colors.ui.font')|noescape}" focusareacolor1="{config('colors.ui.window.header.color')}3" focusareacolor2="{config('colors.ui.window.header.color')}c" ScriptEvents="1" />
<label class="reset" pos="33 -20" size="12 3" halign="center" valign="center" textsize="0.5" text="Reset" textcolor="{config('colors.ui.window.text.primary')}" textfont="{config('colors.ui.font')|noescape}" focusareacolor1="{config('colors.ui.window.btn.warning')}3" focusareacolor2="{config('colors.ui.window.btn.warning')}6" ScriptEvents="1" />
</frame>

<script><!--
@@ -35,10 +38,22 @@
Real scale;
}
declare SpeedoSettingsTest settings;
{(new esc\Classes\ManiaLinkDrag())|noescape}
Void resetMeter(){
settings.showLabel = True;
settings.position = <80.0, -79.5>;
settings.scale = 1.0;
}
main(){
declare SpeedoSettingsTest settings;
{if $settings}
settings.fromjson("""{$settings|noescape}""");
{else}
resetMeter();
{/if}
declare player <=> InputPlayer;
declare labelEnabled <=> (Page.MainFrame.GetFirstChild("label-enabled") as CMlLabel);
@@ -53,12 +68,6 @@
declare Boolean hidden = False;
declare Boolean settingsVisible = False;
if(settings.scale == 0.0){
settings.showLabel = True;
settings.position = <80.0, -79.5>;
settings.scale = 1.0;
}
speedometer.RelativeScale = settings.scale;
labelLabel.Visible = settings.showLabel;
speedometer.RelativePosition_V3 = settings.position;
@@ -101,6 +110,16 @@
settingsFrame.Hide();
settingsVisible = False;
}
if(event.Control.HasClass("reset") && event.Type == CMlScriptEvent::Type::MouseClick){
resetMeter();
speedometer.RelativeScale = settings.scale;
labelLabel.Visible = settings.showLabel;
speedometer.RelativePosition_V3 = settings.position;
TriggerPageAction("speedo.reset");
}
if(event.Control.HasClass("save") && event.Type == CMlScriptEvent::Type::MouseClick){
TriggerPageAction("speedo.save," ^ settings.tojson());
}
if(event.Control.HasClass("action") && event.Type == CMlScriptEvent::Type::MouseClick){
if(settingsVisible){
declare startPos = speedometer.RelativePosition_V3;
@@ -127,6 +146,7 @@
labelEnabled.Hide();
labelDisabled.Show();
}
scaleEntry.SetText(settings.scale ^ "", False);
settingsFrame.Show();
settingsVisible = True;

0 comments on commit 5422c9f

Please sign in to comment.
You can’t perform that action at this time.