Skip to content

Commit

Permalink
Confirmation alert: return 'No' as default value when clicking anothe…
Browse files Browse the repository at this point in the history
…r action. (#1257)

* Confirmation alert: return 'No' as default value when clicking another action.

* Disallow clicking other actions with open alert/prompt pop-up.
  • Loading branch information
TheMaximum committed Aug 24, 2023
1 parent 2c7c432 commit bbf65cb
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 5 additions & 1 deletion pyplanet/views/generics/alert.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ async def ask_confirmation(player, message, size='md', buttons=None): # pragma:
:param buttons: Buttons, optional, default is yes and no.
:return: Number of button that is clicked.
"""
default_buttons_displayed = buttons is None
buttons = buttons or [{'name': 'Yes'}, {'name': 'No'}]
view = AlertView(message, size, buttons)
if isinstance(player, Player):
Expand All @@ -278,7 +279,10 @@ async def ask_confirmation(player, message, size='md', buttons=None): # pragma:
try:
reaction = int(reaction)
except:
reaction = None
# If another action is clicked without completing the alert view, the action name (= string) is returned as reaction.
# To ensure no action is taken without confirmation, 1 (= No) should be returned if the casting causes an exception.
# If custom buttons are used, None will be returned.
reaction = 1 if default_buttons_displayed else None
del view
return reaction

Expand Down
2 changes: 1 addition & 1 deletion pyplanet/views/templates/generics/alert.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<frame pos="0 0" z-index="900">
<quad pos="0 0" size="320 180" halign="center" valign="center" style="Bgs1" substyle="BgDialogBlur" z-index="500" />
<quad pos="0 0" size="320 180" halign="center" valign="center" style="Bgs1" substyle="BgDialogBlur" z-index="500" scriptevents="1" />
<quad pos="{{ sizes.top__pos }}" size="{{ sizes.top__size }}" halign="center" style="Bgs1InRace" substyle="BgGlow2" z-index="520" />
<quad size="{{ sizes.box__size }}" halign="center" valign="center" style="Bgs1InRace" substyle="BgWindow2" z-index="510" />
<quad pos="{{ sizes.bottom__pos }}" size="{{ sizes.bottom__size }}" halign="center" style="Bgs1InRace" substyle="BgMetalBar" z-index="520" />
Expand Down
2 changes: 1 addition & 1 deletion pyplanet/views/templates/generics/prompt.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<frame pos="0 0" z-index="900">
<quad pos="0 0" size="320 180" halign="center" valign="center" style="Bgs1" substyle="BgDialogBlur" z-index="500" />
<quad pos="0 0" size="320 180" halign="center" valign="center" style="Bgs1" substyle="BgDialogBlur" z-index="500" scriptevents="1" />
<quad pos="{{ sizes.top__pos }}" size="{{ sizes.top__size }}" halign="center" style="Bgs1InRace" substyle="BgGlow2" z-index="520" />
<quad size="{{ sizes.box__size }}" halign="center" valign="center" style="Bgs1InRace" substyle="BgWindow2" z-index="510" />
<quad pos="{{ sizes.bottom__pos }}" size="{{ sizes.bottom__size }}" halign="center" style="Bgs1InRace" substyle="BgMetalBar" z-index="520" />
Expand Down

0 comments on commit bbf65cb

Please sign in to comment.