2023-01-05 12:25:55 +00:00
/**************************************************************************/
/* dialogs.cpp */
/**************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
/* https://godotengine.org */
/**************************************************************************/
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining */
/* a copy of this software and associated documentation files (the */
/* "Software"), to deal in the Software without restriction, including */
/* without limitation the rights to use, copy, modify, merge, publish, */
/* distribute, sublicense, and/or sell copies of the Software, and to */
/* permit persons to whom the Software is furnished to do so, subject to */
/* the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/**************************************************************************/
2018-01-04 23:50:27 +00:00
2014-02-10 01:10:30 +00:00
# include "dialogs.h"
2024-03-12 12:26:37 +00:00
# include "dialogs.compat.inc"
2020-03-06 17:00:16 +00:00
# include "core/os/keyboard.h"
2020-11-07 22:33:38 +00:00
# include "core/string/print_string.h"
# include "core/string/translation.h"
2022-02-14 13:00:03 +00:00
# include "scene/gui/line_edit.h"
2023-09-08 19:00:10 +00:00
# include "scene/theme/theme_db.h"
2017-03-06 19:11:56 +00:00
2020-03-06 17:00:16 +00:00
// AcceptDialog
2017-05-02 20:13:12 +00:00
2020-03-06 17:00:16 +00:00
void AcceptDialog : : _input_from_window ( const Ref < InputEvent > & p_event ) {
2023-08-03 11:22:03 +00:00
if ( close_on_escape & & p_event - > is_action_pressed ( SNAME ( " ui_cancel " ) , false , true ) ) {
2020-03-06 17:00:16 +00:00
_cancel_pressed ( ) ;
2017-03-02 21:43:56 +00:00
}
2023-09-01 06:40:35 +00:00
Window : : _input_from_window ( p_event ) ;
2017-03-02 21:43:56 +00:00
}
2023-07-05 23:04:16 +00:00
void AcceptDialog : : _parent_focused ( ) {
2023-07-14 17:09:13 +00:00
if ( ! is_exclusive ( ) & & get_flag ( FLAG_POPUP ) ) {
2023-07-05 23:04:16 +00:00
_cancel_pressed ( ) ;
}
}
2020-03-06 17:00:16 +00:00
void AcceptDialog : : _notification ( int p_what ) {
switch ( p_what ) {
2022-09-05 18:30:44 +00:00
case NOTIFICATION_POST_ENTER_TREE : {
2020-03-06 17:00:16 +00:00
if ( is_visible ( ) ) {
2020-12-14 18:37:30 +00:00
get_ok_button ( ) - > grab_focus ( ) ;
2022-09-05 18:30:44 +00:00
}
} break ;
case NOTIFICATION_VISIBILITY_CHANGED : {
if ( is_visible ( ) ) {
if ( get_ok_button ( ) - > is_inside_tree ( ) ) {
get_ok_button ( ) - > grab_focus ( ) ;
}
2020-03-06 17:00:16 +00:00
_update_child_rects ( ) ;
2023-07-05 23:04:16 +00:00
parent_visible = get_parent_visible_window ( ) ;
if ( parent_visible ) {
parent_visible - > connect ( " focus_entered " , callable_mp ( this , & AcceptDialog : : _parent_focused ) ) ;
}
} else {
if ( parent_visible ) {
parent_visible - > disconnect ( " focus_entered " , callable_mp ( this , & AcceptDialog : : _parent_focused ) ) ;
parent_visible = nullptr ;
}
2017-01-24 17:21:54 +00:00
}
2014-02-10 01:10:30 +00:00
} break ;
2022-02-15 17:06:48 +00:00
2020-03-06 17:00:16 +00:00
case NOTIFICATION_THEME_CHANGED : {
2022-09-06 21:55:57 +00:00
bg_panel - > add_theme_style_override ( " panel " , theme_cache . panel_style ) ;
2022-09-01 10:38:08 +00:00
2022-09-06 21:55:57 +00:00
child_controls_changed ( ) ;
if ( is_visible ( ) ) {
_update_child_rects ( ) ;
}
2017-03-06 19:11:56 +00:00
} break ;
2022-02-15 17:06:48 +00:00
2023-07-05 23:04:16 +00:00
case NOTIFICATION_EXIT_TREE : {
if ( parent_visible ) {
parent_visible - > disconnect ( " focus_entered " , callable_mp ( this , & AcceptDialog : : _parent_focused ) ) ;
parent_visible = nullptr ;
2020-03-12 12:37:40 +00:00
}
} break ;
2022-02-15 17:06:48 +00:00
2020-03-06 17:00:16 +00:00
case NOTIFICATION_READY :
case NOTIFICATION_WM_SIZE_CHANGED : {
if ( is_visible ( ) ) {
_update_child_rects ( ) ;
2020-02-27 23:02:06 +00:00
}
2017-03-06 19:11:56 +00:00
} break ;
2022-02-15 17:06:48 +00:00
2020-03-06 17:00:16 +00:00
case NOTIFICATION_WM_CLOSE_REQUEST : {
_cancel_pressed ( ) ;
2019-08-04 16:42:46 +00:00
} break ;
2016-03-08 23:00:52 +00:00
}
2014-02-10 01:10:30 +00:00
}
2021-06-16 16:43:34 +00:00
void AcceptDialog : : _text_submitted ( const String & p_text ) {
2022-03-23 20:08:54 +00:00
if ( get_ok_button ( ) & & get_ok_button ( ) - > is_disabled ( ) ) {
return ; // Do not allow submission if OK button is disabled.
}
2014-02-10 01:10:30 +00:00
_ok_pressed ( ) ;
}
void AcceptDialog : : _ok_pressed ( ) {
2020-05-14 14:41:43 +00:00
if ( hide_on_ok ) {
2020-03-06 17:00:16 +00:00
set_visible ( false ) ;
2020-05-14 14:41:43 +00:00
}
2014-02-10 01:10:30 +00:00
ok_pressed ( ) ;
2021-07-17 21:22:52 +00:00
emit_signal ( SNAME ( " confirmed " ) ) ;
2023-06-02 09:06:41 +00:00
set_input_as_handled ( ) ;
2014-02-10 01:10:30 +00:00
}
2020-02-27 21:49:16 +00:00
2020-03-06 17:00:16 +00:00
void AcceptDialog : : _cancel_pressed ( ) {
2023-07-05 23:04:16 +00:00
Window * parent_window = parent_visible ;
if ( parent_visible ) {
parent_visible - > disconnect ( " focus_entered " , callable_mp ( this , & AcceptDialog : : _parent_focused ) ) ;
parent_visible = nullptr ;
}
2023-12-18 14:46:56 +00:00
callable_mp ( ( Window * ) this , & Window : : hide ) . call_deferred ( ) ;
2023-07-05 23:04:16 +00:00
2023-01-21 11:25:29 +00:00
emit_signal ( SNAME ( " canceled " ) ) ;
2023-07-05 23:04:16 +00:00
2014-02-10 01:10:30 +00:00
cancel_pressed ( ) ;
2023-07-05 23:04:16 +00:00
if ( parent_window ) {
//parent_window->grab_focus();
}
2023-06-02 09:06:41 +00:00
set_input_as_handled ( ) ;
2020-02-27 21:49:16 +00:00
}
2014-02-10 01:10:30 +00:00
String AcceptDialog : : get_text ( ) const {
2022-09-06 21:55:57 +00:00
return message_label - > get_text ( ) ;
2014-02-10 01:10:30 +00:00
}
2020-05-14 12:29:06 +00:00
2014-02-10 01:10:30 +00:00
void AcceptDialog : : set_text ( String p_text ) {
2022-09-06 21:55:57 +00:00
if ( message_label - > get_text ( ) = = p_text ) {
2022-03-16 07:50:48 +00:00
return ;
}
2022-09-06 21:55:57 +00:00
message_label - > set_text ( p_text ) ;
2020-03-06 17:00:16 +00:00
child_controls_changed ( ) ;
if ( is_visible ( ) ) {
_update_child_rects ( ) ;
}
2014-02-10 01:10:30 +00:00
}
void AcceptDialog : : set_hide_on_ok ( bool p_hide ) {
2017-03-05 15:44:50 +00:00
hide_on_ok = p_hide ;
2014-02-10 01:10:30 +00:00
}
2020-05-14 12:29:06 +00:00
2014-02-10 01:10:30 +00:00
bool AcceptDialog : : get_hide_on_ok ( ) const {
return hide_on_ok ;
}
2022-03-31 20:00:17 +00:00
void AcceptDialog : : set_close_on_escape ( bool p_hide ) {
close_on_escape = p_hide ;
}
bool AcceptDialog : : get_close_on_escape ( ) const {
return close_on_escape ;
}
2019-03-24 23:21:32 +00:00
void AcceptDialog : : set_autowrap ( bool p_autowrap ) {
2022-09-06 21:55:57 +00:00
message_label - > set_autowrap_mode ( p_autowrap ? TextServer : : AUTOWRAP_WORD : TextServer : : AUTOWRAP_OFF ) ;
2019-03-24 23:21:32 +00:00
}
2020-05-14 12:29:06 +00:00
2019-03-24 23:21:32 +00:00
bool AcceptDialog : : has_autowrap ( ) {
2022-09-06 21:55:57 +00:00
return message_label - > get_autowrap_mode ( ) ! = TextServer : : AUTOWRAP_OFF ;
2019-03-24 23:21:32 +00:00
}
2022-07-08 00:31:19 +00:00
void AcceptDialog : : set_ok_button_text ( String p_ok_button_text ) {
2022-09-06 21:55:57 +00:00
ok_button - > set_text ( p_ok_button_text ) ;
child_controls_changed ( ) ;
if ( is_visible ( ) ) {
_update_child_rects ( ) ;
}
2022-07-08 00:31:19 +00:00
}
String AcceptDialog : : get_ok_button_text ( ) const {
2022-09-06 21:55:57 +00:00
return ok_button - > get_text ( ) ;
2022-07-08 00:31:19 +00:00
}
2024-03-12 12:26:37 +00:00
void AcceptDialog : : register_text_enter ( LineEdit * p_line_edit ) {
2014-02-10 01:10:30 +00:00
ERR_FAIL_NULL ( p_line_edit ) ;
2024-03-12 12:26:37 +00:00
p_line_edit - > connect ( " text_submitted " , callable_mp ( this , & AcceptDialog : : _text_submitted ) ) ;
2014-02-10 01:10:30 +00:00
}
2017-01-10 04:49:55 +00:00
void AcceptDialog : : _update_child_rects ( ) {
2022-09-29 09:53:28 +00:00
Size2 dlg_size = get_size ( ) ;
2022-09-06 21:55:57 +00:00
float h_margins = theme_cache . panel_style - > get_margin ( SIDE_LEFT ) + theme_cache . panel_style - > get_margin ( SIDE_RIGHT ) ;
float v_margins = theme_cache . panel_style - > get_margin ( SIDE_TOP ) + theme_cache . panel_style - > get_margin ( SIDE_BOTTOM ) ;
// Fill the entire size of the window with the background.
bg_panel - > set_position ( Point2 ( ) ) ;
2022-09-29 09:53:28 +00:00
bg_panel - > set_size ( dlg_size ) ;
2016-05-30 03:28:29 +00:00
2022-09-06 21:55:57 +00:00
// Place the buttons from the bottom edge to their minimum required size.
Size2 buttons_minsize = buttons_hbox - > get_combined_minimum_size ( ) ;
2022-09-29 09:53:28 +00:00
Size2 buttons_size = Size2 ( dlg_size . x - h_margins , buttons_minsize . y ) ;
Point2 buttons_position = Point2 ( theme_cache . panel_style - > get_margin ( SIDE_LEFT ) , dlg_size . y - theme_cache . panel_style - > get_margin ( SIDE_BOTTOM ) - buttons_size . y ) ;
2022-09-06 21:55:57 +00:00
buttons_hbox - > set_position ( buttons_position ) ;
buttons_hbox - > set_size ( buttons_size ) ;
// Place the content from the top to fill the rest of the space (minus the separation).
Point2 content_position = Point2 ( theme_cache . panel_style - > get_margin ( SIDE_LEFT ) , theme_cache . panel_style - > get_margin ( SIDE_TOP ) ) ;
2022-09-29 09:53:28 +00:00
Size2 content_size = Size2 ( dlg_size . x - h_margins , dlg_size . y - v_margins - buttons_size . y - theme_cache . buttons_separation ) ;
2016-05-30 03:28:29 +00:00
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < get_child_count ( ) ; i + + ) {
2017-08-24 20:58:51 +00:00
Control * c = Object : : cast_to < Control > ( get_child ( i ) ) ;
2020-05-14 14:41:43 +00:00
if ( ! c ) {
2017-01-10 04:49:55 +00:00
continue ;
2020-05-14 14:41:43 +00:00
}
2022-09-06 21:55:57 +00:00
if ( c = = buttons_hbox | | c = = bg_panel | | c - > is_set_as_top_level ( ) ) {
2017-01-10 04:49:55 +00:00
continue ;
2020-05-14 14:41:43 +00:00
}
2017-01-10 04:49:55 +00:00
2022-09-06 21:55:57 +00:00
c - > set_position ( content_position ) ;
c - > set_size ( content_size ) ;
2016-05-30 03:28:29 +00:00
}
}
2020-03-06 17:00:16 +00:00
Size2 AcceptDialog : : _get_contents_minimum_size ( ) const {
2022-09-06 21:55:57 +00:00
// First, we then iterate over the label and any other custom controls
// to try and find the size that encompasses all content.
Size2 content_minsize ;
2017-03-05 15:44:50 +00:00
for ( int i = 0 ; i < get_child_count ( ) ; i + + ) {
2017-08-24 20:58:51 +00:00
Control * c = Object : : cast_to < Control > ( get_child ( i ) ) ;
2020-05-14 14:41:43 +00:00
if ( ! c ) {
2017-01-10 04:49:55 +00:00
continue ;
2020-05-14 14:41:43 +00:00
}
2017-01-10 04:49:55 +00:00
2022-09-06 21:55:57 +00:00
// Buttons will be included afterwards.
// The panel only displays the stylebox and doesn't contribute to the size.
if ( c = = buttons_hbox | | c = = bg_panel | | c - > is_set_as_top_level ( ) ) {
2017-01-10 04:49:55 +00:00
continue ;
2020-05-14 14:41:43 +00:00
}
2017-01-10 04:49:55 +00:00
2022-09-06 21:55:57 +00:00
Size2 child_minsize = c - > get_combined_minimum_size ( ) ;
2024-03-03 11:49:08 +00:00
content_minsize = child_minsize . max ( content_minsize ) ;
2016-05-30 03:28:29 +00:00
}
2022-09-06 21:55:57 +00:00
// Then we take the background panel as it provides the offsets,
// which are always added to the minimum size.
if ( theme_cache . panel_style . is_valid ( ) ) {
content_minsize + = theme_cache . panel_style - > get_minimum_size ( ) ;
}
2016-05-30 03:28:29 +00:00
2022-09-06 21:55:57 +00:00
// Then we add buttons. Horizontally we're interested in whichever
// value is the biggest. Vertically buttons add to the overall size.
Size2 buttons_minsize = buttons_hbox - > get_combined_minimum_size ( ) ;
content_minsize . x = MAX ( buttons_minsize . x , content_minsize . x ) ;
content_minsize . y + = buttons_minsize . y ;
// Plus there is a separation size added on top.
content_minsize . y + = theme_cache . buttons_separation ;
return content_minsize ;
2016-05-30 03:28:29 +00:00
}
2017-03-05 15:44:50 +00:00
void AcceptDialog : : _custom_action ( const String & p_action ) {
2021-07-17 21:22:52 +00:00
emit_signal ( SNAME ( " custom_action " ) , p_action ) ;
2014-02-10 01:10:30 +00:00
custom_action ( p_action ) ;
}
2023-07-10 10:17:51 +00:00
void AcceptDialog : : _custom_button_visibility_changed ( Button * button ) {
Control * right_spacer = Object : : cast_to < Control > ( button - > get_meta ( " __right_spacer " ) ) ;
if ( right_spacer ) {
right_spacer - > set_visible ( button - > is_visible ( ) ) ;
}
}
2017-03-05 15:44:50 +00:00
Button * AcceptDialog : : add_button ( const String & p_text , bool p_right , const String & p_action ) {
Button * button = memnew ( Button ) ;
2014-02-10 01:10:30 +00:00
button - > set_text ( p_text ) ;
2022-09-06 21:55:57 +00:00
2023-07-10 10:17:51 +00:00
Control * right_spacer ;
2014-02-10 01:10:30 +00:00
if ( p_right ) {
2022-09-06 21:55:57 +00:00
buttons_hbox - > add_child ( button ) ;
2023-07-10 10:17:51 +00:00
right_spacer = buttons_hbox - > add_spacer ( ) ;
2014-02-10 01:10:30 +00:00
} else {
2022-09-06 21:55:57 +00:00
buttons_hbox - > add_child ( button ) ;
buttons_hbox - > move_child ( button , 0 ) ;
2023-07-10 10:17:51 +00:00
right_spacer = buttons_hbox - > add_spacer ( true ) ;
2022-09-06 21:55:57 +00:00
}
2023-07-10 10:17:51 +00:00
button - > set_meta ( " __right_spacer " , right_spacer ) ;
button - > connect ( " visibility_changed " , callable_mp ( this , & AcceptDialog : : _custom_button_visibility_changed ) . bind ( button ) ) ;
2022-09-06 21:55:57 +00:00
child_controls_changed ( ) ;
if ( is_visible ( ) ) {
_update_child_rects ( ) ;
2014-02-10 01:10:30 +00:00
}
2021-12-09 09:42:46 +00:00
if ( ! p_action . is_empty ( ) ) {
2022-07-28 20:56:41 +00:00
button - > connect ( " pressed " , callable_mp ( this , & AcceptDialog : : _custom_action ) . bind ( p_action ) ) ;
2014-02-10 01:10:30 +00:00
}
return button ;
}
2020-12-14 18:37:30 +00:00
Button * AcceptDialog : : add_cancel_button ( const String & p_cancel ) {
2014-02-10 01:10:30 +00:00
String c = p_cancel ;
2021-12-09 09:42:46 +00:00
if ( p_cancel . is_empty ( ) ) {
2024-03-14 19:09:39 +00:00
c = ETR ( " Cancel " ) ;
2020-05-14 14:41:43 +00:00
}
2022-09-06 21:55:57 +00:00
2020-07-08 23:02:38 +00:00
Button * b = swap_cancel_ok ? add_button ( c , true ) : add_button ( c ) ;
2022-09-06 21:55:57 +00:00
2020-03-06 17:00:16 +00:00
b - > connect ( " pressed " , callable_mp ( this , & AcceptDialog : : _cancel_pressed ) ) ;
2022-09-06 21:55:57 +00:00
2014-02-10 01:10:30 +00:00
return b ;
}
2024-03-12 12:26:37 +00:00
void AcceptDialog : : remove_button ( Button * p_button ) {
ERR_FAIL_NULL ( p_button ) ;
ERR_FAIL_COND_MSG ( p_button - > get_parent ( ) ! = buttons_hbox , vformat ( " Cannot remove button %s as it does not belong to this dialog. " , p_button - > get_name ( ) ) ) ;
ERR_FAIL_COND_MSG ( p_button = = ok_button , " Cannot remove dialog's OK button. " ) ;
2021-07-06 15:51:56 +00:00
2024-03-12 12:26:37 +00:00
Control * right_spacer = Object : : cast_to < Control > ( p_button - > get_meta ( " __right_spacer " ) ) ;
2023-07-10 10:17:51 +00:00
if ( right_spacer ) {
2024-03-12 12:26:37 +00:00
ERR_FAIL_COND_MSG ( right_spacer - > get_parent ( ) ! = buttons_hbox , vformat ( " Cannot remove button %s as its associated spacer does not belong to this dialog. " , p_button - > get_name ( ) ) ) ;
2023-07-10 10:17:51 +00:00
}
2024-03-12 12:26:37 +00:00
p_button - > disconnect ( " visibility_changed " , callable_mp ( this , & AcceptDialog : : _custom_button_visibility_changed ) ) ;
if ( p_button - > is_connected ( " pressed " , callable_mp ( this , & AcceptDialog : : _custom_action ) ) ) {
p_button - > disconnect ( " pressed " , callable_mp ( this , & AcceptDialog : : _custom_action ) ) ;
2021-07-06 15:51:56 +00:00
}
2024-03-12 12:26:37 +00:00
if ( p_button - > is_connected ( " pressed " , callable_mp ( this , & AcceptDialog : : _cancel_pressed ) ) ) {
p_button - > disconnect ( " pressed " , callable_mp ( this , & AcceptDialog : : _cancel_pressed ) ) ;
2021-07-06 15:51:56 +00:00
}
2022-09-06 21:55:57 +00:00
if ( right_spacer ) {
buttons_hbox - > remove_child ( right_spacer ) ;
2024-03-12 12:26:37 +00:00
p_button - > remove_meta ( " __right_spacer " ) ;
2023-07-10 10:17:51 +00:00
right_spacer - > queue_free ( ) ;
2022-09-06 21:55:57 +00:00
}
2024-03-12 12:26:37 +00:00
buttons_hbox - > remove_child ( p_button ) ;
2022-09-06 21:55:57 +00:00
child_controls_changed ( ) ;
if ( is_visible ( ) ) {
_update_child_rects ( ) ;
}
2021-07-06 15:51:56 +00:00
}
2014-02-10 01:10:30 +00:00
void AcceptDialog : : _bind_methods ( ) {
2020-12-14 18:37:30 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_ok_button " ) , & AcceptDialog : : get_ok_button ) ;
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_label " ) , & AcceptDialog : : get_label ) ;
ClassDB : : bind_method ( D_METHOD ( " set_hide_on_ok " , " enabled " ) , & AcceptDialog : : set_hide_on_ok ) ;
ClassDB : : bind_method ( D_METHOD ( " get_hide_on_ok " ) , & AcceptDialog : : get_hide_on_ok ) ;
2022-03-31 20:00:17 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_close_on_escape " , " enabled " ) , & AcceptDialog : : set_close_on_escape ) ;
ClassDB : : bind_method ( D_METHOD ( " get_close_on_escape " ) , & AcceptDialog : : get_close_on_escape ) ;
2017-08-09 11:19:41 +00:00
ClassDB : : bind_method ( D_METHOD ( " add_button " , " text " , " right " , " action " ) , & AcceptDialog : : add_button , DEFVAL ( false ) , DEFVAL ( " " ) ) ;
2020-12-14 18:37:30 +00:00
ClassDB : : bind_method ( D_METHOD ( " add_cancel_button " , " name " ) , & AcceptDialog : : add_cancel_button ) ;
2021-07-06 15:51:56 +00:00
ClassDB : : bind_method ( D_METHOD ( " remove_button " , " button " ) , & AcceptDialog : : remove_button ) ;
2017-08-09 11:19:41 +00:00
ClassDB : : bind_method ( D_METHOD ( " register_text_enter " , " line_edit " ) , & AcceptDialog : : register_text_enter ) ;
2017-03-05 15:44:50 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_text " , " text " ) , & AcceptDialog : : set_text ) ;
ClassDB : : bind_method ( D_METHOD ( " get_text " ) , & AcceptDialog : : get_text ) ;
2019-03-24 23:21:32 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_autowrap " , " autowrap " ) , & AcceptDialog : : set_autowrap ) ;
ClassDB : : bind_method ( D_METHOD ( " has_autowrap " ) , & AcceptDialog : : has_autowrap ) ;
2022-07-08 00:31:19 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_ok_button_text " , " text " ) , & AcceptDialog : : set_ok_button_text ) ;
ClassDB : : bind_method ( D_METHOD ( " get_ok_button_text " ) , & AcceptDialog : : get_ok_button_text ) ;
2014-02-10 01:10:30 +00:00
2017-03-05 15:44:50 +00:00
ADD_SIGNAL ( MethodInfo ( " confirmed " ) ) ;
2023-01-21 11:25:29 +00:00
ADD_SIGNAL ( MethodInfo ( " canceled " ) ) ;
2020-02-20 21:58:05 +00:00
ADD_SIGNAL ( MethodInfo ( " custom_action " , PropertyInfo ( Variant : : STRING_NAME , " action " ) ) ) ;
2015-11-20 21:25:01 +00:00
2022-07-08 00:31:19 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " ok_button_text " ) , " set_ok_button_text " , " get_ok_button_text " ) ;
2022-11-25 04:48:37 +00:00
ADD_GROUP ( " Dialog " , " dialog_ " ) ;
2023-01-09 14:31:44 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " dialog_text " , PROPERTY_HINT_MULTILINE_TEXT ) , " set_text " , " get_text " ) ;
2017-03-05 15:44:50 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " dialog_hide_on_ok " ) , " set_hide_on_ok " , " get_hide_on_ok " ) ;
2022-03-31 20:00:17 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " dialog_close_on_escape " ) , " set_close_on_escape " , " get_close_on_escape " ) ;
2019-03-24 23:21:32 +00:00
ADD_PROPERTY ( PropertyInfo ( Variant : : BOOL , " dialog_autowrap " ) , " set_autowrap " , " has_autowrap " ) ;
2023-09-08 19:00:10 +00:00
BIND_THEME_ITEM_CUSTOM ( Theme : : DATA_TYPE_STYLEBOX , AcceptDialog , panel_style , " panel " ) ;
BIND_THEME_ITEM ( Theme : : DATA_TYPE_CONSTANT , AcceptDialog , buttons_separation ) ;
2014-02-10 01:10:30 +00:00
}
2020-07-08 23:02:38 +00:00
bool AcceptDialog : : swap_cancel_ok = false ;
void AcceptDialog : : set_swap_cancel_ok ( bool p_swap ) {
swap_cancel_ok = p_swap ;
2014-02-10 01:10:30 +00:00
}
AcceptDialog : : AcceptDialog ( ) {
2020-03-12 12:37:40 +00:00
set_wrap_controls ( true ) ;
2020-03-06 17:00:16 +00:00
set_visible ( false ) ;
set_transient ( true ) ;
2020-06-30 17:01:10 +00:00
set_exclusive ( true ) ;
2020-07-01 15:39:42 +00:00
set_clamp_to_embedder ( true ) ;
2023-08-08 08:31:56 +00:00
set_keep_title_visible ( true ) ;
2020-03-06 17:00:16 +00:00
2022-09-06 21:55:57 +00:00
bg_panel = memnew ( Panel ) ;
add_child ( bg_panel , false , INTERNAL_MODE_FRONT ) ;
2020-03-06 17:00:16 +00:00
2022-09-06 21:55:57 +00:00
buttons_hbox = memnew ( HBoxContainer ) ;
2020-03-06 17:00:16 +00:00
2022-09-06 21:55:57 +00:00
message_label = memnew ( Label ) ;
message_label - > set_anchor ( SIDE_RIGHT , Control : : ANCHOR_END ) ;
message_label - > set_anchor ( SIDE_BOTTOM , Control : : ANCHOR_END ) ;
add_child ( message_label , false , INTERNAL_MODE_FRONT ) ;
2014-02-10 01:10:30 +00:00
2022-09-06 21:55:57 +00:00
add_child ( buttons_hbox , false , INTERNAL_MODE_FRONT ) ;
2014-02-10 01:10:30 +00:00
2022-09-06 21:55:57 +00:00
buttons_hbox - > add_spacer ( ) ;
ok_button = memnew ( Button ) ;
2024-03-14 19:09:39 +00:00
ok_button - > set_text ( ETR ( " OK " ) ) ;
2022-09-06 21:55:57 +00:00
buttons_hbox - > add_child ( ok_button ) ;
buttons_hbox - > add_spacer ( ) ;
2016-03-08 23:00:52 +00:00
2022-09-06 21:55:57 +00:00
ok_button - > connect ( " pressed " , callable_mp ( this , & AcceptDialog : : _ok_pressed ) ) ;
2014-02-10 01:10:30 +00:00
2024-03-14 19:09:39 +00:00
set_title ( ETR ( " Alert! " ) ) ;
2014-02-10 01:10:30 +00:00
}
2017-03-05 15:44:50 +00:00
AcceptDialog : : ~ AcceptDialog ( ) {
2014-02-10 01:10:30 +00:00
}
2017-04-12 13:11:44 +00:00
// ConfirmationDialog
2022-07-08 00:31:19 +00:00
void ConfirmationDialog : : set_cancel_button_text ( String p_cancel_button_text ) {
cancel - > set_text ( p_cancel_button_text ) ;
}
String ConfirmationDialog : : get_cancel_button_text ( ) const {
return cancel - > get_text ( ) ;
}
2014-02-10 01:10:30 +00:00
void ConfirmationDialog : : _bind_methods ( ) {
2020-12-14 18:37:30 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_cancel_button " ) , & ConfirmationDialog : : get_cancel_button ) ;
2022-08-08 12:18:26 +00:00
ClassDB : : bind_method ( D_METHOD ( " set_cancel_button_text " , " text " ) , & ConfirmationDialog : : set_cancel_button_text ) ;
2022-07-08 00:31:19 +00:00
ClassDB : : bind_method ( D_METHOD ( " get_cancel_button_text " ) , & ConfirmationDialog : : get_cancel_button_text ) ;
ADD_PROPERTY ( PropertyInfo ( Variant : : STRING , " cancel_button_text " ) , " set_cancel_button_text " , " get_cancel_button_text " ) ;
2014-02-10 01:10:30 +00:00
}
2020-12-14 18:37:30 +00:00
Button * ConfirmationDialog : : get_cancel_button ( ) {
2014-02-10 01:10:30 +00:00
return cancel ;
}
ConfirmationDialog : : ConfirmationDialog ( ) {
2024-03-14 19:09:39 +00:00
set_title ( ETR ( " Please Confirm... " ) ) ;
2021-10-02 20:07:42 +00:00
set_min_size ( Size2 ( 200 , 70 ) ) ;
2020-12-14 18:37:30 +00:00
cancel = add_cancel_button ( ) ;
2014-02-10 01:10:30 +00:00
}