MessageBox.gd 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. extends PanelContainer
  2. #
  3. @onready var label : Label = $Margin/VBoxContainer/Label
  4. @onready var buttonBox : Control = $Margin/VBoxContainer/ButtonBoxes
  5. var wasActionEnabled : bool = true
  6. #
  7. func Display(text : String, primary = null, primaryText : String = "", cancel = null, cancelText : String = "", secondary = null, secondaryText : String = "", tertiary = null, tertiaryText : String = ""):
  8. wasActionEnabled = Launcher.Action.IsEnabled()
  9. if wasActionEnabled:
  10. Launcher.Action.Enable(false)
  11. label.set_text(text)
  12. if primary and primary is Callable: buttonBox.Bind(UICommons.ButtonBox.PRIMARY, primaryText, Call.bind(primary))
  13. if cancel and cancel is Callable: buttonBox.Bind(UICommons.ButtonBox.CANCEL, cancelText, Call.bind(cancel))
  14. if secondary and secondary is Callable: buttonBox.Bind(UICommons.ButtonBox.SECONDARY, secondaryText, Call.bind(secondary))
  15. if tertiary and tertiary is Callable: buttonBox.Bind(UICommons.ButtonBox.TERTIARY, tertiaryText, Call.bind(tertiary))
  16. set_visible(true)
  17. func Clear():
  18. if wasActionEnabled:
  19. Launcher.Action.Enable(true)
  20. set_visible(false)
  21. buttonBox.ClearAll()
  22. label.set_text("")
  23. func Call(callback : Callable):
  24. Clear()
  25. callback.call()
  26. #
  27. func _unhandled_input(event : InputEvent):
  28. if not visible or Launcher.Action.IsEnabled():
  29. return
  30. buttonBox.HandleInput(event)