-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Local Input Config for Keyboard #1067
Open
Hazado
wants to merge
1
commit into
H-uru:master
Choose a base branch
from
Hazado:LocalInputINI
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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,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 | ||
|
@@ -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,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) | ||
|
@@ -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 + ',') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These string concats are very difficult for me to read because it uses two different kinds of quotation marks. I'd prefer to see these become f-strings. |
||
|
||
def ISetDefaultKeyMappings(self): | ||
km = ptKeyMap() | ||
KeyMapString = "" | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably return the path instead of stashing it as a global variable. That way, you can get rid of the
gFilenameAndPath
thing and just dogIniFile.writeFile(ConstructFilenameAndPath())
.