From f467f0a166b6c79cf4785977666ba69b44afc9c3 Mon Sep 17 00:00:00 2001 From: Edmond Mondor Date: Tue, 1 Aug 2023 21:32:37 -0700 Subject: [PATCH 1/8] Disable mouse movement keys when sitting at heek table --- Scripts/Python/nb01RPSGame.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Scripts/Python/nb01RPSGame.py b/Scripts/Python/nb01RPSGame.py index ae2cc915b5..03ca36d333 100644 --- a/Scripts/Python/nb01RPSGame.py +++ b/Scripts/Python/nb01RPSGame.py @@ -389,6 +389,10 @@ def OnNotify(self, state, id, events): # Finished sitting down. if self._HandleNotify(state, id, events, self._sitting, self._OnSitDown): + if self.playing: + PtEnableMouseMovement() + else: + PtDisableMouseMovement() return # A rock/paper/sics button was mashed From 551afa0f69d177d4edc2c31552eb9b96969d3e41 Mon Sep 17 00:00:00 2001 From: Edmond Mondor Date: Fri, 4 Aug 2023 20:42:59 -0700 Subject: [PATCH 2/8] Popup message to unlock leaving --- Scripts/Python/nb01RPSGame.py | 47 ++++++++++++++++++++++++----------- 1 file changed, 32 insertions(+), 15 deletions(-) diff --git a/Scripts/Python/nb01RPSGame.py b/Scripts/Python/nb01RPSGame.py index 03ca36d333..360b3dac6f 100644 --- a/Scripts/Python/nb01RPSGame.py +++ b/Scripts/Python/nb01RPSGame.py @@ -45,6 +45,7 @@ from PlasmaConstants import * from PlasmaKITypes import * from PlasmaTypes import * +import PlasmaControlKeys # detectors detButtonRock = ptAttribActivatorList(1, "Rock ButtonClick det", netForce=True) @@ -380,6 +381,13 @@ def OnSDLNotify(self, VARname, SDLname, playerID, tag): else: raise RuntimeError("Got an SDL notify for {}, but no CB".format(VARname)) + def OnControlKeyEvent(self,controlKey,activeFlag): + PtDebugPrint(controlKey, activeFlag) + if controlKey == PlasmaControlKeys.kKeyExitMode: + PtYesNoDialog(self.key, "Do you want to leave the Ahyoheek game?") + elif controlKey == PlasmaControlKeys.kKeyMoveBackward or controlKey == PlasmaControlKeys.kKeyRotateLeft or controlKey == PlasmaControlKeys.kKeyRotateRight: + PtYesNoDialog(self.key, "Do you want to leave the Ahyoheek game?") + def OnNotify(self, state, id, events): """Handle Plasma Notification Messages""" @@ -389,10 +397,10 @@ def OnNotify(self, state, id, events): # Finished sitting down. if self._HandleNotify(state, id, events, self._sitting, self._OnSitDown): - if self.playing: - PtEnableMouseMovement() - else: - PtDisableMouseMovement() + if not self.playing: + PtEnableControlKeyEvents(self.key) + #PtDisableMouseMovement() + PtDisableMovementKeys() return # A rock/paper/sics button was mashed @@ -945,17 +953,26 @@ def _HandleVariableNotify(self, events): for event in events: args[event[1]] = event[3] - # Now, let's fire it off! - type = args["type"] - del args["type"] - if type not in self._event_handlers: - PtDebugPrint("nb01RPSGame._HandleVariableNotify():\tPyEvent '{}' doesn't have a handler!".format(type)) - return False - try: - self._event_handlers[type](**args) - except TypeError: - PtDebugPrint("nb01RPSGame._HandleVariableNotify():\tPyEvent '{}' has bad kwargs".format(type)) - return True + if "YesNo" in args: + PtDebugPrint("YesNo is",args["YesNo"]) + if args["YesNo"]: + PtDisableControlKeyEvents(self.key) + PtEnableMovementKeys() + return True + else: + return False + elif "type" in args: + # Now, let's fire it off! + type = args["type"] + del args["type"] + if type not in self._event_handlers: + PtDebugPrint("nb01RPSGame._HandleVariableNotify():\tPyEvent '{}' doesn't have a handler!".format(type)) + return False + try: + self._event_handlers[type](**args) + except TypeError: + PtDebugPrint("nb01RPSGame._HandleVariableNotify():\tPyEvent '{}' has bad kwargs".format(type)) + return True def _SendPyNotifyMsg(self, contents): """Sends variable events to everyone. The contents will be unpacked as method arguments.""" From 0c4566bd2f6589137932eda997ae60e4a361c661 Mon Sep 17 00:00:00 2001 From: Edmond Mondor Date: Fri, 4 Aug 2023 21:57:50 -0700 Subject: [PATCH 3/8] Test 2 --- Scripts/Python/nb01RPSGame.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/Scripts/Python/nb01RPSGame.py b/Scripts/Python/nb01RPSGame.py index 360b3dac6f..81bd63900c 100644 --- a/Scripts/Python/nb01RPSGame.py +++ b/Scripts/Python/nb01RPSGame.py @@ -382,10 +382,7 @@ def OnSDLNotify(self, VARname, SDLname, playerID, tag): raise RuntimeError("Got an SDL notify for {}, but no CB".format(VARname)) def OnControlKeyEvent(self,controlKey,activeFlag): - PtDebugPrint(controlKey, activeFlag) - if controlKey == PlasmaControlKeys.kKeyExitMode: - PtYesNoDialog(self.key, "Do you want to leave the Ahyoheek game?") - elif controlKey == PlasmaControlKeys.kKeyMoveBackward or controlKey == PlasmaControlKeys.kKeyRotateLeft or controlKey == PlasmaControlKeys.kKeyRotateRight: + if controlKey in [PlasmaControlKeys.kKeyMoveBackward, PlasmaControlKeys.kKeyRotateLeft, PlasmaControlKeys.kKeyRotateRight, PlasmaControlKeys.kKeyExitMode] and activeFlag: PtYesNoDialog(self.key, "Do you want to leave the Ahyoheek game?") def OnNotify(self, state, id, events): @@ -399,8 +396,8 @@ def OnNotify(self, state, id, events): if self._HandleNotify(state, id, events, self._sitting, self._OnSitDown): if not self.playing: PtEnableControlKeyEvents(self.key) - #PtDisableMouseMovement() PtDisableMovementKeys() + PtEnableMouseMovement() return # A rock/paper/sics button was mashed @@ -958,6 +955,7 @@ def _HandleVariableNotify(self, events): if args["YesNo"]: PtDisableControlKeyEvents(self.key) PtEnableMovementKeys() + PtAvatarExitAFK() return True else: return False From 998a1326636a286863efd67324506df48c586c0d Mon Sep 17 00:00:00 2001 From: Edmond Mondor Date: Sat, 5 Aug 2023 12:57:00 -0700 Subject: [PATCH 4/8] Requested changes Co-authored-by: Adam Johnson --- Scripts/Python/nb01RPSGame.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Scripts/Python/nb01RPSGame.py b/Scripts/Python/nb01RPSGame.py index 81bd63900c..7680d58f76 100644 --- a/Scripts/Python/nb01RPSGame.py +++ b/Scripts/Python/nb01RPSGame.py @@ -383,7 +383,7 @@ def OnSDLNotify(self, VARname, SDLname, playerID, tag): def OnControlKeyEvent(self,controlKey,activeFlag): if controlKey in [PlasmaControlKeys.kKeyMoveBackward, PlasmaControlKeys.kKeyRotateLeft, PlasmaControlKeys.kKeyRotateRight, PlasmaControlKeys.kKeyExitMode] and activeFlag: - PtYesNoDialog(self.key, "Do you want to leave the Ahyoheek game?") + PtYesNoDialog(self.key, PtGetLocalizedString("Heek.Messages.Quit")) def OnNotify(self, state, id, events): """Handle Plasma Notification Messages""" @@ -951,7 +951,6 @@ def _HandleVariableNotify(self, events): args[event[1]] = event[3] if "YesNo" in args: - PtDebugPrint("YesNo is",args["YesNo"]) if args["YesNo"]: PtDisableControlKeyEvents(self.key) PtEnableMovementKeys() @@ -959,7 +958,7 @@ def _HandleVariableNotify(self, events): return True else: return False - elif "type" in args: + else: # Now, let's fire it off! type = args["type"] del args["type"] From c502ac5f8bcae8f6f140b6aae8b3eac6c5cf6a51 Mon Sep 17 00:00:00 2001 From: Edmond Mondor Date: Mon, 7 Aug 2023 10:03:54 -0700 Subject: [PATCH 5/8] Request Changes part Deux Co-authored-by: Adam Johnson --- Scripts/Python/nb01RPSGame.py | 57 ++++++++++++++++++++--------------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/Scripts/Python/nb01RPSGame.py b/Scripts/Python/nb01RPSGame.py index 7680d58f76..8918af9451 100644 --- a/Scripts/Python/nb01RPSGame.py +++ b/Scripts/Python/nb01RPSGame.py @@ -191,6 +191,7 @@ NOTIFY_HELLO = 0 NOTIFY_JOINLEAVE = 1 NOTIFY_SCORE_UPDATE = 2 +NOTIFY_YESNO_QUIT = 3 # Rank stuff RANK_UP = 100 @@ -292,6 +293,7 @@ def __init__(self): NOTIFY_HELLO: self._OnHello, NOTIFY_JOINLEAVE: self._OnJoinLeave, NOTIFY_SCORE_UPDATE: self._OnGameOver, + NOTIFY_YESNO_QUIT: self._QuitGame, } # These get called when an SDL variable touches itself. @@ -381,9 +383,16 @@ def OnSDLNotify(self, VARname, SDLname, playerID, tag): else: raise RuntimeError("Got an SDL notify for {}, but no CB".format(VARname)) - def OnControlKeyEvent(self,controlKey,activeFlag): + def OnControlKeyEvent(self, controlKey, activeFlag): if controlKey in [PlasmaControlKeys.kKeyMoveBackward, PlasmaControlKeys.kKeyRotateLeft, PlasmaControlKeys.kKeyRotateRight, PlasmaControlKeys.kKeyExitMode] and activeFlag: - PtYesNoDialog(self.key, PtGetLocalizedString("Heek.Messages.Quit")) + if self._round_played: + PtYesNoDialog(self.key, PtGetLocalizedString("Heek.Messages.Quit")) + else: + quit = { + "type": NOTIFY_YESNO_QUIT, + "YesNo": 1, + } + self._SendPyNotifyMsg(quit) def OnNotify(self, state, id, events): """Handle Plasma Notification Messages""" @@ -394,10 +403,6 @@ def OnNotify(self, state, id, events): # Finished sitting down. if self._HandleNotify(state, id, events, self._sitting, self._OnSitDown): - if not self.playing: - PtEnableControlKeyEvents(self.key) - PtDisableMovementKeys() - PtEnableMouseMovement() return # A rock/paper/sics button was mashed @@ -451,6 +456,9 @@ def _OnSitDown(self, state, seat, events): if state: if PtWasLocallyNotified(self.key): PtSendKIMessage(kDisableEntireYeeshaBook, 0) + PtEnableControlKeyEvents(self.key) + PtDisableMovementKeys() + PtEnableMouseMovement() self._JoinTheGame(seat) else: self._seats[seat].enable() @@ -719,6 +727,11 @@ def _SendLocalStatusMsg(self, msg): """Sends a status chat message (purple text) to the local player's KI.""" PtSendKIMessage(kKILocalChatStatusMsg, msg) + def _QuitGame(self, YesNo): + if YesNo: + PtDisableControlKeyEvents(self.key) + PtEnableMovementKeys() + PtAvatarExitAFK() ######### def _ChangeButtonState(self, seat, enable=True, ff=False, force=False): @@ -951,25 +964,19 @@ def _HandleVariableNotify(self, events): args[event[1]] = event[3] if "YesNo" in args: - if args["YesNo"]: - PtDisableControlKeyEvents(self.key) - PtEnableMovementKeys() - PtAvatarExitAFK() - return True - else: - return False - else: - # Now, let's fire it off! - type = args["type"] - del args["type"] - if type not in self._event_handlers: - PtDebugPrint("nb01RPSGame._HandleVariableNotify():\tPyEvent '{}' doesn't have a handler!".format(type)) - return False - try: - self._event_handlers[type](**args) - except TypeError: - PtDebugPrint("nb01RPSGame._HandleVariableNotify():\tPyEvent '{}' has bad kwargs".format(type)) - return True + args["type"] = NOTIFY_YESNO_QUIT + + # Now, let's fire it off! + type = args["type"] + del args["type"] + if type not in self._event_handlers: + PtDebugPrint("nb01RPSGame._HandleVariableNotify():\tPyEvent '{}' doesn't have a handler!".format(type)) + return False + try: + self._event_handlers[type](**args) + except TypeError: + PtDebugPrint("nb01RPSGame._HandleVariableNotify():\tPyEvent '{}' has bad kwargs".format(type)) + return True def _SendPyNotifyMsg(self, contents): """Sends variable events to everyone. The contents will be unpacked as method arguments.""" From 59bd9af756f5c889ef073a42fafbeeb5d684ec69 Mon Sep 17 00:00:00 2001 From: Edmond Mondor Date: Tue, 8 Aug 2023 20:21:50 -0700 Subject: [PATCH 6/8] Additional requested change and commenting Co-authored-by: Adam Johnson --- Scripts/Python/nb01RPSGame.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Scripts/Python/nb01RPSGame.py b/Scripts/Python/nb01RPSGame.py index 8918af9451..a47f75cdb9 100644 --- a/Scripts/Python/nb01RPSGame.py +++ b/Scripts/Python/nb01RPSGame.py @@ -384,9 +384,10 @@ def OnSDLNotify(self, VARname, SDLname, playerID, tag): raise RuntimeError("Got an SDL notify for {}, but no CB".format(VARname)) def OnControlKeyEvent(self, controlKey, activeFlag): + """Captures movement keys and prompt a yes/no dialog during a game or standup animation otherwise""" if controlKey in [PlasmaControlKeys.kKeyMoveBackward, PlasmaControlKeys.kKeyRotateLeft, PlasmaControlKeys.kKeyRotateRight, PlasmaControlKeys.kKeyExitMode] and activeFlag: if self._round_played: - PtYesNoDialog(self.key, PtGetLocalizedString("Heek.Messages.Quit")) + PtLocalizedYesNoDialog(self.key, "Heek.Messages.Quit") else: quit = { "type": NOTIFY_YESNO_QUIT, @@ -455,6 +456,10 @@ def _OnSitDown(self, state, seat, events): # Manage game state if standing up if state: if PtWasLocallyNotified(self.key): + """Disable Yeesha Book to prevent linking out + Enable control keys to capture button presses or mouse movements + Disable all movement keys so sit modifier wont trigger before we want it to + Enable the mouse movement so we can move the camera and use the sides of the screen to trigger a movement""" PtSendKIMessage(kDisableEntireYeeshaBook, 0) PtEnableControlKeyEvents(self.key) PtDisableMovementKeys() @@ -728,6 +733,10 @@ def _SendLocalStatusMsg(self, msg): PtSendKIMessage(kKILocalChatStatusMsg, msg) def _QuitGame(self, YesNo): + """Performs the standup animation when sitting down + Disable control key events + Enables the disabled movement keys + PtAvatarExitAFK() is actually just performing a GoToStage 2 which for the sit brain is the standup animation - https://github.com/H-uru/Plasma/blob/9956967363f383d91f43162d116ad3477148adb2/Sources/Plasma/FeatureLib/pfPython/cyAvatar.cpp#L1970""" if YesNo: PtDisableControlKeyEvents(self.key) PtEnableMovementKeys() From f388c53fdb4e5658c60ec1f996718048eadc0548 Mon Sep 17 00:00:00 2001 From: Edmond Mondor Date: Fri, 11 Aug 2023 09:51:28 -0700 Subject: [PATCH 7/8] more Requested Changes Co-authored-by: Adam Johnson --- Scripts/Python/nb01RPSGame.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Scripts/Python/nb01RPSGame.py b/Scripts/Python/nb01RPSGame.py index a47f75cdb9..657f6b5631 100644 --- a/Scripts/Python/nb01RPSGame.py +++ b/Scripts/Python/nb01RPSGame.py @@ -384,7 +384,7 @@ def OnSDLNotify(self, VARname, SDLname, playerID, tag): raise RuntimeError("Got an SDL notify for {}, but no CB".format(VARname)) def OnControlKeyEvent(self, controlKey, activeFlag): - """Captures movement keys and prompt a yes/no dialog during a game or standup animation otherwise""" + #Captures movement keys and prompt a yes/no dialog during a game or standup animation otherwise if controlKey in [PlasmaControlKeys.kKeyMoveBackward, PlasmaControlKeys.kKeyRotateLeft, PlasmaControlKeys.kKeyRotateRight, PlasmaControlKeys.kKeyExitMode] and activeFlag: if self._round_played: PtLocalizedYesNoDialog(self.key, "Heek.Messages.Quit") @@ -456,10 +456,10 @@ def _OnSitDown(self, state, seat, events): # Manage game state if standing up if state: if PtWasLocallyNotified(self.key): - """Disable Yeesha Book to prevent linking out - Enable control keys to capture button presses or mouse movements - Disable all movement keys so sit modifier wont trigger before we want it to - Enable the mouse movement so we can move the camera and use the sides of the screen to trigger a movement""" + #Disable Yeesha Book to prevent linking out + #Enable control keys to capture button presses or mouse movements + #Disable all movement keys so sit modifier wont trigger before we want it to + #Enable the mouse movement so we can move the camera and use the sides of the screen to trigger a movement PtSendKIMessage(kDisableEntireYeeshaBook, 0) PtEnableControlKeyEvents(self.key) PtDisableMovementKeys() @@ -733,10 +733,10 @@ def _SendLocalStatusMsg(self, msg): PtSendKIMessage(kKILocalChatStatusMsg, msg) def _QuitGame(self, YesNo): - """Performs the standup animation when sitting down - Disable control key events - Enables the disabled movement keys - PtAvatarExitAFK() is actually just performing a GoToStage 2 which for the sit brain is the standup animation - https://github.com/H-uru/Plasma/blob/9956967363f383d91f43162d116ad3477148adb2/Sources/Plasma/FeatureLib/pfPython/cyAvatar.cpp#L1970""" + #Performs the standup animation when sitting down + #Disable control key events + #Enables the disabled movement keys + #PtAvatarExitAFK() is just doing IExitTopmostGenericMode() if YesNo: PtDisableControlKeyEvents(self.key) PtEnableMovementKeys() From 14a281a022659275f9bca3c942e344dbc0c4a19c Mon Sep 17 00:00:00 2001 From: Hazado Date: Sat, 12 Aug 2023 17:41:41 -0700 Subject: [PATCH 8/8] Apply suggestions from code review Co-authored-by: Adam Johnson --- Scripts/Python/nb01RPSGame.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Scripts/Python/nb01RPSGame.py b/Scripts/Python/nb01RPSGame.py index 657f6b5631..94106827ea 100644 --- a/Scripts/Python/nb01RPSGame.py +++ b/Scripts/Python/nb01RPSGame.py @@ -384,7 +384,7 @@ def OnSDLNotify(self, VARname, SDLname, playerID, tag): raise RuntimeError("Got an SDL notify for {}, but no CB".format(VARname)) def OnControlKeyEvent(self, controlKey, activeFlag): - #Captures movement keys and prompt a yes/no dialog during a game or standup animation otherwise + # Captures movement keys and prompt a yes/no dialog during a game or standup animation otherwise if controlKey in [PlasmaControlKeys.kKeyMoveBackward, PlasmaControlKeys.kKeyRotateLeft, PlasmaControlKeys.kKeyRotateRight, PlasmaControlKeys.kKeyExitMode] and activeFlag: if self._round_played: PtLocalizedYesNoDialog(self.key, "Heek.Messages.Quit") @@ -456,10 +456,10 @@ def _OnSitDown(self, state, seat, events): # Manage game state if standing up if state: if PtWasLocallyNotified(self.key): - #Disable Yeesha Book to prevent linking out - #Enable control keys to capture button presses or mouse movements - #Disable all movement keys so sit modifier wont trigger before we want it to - #Enable the mouse movement so we can move the camera and use the sides of the screen to trigger a movement + # Disable Yeesha Book to prevent linking out + # Enable control keys to capture button presses or mouse movements + # Disable all movement keys so sit modifier wont trigger before we want it to + # Enable the mouse movement so we can move the camera and use the sides of the screen to trigger a movement PtSendKIMessage(kDisableEntireYeeshaBook, 0) PtEnableControlKeyEvents(self.key) PtDisableMovementKeys() @@ -733,10 +733,10 @@ def _SendLocalStatusMsg(self, msg): PtSendKIMessage(kKILocalChatStatusMsg, msg) def _QuitGame(self, YesNo): - #Performs the standup animation when sitting down - #Disable control key events - #Enables the disabled movement keys - #PtAvatarExitAFK() is just doing IExitTopmostGenericMode() + # Performs the standup animation when sitting down + # Disable control key events + # Enables the disabled movement keys + # PtAvatarExitAFK() is just doing IExitTopmostGenericMode() if YesNo: PtDisableControlKeyEvents(self.key) PtEnableMovementKeys()