Skip to content

Commit

Permalink
Allow alternative actions in menu popups
Browse files Browse the repository at this point in the history
  • Loading branch information
psiberx committed Jul 18, 2023
1 parent d47584d commit 0a3bdd6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
9 changes: 8 additions & 1 deletion scripts/UI/Popups/CustomPopup.reds
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public abstract class CustomPopup extends inkCustomController {
protected let m_notificationData: ref<inkGameNotificationData>;
protected let m_notificationToken: ref<inkGameNotificationToken>;
protected let m_transitionAnimProxy: ref<inkAnimProxy>;
protected let m_closeAction: CName;

protected func SetNotificationData(notificationData: ref<inkGameNotificationData>) {
this.m_notificationData = notificationData;
Expand All @@ -43,6 +44,12 @@ public abstract class CustomPopup extends inkCustomController {
return !IsDefined(popupData) || popupData.manager.IsOnTop(this);
}

protected cb func OnInitialize() {
super.OnInitialize();

this.m_closeAction = n"cancel";
}

protected cb func OnAttach() {
this.RegisterToGlobalInputCallback(n"OnPostOnRelease", this, n"OnGlobalReleaseInput");

Expand Down Expand Up @@ -113,7 +120,7 @@ public abstract class CustomPopup extends inkCustomController {
}

protected cb func OnGlobalReleaseInput(evt: ref<inkPointerEvent>) -> Bool {
if evt.IsAction(n"cancel") && !evt.IsHandled() && this.IsTopPopup() {
if evt.IsAction(this.m_closeAction) && !evt.IsHandled() && this.IsTopPopup() {
this.Close();
evt.Handle();
return true;
Expand Down
19 changes: 16 additions & 3 deletions scripts/UI/Popups/InMenuPopup.reds
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public abstract class InMenuPopup extends CustomPopup {
protected let m_container: wref<inkCompoundWidget>;

protected let m_result: GenericMessageNotificationResult;
protected let m_confirmAction: CName;

protected cb func OnCreate() {
super.OnCreate();
Expand Down Expand Up @@ -77,16 +78,28 @@ public abstract class InMenuPopup extends CustomPopup {
protected cb func OnInitialize() {
super.OnInitialize();

this.m_confirmAction = n"proceed";

let buttons: array<ref<inkLogicController>>;
inkWidgetHelper.GetControllersByType(this.m_container, n"Codeware.UI.PopupButton", buttons);

for button in buttons {
switch (button as PopupButton).GetInputAction() {
let action = (button as PopupButton).GetInputAction();
switch action {
case n"proceed":
case n"proceed_popup":
case n"one_click_confirm":
case n"system_notification_confirm":
case n"UI_Apply":
button.RegisterToCallback(n"OnBtnClick", this, n"OnConfirmClick");
this.m_confirmAction = action;
break;
case n"cancel":
case n"cancel_popup":
case n"back":
case n"UI_Cancel":
button.RegisterToCallback(n"OnBtnClick", this, n"OnCancelClick");
this.m_closeAction = action;
break;
}
}
Expand All @@ -101,13 +114,13 @@ public abstract class InMenuPopup extends CustomPopup {
}

protected cb func OnGlobalReleaseInput(evt: ref<inkPointerEvent>) -> Bool {
if evt.IsAction(n"cancel") && !evt.IsHandled() && this.IsTopPopup() {
if evt.IsAction(this.m_closeAction) && !evt.IsHandled() && this.IsTopPopup() {
this.Cancel();
evt.Handle();
return true;
}

if evt.IsAction(n"proceed") && !evt.IsHandled() && this.IsTopPopup() {
if evt.IsAction(this.m_confirmAction) && !evt.IsHandled() && this.IsTopPopup() {
this.Confirm();
evt.Handle();
return true;
Expand Down

0 comments on commit 0a3bdd6

Please sign in to comment.