diff --git a/Scripts/Python/xIniInput.py b/Scripts/Python/xIniInput.py index 7526280bab..874544cf6a 100644 --- a/Scripts/Python/xIniInput.py +++ b/Scripts/Python/xIniInput.py @@ -45,10 +45,12 @@ """ import xIniHelper +from PlasmaConstants import * +from Plasma import * - -gFilename = "./init/input.fni" gIniFile = None +gFilename = "input.ini" +gFilenameAndPath = "" # the different volume commands kBindCmd = "Keyboard.BindAction" @@ -60,19 +62,48 @@ kTurnLeft = '"Turn Left"' kTurnRight = '"Turn Right"' kJump = '"Jump Key"' +kStrafeLeft = '"Strafe Left"' +kStrafeRight = '"Strafe Right"' kExit = '"Exit Mode"' -kExiGUI = '"Exit GUI Mode"' +kToggleFP = '"Toggle First Person"' +kOpenYB = '"Game.KIOpenYeeshaBook"' +kHelp = '"Game.KIHelp"' +kOpenKi = '"Game.KIOpenKI"' +kTakePicture = '"Game.KITakePicture"' +kKICreateJournal = '"Game.KICreateJournal"' kTalk = '"Push to talk"' +kChat = '"Game.EnterChatMode"' +kCreateMarkerFolder = '"Game.KICreateMarkerFolder"' +kCreateMarker = '"Game.KICreateMarker"' + +kIniArray = [ kWalkForward, kWalkBack, kTurnLeft, kTurnRight, kJump, kStrafeLeft, kStrafeRight, kExit, kToggleFP, kOpenYB, kHelp, kOpenKi, kTakePicture, kKICreateJournal, kTalk, kChat, kCreateMarkerFolder, kCreateMarker ] + + +def ConstructFilenameAndPath(): + global gFilenameAndPath + if gFilenameAndPath == "": + if PtIsInternalRelease(): + # check for local file + localNameAndPath = "init/" + gFilename + if PtFileExists(localNameAndPath): + gFilenameAndPath = localNameAndPath + PtDebugPrint("xIniInput::ConstructFilenameAndPath(): Using internal \"" + gFilenameAndPath + "\" file") + return + # otherwise, use the standard init path + gFilenameAndPath = PtGetInitPath() + "/" + gFilename + PtDebugPrint("xIniInput::ConstructFilenameAndPath(): Using user-level \"" + gFilenameAndPath + "\" file") def WriteIni(): global gIniFile if gIniFile: - gIniFile.writeFile(gFilename) + ConstructFilenameAndPath() + gIniFile.writeFile(gFilenameAndPath) def ReadIni(): global gIniFile - gIniFile = xIniHelper.iniFile(gFilename) + ConstructFilenameAndPath() + gIniFile = xIniHelper.iniFile(gFilenameAndPath) if gIniFile.isEmpty(): # add defaults gIniFile.addEntry("# This is an auto-generated file.") @@ -93,7 +124,7 @@ def GetControlKey(controlKey): if entry and entry.getValue(0) and entry.getValue(1): return entry.getValue(0),entry.getValue(1) else: - return "(unmapped),","(unmapped)," + return None def SetConsoleKey(consoleCommand,primary="(unmapped),"): if gIniFile: diff --git a/Scripts/Python/xOptionsMenu.py b/Scripts/Python/xOptionsMenu.py index 152e637dcd..c95530f522 100644 --- a/Scripts/Python/xOptionsMenu.py +++ b/Scripts/Python/xOptionsMenu.py @@ -65,9 +65,11 @@ from xGUILinkHandler import xGUILinkHandler import xJournalBookDefs +import xIniInput import xIniAudio import xIniDisplay import xIniNumSounds +import re # define the attributes that will be entered in max OptionsMenuDlg = ptAttribGUIDialog(1,"The Options Menu dialog") @@ -502,12 +504,13 @@ def BeginAgeUnLoad(self,avatar): gJournalBook.hide() def OnServerInitComplete(self): + xIniInput.ReadIni() if self.refreshBindings: self.refreshBindings = False - + testInputINI = xIniInput.GetControlKey(xIniInput.kWalkForward) vault = ptVault() entry = vault.findChronicleEntry("KeyMap") - if entry is None: + if entry is None and testInputINI is None: # not found... create defaults self.ISetDefaultKeyMappings() @@ -723,10 +726,9 @@ def OnGUINotify(self,id,control,event): textField.setStringW(PtGetLocalizedString("OptionsMenu.Main.GoBack")) self.IShowMappedKeys(control,gKM1ControlCodesRow1,gKM1ControlCodesRow2) # read the ini file in - # xIniInput.ReadIni() + xIniInput.ReadIni() else: - # xIniInput.WriteIni() - pass + xIniInput.WriteIni() elif event == kAction or event == kValueChanged: kmID = control.getTagID() if kmID == kKMOkBtn: @@ -745,6 +747,7 @@ def OnGUINotify(self,id,control,event): for key in KeyMapArray: NewKeyMapString += key + " " self.setNewChronicleVar("KeyMap", NewKeyMapString.rstrip()) + xIniInput.SetConsoleKey('"' + cCode + '"', key1 + ',') elif cCode is not None: otherID = kmID + 100 otherField = ptGUIControlEditBox(KeyMapDlg.dialog.getControlFromTag(otherID)) @@ -758,6 +761,7 @@ def OnGUINotify(self,id,control,event): for key in KeyMapArray: NewKeyMapString += key + " " self.setNewChronicleVar("KeyMap", NewKeyMapString.rstrip()) + xIniInput.SetControlKey('"' + controlStr + '"', key1 + ',', key2 + ',') # lose the focus when done KeyMapDlg.dialog.noFocus() # force writing the keymap @@ -765,7 +769,7 @@ def OnGUINotify(self,id,control,event): # re-show the keymap because they may have been stupid and map the same key to multiple actions self.IShowMappedKeys(KeyMapDlg.dialog,gKM1ControlCodesRow1,gKM1ControlCodesRow2) # need to re-set the ini file, in case something got unmapped - #self.IMatchIniToGame() + self.IMatchIniToGame() elif kmID in gKM1ControlCodesRow2.keys(): NewKeyMapString = "" # get the new keys and bind @@ -782,7 +786,7 @@ def OnGUINotify(self,id,control,event): for key in KeyMapArray: NewKeyMapString += key + " " self.setNewChronicleVar("KeyMap", NewKeyMapString.rstrip()) - #xIniInput.SetConsoleKey('"'+cCode+'"',key1+',') + xIniInput.SetConsoleKey('"'+cCode+'"',key1+',') elif cCode is not None: otherID = kmID - 100 otherField = ptGUIControlEditBox(KeyMapDlg.dialog.getControlFromTag(otherID)) @@ -796,7 +800,7 @@ def OnGUINotify(self,id,control,event): for key in KeyMapArray: NewKeyMapString += key + " " self.setNewChronicleVar("KeyMap", NewKeyMapString.rstrip()) - #xIniInput.SetControlKey('"'+controlStr+'"',key1+',',key2+',') + xIniInput.SetControlKey('"'+controlStr+'"',key1+',',key2+',') # lose the focus when done KeyMapDlg.dialog.noFocus() # force writing the keymap @@ -804,7 +808,7 @@ def OnGUINotify(self,id,control,event): # re-show the keymap because they may have been stupid and map the same key to multiple actions self.IShowMappedKeys(KeyMapDlg.dialog,gKM1ControlCodesRow1,gKM1ControlCodesRow2) # need to re-set the ini file, in case something got unmapped - #self.IMatchIniToGame() + self.IMatchIniToGame() elif kmID == kKMDefaultsBtn: self.ISetDefaultKeyMappings() self.IShowMappedKeys(KeyMapDlg.dialog,gKM1ControlCodesRow1,gKM1ControlCodesRow2) @@ -1876,10 +1880,18 @@ def LoadAdvSettings(self): def LoadKeyMap(self): km = ptKeyMap() - KeyMapString = self.getChronicleVar("KeyMap") - if not KeyMapString: - PtDebugPrint("xOptionsMenu.LoadKeyMap():\tHmm... Empty chronicle...") - return + KeyMapString = "" + kWalkForward = xIniInput.GetControlKey(xIniInput.kWalkForward) + if kWalkForward is None: + KeyMapString = self.getChronicleVar("KeyMap") + if not KeyMapString: + PtDebugPrint("xOptionsMenu.LoadKeyMap():\tHmm... Empty chronicle...") + return + else: + for key in xIniInput.kIniArray: + key = xIniInput.GetControlKey(key) + KeyMapString += re.sub('\$ $', ' ', key[0].replace(",","")+"$"+re.sub('"Game.*', '', key[1].replace(",",""))+" ") + KeyMapArray = KeyMapString.split() # set the key binds back to the saved @@ -1940,6 +1952,18 @@ def IShowMappedKeys(self,dlg,mapRow1,mapRow2): # disable this field field.hide() + def IMatchIniToGame(self): + km = ptKeyMap() + for control_code in defaultControlCodeBinds.keys(): + if type(control_code) == type(''): + key1 = km.convertVKeyToChar(km.getBindingKeyConsole(control_code), km.getBindingFlagsConsole(control_code)) + xIniInput.SetConsoleKey('"' + control_code + '"', key1 + ',') + else: + controlStr = km.convertControlCodeToString(control_code) + key1 = km.convertVKeyToChar(km.getBindingKey1(control_code), km.getBindingFlags1(control_code)) + key2 = km.convertVKeyToChar(km.getBindingKey2(control_code), km.getBindingFlags2(control_code)) + xIniInput.SetControlKey('"' + controlStr + '"', key1 + ',', key2 + ',') + def ISetDefaultKeyMappings(self): km = ptKeyMap() KeyMapString = ""