From 091552c4a485fc4a5a117c1d87283c014190a14e Mon Sep 17 00:00:00 2001 From: Mika Stamm Date: Tue, 25 Feb 2025 21:01:49 +0100 Subject: [PATCH] Add additional hotkey functionality The add to conversation hotkey can now also - Remove from conversation (press and hold) - Start a radiant conversation (Press on one NPC and release on another while not in a conversation) Update description Delete MantellaSoftware.code-workspace Fix --- Scripts/Source/MantellaMCM.psc | 2 +- Scripts/Source/MantellaRepository.psc | 49 +++++++++++++++++++++++---- 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/Scripts/Source/MantellaMCM.psc b/Scripts/Source/MantellaMCM.psc index 6afca7f..bceccb5 100644 --- a/Scripts/Source/MantellaMCM.psc +++ b/Scripts/Source/MantellaMCM.psc @@ -228,7 +228,7 @@ Event OnOptionHighlight (Int optionID) SetInfoText("Periodically reminds the player it is their turn to speak / input text.") elseIf optionID == oid_keymapStartAddHotkey - SetInfoText("Either starts a conversation or adds an NPC to a conversation.") + SetInfoText("Either starts a conversation or adds an NPC to a conversation. Press & hold on an NPC to remove them. Press while targeting one npc and release while targeting another to start a radiant conversation. ") elseIf optionID == oid_keymapPromptHotkey SetInfoText("Opens the text prompt or starts the mic recording depending on the context and the microphone options above. \nDefault: H") elseIf optionID == oid_keymapEndHotkey diff --git a/Scripts/Source/MantellaRepository.psc b/Scripts/Source/MantellaRepository.psc index 8c2d43b..bc54844 100644 --- a/Scripts/Source/MantellaRepository.psc +++ b/Scripts/Source/MantellaRepository.psc @@ -105,7 +105,10 @@ bool property NPCdebugSelectModeEnabled auto int property HttpPort auto +MantellaConversation conversation + event OnInit() + conversation = Quest.GetQuest("MantellaConversation") as MantellaConversation assignDefaultSettings(0, true) endEvent @@ -267,6 +270,7 @@ bool function restartMantellaExe() ; Check the corresponding commented out OnUpdate at the beginning of the script. EndFunction +Actor startConversationKeyDownTargetedActor Event OnKeyDown(int KeyCode) ;this function was previously in MantellaListener Script back in Mantella 0.9.2 ;this ensures the right key is pressed and only activated while not in menu mode @@ -274,17 +278,14 @@ Event OnKeyDown(int KeyCode) if KeyCode == MantellaStartHotkey Actor targetRef = (Game.GetCurrentCrosshairRef() as actor) if (targetRef) ;If we have a target under the crosshair, cast sepll on it - MantellaSpell.cast(PlayerRef, targetRef) - ;Utility.Wait(0.5) - endIf + startConversationKeyDownTargetedActor = targetRef + endIf elseIf KeyCode == MantellaListenerTextHotkey If(!microphoneEnabled) ;Otherwise, try to open player text input if microphone is off - MantellaConversation conversation = Quest.GetQuest("MantellaConversation") as MantellaConversation if(conversation.IsRunning()) conversation.GetPlayerTextInput() endIf elseIf (useHotkeyToStartMic) - MantellaConversation conversation = Quest.GetQuest("MantellaConversation") as MantellaConversation if(conversation.IsRunning()) conversation.sendRequestForVoiceTranscribe() endIf @@ -297,7 +298,6 @@ Event OnKeyDown(int KeyCode) MantellaEndSpell.cast(PlayerRef) endIf elseIf KeyCode == MantellaCustomGameEventHotkey - MantellaConversation conversation = Quest.GetQuest("MantellaConversation") as MantellaConversation if(conversation.IsRunning()) UIExtensions.InitMenu("UITextEntryMenu") UIExtensions.OpenMenu("UITextEntryMenu") @@ -316,4 +316,41 @@ Event OnKeyDown(int KeyCode) endIf endIf endIf +endEvent + + + +Event OnKeyUp(int KeyCode, Float HoldTime) + Float longPressTime = 0.6 + ;this function was previously in MantellaListener Script back in Mantella 0.9.2 + if !utility.IsInMenuMode() + if KeyCode == MantellaStartHotkey + Actor targetRef = (Game.GetCurrentCrosshairRef() as actor) + + ; Add the actor to the conversation that was targeted when the key was pressed + if targetRef == none || targetRef == startConversationKeyDownTargetedActor && startConversationKeyDownTargetedActor != none + if (HoldTime < longPressTime) + MantellaSpell.cast(PlayerRef, startConversationKeyDownTargetedActor) + Else + MantellaRemoveNpcSpell.cast(PlayerRef, startConversationKeyDownTargetedActor) + endif + endif + + ; Add the actor to the conversation that was targeted when the key was let go + if targetRef != none && startConversationKeyDownTargetedActor == none + if (HoldTime < longPressTime) + MantellaSpell.cast(PlayerRef, targetRef) + Else + MantellaRemoveNpcSpell.cast(PlayerRef, targetRef) + endif + endif + + ; Start a radiant conversation, if the target of the keyDown is different from keyUp + if targetRef != none && startConversationKeyDownTargetedActor != none && startConversationKeyDownTargetedActor != targetRef && !conversation.IsRunning() + MantellaSpell.cast(startConversationKeyDownTargetedActor, targetRef) + endif + + startConversationKeyDownTargetedActor = none + endIf + endIf endEvent \ No newline at end of file