-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
193 lines (135 loc) · 4.43 KB
/
main.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
#!/usr/bin/env python
# Default libs
import sys
import os
from pathlib import Path
# Ursina
from ursina import *
from prefabs import osu_splash
# ConfigSections
import tomli
#app = Ursina()
app = Ursina(borderless=False)
camera.ortographic = True
#camera.fov = 1
camerae = EditorCamera(enabled=1)
class OsuMenu(Entity):
def __init__(self, configItems):
super().__init__()
self.configItems = configItems
self.current_background = 0
self.background_textures = ['bg1.jpg', 'bg2.jpg', 'bg3.jpg', 'bg4.jpg']
#cursor = Cursor(model=Mesh(vertices=[(-.5,0,0),(.5,0,0),(0,-.5,0),(0,.5,0)], triangles=[(0,1),(2,3)], mode='line', thickness=2), scale=.02)
mouse.visible = False
cursor = Cursor(texture="osu-resources/osu.Game.Resources/Textures/Cursor/menu-cursor.png", scale_x=.02, scale_y=.035)
self.background = Entity(
model='quad',
texture=f"osu-resources/osu.Game.Resources/Textures/Backgrounds/{self.background_textures[self.current_background]}",
scale=(
14 *camera.aspect_ratio,
7 * camera.aspect_ratio
)
)
self.textures: dict = self.loadTextures()
self.CentralOsuButton = Button(
color=color.white,
parent=scene,
model = "quad",
texture = self.textures['menuTextures']['content']['logo'],
scale=4,
z = -1,
on_click = self.osuButtonClicked
)
self.welcome_audio = Audio("osu-resources/osu.Game.Resources/Samples/Intro/welcome.mp3")
#self.audio = Audio("osu-resources/osu.Game.Resources/Samples/Gameplay/pause-loop.mp3", loop=True, autoplay=True)
def loadTextures(self) -> dict:
#print(self.configItems)
resources_path = self.configItems['resources']['path']
textures_dict = self.configItems['resources']['textures']
textures_folder = resources_path + textures_dict['path']
menu_textures_path = str(textures_folder + textures_dict['menu']['path'])
newDict = {
'menuTextures': {
'path': menu_textures_path,
'content': textures_dict['menu']['textures']
}
}
return newDict
def osuButtonClicked(self):
#play sound
play_audio = Audio("osu-resources/osu.Game.Resources/Samples/Menu/osu-logo-select.wav", volume=.5).play()
if self.current_background <= len(self.background_textures) - 1:
self.current_background += 1
if self.current_background == len(self.background_textures):
self.current_background = 0
self.background.texture = f"osu-resources/osu.Game.Resources/Textures/Backgrounds/{self.background_textures[self.current_background]}"
class Textures():
def __init__(self, config_dict):
self.origin_config_dict = config_dict
class Engine(Entity):
def __init__(self):
super().__init__()
self.ent = Entity(
model="quad",
visible=False
)
camera.add_script(
SmoothFollow(
target=self.ent,
offset=[0,0,-30],
speed=4
)
)
def input(self, key):
pass
def update(self):
parallax = .5
mp = (
mouse.position[0] * parallax,
mouse.position[1] * parallax,
mouse.position[2] * parallax
)
self.ent.position = mp
class Central():
def __init__(self):
# Window defaults (if config.toml does not exist)
self.window_title : str = "Test"
self.fullscreen: bool = False
self.borderless: bool = True
self.exit_button_visible: bool = True
self.showfps: bool = True
self.config_file = "config.toml"
self.config_content = self.LoadConfigContent(self.config_file)
self.loadGlobalVars()
self.defineWindow()
def LoadConfigContent(self,config_file) -> dict:
try:
with open(config_file, 'rb') as cfile:
cfg = tomli.load(cfile)
return cfg
except Exception as e:
return {"error": f"Config file couldn't be loaded\n Error: {str(e)}"}
def loadGlobalVars(self):
try:
with open("config.toml", 'rb') as cfile:
cfg = tomli.load(cfile)
self.window_title= cfg["window"]["title"]
self.fullscreen = cfg["window"]["fullscreen"]
self.borderless = cfg["window"]["borderless"]
self.exit_button_visible = cfg["window"]["exit_button_visible"]
self.showfps = cfg["window"]["fps_counter"]
except Exception as e:
print("Error reading config.toml")
raise e
def defineWindow(self):
window.title = self.window_title
window.fullscreen = self.fullscreen
window.borderless = self.borderless
window.exit_button.visible = self.exit_button_visible
window.fps_counter.enabled = self.showfps
#window.color = color._16
if __name__ == "__main__":
central = Central()
engine = Engine()
menu = OsuMenu(configItems=central.config_content)
app.run()