@@ -11,7 +11,8 @@ signal window_closed
11
11
@export var _resize_btn :Button
12
12
@export var _shadow_focus :Panel
13
13
@export var _shadow :NinePatchRect
14
- @export var _content :Panel
14
+ @export var _container :Panel
15
+ @export var _pop_btn :Button
15
16
16
17
@export var no_resize := false
17
18
@export var no_resize_x := false
@@ -31,22 +32,30 @@ var _drag_start_position:Vector2
31
32
var _drag_start_position_global :Vector2
32
33
var _is_resizing := false
33
34
var _resize_start_position :Vector2
35
+ var _os_window :Window
36
+ var _content :Control
34
37
35
38
func centered ():
36
39
var window_rect = get_rect ()
37
40
var screen_rect = get_viewport_rect ()
38
41
position = (screen_rect .size - window_rect .size ) / 2
39
42
40
43
func get_content ():
41
- if _content .get_child_count () > 0 :
42
- return _content .get_child (0 )
43
- return null
44
+ return _content
44
45
45
46
func set_content (node :Control ):
46
- assert (_content .get_child_count () == 0 )
47
- assert (node .get_parent () == null )
48
- _content .add_child (node )
49
-
47
+ _content = node
48
+ if _os_window and _os_window .visible :
49
+ if _os_window .get_child_count () > 0 :
50
+ push_error ("Error: error in set_content" )
51
+ return
52
+ _os_window .add_child (node )
53
+ return
54
+ if _container .get_child_count () > 0 :
55
+ push_error ("Error: error in set_content." )
56
+ return
57
+ _container .add_child (node )
58
+
50
59
func highlight (v :bool ):
51
60
_shadow_focus .visible = v
52
61
@@ -93,9 +102,74 @@ func _ready():
93
102
if is_visible_in_tree () and flicker :
94
103
$ Border .hey_i_am_here ()
95
104
)
96
-
105
+
97
106
if flicker :
98
107
$ Border .hey_i_am_here ()
108
+
109
+ _pop_btn .pressed .connect (switch_to_os_window )
110
+
111
+ if _container .get_child_count () > 0 :
112
+ _content = _container .get_child (0 )
113
+
114
+ if get_parent ().has_method ("get_enable_os_popup_btns" ):
115
+ _pop_btn .visible = get_parent ().get_enable_os_popup_btns ()
116
+
117
+ func init_os_window ():
118
+ _os_window = Window .new ()
119
+ var color_rect = ColorRect .new ()
120
+ color_rect .set_anchors_and_offsets_preset (Control .PRESET_FULL_RECT )
121
+ _os_window .add_child (color_rect )
122
+ get_tree ().root .add_child (_os_window )
123
+ # destructor
124
+ tree_exiting .connect (
125
+ func ():
126
+ _os_window .queue_free ()
127
+ )
128
+ # switch back to embed window when os window close requested
129
+ _os_window .close_requested .connect (
130
+ func ():
131
+ _os_window .remove_child (_content )
132
+ _os_window .hide ()
133
+ set_content (_content )
134
+ show ()
135
+ )
136
+ if get_parent ().has_method ("get_os_window_bg_color" ):
137
+ color_rect .color = get_parent ().get_os_window_bg_color ()
138
+
139
+ func switch_to_os_window ():
140
+ if _content == null :
141
+ push_error ("Error: No content. " )
142
+ return
143
+ if _os_window == null :
144
+ init_os_window ()
145
+ _container .remove_child (_content )
146
+ _os_window .add_child (_content )
147
+ _os_window .size = size
148
+ _os_window .title = _title_btn .text
149
+ _os_window .position = Vector2 (DisplayServer .window_get_position (0 )) + position
150
+ _content .set_anchors_and_offsets_preset (Control .PRESET_FULL_RECT )
151
+ _os_window .show ()
152
+ hide ()
153
+
154
+ func show_window ():
155
+ if _os_window and _os_window .visible :
156
+ return
157
+ show ()
158
+
159
+ func hide_window ():
160
+ if _os_window and _os_window .visible :
161
+ _os_window .close_requested .emit ()
162
+ hide ()
163
+
164
+ func set_window_visibility (b :bool ):
165
+ if b : show_window ()
166
+ else : hide_window ()
167
+
168
+ func set_window_title_text (text :String ):
169
+ if _os_window and _os_window .visible :
170
+ _os_window .title = text
171
+ else :
172
+ _title_btn .text = text
99
173
100
174
func _input (e ):
101
175
# release focus when you click outside of the window
0 commit comments