Skip to content

Commit

Permalink
✨Improvements
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Ark2000 committed Dec 5, 2022
1 parent c49eab3 commit 555bf90
Show file tree
Hide file tree
Showing 16 changed files with 252 additions and 131 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.godot/

# Others
stats/
test/
icon.svg
icon.svg.import
Expand Down
32 changes: 23 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
<img src="https://github.com/Ark2000/Files/blob/main/F2.gif?raw=true" width = "640" height = "360" alt="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

Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions addons/panku_console/components/config.gd
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ 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": "",
},
{
"position": Vector2(0, 0),
"update_delay": 9223372036854775807,
"env": "default",
"update_exp": '"Hint!"',
"pressed_exp": 'hints'
"pressed_exp": 'console_hints'
},
],
"empty": []
Expand Down
16 changes: 11 additions & 5 deletions addons/panku_console/components/hints_list/hints_list.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions addons/panku_console/components/input_field/input_area.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 3 additions & 8 deletions addons/panku_console/components/input_field/input_area.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -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(".")
Expand All @@ -29,19 +28,15 @@ 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"
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
12 changes: 6 additions & 6 deletions addons/panku_console/components/input_field/input_field.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 4 additions & 3 deletions addons/panku_console/components/lynx_window/lynx_window.tscn
Original file line number Diff line number Diff line change
@@ -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

Expand Down
5 changes: 5 additions & 0 deletions addons/panku_console/components/resident_logs/log_item.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 1 addition & 7 deletions addons/panku_console/components/resident_logs/log_item.tscn
Original file line number Diff line number Diff line change
@@ -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"]

Expand All @@ -12,40 +12,34 @@ 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
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
Expand Down
6 changes: 4 additions & 2 deletions addons/panku_console/components/utils.gd
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand All @@ -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)))
Expand Down
Loading

0 comments on commit 555bf90

Please sign in to comment.