Up to date

This page is up to date for Godot 4.2. If you still find outdated information, please open an issue.

AcceptDialog

继承: Window < Viewport < Node < Object

派生: ConfirmationDialog

用于用户通知的基本对话框。

描述

AcceptDialog 的默认用途是允许它只被接受或关闭,结果相同。但是,confirmedcanceled 信号允许使两个动作不同,add_button 方法允许添加自定义按钮和动作。

属性

bool

dialog_autowrap

false

bool

dialog_close_on_escape

true

bool

dialog_hide_on_ok

true

String

dialog_text

""

bool

exclusive

true (overrides Window)

bool

keep_title_visible

true (overrides Window)

String

ok_button_text

"OK"

String

title

"Alert!" (overrides Window)

bool

transient

true (overrides Window)

bool

visible

false (overrides Window)

bool

wrap_controls

true (overrides Window)

方法

Button

add_button ( String text, bool right=false, String action="" )

Button

add_cancel_button ( String name )

Label

get_label ( )

Button

get_ok_button ( )

void

register_text_enter ( Control line_edit )

void

remove_button ( Control button )

主题属性

int

buttons_separation

10

StyleBox

panel


信号

canceled ( )

当对话框关闭或按下 add_cancel_button 创建的按钮时发出。


confirmed ( )

接受对话框时,即按下确定按钮时发出。


custom_action ( StringName action )

按下自定义按钮时发出。见 add_button


属性说明

bool dialog_autowrap = false

  • void set_autowrap ( bool value )

  • bool has_autowrap ( )

为对话框中的文本设置自动换行。


bool dialog_close_on_escape = true

  • void set_close_on_escape ( bool value )

  • bool get_close_on_escape ( )

如果为 true,当按下退出键(@GlobalScope.KEY_ESCAPE)时,对话框将被隐藏。


bool dialog_hide_on_ok = true

  • void set_hide_on_ok ( bool value )

  • bool get_hide_on_ok ( )

如果为 true,按下确定按钮时对话框将隐藏。如果要在收到 confirmed 信号时执行类似输入验证的操作,则可以将其设置为 false,然后在自己的逻辑中处理对话框的隐藏。

注意:从此类派生的某些节点可以具有不同的默认值,并且可能有自己的内置逻辑会覆盖此设置。例如 FileDialog 默认其为 false,并在按下确定时实现了自己的输入验证代码,如果输入有效,最终将隐藏对话框。因此,不能在 FileDialog 中使用此属性来禁止在按确定时隐藏对话框。


String dialog_text = ""

对话框显示的文本。


String ok_button_text = "OK"

  • void set_ok_button_text ( String value )

  • String get_ok_button_text ( )

确定按钮(参见 get_ok_button)显示的文本。


方法说明

Button add_button ( String text, bool right=false, String action="" )

将带有标签 text 和自定义 action 的按钮添加到对话框,并返回该创建的按钮。action 将在按钮被按下时传递给 custom_action 信号。

如果 righttrue,按钮会被放置在所有同级按钮的右侧。

可以使用 remove_button 方法从对话框中移除使用该方法创建的按钮。


Button add_cancel_button ( String name )

在对话框中添加一个带有标签 name 和取消动作的按钮,并返回创建的按钮。

你可以使用 remove_button 方法从对话框中删除用此方法创建的按钮。


Label get_label ( )

返回内置文本所使用的标签。

警告:这是个必要的内部节点,移除并释放它有可能造成崩溃。如果你希望隐藏它或它的任意一个子节点,请使用它们的 CanvasItem.visible 属性。


Button get_ok_button ( )

返回确定按钮 Button 实例。

警告:这是个必要的内部节点,移除并释放它有可能造成崩溃。如果你希望隐藏它或它的任意一个子节点,请使用它们的 CanvasItem.visible 属性。


void register_text_enter ( Control line_edit )

在对话框中注册 LineEdit。当按下回车键时,对话框将被接受。


void remove_button ( Control button )

从对话框中移除 button。但不释放该 button 对象。button 必须是用 add_buttonadd_cancel_button 方法添加的 Button。移除后,按下该 button 将不再发出该对话框的 custom_actioncanceled 信号。


主题属性说明

int buttons_separation = 10

对话框内容和按钮行之间的垂直空间的大小。


StyleBox panel

填充窗口背景的面板。