-
Notifications
You must be signed in to change notification settings - Fork 32
/
mood_light.py
338 lines (288 loc) · 11.8 KB
/
mood_light.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
# Porting to api 8 made easier by baport.(https://github.com/bombsquad-community/baport)
# ba_meta require api 8
from __future__ import annotations
from typing import TYPE_CHECKING, cast
if TYPE_CHECKING:
from typing import Any, Sequence, Callable, List, Dict, Tuple, Optional, Union
import random
import babase
import bauiv1 as bui
import bascenev1 as bs
import _babase
from bascenev1._map import Map
from bascenev1lib import mainmenu
from bauiv1lib.mainmenu import MainMenuWindow
from bauiv1lib.party import PartyWindow
from bascenev1lib.gameutils import SharedObjects
"""mood light plugin by ʟօʊքɢǟʀօʊ
type ml in chat or use plugin manager to open settings"""
def Print(*args):
out = ""
for arg in args:
a = str(arg)
out += a
bui.screenmessage(out)
def cprint(*args):
out = ""
for arg in args:
a = str(arg)
out += a
bs.chatmessage(out)
try:
Ldefault, Udefault = babase.app.config.get("moodlightingSettings")
except:
babase.app.config["moodlightingSettings"] = (15, 20)
Ldefault, Udefault = babase.app.config.get("moodlightingSettings")
Print("settings up moodlight")
Print("Type ml in chat or use plugin manager to access settings")
try:
loop = babase.app.config.get("moodlightEnabled")
except:
babase.app.config["moodlightEnabled"] = True
babase.app.config.commit()
loop = True
class SettingWindow(bui.Window):
def __init__(self):
self.draw_ui()
def increase_limit(self):
global Ldefault, Udefault
try:
if Udefault >= 29 and self.selected == "upper":
bui.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:
bui.textwidget(edit=self.warn_text, text="")
if self.selected == "lower":
Ldefault += 1
bui.textwidget(edit=self.lower_text, text=str(Ldefault))
elif self.selected == "upper":
Udefault += 1
bui.textwidget(edit=self.upper_text, text=str(Udefault))
except AttributeError:
bui.textwidget(edit=self.warn_text, text="Click on number to select it")
def decrease_limit(self):
global Ldefault, Udefault
try:
if Ldefault <= -19 and self.selected == "lower":
bui.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):
bui.textwidget(edit=self.warn_text, text="")
if self.selected == "lower":
Ldefault -= 1
bui.textwidget(edit=self.lower_text, text=str(Ldefault))
elif self.selected == "upper":
Udefault -= 1
bui.textwidget(edit=self.upper_text, text=str(Udefault))
except AttributeError:
bui.textwidget(edit=self.warn_text, text="Click on number to select it")
def on_text_click(self, selected):
self.selected = selected
if selected == "upper":
bui.textwidget(edit=self.upper_text, color=(0, 0, 1))
bui.textwidget(edit=self.lower_text, color=(1, 1, 1))
elif selected == "lower":
bui.textwidget(edit=self.lower_text, color=(0, 0, 1))
bui.textwidget(edit=self.upper_text, color=(1, 1, 1))
else:
Print("this should't happen from on_text_click")
def draw_ui(self):
self.uiscale = bui.app.ui_v1.uiscale
super().__init__(
root_widget=bui.containerwidget(
size=(670, 670),
on_outside_click_call=self.close,
transition="in_right",))
moodlight_label = bui.textwidget(
parent=self._root_widget,
size=(200, 100),
position=(150, 550),
scale=2,
selectable=False,
h_align="center",
v_align="center",
text="Mood light settings",
color=(0, 1, 0))
self.enable_button = bui.buttonwidget(
parent=self._root_widget,
position=(100, 470),
size=(90, 70),
scale=1.5,
color=(1, 0, 0) if loop else (0, 1, 0),
label="DISABLE" if loop else "ENABLE",
on_activate_call=self.on_enableButton_press)
save_button = bui.buttonwidget(
parent=self._root_widget,
position=(520, 470),
size=(90, 70),
scale=1.5,
label="SAVE",
on_activate_call=self.save_settings)
self.close_button = bui.buttonwidget(
parent=self._root_widget,
position=(550, 590),
size=(35, 35),
icon=bui.gettexture("crossOut"),
icon_color=(1, 0.2, 0.2),
scale=2,
color=(1, 0.2, 0.2),
extra_touch_border_scale=5,
on_activate_call=self.close)
self.lower_text = bui.textwidget(
parent=self._root_widget,
size=(200, 100),
scale=2,
position=(100, 200),
h_align="center",
v_align="center",
maxwidth=400.0,
text=str(Ldefault),
click_activate=True,
selectable=True)
lower_text_label = bui.textwidget(
parent=self._root_widget,
size=(200, 100),
position=(100, 150),
h_align="center",
v_align="center",
text="Limit darkness")
self.upper_text = bui.textwidget(
parent=self._root_widget,
size=(200, 100),
scale=2,
position=(400, 200),
h_align="center",
v_align="center",
maxwidth=400.0,
text=str(Udefault),
click_activate=True,
selectable=True)
upper_text_label = bui.textwidget(
parent=self._root_widget,
size=(200, 100),
position=(400, 150),
h_align="center",
v_align="center",
text="Limit brightness")
decrease_button = bui.buttonwidget(
parent=self._root_widget,
position=(100, 100),
size=(5, 1),
scale=3.5,
extra_touch_border_scale=2.5,
icon=bui.gettexture("downButton"),
on_activate_call=self.decrease_limit)
increase_button = bui.buttonwidget(
parent=self._root_widget,
position=(600, 100),
size=(5, 1),
scale=3.5,
extra_touch_border_scale=2.5,
icon=bui.gettexture("upButton"),
on_activate_call=self.increase_limit)
self.warn_text = bui.textwidget(
parent=self._root_widget,
text="",
size=(400, 200),
position=(150, 300),
h_align="center",
v_align="center",
maxwidth=600)
# ++++++++++++++++for keyboard navigation++++++++++++++++
bui.widget(edit=self.enable_button, up_widget=decrease_button,
down_widget=self.lower_text, left_widget=save_button, right_widget=save_button)
bui.widget(edit=save_button, up_widget=self.close_button, down_widget=self.upper_text,
left_widget=self.enable_button, right_widget=self.enable_button)
bui.widget(edit=self.close_button, up_widget=increase_button, down_widget=save_button,
left_widget=self.enable_button, right_widget=save_button)
bui.widget(edit=self.lower_text, up_widget=self.enable_button, down_widget=decrease_button,
left_widget=self.upper_text, right_widget=self.upper_text)
bui.widget(edit=self.upper_text, up_widget=save_button, down_widget=increase_button,
left_widget=self.lower_text, right_widget=self.lower_text)
bui.widget(edit=decrease_button, up_widget=self.lower_text, down_widget=self.enable_button,
left_widget=increase_button, right_widget=increase_button)
bui.widget(edit=increase_button, up_widget=self.upper_text, down_widget=self.close_button,
left_widget=decrease_button, right_widget=decrease_button)
# --------------------------------------------------------------------------------------------------
bui.textwidget(edit=self.upper_text, on_activate_call=babase.Call(
self.on_text_click, "upper"))
bui.textwidget(edit=self.lower_text, on_activate_call=babase.Call(
self.on_text_click, "lower"))
def on_enableButton_press(self):
global loop
loop = babase.app.config.get("moodlightEnabled")
if loop:
loop = False
label = "ENABLE"
color = (0, 1, 0)
elif not loop:
loop = True
label = "DISABLE"
color = (1, 0, 0)
in_game = not isinstance(bs.get_foreground_host_session(), mainmenu.MainMenuSession)
if in_game:
Print("Restart level to apply")
babase.app.config["moodlightEnabled"] = loop
babase.app.config.commit()
bui.buttonwidget(edit=self.enable_button, label=label, color=color)
def save_settings(self):
babase.app.config["moodlightingSettings"] = (Ldefault, Udefault)
babase.app.config.commit()
Print("settings saved")
self.close()
def close(self):
bui.containerwidget(edit=self._root_widget, transition="out_right",)
def new_chat_message(msg: Union[str, babase.Lstr], clients: Sequence[int] = None, sender_override: str = None):
old_fcm(msg, clients, sender_override)
if msg == 'ml':
try:
global Ldefault, Udefault
Ldefault, Udefault = babase.app.config.get("moodlightingSettings")
SettingWindow()
cprint("Mood light settings opened")
except Exception as err:
Print(err, "-from new_chat_message")
class NewMainMenuWindow(MainMenuWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
# Display chat icon, but if user open/close gather it may disappear
bui.set_party_icon_always_visible(True)
old_fcm = bs.chatmessage
bs.chatmessage = new_chat_message
Map._old_init = Map.__init__
# ba_meta export plugin
class moodlight(babase.Plugin):
def __init__(self):
pass
def on_app_running(self):
_babase.show_progress_bar()
MainMenuWindow = NewMainMenuWindow
def show_settings_ui(self, source_widget):
SettingWindow()
def has_settings_ui(self):
return True
def show_settings_ui(self, button):
SettingWindow()
def _new_init(self, vr_overlay_offset: Optional[Sequence[float]] = None) -> None:
self._old_init(vr_overlay_offset)
in_game = not isinstance(bs.get_foreground_host_session(), mainmenu.MainMenuSession)
if not in_game:
return
gnode = bs.getactivity().globalsnode
default_tint = (1.100000023841858, 1.0, 0.8999999761581421)
transition_duration = 1.0 # for future improvements
def changetint():
if loop:
Range = (random.randrange(Ldefault, Udefault)/10, random.randrange(Ldefault,
Udefault)/10, random.randrange(Ldefault, Udefault)/10)
bs.animate_array(gnode, 'tint', 3, {
0.0: gnode.tint,
transition_duration: Range
})
else:
global timer
timer = None
bs.animate_array(gnode, "tint", 3, {0.0: gnode.tint, 0.4: default_tint})
global timer
timer = bs.Timer(0.3, changetint, repeat=True)
Map.__init__ = _new_init