This repository was archived by the owner on May 20, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
105 lines (87 loc) · 4.22 KB
/
Copy pathsettings.py
File metadata and controls
105 lines (87 loc) · 4.22 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
import libscene
import phrases
from pygame.locals import *
class SettingManager():
def __init__(self,filename="resources/config/settings.txt"):
self.filename = filename
self.load_settings()
def load_settings(self):
f = open(self.filename,'r')
self.setdict = {}
for line in f:
key,value = line.split('=')
key = key.strip()
value = value.strip()
if value == "True":
value = True
elif value == "False":
value = False
self.setdict[key] = value
f.close()
def save_settings(self):
f = open(self.filename,'w')
for key in self.setdict:
writeline = str(key) + '=' + str(self.setdict[key]) + '\n'
f.write(writeline)
f.close()
class SettingScene(libscene.MenuScene):
def __init__ (self, game):
libscene.MenuScene.__init__ (self, game, 121, 160, 60, 8, {
"normal": (238, 238, 236),
"highlight": (46, 52, 54),
"disabled": (85, 87, 83)
}, "resources/menu/selectbg.png")
def load_scene (self):
self.add_prevscene_keybind()
self.add_background ("resources/menu/generic_background.png", -3)
self.add_button ("phrases", "Setup Phrases", lambda x: self.load_next_scene(phrases.PhraseScene(self.game)))
self.add_button ("name", "Player Name",lambda x: self.load_next_scene(NameScene(self.game)))
self.add_button ("difficulty","Difficulty: easy", self.swap_difficulty)
fullscreen = "off"
if not self.game.fullscreen:
fullscreen = "on"
self.difficulty = self.game.set_man.setdict["difficulty"]
self.add_button ("fullscreen", "Fullscreen %s" % fullscreen, self.swap_fullscreen)
self.add_button ("back", "< back", self.load_prev_scene)
def swap_fullscreen (self, evt):
self.game.switch_fullscreen()
fullscreen = "off"
if not self.game.fullscreen:
fullscreen = "on"
self.objects["fullscreen"].obj.update_text ("Fullscreen %s" % fullscreen)
def swap_difficulty(self, event):
if self.difficulty == "easy":
self.difficulty = "medium"
print self.game.set_man.setdict["difficulty"]
elif self.difficulty == "medium":
self.difficulty = "hard"
print self.game.set_man.setdict["difficulty"]
elif self.difficulty == "hard":
self.difficulty = "easy"
print self.game.set_man.setdict["difficulty"]
self.game.set_man.setdict["difficulty"] = self.difficulty
self.objects["difficulty"].obj.update_text("Difficulty: " + self.difficulty)
class NameScene(libscene.MenuScene):
def __init__(self,game):
libscene.MenuScene.__init__ (self, game, 50, 320, 60, 8, {
"normal": (238, 238, 236),
"highlight": (46, 52, 54),
"disabled": (85, 87, 83)
}, "resources/menu/selectbg.png")
def load_scene (self):
self.game.set_man.load_settings()
self.add_background("resources/menu/generic_background.png", -3)
self.add_label ("name",(50,50),"resources/fonts/Harabara.ttf","Name:",(255,255,255))
self.add_object ("namedisp","textbox",(60,90),{"color":(255,255,255),
"nocolor":(200,200,200),
"fontfile":"resources/fonts/Harabara.ttf",
"fontsize":36,
"text":self.game.set_man.setdict["name"]})
self.set_focus(self.objects["namedisp"])
self.add_button ("save","Apply",self.send_name)
self.add_button ("main","< back",self.load_prev_scene)
self.add_prevscene_keybind()
def send_name(self,event):
self.game.set_man.setdict["name"] = self.objects["namedisp"].obj.text
self.game.set_man.save_settings()
print "[setdict]", self.game.set_man.setdict