44 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
55 */
66
7- use godot:: engine :: { EditorInterface , Engine } ;
8- use godot:: log :: godot_warn;
7+ use godot:: classes :: { EditorInterface , Engine } ;
8+ use godot:: global :: godot_warn;
99use godot:: meta:: ToGodot ;
1010use godot:: prelude:: GodotConvert ;
1111
1212#[ derive( Clone , Copy ) ]
13- pub enum EditorToaserSeverity {
13+ pub enum EditorToasterSeverity {
1414 Warning ,
1515}
1616
17- impl From < EditorToaserSeverity > for u8 {
18- fn from ( value : EditorToaserSeverity ) -> Self {
19- use EditorToaserSeverity :: * ;
17+ impl From < EditorToasterSeverity > for u8 {
18+ fn from ( value : EditorToasterSeverity ) -> Self {
19+ use EditorToasterSeverity :: * ;
2020
2121 match value {
2222 Warning => 1 ,
2323 }
2424 }
2525}
2626
27- impl GodotConvert for EditorToaserSeverity {
27+ impl GodotConvert for EditorToasterSeverity {
2828 type Via = u8 ;
2929}
3030
31- impl ToGodot for EditorToaserSeverity {
32- fn to_godot ( & self ) -> Self :: Via {
31+ impl ToGodot for EditorToasterSeverity {
32+ type ToVia < ' v > = Self :: Via ;
33+
34+ fn to_godot ( & self ) -> Self :: ToVia < ' static > {
3335 ( * self ) . into ( )
3436 }
3537}
3638
37- pub fn show_editor_toast ( message : & str , severity : EditorToaserSeverity ) {
39+ pub fn show_editor_toast ( message : & str , severity : EditorToasterSeverity ) {
3840 if !Engine :: singleton ( ) . is_editor_hint ( ) {
3941 return ;
4042 }
4143
44+ #[ cfg( before_api = "4.2" ) ]
45+ let Some ( base_control) = Engine :: singleton ( )
46+ . get_singleton ( "EditorInterface" )
47+ . and_then ( |obj| obj. cast :: < EditorInterface > ( ) . get_base_control ( ) )
48+ else {
49+ godot_warn ! ( "[godot-rust-script] unable to access editor UI!" ) ;
50+ return ;
51+ } ;
52+
53+ #[ cfg( since_api = "4.2" ) ]
4254 let Some ( base_control) = EditorInterface :: singleton ( ) . get_base_control ( ) else {
4355 godot_warn ! ( "[godot-rust-script] unable to access editor UI!" ) ;
4456 return ;
4557 } ;
4658
4759 let editor_toaser = base_control
48- . find_children_ex ( "*" . into ( ) )
49- . type_ ( "EditorToaster" . into ( ) )
60+ . find_children_ex ( "*" )
61+ . type_ ( "EditorToaster" )
5062 . recursive ( true )
5163 . owned ( false )
5264 . done ( )
@@ -57,13 +69,13 @@ pub fn show_editor_toast(message: &str, severity: EditorToaserSeverity) {
5769 return ;
5870 } ;
5971
60- if !editor_toaser. has_method ( "_popup_str" . into ( ) ) {
72+ if !editor_toaser. has_method ( "_popup_str" ) {
6173 godot_warn ! ( "[godot-rust-script] Internal toast notifications API no longer exists!" ) ;
6274 return ;
6375 }
6476
6577 editor_toaser. call (
66- "_popup_str" . into ( ) ,
78+ "_popup_str" ,
6779 & [ message. to_variant ( ) , severity. to_variant ( ) , "" . to_variant ( ) ] ,
6880 ) ;
6981}
0 commit comments