From 555bf907031259e79c72dd45249376d6ae11d90f Mon Sep 17 00:00:00 2001 From: Rey Beebe Date: Mon, 5 Dec 2022 19:15:15 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8Improvements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. You can click notifications now. 2. Add more built-in functions. 3. Visible histories. 4. Documentation comments for console.gd 5. Pause the game when the console window is active. 6. Define help information in your scripts. 7. Update README.md --- .gitignore | 1 + README.md | 32 +++-- addons/panku_console/components/config.gd | 4 +- .../components/hints_list/hints_list.gd | 16 ++- .../components/input_field/input_area.gd | 1 + .../components/input_field/input_area.tscn | 11 +- .../components/input_field/input_field.gd | 12 +- .../components/lynx_window/lynx_window.tscn | 7 +- .../components/resident_logs/log_item.gd | 5 + .../components/resident_logs/log_item.tscn | 8 +- addons/panku_console/components/utils.gd | 6 +- addons/panku_console/console.gd | 101 +++++++++++---- addons/panku_console/console.tscn | 45 +++++-- addons/panku_console/default_env.gd | 118 +++++++++++------- addons/panku_console/plugin.gd | 4 +- ...sted_glass.tres => frosted_glass.gdshader} | 12 +- 16 files changed, 252 insertions(+), 131 deletions(-) rename addons/panku_console/res/shader/{frosted_glass.tres => frosted_glass.gdshader} (62%) diff --git a/.gitignore b/.gitignore index d48b8ac..733360e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ .godot/ # Others +stats/ test/ icon.svg icon.svg.import diff --git a/README.md b/README.md index 9cb285d..97cf5f8 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,31 @@ -# Panku Console ![](https://badgen.net/badge/Godot%20Compatible/4.0Beta6%2B/cyan) ![](https://badgen.net/github/release/Ark2000/PankuConsole) ![](https://badgen.net/github/license/Ark2000/PankuConsole) +# Panku Console ![](https://badgen.net/badge/Godot%20Compatible/4.0Beta7%2B/cyan) ![](https://badgen.net/github/release/Ark2000/PankuConsole) ![](https://badgen.net/github/license/Ark2000/PankuConsole) -[Godot 4](https://godotengine.org/) Plugin. Provide a runtime console so your can just run any script expression in your game! +![zr5DqU.md.png](https://s1.ax1x.com/2022/12/04/zr5DqU.md.png) + +A [Godot 4](https://godotengine.org/) Plugin. Provide a runtime console so your can run any script expression in your game! -[![z1GFnH.png](https://s1.ax1x.com/2022/11/22/z1GFnH.png)](https://imgse.com/i/z1GFnH) # ✨Features - ✅ Resizable conosle with edge snapping. + ✅ Flexible conosle window with edge snapping, resizing and dragging. + + ✅ No need to define complex commands, extremely easy to run code in your game directly. + + ✅ Simple but reliable notification system. Send notifications whenerver you want. + + ✅ Floating widgets system. Monitor variables or performance, add buttons and save them in runtime . + + ✅ Auto-complete your expression using `tab` with help information extracted from your code. + + ✅ Navigate throught submit histories using `up`/`down`. + + ✅ You can always press F1 and search `PankuConsole` in your editor to get the coding documentation. - ✅ No need to define complex commands, extremely easy to run code in your game. + f2 - ✅ Nice-looking blur effect (Not sure if this is a point). + ![f1](https://github.com/Ark2000/Files/blob/main/F1.gif?raw=true) - ✅ Provide a notification panel that may help. + ![f3](https://github.com/Ark2000/Files/blob/main/F3.gif?raw=true) # 📦Installation @@ -44,7 +57,8 @@ For more detailed information, please visit [Installing plugins](https://docs.go How is this implemented? Well, it's EXTREMELY easy, just define a variable or constant like this in the `default_env.gd`, more details will be explained in the next step. ```gdscript - const help = "available methods: say_hi(), enable_in_game_logs(bool), cls()" + const _HELP_help = "this string will be used as help info in auto-completion" + var help = "available methods: say_hi(), enable_in_game_logs(bool), cls()" ``` 6. The core execution procedure is implemented by `Expression` which is a class that stores an expression you can execute. @@ -54,7 +68,7 @@ For more detailed information, please visit [Installing plugins](https://docs.go For more information about what is `Expression`, please visit [Evaluating expressions](https://docs.godotengine.org/en/stable/tutorials/scripting/evaluating_expressions.html) -7. Check `panku.gd` to see what you can do with the global singleton `Panku` +7. Check `panku.gd` or type `F1` and search `PankuConsole` to see what you can do with the global singleton `Console` At last, please pay attention that while this plugin is powerful, it's not ready for players since `Expression` is unsafe and exposes lots of internal structure. diff --git a/addons/panku_console/components/config.gd b/addons/panku_console/components/config.gd index 2724be0..f51e662 100644 --- a/addons/panku_console/components/config.gd +++ b/addons/panku_console/components/config.gd @@ -13,7 +13,7 @@ static func get_default_configs(): "position": Vector2(80, 0), "update_delay": 0.5, "env": "default", - "update_exp": 'performance_info', + "update_exp": 'engine_performance_info', "pressed_exp": "", }, { @@ -21,7 +21,7 @@ static func get_default_configs(): "update_delay": 9223372036854775807, "env": "default", "update_exp": '"Hint!"', - "pressed_exp": 'hints' + "pressed_exp": 'console_hints' }, ], "empty": [] diff --git a/addons/panku_console/components/hints_list/hints_list.gd b/addons/panku_console/components/hints_list/hints_list.gd index 22418de..ddd1751 100644 --- a/addons/panku_console/components/hints_list/hints_list.gd +++ b/addons/panku_console/components/hints_list/hints_list.gd @@ -8,6 +8,8 @@ const hint_pck = preload("res://addons/panku_console/components/hints_list/hint. var hints_count = 0 +var disable_buttons := false + var selected:int = 0: set(v): if !container: return @@ -41,13 +43,17 @@ func set_hints(texts:Array, icons:Array): h = hint_pck.instantiate() container.add_child(h) h.set_meta("idx", i) - h.button_down.connect( - func(): - hint_button_clicked.emit(i) - ) + h.button_down.connect(func(): _on_btn_clicked(i)) h.label.text = texts[i] - h.icon2.texture = icons[i] + if i < icons.size(): + h.icon2.texture = icons[i] + else: + h.icon2.texture = null h.set_highlight(false) if texts.size() < container.get_child_count(): for i in range(texts.size(), container.get_child_count()): container.get_child(i).hide() + +func _on_btn_clicked(i:int): + if !disable_buttons: + hint_button_clicked.emit(i) diff --git a/addons/panku_console/components/input_field/input_area.gd b/addons/panku_console/components/input_field/input_area.gd index 3ebbe85..3007de3 100644 --- a/addons/panku_console/components/input_field/input_area.gd +++ b/addons/panku_console/components/input_field/input_area.gd @@ -5,6 +5,7 @@ signal update_hints(env:String, exp:String) signal env_changed(env:String) signal next_hint() signal prev_hint() +signal navigate_histories(histories:Array, cur:int) @onready var opt:OptionButton = $OptionButton @onready var input:LineEdit = $InputField diff --git a/addons/panku_console/components/input_field/input_area.tscn b/addons/panku_console/components/input_field/input_area.tscn index 0468cc7..8e7506a 100644 --- a/addons/panku_console/components/input_field/input_area.tscn +++ b/addons/panku_console/components/input_field/input_area.tscn @@ -13,8 +13,7 @@ theme_override_constants/separation = 0 script = ExtResource("2_6g40s") [node name="InputField" type="LineEdit" parent="."] -offset_right = 168.0 -offset_bottom = 25.0 +layout_mode = 2 size_flags_horizontal = 3 focus_neighbor_left = NodePath(".") focus_neighbor_top = NodePath(".") @@ -29,9 +28,7 @@ caret_blink = true script = ExtResource("4_xjt2l") [node name="OptionButton" type="OptionButton" parent="."] -offset_left = 168.0 -offset_right = 253.0 -offset_bottom = 25.0 +layout_mode = 2 item_count = 1 selected = 0 popup/item_0/text = "default" @@ -39,9 +36,7 @@ popup/item_0/id = 0 [node name="Button" type="Button" parent="."] custom_minimum_size = Vector2(24, 0) -offset_left = 253.0 -offset_right = 277.0 -offset_bottom = 25.0 +layout_mode = 2 icon = ExtResource("5_0m8mk") icon_alignment = 1 expand_icon = true diff --git a/addons/panku_console/components/input_field/input_field.gd b/addons/panku_console/components/input_field/input_field.gd index 5f5b231..6adcd2c 100644 --- a/addons/panku_console/components/input_field/input_field.gd +++ b/addons/panku_console/components/input_field/input_field.gd @@ -25,17 +25,17 @@ func _gui_input(e): #navigate through histories if hints.is_empty(): if e is InputEventKey and e.keycode == KEY_UP and e.pressed: - if !histories.is_empty() and history_idx > 0: - history_idx -= 1 - history_idx = clamp(history_idx, 0, histories.size() - 1) + if !histories.is_empty() : + history_idx = wrapi(history_idx-1, 0, histories.size()) text = histories[history_idx] + get_parent().navigate_histories.emit(histories, history_idx) await get_tree().process_frame caret_column = text.length() elif e is InputEventKey and e.keycode == KEY_DOWN and e.pressed: - if !histories.is_empty() and history_idx < histories.size() - 1: - history_idx += 1 - history_idx = clamp(history_idx, 0, histories.size() - 1) + if !histories.is_empty(): + history_idx = wrapi(history_idx+1, 0, histories.size()) text = histories[history_idx] + get_parent().navigate_histories.emit(histories, history_idx) await get_tree().process_frame caret_column = text.length() #navigate through hints diff --git a/addons/panku_console/components/lynx_window/lynx_window.tscn b/addons/panku_console/components/lynx_window/lynx_window.tscn index 3cb1929..8b858f7 100644 --- a/addons/panku_console/components/lynx_window/lynx_window.tscn +++ b/addons/panku_console/components/lynx_window/lynx_window.tscn @@ -1,14 +1,15 @@ -[gd_scene load_steps=7 format=3 uid="uid://xdco13uda1w"] +[gd_scene load_steps=7 format=3 uid="uid://c74omggfq20i5"] -[ext_resource type="Shader" uid="uid://b68lpjnldit2k" path="res://addons/panku_console/res/shader/frosted_glass.tres" id="1_vslvu"] +[ext_resource type="Shader" path="res://addons/panku_console/res/shader/frosted_glass.gdshader" id="1_63tvc"] [ext_resource type="Script" path="res://addons/panku_console/components/lynx_window/lynx_window.gd" id="2_5uhes"] [ext_resource type="Texture2D" uid="uid://cg4cjiaaowtdb" path="res://addons/panku_console/res/pics/icons8-multiply-32.png" id="3_3vmkx"] [ext_resource type="Texture2D" uid="uid://dlyws6x2sy7n5" path="res://addons/panku_console/res/pics/drop_shadow.png" id="4_fd5qw"] [ext_resource type="Texture2D" uid="uid://cctd4p2wyly50" path="res://addons/panku_console/res/pics/icons8-triangle-32.png" id="5_sml72"] [sub_resource type="ShaderMaterial" id="ShaderMaterial_l0fhi"] -shader = ExtResource("1_vslvu") +shader = ExtResource("1_63tvc") shader_parameter/amount = 2.0 +shader_parameter/fancy = null shader_parameter/noise = 0.123 shader_parameter/sz = 0.25 diff --git a/addons/panku_console/components/resident_logs/log_item.gd b/addons/panku_console/components/resident_logs/log_item.gd index c2029bf..717df57 100644 --- a/addons/panku_console/components/resident_logs/log_item.gd +++ b/addons/panku_console/components/resident_logs/log_item.gd @@ -20,6 +20,11 @@ func amount_pop_anim(): tween2.tween_property(amount_panel, "scale", Vector2(1, 1), 0.05) func _ready(): + content_label.meta_clicked.connect( + func(meta): + OS.shell_open(str(meta)) + ) + await get_tree().process_frame var tween = get_tree().create_tween() modulate.a = 0.0 diff --git a/addons/panku_console/components/resident_logs/log_item.tscn b/addons/panku_console/components/resident_logs/log_item.tscn index e1fd2f6..3681c4e 100644 --- a/addons/panku_console/components/resident_logs/log_item.tscn +++ b/addons/panku_console/components/resident_logs/log_item.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=2 format=3] +[gd_scene load_steps=2 format=3 uid="uid://c708ijd74a17d"] [ext_resource type="Script" path="res://addons/panku_console/components/resident_logs/log_item.gd" id="1_ddump"] @@ -12,19 +12,16 @@ metadata/amount_label = NodePath("Amount/MarginContainer/Label") metadata/amount_panel = NodePath("Amount") [node name="Content" type="PanelContainer" parent="."] -layout_mode = 2 offset_right = 290.0 offset_bottom = 26.0 size_flags_horizontal = 3 [node name="MarginContainer" type="MarginContainer" parent="Content"] -layout_mode = 2 offset_right = 290.0 offset_bottom = 26.0 theme_override_constants/margin_left = 8 [node name="RichTextLabel" type="RichTextLabel" parent="Content/MarginContainer"] -layout_mode = 2 offset_left = 8.0 offset_right = 290.0 offset_bottom = 26.0 @@ -32,20 +29,17 @@ bbcode_enabled = true fit_content_height = true [node name="Amount" type="PanelContainer" parent="."] -layout_mode = 2 offset_left = 294.0 offset_right = 320.0 offset_bottom = 26.0 [node name="MarginContainer" type="MarginContainer" parent="Amount"] -layout_mode = 2 offset_right = 26.0 offset_bottom = 26.0 theme_override_constants/margin_left = 4 theme_override_constants/margin_right = 4 [node name="Label" type="Label" parent="Amount/MarginContainer"] -layout_mode = 2 offset_left = 4.0 offset_right = 22.0 offset_bottom = 26.0 diff --git a/addons/panku_console/components/utils.gd b/addons/panku_console/components/utils.gd index cd33e35..98e80d0 100644 --- a/addons/panku_console/components/utils.gd +++ b/addons/panku_console/components/utils.gd @@ -50,7 +50,9 @@ const type_names = { static func generate_help_text_from_script(script:Script): var result = ["[color=cyan][b]User script defined identifiers[/b][/color]: "] var env_info = extract_info_from_script(script) - for k in env_info.keys().sort(): + var keys = env_info.keys() + keys.sort() + for k in keys: result.push_back("%s - [i]%s[/i]"%[k + env_info[k]["bbcode_postfix"], env_info[k]["help"]]) return "\n".join(PackedStringArray(result)) @@ -66,7 +68,7 @@ static func extract_info_from_script(script:Script): if m["name"] != "" and m["name"].is_valid_identifier() and !m["name"].begins_with("_"): var args = [] for a in m["args"]: - args.push_back("%s[color=gray]:[/color][color=orange]%s[/color]"%[a["name"], type_names[a["type"]]]) + args.push_back("[color=cyan]%s[/color][color=gray]:[/color][color=orange]%s[/color]"%[a["name"], type_names[a["type"]]]) result[m["name"]] = { "type": "method", "bbcode_postfix": "(%s)"%("[color=gray], [/color]".join(PackedStringArray(args))) diff --git a/addons/panku_console/console.gd b/addons/panku_console/console.gd index b8ea627..55e12e0 100644 --- a/addons/panku_console/console.gd +++ b/addons/panku_console/console.gd @@ -1,17 +1,38 @@ +## Panku Console. Provide a runtime console so your can run any script expressions in your game! +## +## This class will be an autoload ([code] Console [/code] by default) if you enable the plugin. The basic idea is that you can run [Expression] based on an environment(or base instance) by [method execute]. You can view [code]default_env.gd[/code] to see how to prepare your own environment. +## [br] +## [br] What's more, you can... +## [br] +## [br] ● Send in-game notifications by [method notify] +## [br] ● Output something to the console window by [method output] +## [br] ● Manage widgets plans by [method add_widget], [method save_current_widgets_as], etc. +## [br] ● Lot's of useful expressions defined in [code]default_env.gd[/code]. +## +## @tutorial: https://github.com/Ark2000/PankuConsole class_name PankuConsole extends CanvasLayer +## Emitted when the visibility (hidden/visible) of console window changes. signal console_window_visibility_changed(is_visible:bool) -@export var open_console_action = "open_console" +## The input action used to toggle console. By default it is KEY_QUOTELEFT. +@export var toggle_console_action := "toggle_console" + +## If [code]true[/code], the user can drag the console window. @export var draggable_window := true: set(v): draggable_window = v if _window: _window.draggable = v + +## If [code]true[/code], the user can resize the console window. @export var resizable_window := true: set(v): resizable_window = v if _window: _window.resizable = v +## If [code]true[/code], pause the game when the console window is active. +@export var pause_when_active := true + @onready var _resident_logs = $ResidentLogs @onready var _console_logs = $LynxWindow/Content/ConsoleLogs @onready var _window = $LynxWindow @@ -30,7 +51,7 @@ var _config = PankuConfig.get_config() var _current_hints := {} var _hint_idx := 0 var _current_env := "default" -func set_hint_idx(v): +func _set_hint_idx(v): _hint_idx = v if _current_hints["hints_value"].size() > 0: v = wrapi(v, 0, _current_hints["hints_value"].size()) @@ -42,9 +63,13 @@ func set_hint_idx(v): var env_info = _envs[_current_env].get_meta("panku_env_info") _helpbar_label.text = " [b][color=green][Help][/color][/b] [i]%s[/i]" % env_info[k]["help"] +## Returns whether the console window is opened. func is_console_window_opened(): return _window.visible +## Register an environment that run expressions. +## [br][code]env_name[/code]: the name of the environment +## [br][code]env[/code]: The base instance that runs the expressions. For exmaple your player node. func register_env(env_name:String, env:Object): _envs[env_name] = env _input_area.add_option(env_name) @@ -56,24 +81,27 @@ func register_env(env_name:String, env:Object): if env.get_script(): env.set_meta("panku_env_info", PankuUtils.extract_info_from_script(env.get_script())) +## Return the environment object or [code]null[/code] by its name. func get_env(env_name:String) -> Node: return _envs.get(env_name) +## Remove the environment named [code]env_name[/code] func remove_env(env_name:String): if _envs.has(env_name): _envs.erase(env_name) _input_area.remove_option(env_name) notify("[color=green][Info][/color] [b]%s[/b] env unloaded!"%env_name) +## Output [code]bbcode[/code] to the console window func output(bbcode:String): _console_logs.add_log(bbcode) -# print(bbcode) -func notify(bbcode:String): +## Generate a notification +func notify(bbcode:String) -> void: _resident_logs.add_log(bbcode) _console_logs.add_log(bbcode) -# print(bbcode) - + +## This is exactly what happened when you submit something in the console window. func execute(env:String, exp:String): var result = _execute(env, exp) output("[%s] %s"%[env, exp]) @@ -82,7 +110,7 @@ func execute(env:String, exp:String): else: output("> [color=red]%s[/color]"%(result["result"])) -#this return the expression result +#This only return the expression result func _execute(env:String, exp:String) -> Dictionary: var failed := false var result @@ -101,7 +129,9 @@ func _execute(env:String, exp:String) -> Dictionary: "result": result } -#update config when adding a widget +## Add a new widget to current widgets plan. +## [br]The [code]update_exp[/code] will be executed every [code]update_delay[/code] seconds and the result will be used as display text. +## [br]The [code]pressed_exp[/code] will be executed when the widget is clicked. func add_widget(update_delay:float, env:String, update_exp:String, pressed_exp:String, position:Vector2): var w = _add_widget(update_delay, env, update_exp, pressed_exp, position) save_current_widgets_as(_config["widgets_system"]["current_plan"]) @@ -131,15 +161,20 @@ func _add_widget(update_delay:float, env:String, update_exp:String, pressed_exp: ) return new_widget +## Return a Dictionary contains all widgets plans. +func get_widgets_plans() -> Dictionary: + return _config["widgets_system"] + +## Load a widgets plan func load_widgets_plan(plan:String): var plans = _config["widgets_system"]["plans"] - + #do not have this plan if !plans.has(plan): return false #prepare to load this plan - + #save current if _config["widgets_system"]["current_plan"] != plan: save_current_widgets_as(_config["widgets_system"]["current_plan"]) @@ -151,17 +186,20 @@ func load_widgets_plan(plan:String): #load widgets for winfo in plans[plan]: _add_widget( - winfo.get("update_delay", 1.0), - winfo.get("env", "default"), - winfo.get("update_exp", ""), - winfo.get("pressed_exp", ""), + winfo.get("update_delay", 1.0), + winfo.get("env", "default"), + winfo.get("update_exp", ""), + winfo.get("pressed_exp", ""), winfo.get("position", Vector2(0, 0)) ) _config["widgets_system"]["current_plan"] = plan - + + notify("[color=green][Info][/color] [b]%s[/b] widgets plan loaded!" % plan) + return true +## Save current widgets plan as a new plan. func save_current_widgets_as(plan:String): var d = [] for w in _widgets.get_children(): @@ -169,14 +207,19 @@ func save_current_widgets_as(plan:String): _config["widgets_system"]["plans"][plan] = d _config["widgets_system"]["current_plan"] = plan +## Delete a widgets plan(except current) func delete_widgets_plan(plan:String): if plan == _config["widgets_system"]["current_plan"]: return false _config["widgets_system"]["plans"].erase(plan) return true +## Let's dance! +func party_time(): + _window.material.set("shader_parameter/fancy", 0.1) + func _input(_e): - if Input.is_action_just_pressed(open_console_action): + if Input.is_action_just_pressed(toggle_console_action): _input_area.input.editable = !_window.visible await get_tree().process_frame _window.visible = !_window.visible @@ -203,6 +246,7 @@ func _ready(): _hints.visible = _current_hints["hints_value"].size() > 0 _helpbar.visible = _hints.visible _input_area.input.hints = _current_hints["hints_value"] + _hints.disable_buttons = false _hints.set_hints(_current_hints["hints_bbcode"], _current_hints["hints_icon"]) _hint_idx = -1 _helpbar_label.text = " [b][color=green][Hint][/color][/b] Use [b]TAB[/b] or [b]up/down[/b] to autocomplete!" @@ -213,17 +257,30 @@ func _ready(): ) _input_area.next_hint.connect( func(): - set_hint_idx(_hint_idx + 1) + _set_hint_idx(_hint_idx + 1) ) _input_area.prev_hint.connect( func(): if _hint_idx == -1: _hint_idx = 0 - set_hint_idx(_hint_idx - 1) + _set_hint_idx(_hint_idx - 1) + ) + _input_area.navigate_histories.connect( + func(histories, id): + if histories.size() > 0: + _hints.disable_buttons = true + _hints.set_hints(histories, []) + _hints.selected = id + _hints.visible = true + else: + _hints.visible = false + _helpbar.visible = _hints.visible + _helpbar_label.text = "[b][color=green][Hint][/color][/b] Use [b]up/down[/b] to navigate through submit histories!" + ) _hints.hint_button_clicked.connect( func(i:int): - set_hint_idx(i) + _set_hint_idx(i) ) _window.hide() _window.draggable = draggable_window @@ -231,6 +288,8 @@ func _ready(): _window.visibility_changed.connect( func(): console_window_visibility_changed.emit(_window.visible) + if pause_when_active: + get_tree().paused = _window.visible ) console_window_visibility_changed.connect(_glow.set_visible) _helpbar.hide() @@ -238,10 +297,10 @@ func _ready(): #check the action key #the open console action can be change in the export options of panku.tscn - assert(InputMap.has_action(open_console_action), "Please specify an action to open the console!") + assert(InputMap.has_action(toggle_console_action), "Please specify an action to open the console!") #load widgets plan last time - await get_tree().create_timer(0.5).timeout + await get_tree().create_timer(1.0).timeout load_widgets_plan(_config["widgets_system"]["current_plan"]) func _notification(what): diff --git a/addons/panku_console/console.tscn b/addons/panku_console/console.tscn index 861a546..22a66e3 100644 --- a/addons/panku_console/console.tscn +++ b/addons/panku_console/console.tscn @@ -1,13 +1,13 @@ -[gd_scene load_steps=12 format=3 uid="uid://diwtnxl41ygfr"] +[gd_scene load_steps=12 format=3 uid="uid://c6neu5ea7cfpg"] [ext_resource type="Script" path="res://addons/panku_console/console.gd" id="1_dohs1"] [ext_resource type="PackedScene" path="res://addons/panku_console/components/resident_logs/resident_logs.tscn" id="2_th8we"] -[ext_resource type="PackedScene" uid="uid://xdco13uda1w" path="res://addons/panku_console/components/lynx_window/lynx_window.tscn" id="3_31oow"] +[ext_resource type="PackedScene" uid="uid://c74omggfq20i5" path="res://addons/panku_console/components/lynx_window/lynx_window.tscn" id="3_31oow"] [ext_resource type="Theme" uid="uid://bbrtkqa42u3ak" path="res://addons/panku_console/res/panku_theme.tres" id="4_bqu35"] [ext_resource type="PackedScene" uid="uid://bcfn2f7rjd5vl" path="res://addons/panku_console/components/console_logs/console_logs.tscn" id="6_5deu3"] [ext_resource type="PackedScene" uid="uid://b3jf18wonocnv" path="res://addons/panku_console/components/hints_list/hints_list.tscn" id="7_n7sin"] [ext_resource type="PackedScene" uid="uid://dp5scckgpkty" path="res://addons/panku_console/components/input_field/input_area.tscn" id="7_olqdb"] -[ext_resource type="Shader" uid="uid://b68lpjnldit2k" path="res://addons/panku_console/res/shader/frosted_glass.tres" id="8_bpw5w"] +[ext_resource type="Shader" path="res://addons/panku_console/res/shader/frosted_glass.gdshader" id="8_bpw5w"] [ext_resource type="Script" path="res://addons/panku_console/default_env.gd" id="8_xaqop"] [sub_resource type="LabelSettings" id="LabelSettings_nth2r"] @@ -18,13 +18,16 @@ shadow_color = Color(0, 0, 0, 0.501961) [sub_resource type="ShaderMaterial" id="ShaderMaterial_ui6f0"] resource_local_to_scene = true shader = ExtResource("8_bpw5w") -shader_parameter/amount = 0.1 -shader_parameter/noise = 0.0 +shader_parameter/amount = 0.2 +shader_parameter/fancy = 0.0 +shader_parameter/noise = null shader_parameter/sz = null [node name="Console" type="CanvasLayer"] +process_mode = 3 layer = 128 script = ExtResource("1_dohs1") +pause_when_active = false [node name="ResidentLogs" parent="." instance=ExtResource("2_th8we")] anchors_preset = 9 @@ -47,8 +50,17 @@ grow_horizontal = 1 grow_vertical = 1 theme = ExtResource("4_bqu35") +[node name="Title" parent="LynxWindow" index="0"] +layout_mode = 3 + +[node name="ExitButton" parent="LynxWindow/Title" index="0"] +layout_mode = 3 +offset_left = -22.703 +offset_top = -0.188995 +offset_right = 1.297 +offset_bottom = -0.188995 + [node name="Label" type="Label" parent="LynxWindow/Title" index="1"] -layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 @@ -62,10 +74,10 @@ label_settings = SubResource("LabelSettings_nth2r") vertical_alignment = 1 [node name="Content" parent="LynxWindow" index="1"] +layout_mode = 3 color = Color(0, 0, 0, 0.25098) [node name="ConsoleLogs" parent="LynxWindow/Content" index="0" instance=ExtResource("6_5deu3")] -layout_mode = 1 anchors_preset = 15 anchor_right = 1.0 anchor_bottom = 1.0 @@ -75,7 +87,6 @@ grow_horizontal = 2 grow_vertical = 2 [node name="InputArea" parent="LynxWindow/Content" index="1" instance=ExtResource("7_olqdb")] -layout_mode = 1 anchors_preset = 12 anchor_top = 1.0 anchor_right = 1.0 @@ -87,11 +98,9 @@ grow_horizontal = 2 grow_vertical = 0 [node name="HintsList" parent="LynxWindow/Content" index="2" instance=ExtResource("7_n7sin")] -layout_mode = 1 offset_bottom = -43.0 [node name="HelpBar" type="PanelContainer" parent="LynxWindow/Content" index="3"] -layout_mode = 1 anchors_preset = 12 anchor_top = 1.0 anchor_right = 1.0 @@ -102,18 +111,30 @@ grow_horizontal = 2 grow_vertical = 0 [node name="ColorRect" type="ColorRect" parent="LynxWindow/Content/HelpBar"] -layout_mode = 2 +offset_right = 484.0 +offset_bottom = 18.0 color = Color(0.0470588, 0.0470588, 0.0470588, 0.882353) [node name="RichTextLabel" type="RichTextLabel" parent="LynxWindow/Content/HelpBar"] custom_minimum_size = Vector2(0, 18) -layout_mode = 2 +offset_right = 484.0 +offset_bottom = 18.0 bbcode_enabled = true text = " [Hint] Use TAB or up/down to autocomplete!" autowrap_mode = 0 shortcut_keys_enabled = false +[node name="Shadow" parent="LynxWindow" index="2"] +layout_mode = 3 + +[node name="ResizeButton" parent="LynxWindow" index="3"] +layout_mode = 3 + +[node name="TextureRect" parent="LynxWindow/ResizeButton" index="0"] +layout_mode = 3 + [node name="GlowEffect" type="CanvasLayer" parent="."] +layer = 128 [node name="ColorRect" type="ColorRect" parent="GlowEffect"] visible = false diff --git a/addons/panku_console/default_env.gd b/addons/panku_console/default_env.gd index 0a39b0f..49cd70c 100644 --- a/addons/panku_console/default_env.gd +++ b/addons/panku_console/default_env.gd @@ -3,12 +3,16 @@ #Panku will generate hints for thoses constants, variables and functions that don't begin with _ extends Node +func _ready(): + await get_parent().ready + get_parent().register_env("default",self) + #you can add const _HELP_xxx to provide help info which will be extracted by panku. -const _HELP_help = "Provide some information you may need" -var help:String = PankuUtils.generate_help_text_from_script(get_script()) +const _HELP_console_help = "Provide some information you may need" +var console_help:String = PankuUtils.generate_help_text_from_script(get_script()) -const _HELP_hints = "Get a random hint!" -var hints: +const _HELP_console_hints = "Get a random hint!" +var console_hints: get: var words = [ "[color=orange]Thank you for using Panku Console![/color]", @@ -18,58 +22,61 @@ var hints: words.shuffle() get_parent().notify(words[0]) -const _HELP_cls = "clear console logs" -var cls: +const _HELP_console_cls = "Clear console logs" +var console_cls: get: (func(): await get_tree().process_frame get_parent()._console_logs.clear() ).call() +const _HELP_console_enable_notifications = "Toggle notification system" +func console_enable_notifications(b:bool): + get_parent()._resident_logs.visible = b -const _HELP_performance_info = "show performance info" -var performance_info: - get: - return "FPS: %d | Mem: %.2fMB | Objs: %d" % [Engine.get_frames_per_second(), OS.get_static_memory_usage()/1048576.0, Performance.get_monitor(Performance.OBJECT_COUNT)] - -const _HELP_w_plans = "Show all widgets plans" -var w_plans: - get: - var c = get_parent()._config["widgets_system"] - return "[b]Current Plan[/b]: %s\n[b]All Plans[/b]: %s" %[c["current_plan"], ",".join(PackedStringArray(c["plans"].keys()))] +const _HELP_console_notify = "Send a notification" +func console_notify(s:String): + get_parent().notify(s) -const _HELP_w_perf = "Add a widget to monitor performance" -var w_perf: +const _HELP_console_party_time = "Let's dance!" +var console_party_time: get: - get_parent().add_widget( - 1.0, - "default", - "performance_info", - "", - Vector2(0, 0) - ) + get_parent().party_time() -func _ready(): - await get_parent().ready - get_parent().register_env("default",self) - -const _HELP_fullscreen = "toggle [fullscreen / window] mode" -func fullscreen(b:bool): +const _HELP_engine_fullscreen = "Toggle [fullscreen / window] mode" +func engine_fullscreen(b:bool): if b: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN) else: DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED) -const _HELP_enable_notifications = "toggle notification system" -func enable_notifications(b:bool): - get_parent()._resident_logs.visible = b +const _HELP_engine_time_scale = "Equals to [color=green]Engine.time_scale[/color]" +func engine_time_scale(val:float): + Engine.time_scale = val -const _HELP_notify = "Send a notification" -func notify(s:String): - get_parent().notify(s) +const _HELP_engine_performance_info = "Show performance info" +var engine_performance_info: + get: + return "FPS: %d | Mem: %.2fMB | Objs: %d" % [Engine.get_frames_per_second(), OS.get_static_memory_usage()/1048576.0, Performance.get_monitor(Performance.OBJECT_COUNT)] -const _HELP_w_watch = "Add a widget to watch an expression" -func w_watch(env:String, exp:String): +const _HELP_engine_snap_screenshot = "Snap a screenshot of current window" +var engine_snap_screenshot: + get: + var image = get_viewport().get_texture().get_image() + var time = str(int(Time.get_unix_time_from_system() * 1000.0)) + var file_name = "screenshot_%s.png" % time + var path = "user://".path_join(file_name) + var real_path = OS.get_user_data_dir().path_join(file_name) + image.save_png(path) + console_notify("[b]Screenshot[/b] saved at [color=green][url=%s]%s[/url][/color]" % [real_path, real_path]) + +const _HELP_engine_quit = "Quit application" +var engine_quit: + get: + get_tree().quit() + +const _HELP_widget_watch = "Add a widget to watch an expression" +func widget_watch(env:String, exp:String): get_parent().add_widget( 0.1, env, @@ -78,8 +85,8 @@ func w_watch(env:String, exp:String): Vector2(0, 0) ) -const _HELP_w_button = "Add an expression widget button" -func w_button(display_name:String, env:String, exp:String): +const _HELP_widget_button = "Add an expression widget button" +func widget_button(display_name:String, env:String, exp:String): get_parent().add_widget( 9223372036854775807, env, @@ -88,18 +95,35 @@ func w_button(display_name:String, env:String, exp:String): Vector2(0, 0) ) -const _HELP_w_save_as = "Save current widgets as a new plan" -func w_save_as(plan:String): +const _HELP_widget_plans = "Show all widgets plans" +var widget_plans: + get: + var c = get_parent()._config["widgets_system"] + return "[b]Current Plan[/b]: %s\n[b]All Plans[/b]: %s" %[c["current_plan"], ",".join(PackedStringArray(c["plans"].keys()))] + +const _HELP_widget_perf = "Add a widget to monitor performance" +var widget_perf: + get: + get_parent().add_widget( + 1.0, + "default", + "engine_performance_info", + "", + Vector2(0, 0) + ) + +const _HELP_widget_save_as = "Save current widgets as a new plan" +func widget_save_as(plan:String): get_parent().save_current_widgets_as(plan) -const _HELP_w_delete = "Delete a widgets plan (Except for current plan)" -func w_delete(plan:String): +const _HELP_widget_delete = "Delete a widgets plan (Except for current plan)" +func widget_delete(plan:String): if get_parent()._config["widgets_system"]["current_plan"] == plan: return "failed" get_parent().delete_widgets_plan(plan) -const _HELP_w_load = "Clear current widgets and load a plan" -func w_load(plan:String): +const _HELP_widget_load = "Clear current widgets and load a plan" +func widget_load(plan:String): if !get_parent().load_widgets_plan(plan): (func(): await get_tree().process_frame diff --git a/addons/panku_console/plugin.gd b/addons/panku_console/plugin.gd index 9c539f7..15fdb2c 100644 --- a/addons/panku_console/plugin.gd +++ b/addons/panku_console/plugin.gd @@ -9,7 +9,7 @@ func _enter_tree(): add_autoload_singleton("Console", "res://addons/panku_console/console.tscn") var default_open_console_event = InputEventKey.new() default_open_console_event.physical_keycode = KEY_QUOTELEFT - ProjectSettings.set_setting("input/open_console", {"deadzone":0.5,"events":[default_open_console_event]}) + ProjectSettings.set_setting("input/toggle_console", {"deadzone":0.5,"events":[default_open_console_event]}) ProjectSettings.save() print("Panku Console was initialized!") print("Project page: https://github.com/Ark2000/PankuConsole") @@ -17,6 +17,6 @@ func _enter_tree(): func _exit_tree(): # Clean-up of the plugin goes here. remove_autoload_singleton("Console") - ProjectSettings.clear("input/open_console") + ProjectSettings.clear("input/toggle_console") ProjectSettings.save() print("Panku Console was unloaded!") diff --git a/addons/panku_console/res/shader/frosted_glass.tres b/addons/panku_console/res/shader/frosted_glass.gdshader similarity index 62% rename from addons/panku_console/res/shader/frosted_glass.tres rename to addons/panku_console/res/shader/frosted_glass.gdshader index b9c952a..331ecff 100644 --- a/addons/panku_console/res/shader/frosted_glass.tres +++ b/addons/panku_console/res/shader/frosted_glass.gdshader @@ -1,16 +1,14 @@ -[gd_resource type="Shader" format=3 uid="uid://b68lpjnldit2k"] - -[resource] -code = "shader_type canvas_item; +shader_type canvas_item; uniform float amount: hint_range(0.0, 5.0); uniform float noise: hint_range(0.0, 1.0); uniform float sz: hint_range(0.0, 0.5); +uniform float fancy: hint_range(0.0, 1.0) = 0.0; void fragment() { vec3 col1 = textureLod(SCREEN_TEXTURE, SCREEN_UV, amount).rgb; + vec3 col2 = vec3((sin(UV.x + TIME*1.0) + 1.0)/2.0, (sin(UV.y+TIME*1.5))/2.0,(sin(UV.x * UV.y + TIME*2.0)+1.0)/2.0); float m = step(fract((sz / SCREEN_PIXEL_SIZE.x)*SCREEN_UV.x), 0.5) * step(fract((sz / SCREEN_PIXEL_SIZE.y)*SCREEN_UV.y), 0.5); col1 = col1 * (m * noise + (1.0 - noise)); - COLOR.rgb = col1; -} -" + COLOR.rgb = mix(col1, col2, fancy); +} \ No newline at end of file