-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
214 lines (162 loc) · 7.01 KB
/
main.py
File metadata and controls
214 lines (162 loc) · 7.01 KB
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
from kivymd.app import MDApp
from kivymd.uix.gridlayout import MDGridLayout
from kivymd.uix.button import MDRaisedButton
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.scrollview import ScrollView
from kivy.uix.label import Label
from kivy.uix.image import Image
from kivy.uix.effectwidget import EffectWidget
from kivy.uix.modalview import ModalView
from kivy.properties import ObjectProperty , StringProperty ,BooleanProperty, NumericProperty , DictProperty , ListProperty
from kivy.lang.builder import Builder
from kivy.core.text import LabelBase
from kivy.clock import Clock
from kivy.animation import Animation
from kivy.core.audio import SoundLoader
import json
import random
import os
class BuildingFloorWidget(BoxLayout):
floors : list = ListProperty([ "Ground Floor" , "Second Floor" , "Third Floor" , "Fourth Floor" , "Fifth Floor" , "Sixth Floor"])
current_floor : str = StringProperty("Ground Floor")
class TourerScreen(BoxLayout):
name_holder : Label = ObjectProperty()
dialog : Label = ObjectProperty()
tourer_picture : Image = ObjectProperty()
def update(self , name_holder = None , dialog = None , picture = None):
if name_holder :
self.name_holder.text = name_holder
if dialog:
self.dialog.text = dialog
if picture:
self.tourer_picture.source = picture
class TourerActivity(BoxLayout):
talking = BooleanProperty(True)
start_tour = BooleanProperty(False)
start_acitivity : callable = ObjectProperty()
class CustomActionButton(MDRaisedButton):
activity : callable = ObjectProperty()
class ActionList(ScrollView):
button_list : MDGridLayout = ObjectProperty()
ready_to_change = BooleanProperty(False)
parent_activity : callable = ObjectProperty()
def update(self , rooms : list[str , ...]):
self.button_list.clear_widgets()
for room in rooms :
widget = CustomActionButton()
widget.text = room
widget.activity = self.action
self.button_list.add_widget(widget)
for child in self.button_list.children:
Animation(opacity = 1 , duration = .6).start(child)
def action(self , text : str):
def ready_to_change( _ ):
self.ready_to_change = False
if not self.ready_to_change:
Clock.schedule_once(ready_to_change , 0.2)
self.parent_activity(text)
class ExitWidget(ModalView):
image : str = StringProperty("")
class MainWindow(FloatLayout):
tourer_screen : TourerScreen = ObjectProperty()
tourer_activity : TourerActivity = ObjectProperty()
action_list : ActionList = ObjectProperty()
exit_popup : ExitWidget = ObjectProperty(None)
building_floor_widget : BuildingFloorWidget = ObjectProperty()
building_picture : EffectWidget = ObjectProperty()
size_effect = NumericProperty(8.0)
title_1 : Label = ObjectProperty()
title_2 : Label = ObjectProperty()
buidings_info : dict = DictProperty({})
selections : dict = DictProperty({})
tourers : list = ListProperty([])
current_floor : str = StringProperty("")
def on_kv_post(self , _ ):
Clock.schedule_once(self.load_all_data )
Clock.schedule_interval(self.update , 1 / 30)
def load_all_data(self , _ ):
# set the Exit Widget
filename = os.path.join("Tourers" , "all_devs.png")
self.exit_popup = ExitWidget()
self.exit_popup.image = filename
# set the Command In Action List and Tourer Activity
self.action_list.parent_activity = self.change_location
self.tourer_activity.start_acitivity = self.change_location
# display the Mahogany Building
self.building_picture.picture.source = os.path.join("Rooms", "Building.jpeg")
# load tourers in update the TourerScreen
filename = os.path.join("Tourers" , "tourer.json")
with open(filename , "r") as jf:
for tourer in json.load(jf):
self.tourers.append(tourer)
selected = random.choices(self.tourers , weights=[.25 , .25, .25, .25] )
tourer = selected[0]
self.tourer_screen.update(name_holder=tourer["name"] , dialog=tourer["intro"] , picture=tourer["picture"] )
# load Selection Building
filename = os.path.join("Rooms" , "building_selection.json")
with open( filename , "r") as jf :
for key , values in json.load(jf).items() :
self.selections[key] = values
# load Building Information
filename = os.path.join("Rooms" , "building_information.json")
with open( filename , "r") as jf :
for key , values in json.load(jf).items() :
self.buidings_info[key] = values
def update(self , _ ):
# remove TourerScreen if not talking
self.tourer_screen.opacity = 0 if not self.tourer_activity.talking else 1
# remove title when talking
if not self.tourer_activity.start_tour :
self.title_1.opacity = 0 if self.tourer_activity.talking else 1
self.title_2.opacity = 0 if self.tourer_activity.talking else 1
# MAIN ACTIVITY
if self.tourer_activity.start_tour:
# check the current floor and update the BuildingFloorWidget
if not self.building_floor_widget.opacity:
self.building_floor_widget.opacity = 1
if self.current_floor in self.building_floor_widget.floors:
self.building_floor_widget.current_floor = self.current_floor
self.building_floor_widget.opacity = 0 if self.tourer_activity.talking else 1
# blur the image when tourer talking
self.size_effect = 8.0 if self.tourer_activity.talking else 0.0
# remove title when start tour
if self.title_1.opacity :
self.title_1.opacity = 0
self.title_2.opacity = 0
# show the ActionList when user start touring
if not self.action_list.opacity :
self.action_list.opacity = 1
def update_display_image(self , image : str):
folder = "Rooms"
self.building_picture.picture.source = os.path.join(folder , self.buidings_info[self.tourer_screen.name_holder.text][image][0])
def change_location(self , location : str):
self.current_floor = location
self.update_display_image(location)
self.tourer_screen.update(dialog=self.buidings_info[self.tourer_screen.name_holder.text][location][1])
self.action_list.update(rooms=self.selections[location])
class OCTourApp(MDApp):
sound : SoundLoader = ObjectProperty()
def on_start(self):
from kivy.base import EventLoop
EventLoop.window.bind(on_keyboard=self.hook_keyboard)
self.sound = SoundLoader.load("background_song.mp3") # Load audio file in the background
if self.sound:
print(self.sound)
self.sound.loop = True
self.sound.volume = .9
self.sound.play()
def hook_keyboard(self, window, key, *largs):
if key == 27:
if self.root.exit_popup :
self.root.exit_popup.open()
return True
def build(self):
return Builder.load_file("design.kv")
LabelBase.register(name = "font_Obli" , fn_regular="fonts/Quicksand_Bold_Oblique.otf")
LabelBase.register(name = "font_bold" , fn_regular="fonts/Quicksand_Bold.otf")
LabelBase.register(name = "font_book" , fn_regular="fonts/Quicksand_Book_Oblique.otf")
LabelBase.register(name = "font_book_reg" , fn_regular="fonts/Quicksand_Book.otf")
LabelBase.register(name = "azonix" , fn_regular="fonts/Azonix.otf")
LabelBase.register(name = "font_light_Obli" , fn_regular="fonts/Quicksand_Light_Oblique.otf")
OCTourApp().run()