comparison clients/rio_de_hola/settings.py @ 121:ae3b8139c7c7

* Applying settings patch by greyghost * See: #274
author mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
date Tue, 05 Aug 2008 14:44:15 +0000
parents e21b1a26fa5f
children 6b2f3a151f81
comparison
equal deleted inserted replaced
120:e21b1a26fa5f 121:ae3b8139c7c7
1 BitsPerPixel = 0 1 import shutil
2 FullScreen = 0 2 import pychan
3 InitialVolume = 5.0 3 try:
4 PlaySounds = 1 4 import xml.etree.cElementTree as ET
5 RenderBackend = "OpenGL" 5 except:
6 SDLRemoveFakeAlpha = 1 6 import xml.etree.ElementTree as ET
7 ScreenWidth = 1024
8 ScreenHeight = 768
9 WindowTitle = 'FIFE - Rio de hola'
10 WindowIcon = 'gui/icons/boy.png'
11 7
12 MapFile = 'maps/shrine.xml' 8 class Setting(object):
13 Font = 'fonts/samanata.ttf' 9 def onOptionsPress(self):
14 FontGlyphs = " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789.,!?-+/():;%&`'*#=[]\"" 10 self.changesRequireRestart = False
11 self.isSetToDefault = False
12 self.Resolutions = ['800x600', '1024x768', '1440x900']
13 if not hasattr(self, 'OptionsDlg'):
14 self.OptionsDlg = None
15 if not self.OptionsDlg:
16 self.OptionsDlg = pychan.loadXML('gui/settings.xml')
17 self.OptionsDlg.distributeInitialData({
18 'screen_resolution' : self.Resolutions,
19 'render_backend' : ['OpenGL', 'SDL']
20 })
21 self.OptionsDlg.distributeData({
22 'screen_resolution' : self.Resolutions.index(str(self.readSetting("ScreenWidth")) + 'x' + str(self.readSetting("ScreenHeight"))),
23 'render_backend' : 0 if str(self.readSetting("RenderBackend")) == "OpenGL" else 1,
24 'enable_fullscreen' : int(self.readSetting("FullScreen")),
25 'enable_sound' : int(self.readSetting("PlaySounds"))
26 })
27 self.OptionsDlg.mapEvents({
28 'okButton' : self.saveSettings,
29 'cancelButton' : self.OptionsDlg.hide,
30 'defaultButton' : self.setDefaults
31 })
32 self.OptionsDlg.show()
15 33
16 LogModules = ['controller'] 34 def setDefaults(self):
17 PychanDebug = False 35 shutil.copyfile('settings-dist.xml', 'settings.xml')
18 LogToPrompt = 1 36 self.isSetToDefault = True
19 LogToFile = 0 37 self.changesRequireRestart = True
20 UsePsyco = False
21 ImageChunkSize = 256
22 ProfilingOn = False
23 38
24 CoordinateLayerName = "TechdemoMapTileLayer" 39 def readSetting(self, name, type='int', strip=True, text=False):
25 QuadTreeLayerName = "" #"TechdemoMapObjectLayer" 40 if not hasattr(self, 'tree'):
41 self.tree = ET.parse('settings.xml')
42 self.root_element = self.tree.getroot()
43 element = self.root_element.find(name)
44 if element is not None:
45 element_value = element.text
46 if element_value is None:
47 if type == 'int':
48 return 0
49 elif type == 'list':
50 list = []
51 return list
52 else:
53 if type == 'int':
54 return element_value.strip() if strip else element_value
55 elif type == 'list':
56 list = []
57 list_s = []
58 list = str(element_value.strip()).split(";")
59 for item in list:
60 item = item.strip()
61 if text:
62 item = item.replace('\\n', '\n')
63 list_s.append(item)
64 return list_s
65 elif type == 'bool':
66 return False if element_value.strip() == 'False' else True
67 else:
68 print 'Setting,', name, 'does not exist!'
26 69
27 heroTexts = ( 70 def setSetting(self, name, value):
28 'I wonder when the guys will\n' + 'get this world ready for me', 71 element = self.root_element.find(name)
29 "Bring it on baby,\nI'm ready for action!", 72 if element is not None:
30 'humm di dum....', 73 if value is not element.text:
31 ) 74 element.text = str(value)
75 else:
76 print 'Setting,', name, 'does not exist!'
32 77
33 girlTexts = ( 78 def saveSettings(self):
34 "Why I am running? Haven't you heard\nthat the bees are coming?!", 79 screen_resolution, render_backend, enable_fullscreen, enable_sound = self.OptionsDlg.collectData('screen_resolution', 'render_backend', 'enable_fullscreen', 'enable_sound')
35 'Heeelp!!! The bees are going to get us!', 80 render_backend = 'OpenGL' if render_backend is 0 else 'SDL'
36 ) 81 if render_backend != str(self.readSetting("RenderBackend")):
82 self.setSetting('RenderBackend', render_backend)
83 self.changesRequireRestart = True
84 if int(enable_fullscreen) != int(self.readSetting("FullScreen")):
85 self.setSetting('FullScreen', int(enable_fullscreen))
86 self.changesRequireRestart = True
87 if int(enable_sound) != int(self.readSetting("PlaySounds")):
88 self.setSetting('PlaySounds', int(enable_sound))
89 self.changesRequireRestart = True
90 if screen_resolution != self.Resolutions.index(str(self.readSetting("ScreenWidth")) + 'x' + str(self.readSetting("ScreenHeight"))):
91 self.setSetting('ScreenWidth', int(self.Resolutions[screen_resolution].partition('x')[0]))
92 self.setSetting('ScreenHeight', int(self.Resolutions[screen_resolution].partition('x')[2]))
93 self.changesRequireRestart = True
37 94
38 beekeeperTexts = ( 95 if not self.isSetToDefault:
39 "Some idiot has grown mutated bees around here", 96 self.tree.write('settings.xml')
40 'Want to take a look at my farm?', 97 self.OptionsDlg.hide()
41 'Did you know that I actually cannot do anything\nelse than stand still and greet everybody?', 98 if self.changesRequireRestart:
42 ) 99 RestartDlg = pychan.loadXML('gui/changes_require_restart.xml')
43 100 RestartDlg.mapEvents({ 'closeButton' : RestartDlg.hide })
44 101 RestartDlg.show()
45 # test settings
46 TestCameraPlacement = 0
47 TestRotationLayerName = "TechdemoMapObjectLayer" # or "TechdemoMapTileLayer"
48 TestAgentSpeed = 0.5
49