Add (slightly broken) mapping helper tool

This commit is contained in:
Hamcha 2020-07-16 14:37:37 +02:00
parent e02d1e4cc3
commit 7dc9c90390
Signed by: hamcha
GPG Key ID: 41467804B19A3315
5 changed files with 138 additions and 0 deletions

View File

@ -0,0 +1,7 @@
[plugin]
name="PowerNetworkHelper"
description="Helper tools for connecting devices to power networks"
author="Hamcha"
version="0.1"
script="plugin.gd"

13
addons/pnhelper/plugin.gd Normal file
View File

@ -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()

51
addons/pnhelper/pngui.gd Normal file
View File

@ -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)]

View File

@ -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" ]]

View File

@ -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"