settings: Initial commit

This commit is contained in:
John Cote 2021-07-07 20:56:19 -04:00
parent cfa209216c
commit db25aaf10d
No known key found for this signature in database
GPG key ID: E3442FF71E9C1C01
7 changed files with 43 additions and 112 deletions

View file

@ -1,2 +1 @@
from panda3d.otp import *
from .settings.Settings import Settings

View file

@ -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

27
otp/settings/Settings.py Normal file
View file

@ -0,0 +1,27 @@
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 getSetting(self, setting, default=None):
result = self.__settings.get(setting, default)
return result

View file

@ -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

View file

@ -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', 1)
music = base.settings.getSetting('music', 1)
sfx = base.settings.getSetting('sfx', 1)
toonChatSounds = base.settings.getSetting('toon-chat-sounds', 1)
res = base.settings.getSetting('resolution', (800, 600))
embed = base.settings.getSetting('embedded-mode', 0)
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():

View file

@ -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', 1)
music = self.settings.getSetting('music', 1)
sfx = self.settings.getSetting('sfx', 1)
toonChatSounds = self.settings.getSetting('toon-chat-sounds', 1)
res = self.settings.getSetting('resolution', (800, 600))
if mode == None:
mode = 1
if res == None: