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

繼承: Window < Viewport < Node < Object

被繼承: ConfirmationDialog

基礎對話框,用於使用者通知。

說明

The default use of AcceptDialog is to allow it to only be accepted or closed, with the same result. However, the confirmed and canceled signals allow to make the two actions different, and the add_button() method allows to add custom buttons and actions.

Note: AcceptDialog is invisible by default. To make it visible, call one of the popup_* methods from Window on the node, such as Window.popup_centered_clamped().

屬性

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)

bool

maximize_disabled

true (overrides Window)

bool

minimize_disabled

true (overrides Window)

String

ok_button_text

""

String

title

"Alert!" (overrides Window)

bool

transient

true (overrides Window)

bool

visible

false (overrides Window)

bool

wrap_controls

true (overrides Window)

方法

Button

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

Button

add_cancel_button(name: String)

Label

get_label()

Button

get_ok_button()

void

register_text_enter(line_edit: LineEdit)

void

remove_button(button: Button)

主題屬性

int

buttons_min_height

0

int

buttons_min_width

0

int

buttons_separation

10

StyleBox

panel


訊號

canceled() 🔗

當對話框關閉或按下用 add_cancel_button() 建立的按鈕時觸發。


confirmed() 🔗

當對話框被接受(即按下 OK 按鈕)時觸發。


custom_action(action: StringName) 🔗

Emitted when a custom button with an action is pressed. See add_button().


屬性說明

bool dialog_autowrap = false 🔗

  • void set_autowrap(value: bool)

  • bool has_autowrap()

設定對話框中文本自動換行。


bool dialog_close_on_escape = true 🔗

  • void set_close_on_escape(value: bool)

  • bool get_close_on_escape()

If true, the dialog will be hidden when the ui_close_dialog action is pressed (by default, this action is bound to Escape, or Cmd + W on macOS).


bool dialog_hide_on_ok = true 🔗

  • void set_hide_on_ok(value: bool)

  • bool get_hide_on_ok()

若為 true,按下 OK 按鈕時對話框會隱藏。若你希望在收到 confirmed 訊號時執行輸入驗證等邏輯,可將此屬性設為 false,並由你自己的程式邏輯來隱藏對話框。

注意:某些繼承自此類別的節點可能預設為不同值,且有自己的內建邏輯會覆蓋此設定。例如 FileDialog 預設為 false,並在按下 OK 時會執行輸入驗證,若輸入有效則最終自動隱藏對話框。因此,此屬性無法用於 FileDialog 來禁止按 OK 時隱藏對話框。


String dialog_text = "" 🔗

對話框顯示的文字。


String ok_button_text = "" 🔗

  • void set_ok_button_text(value: String)

  • String get_ok_button_text()

OK 按鈕顯示的文字(參見 get_ok_button())。如果為空,將使用預設文字。


方法說明

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

Adds a button with label text and a custom action to the dialog and returns the created button.

If action is not empty, pressing the button will emit the custom_action signal with the specified action string.

If true, right will place the button to the right of any sibling buttons.

You can use remove_button() method to remove a button created with this method from the dialog.


Button add_cancel_button(name: String) 🔗

新增帶有標籤 name 及取消動作的按鈕到對話框,並回傳建立的按鈕。

可使用 remove_button() 方法,將用此方法建立的按鈕從對話框中移除。


Label get_label() 🔗

回傳內建文字所用的標籤。

警告:這是必要的內部節點,移除或釋放它可能導致當機。若想隱藏它或其子節點,請使用它們的 CanvasItem.visible 屬性。


Button get_ok_button() 🔗

回傳 OK Button 按鈕實體。

警告:這是必要的內部節點,移除或釋放它可能導致當機。若想隱藏它或其子節點,請使用它們的 CanvasItem.visible 屬性。


void register_text_enter(line_edit: LineEdit) 🔗

在對話框中註冊 LineEdit。當按下 Enter 鍵時,對話框將被接受。


void remove_button(button: Button) 🔗

從對話框中移除 button,但不會釋放該 buttonbutton 必須是使用 add_button()add_cancel_button() 方法新增的 Button。移除後,點擊該 button 將不再觸發本對話框的 custom_actioncanceled 訊號。


主題屬性說明

int buttons_min_height = 0 🔗

底部按鈕列(如 OK/取消)的每個按鈕最小高度(像素)。可增加此值,使短文字的按鈕更易於點擊或觸控。


int buttons_min_width = 0 🔗

底部按鈕列(如 OK/取消)的每個按鈕最小寬度(像素)。可增加此值,使短文字的按鈕更易於點擊或觸控。


int buttons_separation = 10 🔗

對話框內容與按鈕列之間的垂直間距大小。


StyleBox panel 🔗

填滿視窗背景的面板。