Skip to content

Commit 9026840

Browse files
committed
feat: add support for multiple os windows
refers to: #23 Signed-off-by: k2kra <[email protected]>
1 parent f11704e commit 9026840

11 files changed

+219
-21
lines changed

addons/panku_console/components/input_field/input_area.gd

+2-2
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ func _ready():
3232
#get focus automatically.
3333
visibility_changed.connect(
3434
func():
35-
if visible:
36-
input.grab_focus()
35+
if is_visible_in_tree():
36+
input.call_deferred("grab_focus")
3737
)
3838

3939
menubtn.mouse_entered.connect(

addons/panku_console/components/lynx_window2/lynx_window_2.gd

+83-9
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ signal window_closed
1111
@export var _resize_btn:Button
1212
@export var _shadow_focus:Panel
1313
@export var _shadow:NinePatchRect
14-
@export var _content:Panel
14+
@export var _container:Panel
15+
@export var _pop_btn:Button
1516

1617
@export var no_resize := false
1718
@export var no_resize_x := false
@@ -31,22 +32,30 @@ var _drag_start_position:Vector2
3132
var _drag_start_position_global:Vector2
3233
var _is_resizing := false
3334
var _resize_start_position:Vector2
35+
var _os_window:Window
36+
var _content:Control
3437

3538
func centered():
3639
var window_rect = get_rect()
3740
var screen_rect = get_viewport_rect()
3841
position = (screen_rect.size - window_rect.size) / 2
3942

4043
func get_content():
41-
if _content.get_child_count() > 0:
42-
return _content.get_child(0)
43-
return null
44+
return _content
4445

4546
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+
5059
func highlight(v:bool):
5160
_shadow_focus.visible = v
5261

@@ -93,9 +102,74 @@ func _ready():
93102
if is_visible_in_tree() and flicker:
94103
$Border.hey_i_am_here()
95104
)
96-
105+
97106
if flicker:
98107
$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
99173

100174
func _input(e):
101175
#release focus when you click outside of the window

addons/panku_console/components/lynx_window2/lynx_window_2.tscn

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
[gd_scene load_steps=25 format=3 uid="uid://s88loppa6gja"]
1+
[gd_scene load_steps=26 format=3 uid="uid://s88loppa6gja"]
22

33
[ext_resource type="Material" uid="uid://dyipeqsa8lcpc" path="res://addons/panku_console/components/lynx_window2/lynx_window_shader_material.tres" id="1_tvp6i"]
44
[ext_resource type="Script" path="res://addons/panku_console/components/lynx_window2/lynx_window_2.gd" id="2_1ul5o"]
55
[ext_resource type="FontVariation" uid="uid://d2b8bo6ytpt2i" path="res://addons/panku_console/res/font/default_bold.tres" id="3_oes5e"]
66
[ext_resource type="Texture2D" uid="uid://dosm26riekruh" path="res://addons/panku_console/res/icons2/menu.svg" id="4_4dlyn"]
7+
[ext_resource type="Texture2D" uid="uid://gav3m4qtvgje" path="res://addons/panku_console/res/icons2/pop-out-svgrepo-com.svg" id="4_im81u"]
78
[ext_resource type="Texture2D" uid="uid://8g5afcuanbl6" path="res://addons/panku_console/res/icons2/close.svg" id="5_l4qpm"]
89
[ext_resource type="Texture2D" uid="uid://dvr12fl5prm78" path="res://addons/panku_console/res/effect/square_shadow.png" id="6_mfp1h"]
910
[ext_resource type="Texture2D" uid="uid://ciu5jiw4xmkq0" path="res://addons/panku_console/res/icons2/resize-svgrepo-com.svg" id="7_duwqn"]
@@ -105,7 +106,7 @@ border_width_right = 4
105106
border_width_bottom = 4
106107
border_color = Color(1, 0, 0, 1)
107108

108-
[node name="LynxWindow2" type="ColorRect" node_paths=PackedStringArray("_window_title_container", "_title_btn", "_close_btn", "_options_btn", "_resize_btn", "_shadow_focus", "_shadow", "_content")]
109+
[node name="LynxWindow2" type="ColorRect" node_paths=PackedStringArray("_window_title_container", "_title_btn", "_close_btn", "_options_btn", "_resize_btn", "_shadow_focus", "_shadow", "_container", "_pop_btn")]
109110
material = ExtResource("1_tvp6i")
110111
offset_right = 413.0
111112
offset_bottom = 305.0
@@ -117,7 +118,8 @@ _options_btn = NodePath("VBoxContainer/Up/Button3")
117118
_resize_btn = NodePath("Button")
118119
_shadow_focus = NodePath("Shadow2")
119120
_shadow = NodePath("Shadow")
120-
_content = NodePath("VBoxContainer/Down")
121+
_container = NodePath("VBoxContainer/Down")
122+
_pop_btn = NodePath("VBoxContainer/Up/Button4")
121123

122124
[node name="VBoxContainer" type="VBoxContainer" parent="."]
123125
layout_mode = 1
@@ -145,6 +147,16 @@ text = "Window Title"
145147
alignment = 0
146148
text_overrun_behavior = 1
147149

150+
[node name="Button4" type="Button" parent="VBoxContainer/Up"]
151+
layout_mode = 2
152+
theme_override_styles/normal = SubResource("StyleBoxFlat_l6qrt")
153+
theme_override_styles/hover = SubResource("StyleBoxFlat_qf6ov")
154+
theme_override_styles/pressed = SubResource("StyleBoxFlat_8fhjd")
155+
theme_override_styles/focus = SubResource("StyleBoxEmpty_sskw3")
156+
icon = ExtResource("4_im81u")
157+
alignment = 0
158+
icon_alignment = 1
159+
148160
[node name="Button3" type="Button" parent="VBoxContainer/Up"]
149161
layout_mode = 2
150162
theme_override_styles/normal = SubResource("StyleBoxFlat_l6qrt")

addons/panku_console/components/lynx_window2/lynx_windows_manager_2.gd

+47
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#A simple control node managing its child windows
22
extends Control
33

4+
var os_popup_btn_enabled:bool
5+
var os_window_bg_color:Color
6+
7+
func _ready():
8+
load_data()
9+
410
func _input(e):
511
if e is InputEventMouseButton and e.pressed:
612
var flag = true
@@ -18,3 +24,44 @@ func _input(e):
1824
if flag and get_child_count() > 0:
1925
var forefront = get_child(get_child_count() - 1)
2026
if forefront.has_method("highlight"): forefront.highlight(false)
27+
28+
func enable_os_popup_btns(b:bool):
29+
#note that this may affect your project
30+
get_viewport().gui_embed_subwindows = !b
31+
os_popup_btn_enabled = b
32+
for w in get_children():
33+
#maybe there's a better way to get node type
34+
if !w.has_method("switch_to_os_window"):
35+
continue
36+
w._pop_btn.visible = b
37+
38+
func get_enable_os_popup_btns() -> bool:
39+
return os_popup_btn_enabled
40+
41+
func set_os_window_bg_color(c:Color):
42+
os_window_bg_color = c
43+
for w in get_children():
44+
#maybe there's a better way to get node type
45+
if !w.has_method("switch_to_os_window"):
46+
continue
47+
if w._os_window != null:
48+
w._os_window.get_child(0).color = c
49+
50+
func get_os_window_bg_color() -> Color:
51+
return os_window_bg_color
52+
53+
func save_data():
54+
var cfg = Console.Config.get_config()
55+
cfg[Console.Utils.CFG_ENABLE_OS_WINDOW] = os_popup_btn_enabled
56+
cfg[Console.Utils.CFG_OS_WINDOW_BGCOLOR] = os_window_bg_color
57+
Console.Config.set_config(cfg)
58+
59+
func load_data():
60+
var cfg = Console.Config.get_config()
61+
enable_os_popup_btns(cfg.get(Console.Utils.CFG_ENABLE_OS_WINDOW, false))
62+
set_os_window_bg_color(cfg.get(Console.Utils.CFG_OS_WINDOW_BGCOLOR, Color("#2b2e32")))
63+
64+
func _notification(what):
65+
#quit event
66+
if what == NOTIFICATION_WM_CLOSE_REQUEST:
67+
save_data()

addons/panku_console/components/options.gd

+12
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,18 @@ extends Node
6464
get:
6565
return Console.output_overlay.get("theme_override_colors/font_shadow_color") != null
6666

67+
@export_group("Experimental")
68+
@export var enable_os_window := false:
69+
set(v):
70+
Console.w_manager.enable_os_popup_btns(v)
71+
get:
72+
return Console.w_manager.os_popup_btn_enabled
73+
@export var os_window_bg_color:Color:
74+
set(v):
75+
Console.w_manager.set_os_window_bg_color(v)
76+
get:
77+
return Console.w_manager.os_window_bg_color
78+
6779
@export_group("About")
6880
@export var export_button_show_intro := "Show Intro"
6981
@export var export_button_check_update := "Check Update"

addons/panku_console/components/utils.gd

+2
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ const CFG_MONITOR_ARRAY = "monitor_array"
5757
const CFG_FREPL_POSITION = "frepl_position"
5858
const CFG_FREPL_SIZE = "frepl_size"
5959
const CFG_EXP_HISTORY = "exp_history"
60+
const CFG_ENABLE_OS_WINDOW = "enable_os_window"
61+
const CFG_OS_WINDOW_BGCOLOR = "os_window_bgcolor"
6062

6163
static func execute_exp(exp_str:String, expression:Expression, base_instance:Object, env:Dictionary):
6264
var failed := false

addons/panku_console/console.gd

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ var mini_repl_mode = false:
4545
mini_repl_mode = v
4646
if is_repl_window_opened:
4747
_mini_repl.visible = v
48-
_full_repl.visible = !v
48+
_full_repl.set_window_visibility(!v)
4949

5050
var is_repl_window_opened := false:
5151
set(v):
@@ -55,11 +55,11 @@ var is_repl_window_opened := false:
5555
if mini_repl_mode:
5656
_mini_repl.visible = v
5757
else:
58-
_full_repl.visible = v
58+
_full_repl.set_window_visibility(v)
5959
if pause_when_active:
60-
_full_repl._title_btn.text = "</> Panku REPL (Paused)"
60+
_full_repl.set_window_title_text("</> Panku REPL (Paused)")
6161
else:
62-
_full_repl._title_btn.text = "</> Panku REPL"
62+
_full_repl.set_window_title_text("</> Panku REPL")
6363
get_tree().paused = pause_when_active and v
6464
repl_visible_changed.emit(v)
6565

addons/panku_console/console.tscn

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ queue_free_on_close = false
100100
[node name="Button" parent="LynxWindowsManager2/ExpKeyMapper/VBoxContainer/Up" index="0"]
101101
text = "Expression Key Mapper"
102102

103-
[node name="Button3" parent="LynxWindowsManager2/ExpKeyMapper/VBoxContainer/Up" index="1"]
103+
[node name="Button3" parent="LynxWindowsManager2/ExpKeyMapper/VBoxContainer/Up" index="2"]
104104
visible = false
105105

106106
[node name="ExpKeyMapper" parent="LynxWindowsManager2/ExpKeyMapper/VBoxContainer/Down" index="0" instance=ExtResource("9_ua71q")]
@@ -125,7 +125,7 @@ queue_free_on_close = false
125125
[node name="Button" parent="LynxWindowsManager2/ExpHistory/VBoxContainer/Up" index="0"]
126126
text = "Expression History"
127127

128-
[node name="Button3" parent="LynxWindowsManager2/ExpHistory/VBoxContainer/Up" index="1"]
128+
[node name="Button3" parent="LynxWindowsManager2/ExpHistory/VBoxContainer/Up" index="2"]
129129
visible = false
130130

131131
[node name="ExpHistory" parent="LynxWindowsManager2/ExpHistory/VBoxContainer/Down" index="0" instance=ExtResource("10_03tvm")]

addons/panku_console/plugin.cfg

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33
name="PankuConsole"
44
description="All-in-One Godot Engine runtime debugging tool."
55
author="Feo (k2kra) Wu"
6-
version="1.3.73"
6+
version="1.3.75"
77
script="plugin.gd"
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
[remap]
2+
3+
importer="texture"
4+
type="CompressedTexture2D"
5+
uid="uid://gav3m4qtvgje"
6+
path="res://.godot/imported/pop-out-svgrepo-com.svg-54bb73635d5759933a88bbec8ed6aca8.ctex"
7+
metadata={
8+
"vram_texture": false
9+
}
10+
11+
[deps]
12+
13+
source_file="res://addons/panku_console/res/icons2/pop-out-svgrepo-com.svg"
14+
dest_files=["res://.godot/imported/pop-out-svgrepo-com.svg-54bb73635d5759933a88bbec8ed6aca8.ctex"]
15+
16+
[params]
17+
18+
compress/mode=0
19+
compress/high_quality=false
20+
compress/lossy_quality=0.7
21+
compress/hdr_compression=1
22+
compress/normal_map=0
23+
compress/channel_pack=0
24+
mipmaps/generate=false
25+
mipmaps/limit=-1
26+
roughness/mode=0
27+
roughness/src_normal=""
28+
process/fix_alpha_border=true
29+
process/premult_alpha=false
30+
process/normal_map_invert_y=false
31+
process/hdr_as_srgb=false
32+
process/hdr_clamp_exposure=false
33+
process/size_limit=0
34+
detect_3d/compress_to=1
35+
svg/scale=1.0
36+
editor/scale_with_editor_scale=false
37+
editor/convert_colors_with_editor_theme=false

0 commit comments

Comments
 (0)