This repository has been archived by the owner on Sep 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathw_menu_load.py
76 lines (66 loc) · 2.72 KB
/
w_menu_load.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
import os
from direct.gui.OnscreenText import OnscreenText, TextNode
from direct.gui.DirectGui import (
DGG,
DirectFrame,
DirectLabel,
DirectRadioButton)
from w_i_menu import IMenu
class LoadMenu(IMenu):
def __init__(self):
frame = DirectFrame(frameSize=(base.a2dLeft, base.a2dRight,
base.a2dBottom, base.a2dTop),
frameColor=(0, 0, 0, 1.0))
IMenu.__init__(self, frame=frame)
self.menuVerticalChoicesList = []
self.updateSaveSlots()
self.createVerticalButtons()
self.addTitle()
self.hasLoaded = True
def createButton(self, text, index, eventArgs):
btn = DirectRadioButton(text=text,
text_align=TextNode.ALeft,
scale=0.07,
frameColor=(0, 0, 0, 0.0),
pos=(base.a2dLeft + 0.7, 0,
(0.5 - (index * .25))),
variable=self.menuVerticalChoice,
value=[index],
text_fg=(1, 1, 1, 1),
command=self.menuVerticalEvent)
self.menuVerticalButtons.append(btn)
btn.reparentTo(self.frameMain)
def addTitle(self):
self.title = OnscreenText(
'Load Game', 1,
fg=(1, 0, 0, 1),
pos=(base.a2dLeft + 0.7, 0.8),
font=base.font_title,
align=TextNode.ALeft,
scale=.15,
mayChange=1)
self.title.reparentTo(self.frameMain)
def cancelCommand(self):
base.messenger.send("Back-Load")
def menuVerticalEvent(self):
if not self.hasLoaded:
return
eventName = self.menuVerticalChoicesList[self.menuVerticalChoice[0]]["event"]
if eventName == "Back-Load":
base.messenger.send("Back-Load")
return
base.gameData.selectedSaveSlot = eventName
base.gameData.loadGame()
base.messenger.send('MapReload')
base.request('RPGField')
def updateSaveSlots(self):
self.menuVerticalChoicesList = []
for slot in base.gameData.saveSlotNumbers:
filename = os.path.dirname(
base.gameData.filepath) + "/slot{}.txt".format(slot)
if os.path.isfile(filename):
mapName, totalTime = base.gameData.getSaveFileInfo(filename)
self.menuVerticalChoicesList.append(
{"event": slot, "text": "{} - total time played: {}".format(mapName, totalTime)})
self.menuVerticalChoicesList.append(
{"event": "Back-Load", "text": "Back to Menu"})