Skip to content

Commit

Permalink
Merge pull request #884 from Hoikas/better-yesno
Browse files Browse the repository at this point in the history
Confirmation (Yes/No/OK/Quit/Logout) Overhaul
  • Loading branch information
Hoikas committed Jun 16, 2021
2 parents cc0923b + 0138f5a commit f8aaae4
Show file tree
Hide file tree
Showing 27 changed files with 1,274 additions and 475 deletions.
403 changes: 104 additions & 299 deletions Scripts/Python/ki/__init__.py

Large diffs are not rendered by default.

18 changes: 1 addition & 17 deletions Scripts/Python/ki/xKIConstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -503,23 +503,7 @@ class kGUI:
BKEditFieldJRNTitle = 0
BKEditFieldJRNNote = 1
BKEditFieldPICTitle = 2

# Yes/No dialog.
YesNoTextID=12
YesButtonID = 10
NoButtonID = 11
YesButtonTextID = 60
NoButtonTextID = 61
YesNoLogoutButtonID = 62
YesNoLogoutTextID = 63
YNQuit = 0
YNDelete = 1
YNOfferLink = 2
YNOutside = 3
YNKIFull = 4
YNWanaPlay = 5
YNNoReason = 6


# Question note dialog.
QNTitle = 100
QNMessage = 101
Expand Down
20 changes: 15 additions & 5 deletions Scripts/Python/plasma/Plasma.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@
Mead, WA 99021
*==LICENSE==* """

from __future__ import annotations
from typing import Callable, Tuple, Union

def PtAcceptInviteInGame(friendName,inviteKey):
"""Sends a VaultTask to the server to perform the invite"""
pass
Expand Down Expand Up @@ -631,6 +635,12 @@ def PtLocalAvatarRunKeyDown():
"""Returns true if the run key is being held down for the local avatar"""
pass

def PtLocalizedYesNoDialog(cb: Union[None, Callable, ptKey], path: str, *args, /, *, dialogType: int = PtConfirmationType.YesNo) -> None:
"""This will display a confirmation dialog to the user with the localized text `path`
with any optional localization `args` applied. This dialog _has_ to be answered by the user,
and their answer will be returned in a Notify message or callback given by `cb`."""
...

def PtMaxListenDistSq():
"""Returns the maximum distance (squared) of the listen range"""
pass
Expand Down Expand Up @@ -872,11 +882,11 @@ def PtWhatGUIControlType(guiKey):
"""Returns the control type of the key passed in"""
pass

def PtYesNoDialog(selfkey,dialogMessage):
"""This will display a Yes/No dialog to the user with the text dialogMessage
This dialog _has_ to be answered by the user.
And their answer will be returned in a Notify message."""
pass
def PtYesNoDialog(cb: Union[None, ptKey, Callable], message: str, /, dialogType: int = PtConfirmationType.YesNo) -> None:
"""This will display a confirmation dialog to the user with the text `message`. This dialog
_has_ to be answered by the user, and their answer will be returned in a Notify message
or callback given by `cb`."""
...

class ptAgeInfoStruct:
"""Class to hold AgeInfo struct data"""
Expand Down
14 changes: 14 additions & 0 deletions Scripts/Python/plasma/PlasmaConstants.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ class PtButtonNotifyTypes:
kNotifyOnDown = 1
kNotifyOnUpAndDown = 2

class PtConfirmationResult:
OK = 1
Cancel = 0
Yes = 1
No = 0
Quit = 1
Logout = 62

class PtConfirmationType:
OK = 0
ConfirmQuit = 1
ForceQuit = 2
YesNo = 3

class PtCCRPetitionType:
"""(none)"""
kGeneralHelp = 0
Expand Down
12 changes: 3 additions & 9 deletions Scripts/Python/xDialogStartUp.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,12 +216,6 @@ def BeginAgeUnLoad(self,avatar):
if GUIDiag6a.dialog.isEnabled():
PtHideDialog("GUIDialog06a")

###########################
def OnNotify(self,state,id,events):
if id==(-1): ## callback from delete yes/no dialog (hopefully) ##
if state:
PtConsole("App.Quit")

###########################
def OnGUINotify(self,id,control,event):
global gSelectedSlot
Expand All @@ -245,7 +239,7 @@ def OnGUINotify(self,id,control,event):
PtShowDialog("GUIDialog05")

elif tagID == k4aQuitID: ## Quit ##
PtYesNoDialog(self.key,"Are you sure you want to quit?")
PtLocalizedYesNoDialog(None, "KI.Messages.LeaveGame", dialogType=PtConfirmationType.ConfirmQuit)

elif tagID == k4aPlayer01: ## Click Event ##
if gPlayerList[0]:
Expand Down Expand Up @@ -280,7 +274,7 @@ def OnGUINotify(self,id,control,event):
## Or Else?? ##

elif tagID == k4bQuitID: ## Quit ##
PtYesNoDialog(self.key,"Are you sure you want to quit?")
PtLocalizedYesNoDialog(None, "KI.Messages.LeaveGame", dialogType=PtConfirmationType.ConfirmQuit)

elif tagID == k4bDeleteID: ## Delete Explorer ##
if gSelectedSlot:
Expand Down Expand Up @@ -322,7 +316,7 @@ def OnGUINotify(self,id,control,event):
elif id == GUIDiag6.id:
if event == kAction or event == kValueChanged:
if tagID == k6QuitID: ## Quit ##
PtYesNoDialog(self.key,"Are you sure you want to quit?")
PtLocalizedYesNoDialog(None, "KI.Messages.LeaveGame", dialogType=PtConfirmationType.ConfirmQuit)

elif tagID == k6BackID: ## Back To Player Select ##
PtHideDialog("GUIDialog06")
Expand Down
7 changes: 7 additions & 0 deletions Sources/Plasma/Apps/plClient/plClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com
#include "pfAnimation/plAnimDebugList.h"
#include "pfAudio/plListener.h"
#include "pfCamera/plVirtualCamNeu.h"
#include "pfCharacter/pfConfirmationMgr.h"
#include "pfCharacter/pfMarkerMgr.h"
#include "pfConsole/pfConsole.h"
#include "pfConsole/pfConsoleDirSrc.h"
Expand Down Expand Up @@ -246,6 +247,9 @@ bool plClient::Shutdown()
// Let the resmanager know we're going to be shutting down.
hsgResMgr::ResMgr()->BeginShutdown();

// This guy may send callbacks that release resources
pfConfirmationMgr::Shutdown();

// Must kill off all movies before shutting down audio.
IKillMovies();

Expand Down Expand Up @@ -1386,6 +1390,9 @@ bool plClient::StartInit()
fGameGUIMgr->RegisterAs( kGameGUIMgr_KEY );
fGameGUIMgr->Init();

// Yes/No dialog handler
pfConfirmationMgr::Init();

plgAudioSys::Activate(true);

//
Expand Down
7 changes: 6 additions & 1 deletion Sources/Plasma/FeatureLib/pfCharacter/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
set(pfCharacter_SOURCES
pfConfirmationMgr.cpp
pfMarkerInfo.cpp
pfMarkerMgr.cpp
)

set(pfCharacter_HEADERS
pfCharacterCreatable.h
pfConfirmationMgr.h
pfMarkerInfo.h
pfMarkerMgr.h
)
Expand All @@ -15,15 +17,18 @@ target_link_libraries(
PUBLIC
CoreLib
pnKeyedObject
plMessage
PRIVATE
pnMessage
pnNetCommon
pnNucleusInc
pnSceneObject
plMessage
plModifier
plNetClient
plResMgr
plStatusLog
pfGameGUIMgr
pfLocalizationMgr
pfMessage
INTERFACE
pnFactory
Expand Down
3 changes: 3 additions & 0 deletions Sources/Plasma/FeatureLib/pfCharacter/pfCharacterCreatable.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ You can contact Cyan Worlds, Inc. by email legal@cyan.com

#include "pnFactory/plCreator.h"

#include "pfConfirmationMgr.h"
REGISTER_NONCREATABLE(pfConfirmationMgr);

#include "pfMarkerMgr.h"
REGISTER_NONCREATABLE(pfMarkerMgr);

Expand Down
Loading

0 comments on commit f8aaae4

Please sign in to comment.