-
Notifications
You must be signed in to change notification settings - Fork 0
/
difficulty.py
158 lines (133 loc) · 5.01 KB
/
difficulty.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
from st3m.ui.view import BaseView, ViewTransitionBlend
from st3m.ui.interactions import ScrollController
from st3m.input import InputState
from ctx import Context
import math
try:
import media
from st3m.ui.view import ViewTransitionDirection
except ImportError:
pass
from . import flower
from . import loading
from . import utils
class DifficultyView(BaseView):
def __init__(self, app, song):
super().__init__()
self.app = app
self.flower = flower.Flower(0.001)
self._sc = ScrollController()
self.song = song
self._sc.set_item_count(len(self.song.difficulties))
if len(self.song.difficulties) > 2:
self._sc.set_position(1)
self._scroll_pos = 0
self.song.readScores()
def draw(self, ctx: Context) -> None:
utils.background(ctx)
ctx.save()
ctx.scale(1.9, 1.9)
ctx.translate(0, 56)
ctx.rgba(0.1, 0.4, 0.3, 0.42)
self.flower.draw(ctx)
ctx.restore()
ctx.save()
ctx.gray(1.0)
ctx.rectangle(
-120.0,
-15.0,
240.0,
30.0,
).fill()
ctx.translate(0, -30 * self._sc.current_position())
offset = 0
ctx.font = "Camp Font 3"
ctx.text_align = ctx.CENTER
ctx.text_baseline = ctx.MIDDLE
ctx.move_to(0, 0)
if not self.song.difficulties:
ctx.gray(0.0)
ctx.font_size = 24
ctx.text("No guitar track found!")
for idx, diff in enumerate(self.song.difficulties):
distance = self._sc.current_position() - idx
target = idx == self._sc.target_position()
if target:
ctx.gray(0.0)
else:
ctx.gray(0.5 + min(abs(distance / 2), 0.5))
if abs(distance) < 3:
xpos = 0.0
ctx.font_size = 24 - abs(distance) * 3
if target and (width := ctx.text_width(str(diff))) > 220:
xpos = math.sin(self._scroll_pos) * (width - 220) / 2
ctx.move_to(xpos, offset + distance * abs(distance) * 2)
ctx.global_alpha = max(0.0, 1.0 - abs(distance) / 2.5)
ctx.text(str(diff))
ctx.global_alpha = 1.0
offset += 30
ctx.restore()
ctx.rgba(1.0, 1.0, 1.0, 0.05)
ctx.rectangle(-120, -120, 240, 55)
ctx.fill()
"""
ctx.rectangle(-120, 65, 240, 55)
ctx.fill()
"""
utils.fire_gradient(ctx)
ctx.font = "Camp Font 1"
ctx.font_size = 25
ctx.text_align = ctx.CENTER
ctx.text_baseline = ctx.MIDDLE
ctx.move_to (0, -78)
ctx.text("DIFFICULTY")
if self.song.difficulties:
score = self.song.scores[self.song.difficulties[self._sc.target_position()]]
if not score.empty():
ctx.font_size = 15
ctx.gray(0.5)
ctx.text_align = ctx.RIGHT
ctx.font = "Material Icons"
ctx.move_to(-7, 86)
ctx.text("\ue885")
ctx.move_to(-7, 102)
ctx.text("\uea0b")
ctx.font = "Camp Font 3"
ctx.text_align = ctx.LEFT
ctx.move_to(-5, 83)
ctx.text(f"{int(score.max_acc.accuracy * 100)}%")
ctx.move_to(-5, 99)
ctx.text(str(score.max_streak.streak))
def think(self, ins: InputState, delta_ms: int) -> None:
super().think(ins, delta_ms)
media.think(delta_ms)
self.flower.think(delta_ms)
utils.blm_timeout(self, delta_ms)
self._scroll_pos += delta_ms / 1000
if not self.is_active():
self._sc.think(ins, delta_ms)
return
media.set_volume(min(1.0, media.get_volume() + delta_ms / 1000))
if media.get_position() == media.get_duration():
media.seek(0)
if self.input.buttons.app.left.pressed or self.input.buttons.app.left.repeated:
self._sc.scroll_left()
self._scroll_pos = 0.0
utils.play_crunch(self.app)
elif self.input.buttons.app.right.pressed or self.input.buttons.app.right.repeated:
self._sc.scroll_right()
self._scroll_pos = 0.0
utils.play_crunch(self.app)
if self.input.buttons.app.middle.pressed:
utils.play_go(self.app)
if self.song.difficulties:
media.stop()
self.vm.replace(loading.LoadingView(self.app, self.song, self.song.difficulties[self._sc.target_position()]), ViewTransitionBlend())
self._sc.think(ins, delta_ms)
def on_enter(self, vm):
super().on_enter(vm)
utils.emit("difficulty", {"name": self.song.name, "artist": self.song.artist, "path": self.song.dirName})
def on_exit(self):
if self.vm.direction == ViewTransitionDirection.BACKWARD:
utils.play_back(self.app)
return True