diff --git a/addons/pnhelper/plugin.cfg b/addons/pnhelper/plugin.cfg new file mode 100644 index 0000000..9d63049 --- /dev/null +++ b/addons/pnhelper/plugin.cfg @@ -0,0 +1,7 @@ +[plugin] + +name="PowerNetworkHelper" +description="Helper tools for connecting devices to power networks" +author="Hamcha" +version="0.1" +script="plugin.gd" diff --git a/addons/pnhelper/plugin.gd b/addons/pnhelper/plugin.gd new file mode 100644 index 0000000..58db313 --- /dev/null +++ b/addons/pnhelper/plugin.gd @@ -0,0 +1,13 @@ +tool +extends EditorPlugin + +var dock + +func _enter_tree(): + dock = preload("res://addons/pnhelper/pngui.tscn").instance() + dock.api = self + add_control_to_dock(DOCK_SLOT_RIGHT_BL, dock) + +func _exit_tree(): + remove_control_from_docks(dock) + dock.free() diff --git a/addons/pnhelper/pngui.gd b/addons/pnhelper/pngui.gd new file mode 100644 index 0000000..c447675 --- /dev/null +++ b/addons/pnhelper/pngui.gd @@ -0,0 +1,51 @@ +tool + +extends Control + +var socketTemplate = preload("res://Actors/Objects/ElectricSocket/ElectricSocket.tscn") + +var api : EditorPlugin + +onready var socket_types = $Commands/MakeSocket/Type + +func _ready(): + # Add make_socket options + socket_types.add_item("SNK", 0) + socket_types.add_item("SRC", 1) + socket_types.add_item("BID", 2) + +func _make_socket(direction: String) -> void: + var socket_dir = null + var socket_type = null + var offset = Vector2.ZERO + match direction: + "up": + socket_dir = ElectricSocket.Direction.DOWN + offset.y = -32 + "left": + socket_dir = ElectricSocket.Direction.RIGHT + offset.x = -32 + "down": + socket_dir = ElectricSocket.Direction.UP + offset.y = 32 + "right": + socket_dir = ElectricSocket.Direction.LEFT + offset.x = 32 + match socket_types.get_selected_id(): + 0: + socket_type = ElectricSocket.Flow.SINK + 1: + socket_type = ElectricSocket.Flow.SOURCE + 2: + socket_type = ElectricSocket.Flow.BIDIRECTIONAL + var map = api.get_editor_interface().get_edited_scene_root() + var sockets = map.get_node("sockets") + var nodes = api.get_editor_interface().get_selection().get_selected_nodes() + for node in nodes: + var socket = socketTemplate.instance() + socket.direction = socket_dir + socket.flow = socket_type + sockets.add_child(socket) + socket.owner = map + socket.global_position = node.global_position + offset + socket.connectionPaths = [socket.get_path_to(node)] diff --git a/addons/pnhelper/pngui.tscn b/addons/pnhelper/pngui.tscn new file mode 100644 index 0000000..1e23073 --- /dev/null +++ b/addons/pnhelper/pngui.tscn @@ -0,0 +1,63 @@ +[gd_scene load_steps=2 format=2] + +[ext_resource path="res://addons/pnhelper/pngui.gd" type="Script" id=1] + +[node name="Mapping tools" type="Control"] +anchor_right = 1.0 +anchor_bottom = 1.0 +script = ExtResource( 1 ) +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="Commands" type="VBoxContainer" parent="."] +anchor_right = 1.0 +anchor_bottom = 1.0 +size_flags_horizontal = 3 +size_flags_vertical = 3 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="MakeSocket" type="HBoxContainer" parent="Commands"] +margin_right = 1280.0 +margin_bottom = 20.0 + +[node name="Label" type="Label" parent="Commands/MakeSocket"] +margin_top = 3.0 +margin_right = 84.0 +margin_bottom = 17.0 +text = "Make socket " + +[node name="Type" type="OptionButton" parent="Commands/MakeSocket"] +margin_left = 88.0 +margin_right = 117.0 +margin_bottom = 20.0 + +[node name="Left" type="Button" parent="Commands/MakeSocket"] +margin_left = 121.0 +margin_right = 141.0 +margin_bottom = 20.0 +text = "<" + +[node name="Up" type="Button" parent="Commands/MakeSocket"] +margin_left = 145.0 +margin_right = 164.0 +margin_bottom = 20.0 +text = "^" + +[node name="Down" type="Button" parent="Commands/MakeSocket"] +margin_left = 168.0 +margin_right = 187.0 +margin_bottom = 20.0 +text = "v" + +[node name="Right" type="Button" parent="Commands/MakeSocket"] +margin_left = 191.0 +margin_right = 211.0 +margin_bottom = 20.0 +text = ">" +[connection signal="pressed" from="Commands/MakeSocket/Left" to="." method="_make_socket" binds= [ "left" ]] +[connection signal="pressed" from="Commands/MakeSocket/Up" to="." method="_make_socket" binds= [ "up" ]] +[connection signal="pressed" from="Commands/MakeSocket/Down" to="." method="_make_socket" binds= [ "down" ]] +[connection signal="pressed" from="Commands/MakeSocket/Right" to="." method="_make_socket" binds= [ "right" ]] diff --git a/project.godot b/project.godot index cd243bd..6a5f8c6 100644 --- a/project.godot +++ b/project.godot @@ -200,6 +200,10 @@ Gotm="*res://gotm/Gotm.gd" window/size/width=1280 window/size/height=800 +[editor_plugins] + +enabled=PoolStringArray( "pnhelper" ) + [gui] theme/custom="res://Graphics/UI/ui_theme.tres"