Skip to content

Commit

Permalink
First push
Browse files Browse the repository at this point in the history
  • Loading branch information
Hazado committed Feb 9, 2022
1 parent 3b20ede commit d489329
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 19 deletions.
43 changes: 37 additions & 6 deletions Scripts/Python/xIniInput.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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.")
Expand All @@ -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:
Expand Down
50 changes: 37 additions & 13 deletions Scripts/Python/xOptionsMenu.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -450,6 +452,7 @@ def __init__(self):
self.restartWarn = False
self.goingToCalibration = 0
self.refreshBindings = True
xIniInput.ReadIni()

def OnFirstUpdate(self):
global WebLaunchCmd
Expand Down Expand Up @@ -504,10 +507,10 @@ def BeginAgeUnLoad(self,avatar):
def OnServerInitComplete(self):
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()

Expand Down Expand Up @@ -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:
Expand All @@ -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))
Expand All @@ -758,14 +761,15 @@ 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
km.writeKeyMap()
# 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
Expand All @@ -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))
Expand All @@ -796,15 +800,15 @@ 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
km.writeKeyMap()
# 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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = ""
Expand Down

0 comments on commit d489329

Please sign in to comment.