Skip to content

Commit

Permalink
Add addon panel.
Browse files Browse the repository at this point in the history
  • Loading branch information
raldone01 committed Jan 16, 2024
1 parent c689b8c commit ef4723d
Show file tree
Hide file tree
Showing 15 changed files with 157 additions and 10 deletions.
File renamed without changes.
File renamed without changes.
6 changes: 4 additions & 2 deletions .github/workflows/generate_docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,20 @@ jobs:
git clone https://github.com/GDQuest/gdscript-docs-maker.git
cd gdscript-docs-maker
git checkout 07cb0d8f0af6da745260d7bfabfc475504c413f1
git apply ../.github/workflows/gdscript_docs_maker.patch
git apply ../.github/workflows/gdscript_docs_maker/gdscript_docs_maker.patch
docker build -t gdscript-docs-maker .
cd ..
- name: Generate Documentation
run: |
cp .github/workflows/gdscript_docs_maker/project.godot ./
docker run --rm -v ${{ github.workspace }}:/game -v ${{ github.workspace }}/docs/api-md:/output docker.io/library/gdscript-docs-maker /game -o /output
- name: Fix permissions and create output directory
run: |
sudo chown -R $USER:$USER docs/
mkdir -p docs/api
tree -la docs/api-md
- name: Download CSS
run: |
Expand All @@ -44,7 +46,7 @@ jobs:
--standalone
--css github-markdown.min.css
--output=docs/api/index.tmp.html
docs/api-md/logger.gd.md
docs/api-md/funcs/logger.gd.md
- name: Fix body class
run: |
Expand Down
61 changes: 61 additions & 0 deletions addons_shared_gen/addons_panel_manager.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
@tool
extends Node

class AddonsPanelManager:
const ADDONS_DOCK_NAME = "addons_dock_2c39d5937171140c1faaadb702029b32"
static var _addons_dock: Control
var _editor_plugin: EditorPlugin
var _main_panel: Control
var _tree: SceneTree

func _init(p_editor_plugin) -> void:
_editor_plugin = p_editor_plugin
_tree = EditorInterface.get_editor_main_screen().get_tree()

func _find_addons_dock() -> Control:
var group = _tree.get_nodes_in_group(ADDONS_DOCK_NAME)
if group.size() > 0:
return group[0]
return null

func add_main_panel(p_panel) -> void:
if not _addons_dock:
_addons_dock = _find_addons_dock()
if not _addons_dock:
_addons_dock = preload("addons_panel_manager/scenes/ui_addons_dock.tscn").instantiate()
_addons_dock.add_to_group(ADDONS_DOCK_NAME)
_editor_plugin.add_control_to_dock(EditorPlugin.DOCK_SLOT_RIGHT_UL, _addons_dock)

_main_panel = p_panel
_addons_dock.child_container.add_child(p_panel)
_sort_children_alphabetically(_addons_dock.child_container)

func _sort_children_alphabetically(p_container) -> void:
const LABEL_NAME = "AddonTitle"
var children: Array[Dictionary] = []
for child in p_container.get_children():
var label = child.find_child(LABEL_NAME)
children.append({"label": label, "node": child})

var sorter := func (p_a: Dictionary, p_b: Dictionary):
var a_label: Label = p_a["label"]
var b_label: Label = p_b["label"]

# sort null labels to the end
if a_label == null or b_label == null:
return false

return a_label.get_text().to_lower() < b_label.get_text().to_lower()

children.sort_custom(sorter)
for child in children:
p_container.move_child(child["node"], p_container.get_child_count() - 1)

func remove_main_panel() -> void:
if not _addons_dock:
return
_addons_dock.child_container.remove_child(_main_panel)
if _addons_dock.child_container.get_child_count() == 0:
_editor_plugin.remove_control_from_docks(_addons_dock)
_addons_dock.free()
_addons_dock = null
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
@tool
extends Control

@onready
var child_container: Control = $ScrollContainer/VBoxContainer
20 changes: 20 additions & 0 deletions addons_shared_gen/addons_panel_manager/scenes/ui_addons_dock.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[gd_scene load_steps=2 format=3 uid="uid://lgxr7t7u3bh3"]

[ext_resource type="Script" path="ui_addons_dock.gd" id="1_cqnue"]

[node name="Addons" type="HBoxContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_cqnue")

[node name="ScrollContainer" type="ScrollContainer" parent="."]
layout_mode = 2
size_flags_horizontal = 3

[node name="VBoxContainer" type="VBoxContainer" parent="ScrollContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://cosor3lua7vj1"
path="res://.godot/imported/plugin_icon_white.png-b7d8c5289899041bbb03288dadb71282.ctex"
path="res://.godot/imported/plugin_icon_white.png-671ada14546390b6b8f0109f37b4df0e.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://addons/gdlogging/assets/icons/plugin_icon_white.png"
dest_files=["res://.godot/imported/plugin_icon_white.png-b7d8c5289899041bbb03288dadb71282.ctex"]
source_file="res://addons/gdlogging/assets/icons_editor/plugin_icon_white.png"
dest_files=["res://.godot/imported/plugin_icon_white.png-671ada14546390b6b8f0109f37b4df0e.ctex"]

[params]

Expand Down
File renamed without changes
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
importer="texture"
type="CompressedTexture2D"
uid="uid://cgq13w2s6ciqj"
path="res://.godot/imported/plugin_icon_white.svg-02f81bbe94957e9d93b8d8d467b310c2.ctex"
path="res://.godot/imported/plugin_icon_white.svg-83395dca5a397d54e89502906c35696c.ctex"
metadata={
"has_editor_variant": true,
"vram_texture": false
}

[deps]

source_file="res://addons/gdlogging/assets/icons/plugin_icon_white.svg"
dest_files=["res://.godot/imported/plugin_icon_white.svg-02f81bbe94957e9d93b8d8d467b310c2.ctex"]
source_file="res://addons/gdlogging/assets/icons_editor/plugin_icon_white.svg"
dest_files=["res://.godot/imported/plugin_icon_white.svg-83395dca5a397d54e89502906c35696c.ctex"]

[params]

Expand Down
File renamed without changes
File renamed without changes.
11 changes: 9 additions & 2 deletions main_gdlogging.gd
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
@tool
extends EditorPlugin

var main_panel: Control
var addons_panel_manager: Variant

func _enter_tree() -> void:
add_autoload_singleton("Log", "logger.gd")
add_autoload_singleton("Log", "res://addons/gdlogging/funcs/logger.gd")
addons_panel_manager = load("res://addons/gdlogging/addons_shared_gen/addons_panel_manager.gd").AddonsPanelManager.new(self)
main_panel = preload("res://addons/gdlogging/scenes_editor/ui_addon_panel.tscn").instantiate()
addons_panel_manager.add_main_panel(main_panel)

func _exit_tree() -> void:
remove_autoload_singleton("Log")
addons_panel_manager.remove_main_panel()

func _get_plugin_icon():
return preload("assets/icons/plugin_icon_white.svg")
return preload("res://addons/gdlogging/assets/icons_editor/plugin_icon_white.svg")

func _get_plugin_name():
return "gdlogging"
12 changes: 12 additions & 0 deletions scenes_editor/ui_addon_panel.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
@tool
extends Control

@onready
var option_button_log_level: OptionButton = $%OptionButtonLogLevel

func _ready() -> void:
option_button_log_level.connect("item_selected", _on_option_button_log_level_item_selected)

func _on_option_button_log_level_item_selected(p_index: int) -> void:
var log_level: Log.LogLevel = p_index
Log.set_level(log_level)
40 changes: 40 additions & 0 deletions scenes_editor/ui_addon_panel.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[gd_scene load_steps=2 format=3 uid="uid://b02ua2myb78yb"]

[ext_resource type="Script" path="res://addons/gdlogging/scenes_editor/ui_addon_panel.gd" id="1_ykg10"]

[node name="AddonPanel" type="VBoxContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_ykg10")

[node name="AddonTitle" type="Label" parent="."]
layout_mode = 2
theme_type_variation = &"HeaderLarge"
text = "gdlogging"

[node name="HBoxContainer" type="HBoxContainer" parent="."]
layout_mode = 2

[node name="Label" type="Label" parent="HBoxContainer"]
layout_mode = 2
text = "Editor log level"

[node name="OptionButtonLogLevel" type="OptionButton" parent="HBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
item_count = 4
selected = 1
popup/item_0/text = "TRACE"
popup/item_0/id = 0
popup/item_1/text = "DEBUG"
popup/item_1/id = 1
popup/item_2/text = "WARNING"
popup/item_2/id = 2
popup/item_3/text = "ERROR"
popup/item_3/id = 3

[node name="HSeparator" type="HSeparator" parent="."]
layout_mode = 2

0 comments on commit ef4723d

Please sign in to comment.