Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

AcceptDialog

Inherits: Window < Viewport < Node < Object

Inherited By: ConfirmationDialog

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

Description

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

Properties

bool

dialog_autowrap

false

bool

dialog_close_on_escape

true

bool

dialog_hide_on_ok

true

String

dialog_text

""

bool

exclusive

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)

Methods

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 )

Theme Properties

int

buttons_separation

10

StyleBox

panel


Signals

canceled ( )

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


confirmed ( )

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


custom_action ( StringName action )

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


Property Descriptions

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)显示的文本。


Method Descriptions

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 属性。</