More work on map editor

This commit is contained in:
Hamcha 2020-09-18 01:47:16 +02:00
parent 18090a86aa
commit 0fa89de972
Signed by: hamcha
GPG key ID: 41467804B19A3315
10 changed files with 347 additions and 36 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 411 B

View file

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="StreamTexture"
path="res://.import/editor-icons.png-19e09808b25bd1fc0ab5c47cf04a47fd.stex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://Graphics/UI/editor-icons.png"
dest_files=[ "res://.import/editor-icons.png-19e09808b25bd1fc0ab5c47cf04a47fd.stex" ]
[params]
compress/mode=0
compress/lossy_quality=0.7
compress/hdr_mode=0
compress/bptc_ldr=0
compress/normal_map=0
flags/repeat=0
flags/filter=false
flags/mipmaps=false
flags/anisotropic=false
flags/srgb=2
process/fix_alpha_border=true
process/premult_alpha=false
process/HDR_as_SRGB=false
process/invert_color=false
stream=false
size_limit=0
detect_3d=true
svg/scale=1.0

View file

@ -0,0 +1,13 @@
[gd_resource type="StyleBoxFlat" format=2]
[resource]
content_margin_left = 5.0
content_margin_right = 5.0
content_margin_top = 5.0
content_margin_bottom = 5.0
bg_color = Color( 0.6, 0.6, 0.6, 0.392157 )
corner_radius_top_left = 2
corner_radius_top_right = 2
corner_radius_bottom_right = 2
corner_radius_bottom_left = 2
anti_aliasing = false

View file

@ -0,0 +1,7 @@
[gd_resource type="StyleBoxEmpty" format=2]
[resource]
content_margin_left = 5.0
content_margin_right = 5.0
content_margin_top = 5.0
content_margin_bottom = 5.0

View file

@ -0,0 +1,19 @@
[gd_resource type="StyleBoxFlat" format=2]
[resource]
content_margin_left = 5.0
content_margin_right = 5.0
content_margin_top = 5.0
content_margin_bottom = 5.0
bg_color = Color( 0.196078, 0.180392, 0.313726, 1 )
border_width_left = 1
border_width_top = 1
border_width_right = 1
border_width_bottom = 1
border_color = Color( 0.54902, 0.54902, 0.576471, 0.784314 )
corner_radius_top_left = 2
corner_radius_top_right = 2
corner_radius_bottom_right = 2
corner_radius_bottom_left = 2
corner_detail = 4
anti_aliasing = false

View file

@ -2,13 +2,17 @@ extends ScrollContainer
class_name TileTab
const button_theme = preload("res://Scenes/Editor/ToolButtonTheme.tres")
signal tile_selected(id)
func add_entry(id: int, group: ButtonGroup, icon: Texture):
var node := Button.new()
var node := ToolButton.new()
node.toggle_mode = true
node.icon = icon
node.group = group
node.flat = false
node.theme = button_theme
node.connect("pressed", self, "_pressed", [id])
$list.add_child(node)

View file

@ -0,0 +1,28 @@
[gd_resource type="Theme" load_steps=7 format=2]
[ext_resource path="res://Scenes/Editor/Styles/ToolNormal.tres" type="StyleBox" id=1]
[ext_resource path="res://Scenes/Editor/Styles/ToolPressed.tres" type="StyleBox" id=2]
[ext_resource path="res://Scenes/Editor/Styles/ToolHover.tres" type="StyleBox" id=3]
[sub_resource type="DynamicFontData" id=1]
font_path = "res://Graphics/UI/iosevka-aile-regular.ttf"
[sub_resource type="DynamicFont" id=2]
size = 12
use_mipmaps = true
font_data = SubResource( 1 )
[sub_resource type="StyleBoxEmpty" id=3]
[resource]
ToolButton/colors/font_color = Color( 0.88, 0.88, 0.88, 1 )
ToolButton/colors/font_color_disabled = Color( 0.9, 0.95, 1, 0.3 )
ToolButton/colors/font_color_hover = Color( 0.94, 0.94, 0.94, 1 )
ToolButton/colors/font_color_pressed = Color( 1, 1, 1, 1 )
ToolButton/constants/hseparation = 3
ToolButton/fonts/font = SubResource( 2 )
ToolButton/styles/disabled = null
ToolButton/styles/focus = SubResource( 3 )
ToolButton/styles/hover = ExtResource( 3 )
ToolButton/styles/normal = ExtResource( 1 )
ToolButton/styles/pressed = ExtResource( 2 )

View file

@ -34,10 +34,12 @@ var placing := false
var deleting := false
var placing_mode = PlacingMode.NONE
var placing_layer = null
var placing_tile_id := 0
var placing_tile_id := -1
var current_brush := "none"
# Cursor variables
var cursor_pos := Vector2.ZERO
var pressed_pos := Vector2.ZERO
const TILE_SIZE := 32
@ -54,11 +56,10 @@ func _input(ev: InputEvent):
var mouse_offset: Vector2 = (ev.global_position - map_node.global_position) / tile_snap
var new_cursor_pos := Vector2(floor(mouse_offset.x), floor(mouse_offset.y))
if new_cursor_pos != cursor_pos:
var old_pos = cursor_pos
cursor_pos = new_cursor_pos
if placing:
place_tile()
elif deleting:
delete_tile()
if placing or deleting:
handle_held_cursor_move(old_pos, new_cursor_pos)
cursor.position = cursor_pos * TILE_SIZE
if ev is InputEventMouseButton:
@ -66,12 +67,13 @@ func _input(ev: InputEvent):
if mouse.pressed:
match ev.button_index:
BUTTON_LEFT:
# Place tile
place_tile()
if current_brush == "freehand":
place_tiles([cursor_pos], placing_tile_id)
placing = true
pressed_pos = cursor_pos
BUTTON_RIGHT:
# Place tile
delete_tile()
if current_brush == "freehand":
place_tiles([cursor_pos], -1)
deleting = true
BUTTON_WHEEL_UP:
# Zoom in
@ -98,6 +100,8 @@ func _input(ev: InputEvent):
else:
match ev.button_index:
BUTTON_LEFT:
if current_brush == "rect":
place_rect(pressed_pos, cursor_pos, placing_tile_id)
placing = false
BUTTON_RIGHT:
deleting = false
@ -105,31 +109,45 @@ func _input(ev: InputEvent):
dragging = false
map_node.global_position = view_origin - (mouse_origin - ev.global_position)
func place_tile():
match placing_mode:
PlacingMode.NONE:
# Do nothing
pass
PlacingMode.OBJECT:
# TODO
pass
PlacingMode.TILEMAP:
var layer := placing_layer as TileMap
layer.set_cellv(cursor_pos, placing_tile_id)
layer.update_bitmask_area(cursor_pos)
func handle_held_cursor_move(old_pos: Vector2, new_pos: Vector2):
match current_brush:
"freehand":
var id = placing_tile_id
# If deleting, null tile instead
if deleting:
id = -1
place_tiles([new_pos], id)
func delete_tile():
match placing_mode:
PlacingMode.NONE:
# Do nothing
pass
PlacingMode.OBJECT:
# TODO
pass
PlacingMode.TILEMAP:
var layer := placing_layer as TileMap
layer.set_cellv(cursor_pos, -1)
layer.update_bitmask_area(cursor_pos)
func place_rect(a: Vector2, b: Vector2, id: int):
if placing_layer == null:
return
var layer := placing_layer as TileMap
# Sort coordinates
var x_ord = Vector2(a.x, b.x)
var y_ord = Vector2(a.y, b.y)
if a.x > b.x:
x_ord = Vector2(b.x, a.x)
if a.y > b.y:
y_ord = Vector2(b.y, a.y)
var positions = []
for x in range(x_ord.x, x_ord.y+1):
layer.set_cellv(Vector2(x, a.y), id)
layer.set_cellv(Vector2(x, b.y), id)
for y in range(y_ord.x, y_ord.y+1):
layer.set_cellv(Vector2(a.x, y), id)
layer.set_cellv(Vector2(b.x, y), id)
layer.update_bitmask_region(a, b)
func place_tiles(positions: Array, id: int):
if placing_layer == null:
return
var layer := placing_layer as TileMap
for pos in positions:
# Place tile
layer.set_cellv(pos, id)
for pos in positions:
# Update bitmask
layer.update_bitmask_area(pos)
var group := ButtonGroup.new()
@ -169,7 +187,21 @@ func make_tile_texture(tileset: TileSet, id: int) -> AtlasTexture:
tileset.autotile_get_icon_coordinate(id) * tile_size,
tile_size
)
print(tile_icon.region)
TileSet.SINGLE_TILE:
tile_icon.region = tileset.tile_get_region(id)
return tile_icon
onready var layers_panel = $layers
onready var brush_panel = $tools/brushPanel
func _tool_selected(tool_type):
layers_panel.visible = false
brush_panel.visible = false
placing_mode = PlacingMode.NONE
match tool_type:
"tile":
layers_panel.visible = true
brush_panel.visible = true
placing_mode = PlacingMode.TILEMAP
func _set_brush(brush_type: String):
current_brush = brush_type

View file

@ -1,8 +1,9 @@
[gd_scene load_steps=16 format=2]
[gd_scene load_steps=25 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]
[ext_resource path="res://Graphics/tgstation/walls.tres" type="TileSet" id=3]
[ext_resource path="res://Graphics/UI/editor-icons.png" type="Texture" id=4]
[ext_resource path="res://Graphics/tgstation/base.tres" type="TileSet" id=5]
[ext_resource path="res://Graphics/tgstation/floor.tres" type="TileSet" id=6]
[ext_resource path="res://Graphics/tgstation/cables.tres" type="TileSet" id=7]
@ -11,6 +12,7 @@
[ext_resource path="res://Scenes/MapEditor.gd" type="Script" id=10]
[ext_resource path="res://Graphics/UI/grid.png" type="Texture" id=11]
[ext_resource path="res://Graphics/UI/ui_theme.tres" type="Theme" id=12]
[ext_resource path="res://Scenes/Editor/ToolButtonTheme.tres" type="Theme" id=13]
[sub_resource type="StyleBoxFlat" id=1]
content_margin_left = 15.0
@ -45,6 +47,30 @@ corner_radius_bottom_left = 3
content_margin_left = 10.0
content_margin_right = 10.0
[sub_resource type="ButtonGroup" id=5]
[sub_resource type="AtlasTexture" id=6]
atlas = ExtResource( 4 )
region = Rect2( 0, 0, 16, 16 )
[sub_resource type="AtlasTexture" id=7]
atlas = ExtResource( 4 )
region = Rect2( 16, 0, 16, 16 )
[sub_resource type="ButtonGroup" id=8]
[sub_resource type="AtlasTexture" id=9]
atlas = ExtResource( 4 )
region = Rect2( 0, 16, 16, 16 )
[sub_resource type="AtlasTexture" id=11]
atlas = ExtResource( 4 )
region = Rect2( 32, 16, 16, 16 )
[sub_resource type="AtlasTexture" id=10]
atlas = ExtResource( 4 )
region = Rect2( 16, 16, 16, 16 )
[node name="Control" type="Control"]
anchor_right = 1.0
anchor_bottom = 1.0
@ -214,7 +240,96 @@ custom_fonts/font = ExtResource( 9 )
text = "Play"
flat = false
[node name="tools" type="HBoxContainer" parent="."]
margin_left = 9.0
margin_top = 54.0
margin_right = 35.0
margin_bottom = 140.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="toolsPanel" type="PanelContainer" parent="tools"]
margin_right = 55.0
margin_bottom = 64.0
size_flags_vertical = 0
[node name="tools" type="VBoxContainer" parent="tools/toolsPanel"]
margin_left = 4.0
margin_top = 4.0
margin_right = 51.0
margin_bottom = 60.0
[node name="placeTile" type="ToolButton" parent="tools/toolsPanel/tools"]
margin_right = 47.0
margin_bottom = 26.0
theme = ExtResource( 13 )
toggle_mode = true
group = SubResource( 5 )
text = "tile"
icon = SubResource( 6 )
flat = false
align = 0
[node name="placeObject" type="ToolButton" parent="tools/toolsPanel/tools"]
margin_top = 30.0
margin_right = 47.0
margin_bottom = 56.0
theme = ExtResource( 13 )
toggle_mode = true
group = SubResource( 5 )
text = "obj"
icon = SubResource( 7 )
flat = false
align = 0
[node name="brushPanel" 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/brushPanel"]
margin_left = 4.0
margin_top = 4.0
margin_right = 30.0
margin_bottom = 90.0
[node name="FreeHand" type="ToolButton" parent="tools/brushPanel/brush"]
margin_right = 26.0
margin_bottom = 26.0
theme = ExtResource( 13 )
toggle_mode = true
group = SubResource( 8 )
icon = SubResource( 9 )
flat = false
[node name="Rect" type="ToolButton" parent="tools/brushPanel/brush"]
margin_top = 30.0
margin_right = 26.0
margin_bottom = 56.0
theme = ExtResource( 13 )
toggle_mode = true
group = SubResource( 8 )
icon = SubResource( 11 )
flat = false
[node name="Fill" type="ToolButton" parent="tools/brushPanel/brush"]
margin_top = 60.0
margin_right = 26.0
margin_bottom = 86.0
theme = ExtResource( 13 )
toggle_mode = true
group = SubResource( 8 )
icon = SubResource( 10 )
flat = false
[node name="layers" type="MarginContainer" parent="."]
visible = false
anchor_top = 1.0
anchor_right = 1.0
anchor_bottom = 1.0
@ -233,5 +348,13 @@ margin_bottom = 84.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" ]]
[connection signal="pressed" from="tools/toolsPanel/tools/placeObject" to="." method="_tool_selected" binds= [ "obj" ]]
[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" ]]

View file

@ -177,7 +177,9 @@ position = Vector2( -736, -96 )
[node name="Computer" parent="objects" instance=ExtResource( 6 )]
position = Vector2( 800, 0 )
object_name = ""
direction = 0
computer_type = 0
[node name="Door" parent="objects" instance=ExtResource( 4 )]
position = Vector2( -704, 0 )
@ -212,39 +214,49 @@ interlockTargetPath = NodePath("../Door6")
[node name="Computer2" parent="objects" instance=ExtResource( 6 )]
position = Vector2( -864, -32 )
object_name = ""
direction = 1
computer_type = 4
[node name="Computer3" parent="objects" instance=ExtResource( 6 )]
position = Vector2( -864, 0 )
object_name = ""
direction = 1
computer_type = 5
[node name="Computer4" parent="objects" instance=ExtResource( 6 )]
position = Vector2( 736, -96 )
object_name = ""
direction = 3
computer_type = 4
[node name="Computer5" parent="objects" instance=ExtResource( 6 )]
position = Vector2( 704, -96 )
object_name = ""
direction = 3
computer_type = 5
[node name="Computer6" parent="objects" instance=ExtResource( 6 )]
position = Vector2( 800, 32 )
object_name = ""
direction = 0
computer_type = 7
[node name="Computer8" parent="objects" instance=ExtResource( 6 )]
position = Vector2( 736, 96 )
object_name = ""
direction = 2
computer_type = 6
[node name="Computer9" parent="objects" instance=ExtResource( 6 )]
position = Vector2( 704, 96 )
object_name = ""
direction = 2
computer_type = 3
[node name="Computer7" parent="objects" instance=ExtResource( 6 )]
position = Vector2( 800, -32 )
object_name = ""
direction = 0
computer_type = 1
@ -319,160 +331,199 @@ flow = 2
position = Vector2( -928, 96 )
direction = 0
connectionPaths = [ NodePath("../../engines/Engine3") ]
flow = 1
[node name="ElectricSocket6" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( -832, -192 )
direction = 0
connectionPaths = [ NodePath("../../engines/Engine4") ]
flow = 1
[node name="ElectricSocket7" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( -928, 0 )
direction = 0
connectionPaths = [ NodePath("../../engines/Engine5") ]
flow = 1
[node name="ElectricSocket8" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( -832, 192 )
direction = 0
connectionPaths = [ NodePath("../../engines/Engine2") ]
flow = 1
[node name="ElectricSocket9" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( -928, -96 )
direction = 0
connectionPaths = [ NodePath("../../engines/Engine") ]
flow = 1
[node name="ElectricSocket10" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 768, 0 )
direction = 1
connectionPaths = [ NodePath("../../objects/Computer") ]
flow = 1
[node name="ElectricSocket12" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 576, 0 )
direction = 1
connectionPaths = [ NodePath("../../objects/Door2") ]
flow = 1
[node name="ElectricSocket11" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( -736, 0 )
direction = 1
connectionPaths = [ NodePath("../../objects/Door") ]
flow = 1
[node name="ElectricSocket13" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 96, -96 )
direction = 2
connectionPaths = [ NodePath("../../objects/Door3") ]
flow = 1
[node name="ElectricSocket14" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 160, -96 )
direction = 2
connectionPaths = [ NodePath("../../objects/Door4") ]
flow = 1
[node name="ElectricSocket15" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 64, -224 )
direction = 2
connectionPaths = [ NodePath("../../objects/Door7") ]
flow = 1
[node name="ElectricSocket16" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 64, -288 )
direction = 2
connectionPaths = [ NodePath("../../objects/Door5") ]
flow = 1
[node name="ElectricSocket17" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 192, -288 )
direction = 2
connectionPaths = [ NodePath("../../objects/Door6") ]
flow = 1
[node name="ElectricSocket18" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 192, -224 )
direction = 2
connectionPaths = [ NodePath("../../objects/Door8") ]
flow = 1
[node name="ElectricSocket19" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( -832, 0 )
direction = 0
connectionPaths = [ NodePath("../../objects/Computer3") ]
flow = 1
[node name="ElectricSocket20" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( -832, -32 )
direction = 0
connectionPaths = [ NodePath("../../objects/Computer2") ]
flow = 1
[node name="ElectricSocket22" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 736, -64 )
direction = 2
connectionPaths = [ NodePath("../../objects/Computer4") ]
flow = 1
[node name="ElectricSocket21" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 704, -64 )
direction = 2
connectionPaths = [ NodePath("../../objects/Computer5") ]
flow = 1
[node name="ElectricSocket23" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 704, 64 )
direction = 3
connectionPaths = [ NodePath("../../objects/Computer9") ]
flow = 1
[node name="ElectricSocket24" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 736, 64 )
direction = 3
connectionPaths = [ NodePath("../../objects/Computer8") ]
flow = 1
[node name="ElectricSocket25" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 768, -32 )
direction = 1
connectionPaths = [ NodePath("../../objects/Computer7") ]
flow = 1
[node name="ElectricSocket26" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 768, 32 )
direction = 1
connectionPaths = [ NodePath("../../objects/Computer6") ]
flow = 1
[node name="ElectricSocket27" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( -512, 224 )
direction = 0
connectionPaths = [ NodePath("../../objects/Door9") ]
flow = 1
[node name="ElectricSocket28" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( -448, 32 )
direction = 3
connectionPaths = [ NodePath("../../objects/Door10") ]
flow = 1
[node name="ElectricSocket29" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( -320, 128 )
direction = 0
connectionPaths = [ NodePath("../../objects/Door12") ]
flow = 1
[node name="ElectricSocket30" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( -224, 32 )
direction = 3
connectionPaths = [ NodePath("../../objects/Door11") ]
flow = 1
[node name="ElectricSocket31" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( -128, 192 )
direction = 1
connectionPaths = [ NodePath("../../objects/Door13") ]
flow = 1
[node name="ElectricSocket32" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 224, 128 )
direction = 1
connectionPaths = [ NodePath("../../objects/Door16") ]
flow = 1
[node name="ElectricSocket33" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 224, 160 )
direction = 1
connectionPaths = [ NodePath("../../objects/Door17") ]
flow = 1
[node name="ElectricSocket34" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 352, 32 )
direction = 3
connectionPaths = [ NodePath("../../objects/Door14") ]
flow = 1
[node name="ElectricSocket35" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 416, 32 )
direction = 3
connectionPaths = [ NodePath("../../objects/Door15") ]
flow = 1
[node name="ElectricSocket36" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 192, -160 )
direction = 1
connectionPaths = [ NodePath("../../objects/Door19") ]
flow = 1
[node name="ElectricSocket37" parent="sockets" instance=ExtResource( 14 )]
position = Vector2( 416, -32 )
direction = 2
connectionPaths = [ NodePath("../../objects/Door18") ]
flow = 1
[node name="lights" type="Node2D" parent="."]
modulate = Color( 0.980392, 0.980392, 0.980392, 1 )