-
Notifications
You must be signed in to change notification settings - Fork 2
/
savegamescreen.py
94 lines (74 loc) · 2.64 KB
/
savegamescreen.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
# KIVY
from kivy.uix.screenmanager import Screen
from kivy.uix.screenmanager import FadeTransition
from kivy.properties import *
from kivy.app import App
from kivy.uix.floatlayout import FloatLayout
from kivy.uix.gridlayout import GridLayout
from kivy.uix.button import Button
from kivy.uix.label import Label
# CUSTOM
# TODO: rename this to reflect what kind of slot
from slot import Slot
from realbutton import RealButton
'''
This screen will provide gui to save and load savegames
from json-files
savegame-files are:
save_current.json -> allways keep current game
save_1.json -> First savegame-slot
[...]
save_5.json -> last savegame-slot
'''
class SavegameScreen(Screen):
buttonlayout = ObjectProperty(None)
mainlayout = ObjectProperty(None)
menubutton = ObjectProperty(None)
logic = ObjectProperty(None)
def __init__(self, logic, iconsize, iconratio_x, iconratio_y, **kwargs):
super(SavegameScreen, self).__init__(**kwargs)
self.logic = logic
self.iconsize = iconsize
self.iconratio_x = iconratio_x
self.iconratio_y = iconratio_y
self.build_interface()
def on_enter(self):
self.update_saves()
def update_saves(self):
save_times = App.get_running_app().scan_savegames()
slots = self.buttonlayout.children
for index in save_times:
for slot in slots:
if not slot.number == index:
continue
slot.update_label(save_times[index])
def build_interface(self):
self.mainlayout = FloatLayout()
self.buttonlayout = GridLayout(
cols=1,
size_hint=(0.75, 0.5),
pos_hint={"x": 0.125,
"y": 0.25}
)
# XXX: magic number! number of savegame slots!
for i in range(1, 6):
self.buttonlayout.add_widget(Slot(i, self.switchto_main))
self.mainlayout.add_widget(self.buttonlayout)
self.menubutton = RealButton(
'./media/icons/arrowleft.png',
'./media/icons/arrowleft_pressed.png',
self.switchto_menu,
size_hint=(None, None),
size=(self.iconsize, self.iconsize),
pos_hint={'x': 0, 'y': 0},
source='./media/icons/arrowleft.png',
always_release=True
)
self.mainlayout.add_widget(self.menubutton)
self.add_widget(self.mainlayout)
def switchto_menu(self, instance):
self.manager.transition = FadeTransition()
self.manager.current = 'menu'
def switchto_main(self, instance):
self.manager.transition = FadeTransition()
self.manager.current = 'main'