settings: Mostly working

This commit is contained in:
John Cote 2021-07-07 21:30:51 -04:00
parent db25aaf10d
commit 2ec6ceabb4
No known key found for this signature in database
GPG key ID: E3442FF71E9C1C01
3 changed files with 24 additions and 18 deletions

View file

@ -22,6 +22,13 @@ class Settings:
except: except:
self.__settings = {} self.__settings = {}
def writeSettings(self):
with open(self.__filename, 'w+') as f:
json.dump(self.__settings, f, indent=4)
def updateSetting(self, setting, value):
self.__settings[setting] = value
def getSetting(self, setting, default=None): def getSetting(self, setting, default=None):
result = self.__settings.get(setting, default) result = self.__settings.get(setting, default)
return result return result

View file

@ -211,7 +211,7 @@ class OptionsTabPage(DirectFrame):
self.ignore('confirmDone') self.ignore('confirmDone')
self.hide() self.hide()
if self.settingsChanged != 0: if self.settingsChanged != 0:
Settings.writeSettings() base.settings.writeSettings()
self.speedChatStyleText.exit() self.speedChatStyleText.exit()
if self.displaySettingsChanged: if self.displaySettingsChanged:
taskMgr.doMethodLater(self.DisplaySettingsDelay, self.writeDisplaySettings, self.DisplaySettingsTaskName) taskMgr.doMethodLater(self.DisplaySettingsDelay, self.writeDisplaySettings, self.DisplaySettingsTaskName)
@ -253,10 +253,10 @@ class OptionsTabPage(DirectFrame):
messenger.send('wakeup') messenger.send('wakeup')
if base.musicActive: if base.musicActive:
base.enableMusic(0) base.enableMusic(0)
Settings.setMusic(0) base.settings.updateSetting('music', 0)
else: else:
base.enableMusic(1) base.enableMusic(1)
Settings.setMusic(1) base.settings.updateSetting('music', 1)
self.settingsChanged = 1 self.settingsChanged = 1
self.__setMusicButton() self.__setMusicButton()
@ -272,10 +272,10 @@ class OptionsTabPage(DirectFrame):
messenger.send('wakeup') messenger.send('wakeup')
if base.sfxActive: if base.sfxActive:
base.enableSoundEffects(0) base.enableSoundEffects(0)
Settings.setSfx(0) base.settings.updateSetting('sfx', 0)
else: else:
base.enableSoundEffects(1) base.enableSoundEffects(1)
Settings.setSfx(1) base.settings.updateSetting('sfx', 1)
self.settingsChanged = 1 self.settingsChanged = 1
self.__setSoundFXButton() self.__setSoundFXButton()
@ -283,10 +283,10 @@ class OptionsTabPage(DirectFrame):
messenger.send('wakeup') messenger.send('wakeup')
if base.toonChatSounds: if base.toonChatSounds:
base.toonChatSounds = 0 base.toonChatSounds = 0
Settings.setToonChatSounds(0) base.settings.updateSetting('toon-chat-sounds', 0)
else: else:
base.toonChatSounds = 1 base.toonChatSounds = 1
Settings.setToonChatSounds(1) base.settings.updateSetting('toon-chat-sounds', 1)
self.settingsChanged = 1 self.settingsChanged = 1
self.__setToonChatSoundsButton() self.__setToonChatSoundsButton()
@ -317,10 +317,10 @@ class OptionsTabPage(DirectFrame):
messenger.send('wakeup') messenger.send('wakeup')
if base.localAvatar.acceptingNewFriends: if base.localAvatar.acceptingNewFriends:
base.localAvatar.acceptingNewFriends = 0 base.localAvatar.acceptingNewFriends = 0
Settings.setAcceptingNewFriends(0) base.settings.updateSetting('accepting-new-friends', 0)
else: else:
base.localAvatar.acceptingNewFriends = 1 base.localAvatar.acceptingNewFriends = 1
Settings.setAcceptingNewFriends(1) base.settings.updateSetting('accepting-new-friends', 1)
self.settingsChanged = 1 self.settingsChanged = 1
self.__setAcceptFriendsButton() self.__setAcceptFriendsButton()
@ -328,10 +328,10 @@ class OptionsTabPage(DirectFrame):
messenger.send('wakeup') messenger.send('wakeup')
if base.localAvatar.acceptingNonFriendWhispers: if base.localAvatar.acceptingNonFriendWhispers:
base.localAvatar.acceptingNonFriendWhispers = 0 base.localAvatar.acceptingNonFriendWhispers = 0
Settings.setAcceptingNonFriendWhispers(0) base.settings.updateSetting('accepting-non-friend-whispers', 0)
else: else:
base.localAvatar.acceptingNonFriendWhispers = 1 base.localAvatar.acceptingNonFriendWhispers = 1
Settings.setAcceptingNonFriendWhispers(1) base.settings.updateSetting('accepting-non-friend-whispers', 1)
self.settingsChanged = 1 self.settingsChanged = 1
self.__setAcceptWhispersButton() self.__setAcceptWhispersButton()
@ -433,16 +433,16 @@ class OptionsTabPage(DirectFrame):
self.displaySettingsFullscreen, self.displaySettingsFullscreen,
self.displaySettingsEmbedded, self.displaySettingsEmbedded,
self.displaySettingsApi)) self.displaySettingsApi))
Settings.setResolutionDimensions(self.displaySettingsSize[0], self.displaySettingsSize[1]) base.settings.updateSetting('resolution', (self.displaySettingsSize[0], self.displaySettingsSize[1]))
Settings.setWindowedMode(not self.displaySettingsFullscreen) base.settings.updateSetting('windowed-mode', not self.displaySettingsFullscreen)
Settings.setEmbeddedMode(self.displaySettingsEmbedded) base.settings.updateSetting('embedded-mode', self.displaySettingsEmbedded)
if self.displaySettingsApiChanged: if self.displaySettingsApiChanged:
api = self.DisplaySettingsApiMap.get(self.displaySettingsApi) api = self.DisplaySettingsApiMap.get(self.displaySettingsApi)
if api == None: if api == None:
self.notify.warning('Cannot save unknown display API: %s' % self.displaySettingsApi) self.notify.warning('Cannot save unknown display API: %s' % self.displaySettingsApi)
else: else:
Settings.setDisplayDriver(api) Settings.setDisplayDriver(api)
Settings.writeSettings() base.settings.writeSettings()
self.displaySettingsChanged = 0 self.displaySettingsChanged = 0
return Task.done return Task.done

View file

@ -12,7 +12,6 @@ from direct.showbase import PythonUtil
from direct.directnotify import DirectNotifyGlobal from direct.directnotify import DirectNotifyGlobal
from direct.gui import DirectGuiGlobals from direct.gui import DirectGuiGlobals
from pandac.PandaModules import * from pandac.PandaModules import *
from libotp import *
from otp.avatar import LocalAvatar from otp.avatar import LocalAvatar
from otp.login import LeaveToPayDialog from otp.login import LeaveToPayDialog
from otp.avatar import PositionExaminer from otp.avatar import PositionExaminer
@ -163,8 +162,8 @@ class LocalToon(DistributedToon.DistributedToon, LocalAvatar.LocalAvatar):
if not hasattr(base.cr, 'lastLoggedIn'): if not hasattr(base.cr, 'lastLoggedIn'):
base.cr.lastLoggedIn = self.cr.toontownTimeManager.convertStrToToontownTime('') base.cr.lastLoggedIn = self.cr.toontownTimeManager.convertStrToToontownTime('')
self.setLastTimeReadNews(base.cr.lastLoggedIn) self.setLastTimeReadNews(base.cr.lastLoggedIn)
self.acceptingNewFriends = Settings.getAcceptingNewFriends() and base.config.GetBool('accepting-new-friends-default', True) self.acceptingNewFriends = base.settings.getSetting('accepting-new-friends', 1) and base.config.GetBool('accepting-new-friends-default', True)
self.acceptingNonFriendWhispers = Settings.getAcceptingNonFriendWhispers() and base.config.GetBool('accepting-non-friend-whispers-default', True) self.acceptingNonFriendWhispers = base.settings.getSetting('accepting-non-friend-whispers', 1) and base.config.GetBool('accepting-non-friend-whispers-default', True)
self.physControls.event.addAgainPattern('again%in') self.physControls.event.addAgainPattern('again%in')
self.oldPos = None self.oldPos = None
self.questMap = None self.questMap = None