mirror of
https://github.com/bombsquad-community/plugin-manager.git
synced 2025-10-08 14:54:36 +00:00
Persistent settings and settings window improvement
Added moodlightSettings.txt for persistent settings Added save button Added icons to increase and decrease buttons
This commit is contained in:
parent
a63baeccf9
commit
d110ae511e
1 changed files with 92 additions and 60 deletions
|
|
@ -15,11 +15,23 @@ from time import sleep
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from typing import Any, Sequence, Callable, List, Dict, Tuple, Optional, Union
|
from typing import Any, Sequence, Callable, List, Dict, Tuple, Optional, Union
|
||||||
|
|
||||||
|
def Print(arg1,arg2="",arg3=""):
|
||||||
|
ba.screenmessage(str(arg1)+str(arg2)+str(arg3))
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open("moodlightSettings.txt","r") as mltxt:
|
||||||
|
global Ldefault,Udefault
|
||||||
|
data=mltxt.read()
|
||||||
|
Ldefault,Udefault=data.split("\n")
|
||||||
|
Ldefault=int(Ldefault)
|
||||||
|
Udefault=int(Udefault)
|
||||||
|
except:
|
||||||
|
with open("moodlightSettings.txt","w") as mltxt:
|
||||||
|
mltxt.write("15 \n 20")
|
||||||
|
Ldefault,Udefault=15,20
|
||||||
|
|
||||||
class SettingWindow(ba.Window):
|
class SettingWindow(ba.Window):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
global Ldefault,Udefault
|
|
||||||
Ldefault=5
|
|
||||||
Udefault=20
|
|
||||||
self.draw_ui()
|
self.draw_ui()
|
||||||
|
|
||||||
def increase_limit(self):
|
def increase_limit(self):
|
||||||
|
|
@ -29,7 +41,6 @@ class SettingWindow(ba.Window):
|
||||||
ba.textwidget(edit=self.warn_text,text="Careful!You risk get blind beyond this point")
|
ba.textwidget(edit=self.warn_text,text="Careful!You risk get blind beyond this point")
|
||||||
elif self.selected=="lower" and Ldefault>=-20 or self.selected=="upper" and Udefault<=30:
|
elif self.selected=="lower" and Ldefault>=-20 or self.selected=="upper" and Udefault<=30:
|
||||||
ba.textwidget(edit=self.warn_text,text="")
|
ba.textwidget(edit=self.warn_text,text="")
|
||||||
|
|
||||||
if self.selected=="lower":
|
if self.selected=="lower":
|
||||||
Ldefault += 1
|
Ldefault += 1
|
||||||
ba.textwidget(edit=self.lower_text,text=str(Ldefault))
|
ba.textwidget(edit=self.lower_text,text=str(Ldefault))
|
||||||
|
|
@ -46,8 +57,6 @@ class SettingWindow(ba.Window):
|
||||||
ba.textwidget(edit=self.warn_text,text="DON'T BE AFRAID OF DARK,IT'S A PLACE WHERE YOU CAN HIDE")
|
ba.textwidget(edit=self.warn_text,text="DON'T BE AFRAID OF DARK,IT'S A PLACE WHERE YOU CAN HIDE")
|
||||||
elif (self.selected == "upper" and Udefault <=30) or (self.selected== "lower" and Ldefault>=-20):
|
elif (self.selected == "upper" and Udefault <=30) or (self.selected== "lower" and Ldefault>=-20):
|
||||||
ba.textwidget(edit=self.warn_text,text="")
|
ba.textwidget(edit=self.warn_text,text="")
|
||||||
|
|
||||||
|
|
||||||
if self.selected=="lower":
|
if self.selected=="lower":
|
||||||
Ldefault -= 1
|
Ldefault -= 1
|
||||||
ba.textwidget(edit=self.lower_text,text=str(Ldefault))
|
ba.textwidget(edit=self.lower_text,text=str(Ldefault))
|
||||||
|
|
@ -66,39 +75,40 @@ class SettingWindow(ba.Window):
|
||||||
ba.textwidget(edit=self.lower_text,color=(0,0,1))
|
ba.textwidget(edit=self.lower_text,color=(0,0,1))
|
||||||
ba.textwidget(edit=self.upper_text,color=(1,1,1))
|
ba.textwidget(edit=self.upper_text,color=(1,1,1))
|
||||||
else:
|
else:
|
||||||
ba.screenmessage("this should't happen from on_text_click")
|
Print("this should't happen from on_text_click")
|
||||||
|
|
||||||
def draw_ui(self):
|
def draw_ui(self):
|
||||||
self.uiscale=ba.app.ui.uiscale
|
self.uiscale=ba.app.ui.uiscale
|
||||||
|
|
||||||
super().__init__(
|
super().__init__(
|
||||||
root_widget=ba.containerwidget(
|
root_widget=ba.containerwidget(
|
||||||
size=(800, 800),
|
size=(670, 670),
|
||||||
on_outside_click_call=self.close,
|
on_outside_click_call=self.close,
|
||||||
transition="in_right",))
|
transition="in_right",))
|
||||||
|
|
||||||
increase_button=ba.buttonwidget(
|
increase_button=ba.buttonwidget(
|
||||||
parent=self._root_widget,
|
parent=self._root_widget,
|
||||||
position=(250,100),
|
position=(600,100),
|
||||||
size=(50,50),
|
size=(5,1),
|
||||||
label="+",
|
scale=3.5,
|
||||||
scale=2,
|
extra_touch_border_scale=2.5,
|
||||||
|
icon=ba.gettexture("upButton"),
|
||||||
on_activate_call=self.increase_limit)
|
on_activate_call=self.increase_limit)
|
||||||
|
|
||||||
decrease_button=ba.buttonwidget(
|
decrease_button=ba.buttonwidget(
|
||||||
parent=self._root_widget,
|
parent=self._root_widget,
|
||||||
position=(100,100),
|
position=(100,100),
|
||||||
size=(50,50),
|
size=(5,1),
|
||||||
scale=2,
|
scale=3.5,
|
||||||
label="-",
|
extra_touch_border_scale=2.5,
|
||||||
|
icon=ba.gettexture("downButton"),
|
||||||
on_activate_call=self.decrease_limit)
|
on_activate_call=self.decrease_limit)
|
||||||
|
|
||||||
|
|
||||||
self.lower_text=ba.textwidget(
|
self.lower_text=ba.textwidget(
|
||||||
parent=self._root_widget,
|
parent=self._root_widget,
|
||||||
size=(200,100),
|
size=(200,100),
|
||||||
scale=2,
|
scale=2,
|
||||||
position=(100,300),
|
position=(100,200),
|
||||||
h_align="center",
|
h_align="center",
|
||||||
v_align="center",
|
v_align="center",
|
||||||
maxwidth=400.0,
|
maxwidth=400.0,
|
||||||
|
|
@ -110,7 +120,7 @@ class SettingWindow(ba.Window):
|
||||||
parent=self._root_widget,
|
parent=self._root_widget,
|
||||||
size=(200,100),
|
size=(200,100),
|
||||||
scale=2,
|
scale=2,
|
||||||
position=(500,300),
|
position=(400,200),
|
||||||
h_align="center",
|
h_align="center",
|
||||||
v_align="center",
|
v_align="center",
|
||||||
maxwidth=400.0,
|
maxwidth=400.0,
|
||||||
|
|
@ -122,26 +132,42 @@ class SettingWindow(ba.Window):
|
||||||
parent=self._root_widget,
|
parent=self._root_widget,
|
||||||
text="",
|
text="",
|
||||||
size=(400,100),
|
size=(400,100),
|
||||||
position=(200,500),
|
position=(150,300),
|
||||||
h_align="center",
|
h_align="center",
|
||||||
v_align="center",
|
v_align="center",
|
||||||
maxwidth=600)
|
maxwidth=600)
|
||||||
|
|
||||||
close_button=ba.buttonwidget(
|
self.close_button=ba.buttonwidget(
|
||||||
parent=self._root_widget,
|
parent=self._root_widget,
|
||||||
position=(700,650),
|
position=(550,590),
|
||||||
size=(100,100),
|
size=(30,30),
|
||||||
icon=ba.gettexture('crossOut'),
|
icon=ba.gettexture("crossOut"),
|
||||||
on_activate_call=self.close,
|
icon_color=(1,0.2,0.2),
|
||||||
color=(0.8,0.2,0.2))
|
scale=2,
|
||||||
|
color=(1,0.2,0.2),
|
||||||
|
extra_touch_border_scale=5,
|
||||||
|
on_activate_call=self.close,)
|
||||||
|
|
||||||
|
save_button=ba.buttonwidget(
|
||||||
|
parent=self._root_widget,
|
||||||
|
position=(450,450),
|
||||||
|
size=(125,70),
|
||||||
|
scale=1.5,
|
||||||
|
label="SAVE",
|
||||||
|
on_activate_call=self.save_settings)
|
||||||
|
|
||||||
ba.containerwidget(edit=self._root_widget, cancel_button=close_button)
|
|
||||||
ba.textwidget(edit=self.upper_text,on_activate_call=ba.Call(self.on_text_click,"upper"))
|
ba.textwidget(edit=self.upper_text,on_activate_call=ba.Call(self.on_text_click,"upper"))
|
||||||
ba.textwidget(edit=self.lower_text,on_activate_call=ba.Call(self.on_text_click,"lower"))
|
ba.textwidget(edit=self.lower_text,on_activate_call=ba.Call(self.on_text_click,"lower"))
|
||||||
|
|
||||||
def close(self):
|
def save_settings(self):
|
||||||
ba.containerwidget(edit=self._root_widget, transition="out_right")
|
with open("moodlightSettings.txt","w") as mltxt:
|
||||||
|
data="\n".join([str(Ldefault),str(Udefault)])
|
||||||
|
mltxt.write(data)
|
||||||
|
Print("settings saved")
|
||||||
|
self.close()
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
ba.containerwidget(edit=self._root_widget, transition="out_right",)
|
||||||
|
|
||||||
# ba_meta export plugin
|
# ba_meta export plugin
|
||||||
class moodlight(ba.Plugin):
|
class moodlight(ba.Plugin):
|
||||||
|
|
@ -154,15 +180,22 @@ class moodlight(ba.Plugin):
|
||||||
SettingWindow()
|
SettingWindow()
|
||||||
_ba.timer(0.5, self.on_chat_message, True)
|
_ba.timer(0.5, self.on_chat_message, True)
|
||||||
except Exception as err:
|
except Exception as err:
|
||||||
ba.screenmessage(str(err))
|
Print(err)
|
||||||
|
|
||||||
def on_chat_message(self):
|
def on_chat_message(self):
|
||||||
messages=_ba.get_chat_messages()
|
messages=_ba.get_chat_messages()
|
||||||
if len(messages)>0:
|
if len(messages)>0:
|
||||||
lastmessage=messages[-1].split(":")[-1].strip().lower()
|
lastmessage=messages[-1].split(":")[-1].strip().lower()
|
||||||
if lastmessage in ("/mood light","/mood lighting","/mood_light","/mood_lighting","/moodlight","ml"):
|
if lastmessage in ("/mood light","/mood lighting","/mood_light","/mood_lighting","/moodlight","ml"):
|
||||||
_ba.chatmessage("Mood light settings opened")
|
|
||||||
|
with open("moodlightSettings.txt","r") as mltxt:
|
||||||
|
global Ldefault,Udefault
|
||||||
|
data=mltxt.read()
|
||||||
|
Ldefault,Udefault=data.split("\n")
|
||||||
|
Ldefault=int(Ldefault)
|
||||||
|
Udefault=int(Udefault)
|
||||||
SettingWindow()
|
SettingWindow()
|
||||||
|
_ba.chatmessage("Mood light settings opened")
|
||||||
|
|
||||||
def on_plugin_manager_prompt(self):
|
def on_plugin_manager_prompt(self):
|
||||||
SettingWindow()
|
SettingWindow()
|
||||||
|
|
@ -174,12 +207,11 @@ class moodlight(ba.Plugin):
|
||||||
|
|
||||||
gnode = _ba.getactivity().globalsnode
|
gnode = _ba.getactivity().globalsnode
|
||||||
|
|
||||||
def changetint(self):
|
def changetint():
|
||||||
|
Range=(random.randrange(Ldefault,Udefault)/10, random.randrange(Ldefault,Udefault)/10, random.randrange(Ldefault,Udefault)/10)
|
||||||
ba.animate_array(gnode, 'tint', 3, {
|
ba.animate_array(gnode, 'tint', 3, {
|
||||||
0.0: gnode.tint,
|
0.0: gnode.tint,
|
||||||
1.0: (random.randrange(Ldefault,Udefault)/10, random.randrange(Ldefault,Udefault)/10, random.randrange(Ldefault,Udefault)/10)
|
1.0: Range
|
||||||
})
|
})
|
||||||
_ba.timer(0.3, changetint, repeat= True)
|
_ba.timer(0.3, changetint, repeat= True)
|
||||||
|
|
||||||
|
|
||||||
Map.__init__ = _new_init
|
Map.__init__ = _new_init
|
||||||
Loading…
Add table
Add a link
Reference in a new issue