diff --git a/libotp/__init__.py b/libotp/__init__.py index dbc1c03..09acffd 100644 --- a/libotp/__init__.py +++ b/libotp/__init__.py @@ -1,2 +1 @@ from panda3d.otp import * -from .settings.Settings import Settings diff --git a/libotp/settings/Settings.py b/libotp/settings/Settings.py deleted file mode 100644 index 8ff63ac..0000000 --- a/libotp/settings/Settings.py +++ /dev/null @@ -1,80 +0,0 @@ -class Settings: - GL = 0 - DX7 = 1 - DX8 = 5 - - @staticmethod - def readSettings(): - pass # todo - - @staticmethod - def writeSettings(): - pass # lol not yet - - @staticmethod - def setWindowedMode(_): - pass - - @staticmethod - def getWindowedMode(): - return 1 - - @staticmethod - def setMusic(_): - pass - - @staticmethod - def getMusic(): - return 1 - - @staticmethod - def setSfx(_): - pass - - @staticmethod - def getSfx(): - return 1 - - @staticmethod - def setToonChatSounds(_): - pass - - @staticmethod - def getToonChatSounds(): - return 1 - - @staticmethod - def setResolutionDimensions(_, __): - pass - - @staticmethod - def getResolution(): - return 1 - - @staticmethod - def setEmbeddedMode(_): - pass - - @staticmethod - def getEmbeddedMode(): - return 0 - - @staticmethod - def doSavedSettingsExist(): - return 0 - - @staticmethod - def setAcceptingNewFriends(_): - pass - - @staticmethod - def getAcceptingNewFriends(): - return 1 - - @staticmethod - def setAcceptingNonFriendWhispers(_): - pass - - @staticmethod - def getAcceptingNonFriendWhispers(): - return 1 diff --git a/otp/settings/Settings.py b/otp/settings/Settings.py new file mode 100644 index 0000000..bc1e8bc --- /dev/null +++ b/otp/settings/Settings.py @@ -0,0 +1,34 @@ +import json +import os + + +class Settings: + + def __init__(self): + self.__settings = {} + self.__filename = 'useropt.json' + + def doSavedSettingsExist(self): + return os.path.exists(self.__filename) + + def readSettings(self): + if not self.doSavedSettingsExist(): + self.__settings = {} + return + + try: + with open(self.__filename, 'r') as f: + self.__settings = json.load(f) + except: + 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): + result = self.__settings.get(setting, default) + return result diff --git a/libotp/settings/__init__.py b/otp/settings/__init__.py similarity index 100% rename from libotp/settings/__init__.py rename to otp/settings/__init__.py diff --git a/toontown/shtiker/OptionsPage.py b/toontown/shtiker/OptionsPage.py index a340d7f..f202b9f 100644 --- a/toontown/shtiker/OptionsPage.py +++ b/toontown/shtiker/OptionsPage.py @@ -1,9 +1,7 @@ from pandac.PandaModules import * -from libotp import * from . import ShtikerPage from toontown.toontowngui import TTDialog from direct.gui.DirectGui import * -from pandac.PandaModules import * from toontown.toonbase import TTLocalizer from . import DisplaySettingsDialog from direct.task import Task @@ -12,7 +10,6 @@ from otp.speedchat import SCColorScheme from otp.speedchat import SCStaticTextTerminal from direct.showbase import PythonUtil from direct.directnotify import DirectNotifyGlobal -from toontown.toonbase import ToontownGlobals speedChatStyles = ((2000, (200 / 255.0, 60 / 255.0, 229 / 255.0), (200 / 255.0, 135 / 255.0, 255 / 255.0), @@ -123,9 +120,6 @@ class OptionsTabPage(DirectFrame): DisplaySettingsDelay = 60 ChangeDisplaySettings = base.config.GetBool('change-display-settings', 1) ChangeDisplayAPI = base.config.GetBool('change-display-api', 0) - DisplaySettingsApiMap = {'OpenGL': Settings.GL, - 'DirectX7': Settings.DX7, - 'DirectX8': Settings.DX8} def __init__(self, parent = aspect2d): self._parent = parent @@ -217,7 +211,7 @@ class OptionsTabPage(DirectFrame): self.ignore('confirmDone') self.hide() if self.settingsChanged != 0: - Settings.writeSettings() + base.settings.writeSettings() self.speedChatStyleText.exit() if self.displaySettingsChanged: taskMgr.doMethodLater(self.DisplaySettingsDelay, self.writeDisplaySettings, self.DisplaySettingsTaskName) @@ -259,10 +253,10 @@ class OptionsTabPage(DirectFrame): messenger.send('wakeup') if base.musicActive: base.enableMusic(0) - Settings.setMusic(0) + base.settings.updateSetting('music', False) else: base.enableMusic(1) - Settings.setMusic(1) + base.settings.updateSetting('music', True) self.settingsChanged = 1 self.__setMusicButton() @@ -278,10 +272,10 @@ class OptionsTabPage(DirectFrame): messenger.send('wakeup') if base.sfxActive: base.enableSoundEffects(0) - Settings.setSfx(0) + base.settings.updateSetting('sfx', False) else: base.enableSoundEffects(1) - Settings.setSfx(1) + base.settings.updateSetting('sfx', True) self.settingsChanged = 1 self.__setSoundFXButton() @@ -289,10 +283,10 @@ class OptionsTabPage(DirectFrame): messenger.send('wakeup') if base.toonChatSounds: base.toonChatSounds = 0 - Settings.setToonChatSounds(0) + base.settings.updateSetting('toon-chat-sounds', False) else: base.toonChatSounds = 1 - Settings.setToonChatSounds(1) + base.settings.updateSetting('toon-chat-sounds', True) self.settingsChanged = 1 self.__setToonChatSoundsButton() @@ -323,10 +317,10 @@ class OptionsTabPage(DirectFrame): messenger.send('wakeup') if base.localAvatar.acceptingNewFriends: base.localAvatar.acceptingNewFriends = 0 - Settings.setAcceptingNewFriends(0) + base.settings.updateSetting('accepting-new-friends', False) else: base.localAvatar.acceptingNewFriends = 1 - Settings.setAcceptingNewFriends(1) + base.settings.updateSetting('accepting-new-friends', True) self.settingsChanged = 1 self.__setAcceptFriendsButton() @@ -334,10 +328,10 @@ class OptionsTabPage(DirectFrame): messenger.send('wakeup') if base.localAvatar.acceptingNonFriendWhispers: base.localAvatar.acceptingNonFriendWhispers = 0 - Settings.setAcceptingNonFriendWhispers(0) + base.settings.updateSetting('accepting-non-friend-whispers', False) else: base.localAvatar.acceptingNonFriendWhispers = 1 - Settings.setAcceptingNonFriendWhispers(1) + base.settings.updateSetting('accepting-non-friend-whispers', True) self.settingsChanged = 1 self.__setAcceptWhispersButton() @@ -439,16 +433,16 @@ class OptionsTabPage(DirectFrame): self.displaySettingsFullscreen, self.displaySettingsEmbedded, self.displaySettingsApi)) - Settings.setResolutionDimensions(self.displaySettingsSize[0], self.displaySettingsSize[1]) - Settings.setWindowedMode(not self.displaySettingsFullscreen) - Settings.setEmbeddedMode(self.displaySettingsEmbedded) + base.settings.updateSetting('resolution', (self.displaySettingsSize[0], self.displaySettingsSize[1])) + base.settings.updateSetting('windowed-mode', not self.displaySettingsFullscreen) + #base.settings.updateSetting('embedded-mode', self.displaySettingsEmbedded) if self.displaySettingsApiChanged: api = self.DisplaySettingsApiMap.get(self.displaySettingsApi) if api == None: self.notify.warning('Cannot save unknown display API: %s' % self.displaySettingsApi) else: Settings.setDisplayDriver(api) - Settings.writeSettings() + base.settings.writeSettings() self.displaySettingsChanged = 0 return Task.done diff --git a/toontown/toon/LocalToon.py b/toontown/toon/LocalToon.py index a3e5928..eaa7cab 100644 --- a/toontown/toon/LocalToon.py +++ b/toontown/toon/LocalToon.py @@ -12,7 +12,6 @@ from direct.showbase import PythonUtil from direct.directnotify import DirectNotifyGlobal from direct.gui import DirectGuiGlobals from pandac.PandaModules import * -from libotp import * from otp.avatar import LocalAvatar from otp.login import LeaveToPayDialog from otp.avatar import PositionExaminer @@ -163,8 +162,8 @@ class LocalToon(DistributedToon.DistributedToon, LocalAvatar.LocalAvatar): if not hasattr(base.cr, 'lastLoggedIn'): base.cr.lastLoggedIn = self.cr.toontownTimeManager.convertStrToToontownTime('') self.setLastTimeReadNews(base.cr.lastLoggedIn) - self.acceptingNewFriends = Settings.getAcceptingNewFriends() and base.config.GetBool('accepting-new-friends-default', True) - self.acceptingNonFriendWhispers = Settings.getAcceptingNonFriendWhispers() and base.config.GetBool('accepting-non-friend-whispers-default', True) + self.acceptingNewFriends = base.settings.getSetting('accepting-new-friends', True) and base.config.GetBool('accepting-new-friends-default', True) + self.acceptingNonFriendWhispers = base.settings.getSetting('accepting-non-friend-whispers', True) and base.config.GetBool('accepting-non-friend-whispers-default', True) self.physControls.event.addAgainPattern('again%in') self.oldPos = None self.questMap = None diff --git a/toontown/toonbase/DisplayOptions.py b/toontown/toonbase/DisplayOptions.py index 47ffe2e..30d19f5 100644 --- a/toontown/toonbase/DisplayOptions.py +++ b/toontown/toonbase/DisplayOptions.py @@ -4,7 +4,6 @@ import os import sys import datetime from pandac.PandaModules import loadPrcFileData, WindowProperties -from libotp import Settings from otp.otpgui import OTPDialog from otp.otpbase import OTPGlobals from otp.otpbase import OTPRender @@ -22,25 +21,20 @@ class DisplayOptions: self.loadFromSettings() def loadFromSettings(self): - Settings.readSettings() - mode = not Settings.getWindowedMode() - music = Settings.getMusic() - sfx = Settings.getSfx() - toonChatSounds = Settings.getToonChatSounds() - resList = [(640, 480), - (800, 600), - (1024, 768), - (1280, 1024), - (1600, 1200)] - res = resList[Settings.getResolution()] - embed = Settings.getEmbeddedMode() + base.settings.readSettings() + mode = not base.settings.getSetting('windowed-mode', True) + music = base.settings.getSetting('music', True) + sfx = base.settings.getSetting('sfx', True) + toonChatSounds = base.settings.getSetting('toon-chat-sounds', True) + res = base.settings.getSetting('resolution', (800, 600)) + embed = False # base.settings.getSetting('embedded-mode', False) self.notify.debug('before prc settings embedded mode=%s' % str(embed)) self.notify.debug('before prc settings full screen mode=%s' % str(mode)) if mode == None: mode = 1 if res == None: res = (800, 600) - if not Settings.doSavedSettingsExist(): + if not base.settings.doSavedSettingsExist(): self.notify.info('loadFromSettings: No settings; isDefaultEmbedded=%s' % self.isDefaultEmbedded()) embed = self.isDefaultEmbedded() if embed and not self.isEmbeddedPossible(): diff --git a/toontown/toonbase/ToonBase.py b/toontown/toonbase/ToonBase.py index b76cb97..355231a 100644 --- a/toontown/toonbase/ToonBase.py +++ b/toontown/toonbase/ToonBase.py @@ -1,6 +1,7 @@ from otp.otpbase import OTPBase from otp.otpbase import OTPLauncherGlobals from otp.otpbase import OTPGlobals +from otp.settings.Settings import Settings from direct.showbase.PythonUtil import * from . import ToontownGlobals from direct.directnotify import DirectNotifyGlobal @@ -21,18 +22,14 @@ class ToonBase(OTPBase.OTPBase): notify = DirectNotifyGlobal.directNotify.newCategory('ToonBase') def __init__(self): + self.settings = Settings() if not config.GetInt('ignore-user-options', 0): - Settings.readSettings() - mode = not Settings.getWindowedMode() - music = Settings.getMusic() - sfx = Settings.getSfx() - toonChatSounds = Settings.getToonChatSounds() - resList = [(640, 480), - (800, 600), - (1024, 768), - (1280, 1024), - (1600, 1200)] - res = resList[Settings.getResolution()] + self.settings.readSettings() + mode = not self.settings.getSetting('windowed-mode', True) + music = self.settings.getSetting('music', True) + sfx = self.settings.getSetting('sfx', True) + toonChatSounds = self.settings.getSetting('toon-chat-sounds', True) + res = self.settings.getSetting('resolution', (800, 600)) if mode == None: mode = 1 if res == None: