From da43ba87e240b99d6b75efad9624fca6e4171fa0 Mon Sep 17 00:00:00 2001 From: Hamcha Date: Tue, 22 Sep 2020 10:06:17 +0200 Subject: [PATCH] Add fill, start work on adding items --- Actors/Objects/Computer/Computer.gd | 10 ++ Graphics/UI/editor-icons.png | Bin 411 -> 548 bytes Scenes/MapEditor.gd | 138 ++++++++++++++++++++++++---- Scenes/MapEditor.tscn | 93 ++++++++++++++++++- 4 files changed, 219 insertions(+), 22 deletions(-) diff --git a/Actors/Objects/Computer/Computer.gd b/Actors/Objects/Computer/Computer.gd index d414957..f575e10 100644 --- a/Actors/Objects/Computer/Computer.gd +++ b/Actors/Objects/Computer/Computer.gd @@ -17,6 +17,16 @@ var open := false onready var activationRange := $ActivationRange as ActivationRange onready var manager := $PowerManager as PowerManager +static func editor_info(): + var editor_icon = AtlasTexture.new() + editor_icon.atlas = preload("res://Graphics/tgstation/computer.png") + editor_icon.region = Rect2(0, 0, 32, 32) + return { + "name": "Computer", + "scene": load("res://Actors/Objects/Computer/Computer.tscn"), + "icon": editor_icon + } + func _ready(): if not Engine.editor_hint: activationRange.visible = true diff --git a/Graphics/UI/editor-icons.png b/Graphics/UI/editor-icons.png index 416ef72f02f9e4360a55dbfeb1bbf67c723dd09e..ce5a92fef2dd53924132ccc2684644ede47dea65 100644 GIT binary patch delta 536 zcmV+z0_Xjk1Ed6y7k@Aa1^@s6R|5Hm00001b5ch_0Itp)=>Px$-bqA3RA_%W>7M;J0F-B-n?;XeZT4_EiGmXK3W0s6W zE@Eq)@gIJw6d{mgdBjOCH%Lavxb z&Nc(gfLMhr@}6>%*IM#bgfn36StJwvCszT?z=4zAVoipVmbMJR%O=fxPtgI*35&S3 zb|&%^VeNU5&l*^PRpDmw`p+sKo<{fsZDk$z^jY`OrGHRFlz0ZC@N{M`%+>;}M0Mnm z0M1J`Ek|#uLP%cR3UCo>>$z-etQU&jkdl(fyhYwyXW2PTME0O2r;Ty>)i&Z52as^| zV0unyPx$RY^oaR9J=WSX~dp zAPCfE|Nk$$hlPY*kq?C}U3xD~6}c0XvbFZ$x9I$3j4@n`dha;K*GltVn`I0J9Mfzh zaUQOH#UH$~93fC-dc?^uCnORg*WNWjvj|sg;>dQ0=bVeqJbyZb(-HDS-s_kP@4fd5 z@vRkP;M+K5AaVyR$I_juKzau7%$L^w22}`&w8*0vtV~)NwW?SIW#56Sx_{x}FSl+b z9{dw#4c{$*-D@?UScO(E+fI3mZkBj18$d_+EvOK)1GSmk5wqIBS%JbVAAG{&ASxz1 z8zG<3YBB(PJb#M|ZKlm!G;)$XZX%<+Vg}TffEM7K)W}(+XgBk*d TileTab: $layers/tabs.add_child(tab) return tab +func add_object_list(name: String, objects: Array): + var tab := ItemList.new() + tab.connect("item_selected", self, "_item_selected", [tab]) + tab.name = name + for obj in objects: + var editor_info = obj.script.editor_info() + tab.add_item(editor_info.name, editor_info.icon) + tab.set_item_metadata(tab.get_item_count()-1, editor_info) + $objects/tabs.add_child(tab) + +func _item_selected(idx: int, tab: ItemList): + var meta = tab.get_item_metadata(idx) + cursor_sprite.texture = meta.icon + func _toggle_tile_input(enable: bool): input_lock = not enable @@ -192,16 +239,73 @@ func make_tile_texture(tileset: TileSet, id: int) -> AtlasTexture: return tile_icon onready var layers_panel = $layers +onready var objects_panel = $objects onready var brush_panel = $tools/brushPanel +onready var obj_action_panel = $tools/objPanel func _tool_selected(tool_type): layers_panel.visible = false brush_panel.visible = false placing_mode = PlacingMode.NONE + objects_panel.visible = false + obj_action_panel.visible = false match tool_type: "tile": - layers_panel.visible = true + layers_panel.visible = current_brush != "none" brush_panel.visible = true placing_mode = PlacingMode.TILEMAP + "obj": + obj_action_panel.visible = true + objects_panel.visible = current_obj_action == "add" func _set_brush(brush_type: String): current_brush = brush_type + layers_panel.visible = current_brush != "none" + +var ff_cells = {} +var ff_origin = Vector2.ZERO + +const BOUNDS_MAX_X = 40 +const BOUNDS_MAX_Y = 40 + +# Sanity check: force bounds for cell +func ff_is_inbound(cell: Vector2): + return abs(cell.x-ff_origin.x) < BOUNDS_MAX_X and abs(cell.y-ff_origin.y) < BOUNDS_MAX_Y + +func ff_is_valid(tilemap: TileMap, cell: Vector2, matching_tile: int) -> bool: + return ff_is_inbound(cell) and (not ff_cells.has(cell)) and tilemap.get_cellv(cell) == matching_tile + +func ff_get_neighbours(tilemap: TileMap, cell: Vector2, matching_tile: int) -> Array: + var neighbours = [Vector2(cell.x, cell.y-1),Vector2(cell.x-1, cell.y),Vector2(cell.x+1, cell.y), Vector2(cell.x, cell.y+1)] + var out = [] + for neighbour in neighbours: + # Have we checked this already? + if not ff_is_valid(tilemap, neighbour, matching_tile): + continue + out.push_back(neighbour) + return out + +func flood_fill(tilemap: TileMap, pos: Vector2, id: int): + # Reset lists + ff_cells = {} + ff_origin = pos + var current_tile = tilemap.get_cellv(pos) + var queue = ff_get_neighbours(tilemap, pos, current_tile) + place_tile(tilemap, pos, id) + ff_cells[pos] = true + # Depth-first search + while not queue.empty(): + var current = queue.pop_front() + # Have we checked this already? + if not ff_is_valid(tilemap, current, current_tile): + continue + var tile_id = tilemap.get_cellv(current) + if tile_id == current_tile: + ff_cells[current] = true + place_tile(tilemap, current, id) + for neighbour in ff_get_neighbours(tilemap, current, current_tile): + queue.push_front(neighbour) + tilemap.update_bitmask_region() + +func _set_obj_action(action): + current_obj_action = action + objects_panel.visible = action == "add" diff --git a/Scenes/MapEditor.tscn b/Scenes/MapEditor.tscn index c9e2245..b08f060 100644 --- a/Scenes/MapEditor.tscn +++ b/Scenes/MapEditor.tscn @@ -1,4 +1,4 @@ -[gd_scene load_steps=25 format=2] +[gd_scene load_steps=28 format=2] [ext_resource path="res://Graphics/deepspace_mat.tres" type="Material" id=1] [ext_resource path="res://Scenes/InEditorMap.gd" type="Script" id=2] @@ -63,14 +63,26 @@ region = Rect2( 16, 0, 16, 16 ) atlas = ExtResource( 4 ) region = Rect2( 0, 16, 16, 16 ) -[sub_resource type="AtlasTexture" id=11] +[sub_resource type="AtlasTexture" id=10] atlas = ExtResource( 4 ) region = Rect2( 32, 16, 16, 16 ) -[sub_resource type="AtlasTexture" id=10] +[sub_resource type="AtlasTexture" id=11] atlas = ExtResource( 4 ) region = Rect2( 16, 16, 16, 16 ) +[sub_resource type="AtlasTexture" id=12] +atlas = ExtResource( 4 ) +region = Rect2( 0, 32, 16, 16 ) + +[sub_resource type="AtlasTexture" id=13] +atlas = ExtResource( 4 ) +region = Rect2( 16, 32, 16, 16 ) + +[sub_resource type="AtlasTexture" id=14] +atlas = ExtResource( 4 ) +region = Rect2( 32, 32, 16, 16 ) + [node name="Control" type="Control"] anchor_right = 1.0 anchor_bottom = 1.0 @@ -315,7 +327,7 @@ margin_bottom = 56.0 theme = ExtResource( 13 ) toggle_mode = true group = SubResource( 8 ) -icon = SubResource( 11 ) +icon = SubResource( 10 ) flat = false [node name="Fill" type="ToolButton" parent="tools/brushPanel/brush"] @@ -325,7 +337,52 @@ margin_bottom = 86.0 theme = ExtResource( 13 ) toggle_mode = true group = SubResource( 8 ) -icon = SubResource( 10 ) +icon = SubResource( 11 ) +flat = false + +[node name="objPanel" type="PanelContainer" parent="tools"] +visible = false +margin_left = 59.0 +margin_right = 93.0 +margin_bottom = 94.0 +size_flags_vertical = 0 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="brush" type="VBoxContainer" parent="tools/objPanel"] +margin_left = 4.0 +margin_top = 4.0 +margin_right = 30.0 +margin_bottom = 90.0 + +[node name="add" type="ToolButton" parent="tools/objPanel/brush"] +margin_right = 26.0 +margin_bottom = 26.0 +theme = ExtResource( 13 ) +toggle_mode = true +group = SubResource( 8 ) +icon = SubResource( 12 ) +flat = false + +[node name="edit" type="ToolButton" parent="tools/objPanel/brush"] +margin_top = 30.0 +margin_right = 26.0 +margin_bottom = 56.0 +theme = ExtResource( 13 ) +toggle_mode = true +group = SubResource( 8 ) +icon = SubResource( 13 ) +flat = false + +[node name="remove" type="ToolButton" parent="tools/objPanel/brush"] +margin_top = 60.0 +margin_right = 26.0 +margin_bottom = 86.0 +theme = ExtResource( 13 ) +toggle_mode = true +group = SubResource( 8 ) +icon = SubResource( 14 ) flat = false [node name="layers" type="MarginContainer" parent="."] @@ -351,6 +408,29 @@ tab_align = 0 __meta__ = { "_edit_use_anchors_": false } + +[node name="objects" type="MarginContainer" parent="."] +visible = false +anchor_top = 1.0 +anchor_bottom = 1.0 +margin_left = 5.0 +margin_top = -166.0 +margin_right = 172.0 +margin_bottom = -5.0 +size_flags_vertical = 13 +__meta__ = { +"_edit_use_anchors_": false +} + +[node name="tabs" type="TabContainer" parent="objects"] +margin_right = 167.0 +margin_bottom = 161.0 +rect_min_size = Vector2( 0, 80 ) +theme = ExtResource( 12 ) +tab_align = 0 +__meta__ = { +"_edit_use_anchors_": false +} [connection signal="mouse_entered" from="background" to="." method="_toggle_tile_input" binds= [ true ]] [connection signal="mouse_exited" from="background" to="." method="_toggle_tile_input" binds= [ false ]] [connection signal="pressed" from="tools/toolsPanel/tools/placeTile" to="." method="_tool_selected" binds= [ "tile" ]] @@ -358,3 +438,6 @@ __meta__ = { [connection signal="pressed" from="tools/brushPanel/brush/FreeHand" to="." method="_set_brush" binds= [ "freehand" ]] [connection signal="pressed" from="tools/brushPanel/brush/Rect" to="." method="_set_brush" binds= [ "rect" ]] [connection signal="pressed" from="tools/brushPanel/brush/Fill" to="." method="_set_brush" binds= [ "fill" ]] +[connection signal="pressed" from="tools/objPanel/brush/add" to="." method="_set_obj_action" binds= [ "add" ]] +[connection signal="pressed" from="tools/objPanel/brush/edit" to="." method="_set_obj_action" binds= [ "edit" ]] +[connection signal="pressed" from="tools/objPanel/brush/remove" to="." method="_set_obj_action" binds= [ "remove" ]]