Refines tile build and selection
This commit is contained in:
parent
e76a7b1f83
commit
d0bb1ac5f0
@ -1 +0,0 @@
|
||||
extends CheckButton
|
||||
@ -1 +0,0 @@
|
||||
uid://toyg8a6pv2i1
|
||||
51
game.tscn
51
game.tscn
@ -1,6 +1,7 @@
|
||||
[gd_scene load_steps=4 format=3 uid="uid://x8xo5b1b3q41"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://x8xo5b1b3q41"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://b2ytri51qn3r0" path="res://game.gd" id="1_feb5d"]
|
||||
[ext_resource type="Script" uid="uid://bi7t6jxlfl0ln" path="res://interface/build_toggle.gd" id="2_7jktm"]
|
||||
[ext_resource type="PackedScene" uid="uid://0d1d5e1u2fys" path="res://places/place_manager.tscn" id="2_fc0e3"]
|
||||
[ext_resource type="Script" uid="uid://cgfibq8ku7tey" path="res://interface/game_cam.gd" id="3_7jktm"]
|
||||
|
||||
@ -9,42 +10,28 @@ script = ExtResource("1_feb5d")
|
||||
|
||||
[node name="InterfaceLayer" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="SelectToggle" type="CheckButton" parent="InterfaceLayer"]
|
||||
offset_left = 1008.0
|
||||
offset_top = 18.0
|
||||
offset_right = 1120.0
|
||||
offset_bottom = 49.0
|
||||
text = "Building"
|
||||
[node name="BuildToggle" type="CheckButton" parent="InterfaceLayer"]
|
||||
offset_left = 7.0
|
||||
offset_top = 603.0
|
||||
offset_right = 119.0
|
||||
offset_bottom = 634.0
|
||||
text = "Build A Room"
|
||||
script = ExtResource("2_7jktm")
|
||||
|
||||
[node name="BuildButton" type="Button" parent="InterfaceLayer"]
|
||||
offset_left = 1033.0
|
||||
offset_top = 59.0
|
||||
offset_right = 1081.0
|
||||
offset_bottom = 90.0
|
||||
text = "Build"
|
||||
|
||||
[node name="DestroyButton" type="Button" parent="InterfaceLayer"]
|
||||
offset_left = 1031.0
|
||||
offset_top = 105.0
|
||||
offset_right = 1079.0
|
||||
offset_bottom = 136.0
|
||||
text = "Destroy
|
||||
"
|
||||
|
||||
[node name="CancelButton" type="Button" parent="InterfaceLayer"]
|
||||
offset_left = 1031.0
|
||||
offset_top = 145.0
|
||||
offset_right = 1091.0
|
||||
offset_bottom = 176.0
|
||||
text = "Cancel"
|
||||
offset_left = 172.0
|
||||
offset_top = 604.0
|
||||
offset_right = 243.0
|
||||
offset_bottom = 635.0
|
||||
text = "Confirm"
|
||||
|
||||
[node name="GameCam" type="Camera3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 16.504, 23.621, 15.103)
|
||||
transform = Transform3D(1, 0, 0, 0, -4.37114e-08, 1, 0, -1, -4.37114e-08, 24.5127, 23.2849, 20.9667)
|
||||
size = 31.34
|
||||
script = ExtResource("3_7jktm")
|
||||
|
||||
[node name="PlaceManager" parent="." instance=ExtResource("2_fc0e3")]
|
||||
|
||||
[connection signal="toggled" from="InterfaceLayer/SelectToggle" to="PlaceManager" method="_on_build_toggle"]
|
||||
[connection signal="pressed" from="InterfaceLayer/BuildButton" to="PlaceManager" method="_on_build_button_pressed"]
|
||||
[connection signal="pressed" from="InterfaceLayer/DestroyButton" to="PlaceManager" method="_on_destroy_button_pressed"]
|
||||
[connection signal="pressed" from="InterfaceLayer/CancelButton" to="PlaceManager" method="_on_cancel_button_pressed"]
|
||||
[connection signal="toggled" from="InterfaceLayer/BuildToggle" to="PlaceManager" method="_on_build_toggle"]
|
||||
[connection signal="pressed" from="InterfaceLayer/BuildButton" to="PlaceManager" method="_on_confirm_button_pressed"]
|
||||
[connection signal="room_built" from="PlaceManager" to="InterfaceLayer/BuildToggle" method="_on_room_built"]
|
||||
|
||||
5
interface/build_toggle.gd
Normal file
5
interface/build_toggle.gd
Normal file
@ -0,0 +1,5 @@
|
||||
extends CheckButton
|
||||
|
||||
|
||||
func _on_room_built() -> void:
|
||||
button_pressed = false
|
||||
1
interface/build_toggle.gd.uid
Normal file
1
interface/build_toggle.gd.uid
Normal file
@ -0,0 +1 @@
|
||||
uid://bi7t6jxlfl0ln
|
||||
@ -1,9 +1,9 @@
|
||||
[gd_scene load_steps=2 format=3 uid="uid://bujuwgn3y42ek"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://n4vvqmlmq5fp" path="res://places/base_place/place.gd" id="1_5eudc"]
|
||||
[ext_resource type="Script" uid="uid://n4vvqmlmq5fp" path="res://places/base_place/place.gd" id="1_uq3a8"]
|
||||
|
||||
[node name="TestPlace" type="Node3D"]
|
||||
script = ExtResource("1_5eudc")
|
||||
[node name="BasePlace" type="Node3D"]
|
||||
script = ExtResource("1_uq3a8")
|
||||
|
||||
[node name="Grid" type="Node3D" parent="."]
|
||||
|
||||
@ -10,60 +10,58 @@ var tile_dict = {}
|
||||
var selection_drag_dict = {}
|
||||
var selection_dict = {}
|
||||
|
||||
var room_dict = {}
|
||||
|
||||
var tile_count_x_hist = null
|
||||
var tile_count_z_hist = null
|
||||
|
||||
var build_forbidden = false
|
||||
var build_allowed = true
|
||||
|
||||
func _ready():
|
||||
|
||||
# Sets up a simple 2D grid of blank tiles.
|
||||
|
||||
#Sets up a simple 2D grid of blank tiles.
|
||||
|
||||
for x in range(tile_grid_size):
|
||||
for z in range (tile_grid_size):
|
||||
var pos = Vector3i(x + 0.5,0 ,z + 0.5)
|
||||
var pos = Vector3i(x, 0, z)
|
||||
|
||||
var tile = load_tile.instantiate()
|
||||
tile.set_position(pos)
|
||||
tile.type = 0
|
||||
|
||||
tile.update(0, 2)
|
||||
|
||||
tile_dict[pos] = tile
|
||||
|
||||
add_child(tile)
|
||||
|
||||
|
||||
func build_selection(b):
|
||||
|
||||
# When the build or destroy button is clicked, changes the selected tiles to match the button's request
|
||||
#When the build or destroy button is clicked, changes the selected tiles to match the button's request
|
||||
|
||||
if build_forbidden:
|
||||
print("can't build")
|
||||
if not build_allowed:
|
||||
return
|
||||
|
||||
for i in selection_dict:
|
||||
var tile_selected = tile_dict[i]
|
||||
tile_selected.build_this_tile(b)
|
||||
tile_selected.update(1, 4)
|
||||
|
||||
selection_dict.clear()
|
||||
|
||||
for i in tile_dict:
|
||||
if not selection_dict.has(i):
|
||||
var tile_selected = tile_dict[i]
|
||||
tile_selected.select_this_tile(false)
|
||||
#if not selection_dict.has(i):
|
||||
var tile_selected = tile_dict[i]
|
||||
tile_selected.update(1, 0)
|
||||
|
||||
func clear_selection():
|
||||
|
||||
# When the clear button is clicked, it clears the selected tiles without doing anything.
|
||||
#When the clear button is clicked, it clears the selected tiles without doing anything.
|
||||
|
||||
for i in tile_dict:
|
||||
var tile_selected = tile_dict[i]
|
||||
tile_selected.select_this_tile(false)
|
||||
tile_selected.update(1, 0)
|
||||
build_allowed = true
|
||||
|
||||
selection_dict.clear()
|
||||
|
||||
func end_select_drag():
|
||||
|
||||
# Adds dragged tiles to the current selection on mouse-up
|
||||
#Adds dragged tiles to the current selection on mouse-up
|
||||
|
||||
tile_count_x_hist = 0
|
||||
tile_count_z_hist = 0
|
||||
@ -71,17 +69,20 @@ func end_select_drag():
|
||||
selection_dict.merge(selection_drag_dict)
|
||||
|
||||
if verify_room():
|
||||
build_forbidden = false
|
||||
build_allowed = true
|
||||
for i in selection_dict:
|
||||
tile_dict[i].update(3, 0)
|
||||
else:
|
||||
build_forbidden = true
|
||||
|
||||
build_allowed = false
|
||||
for i in selection_dict:
|
||||
tile_dict[i].update(4, 0)
|
||||
|
||||
selection_drag_dict.clear()
|
||||
|
||||
func draw_tile_click(start_pos):
|
||||
func draw_tile_click(click_pos):
|
||||
#starts a selection drag
|
||||
|
||||
# starts a selection drag
|
||||
|
||||
var build_start_pos: Vector3i = start_pos.snapped(Vector3i(1, 1, 1))
|
||||
var build_start_pos: Vector3i = click_pos.floor()
|
||||
tile_count_x_hist = 0
|
||||
tile_count_z_hist = 0
|
||||
|
||||
@ -89,13 +90,12 @@ func draw_tile_click(start_pos):
|
||||
select_tile(build_start_pos)
|
||||
|
||||
func init_select_drag(float_build_start_pos, float_build_mouse_pos):
|
||||
|
||||
# Creats an array of dragged tiles between mouse start and current position
|
||||
#Creats an array of dragged tiles between mouse start and current position
|
||||
|
||||
var select_drag_array = []
|
||||
|
||||
var build_start_pos: Vector3i = float_build_start_pos.snapped(Vector3i(1.0, 1.0, 1.0))
|
||||
var build_mouse_pos: Vector3i = float_build_mouse_pos.snapped(Vector3i(1.0, 1.0, 1.0))
|
||||
var build_start_pos: Vector3i = float_build_start_pos.floor()
|
||||
var build_mouse_pos: Vector3i = float_build_mouse_pos.floor()
|
||||
|
||||
var tile_count_x = build_mouse_pos.x - build_start_pos.x
|
||||
var tile_count_z = build_mouse_pos.z - build_start_pos.z
|
||||
@ -115,34 +115,34 @@ func init_select_drag(float_build_start_pos, float_build_mouse_pos):
|
||||
draw_select_drag(select_drag_array)
|
||||
|
||||
func draw_select_drag(array):
|
||||
|
||||
# Clears previous drag, then calls tile selection on all currently dragged tiles
|
||||
#Clears previous drag, then calls tile selection on all currently dragged tiles
|
||||
|
||||
selection_drag_dict.clear()
|
||||
|
||||
for i in tile_dict:
|
||||
if not selection_dict.has(i):
|
||||
var tile_selected = tile_dict[i]
|
||||
tile_selected.select_this_tile(false)
|
||||
tile_selected.update(1, 0)
|
||||
|
||||
for i in array:
|
||||
var id = i
|
||||
select_tile(id)
|
||||
|
||||
func select_tile(pos):
|
||||
|
||||
# Tells tiles to be selected
|
||||
|
||||
#Tells tiles to be selected
|
||||
|
||||
var tile = tile_dict[pos]
|
||||
tile.select_this_tile(true)
|
||||
selection_drag_dict[pos] = tile
|
||||
|
||||
if not tile.construction_mode == 4:
|
||||
print(tile.construction_mode)
|
||||
if build_allowed:
|
||||
tile.update(3, 0)
|
||||
else:
|
||||
tile.update(4, 0)
|
||||
selection_drag_dict[pos] = tile
|
||||
|
||||
func verify_room():
|
||||
|
||||
# Verifies that a given selection is fully contiguous
|
||||
|
||||
if selection_dict == selection_drag_dict:
|
||||
return true
|
||||
#Verifies that a given selection is fully contiguous
|
||||
|
||||
var verify_array = selection_dict.keys()
|
||||
var verify_queue_array = [verify_array[0]]
|
||||
@ -150,7 +150,7 @@ func verify_room():
|
||||
|
||||
while verify_array:
|
||||
if not verify_queue_array:
|
||||
print("no good")
|
||||
|
||||
return false
|
||||
|
||||
var verify_pos = verify_queue_array.pop_back()
|
||||
@ -161,8 +161,7 @@ func verify_room():
|
||||
Vector3i(verify_pos.x, 0, verify_pos.z + 1),
|
||||
Vector3i(verify_pos.x, 0, verify_pos.z - 1)
|
||||
]
|
||||
|
||||
|
||||
|
||||
for n in verify_neighbor_array:
|
||||
|
||||
if selection_dict.has(n):
|
||||
@ -171,8 +170,6 @@ func verify_room():
|
||||
verify_queue_array.append(n)
|
||||
|
||||
verify_checked_array.append(verify_pos)
|
||||
|
||||
verify_array.erase(verify_pos)
|
||||
|
||||
print("all good")
|
||||
return true
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
extends Node3D
|
||||
|
||||
var load_place = preload("res://places/base_place/test_place.tscn")
|
||||
var load_place = preload("res://places/base_place/base_place.tscn")
|
||||
var place = load_place.instantiate()
|
||||
|
||||
var build_enabled = false
|
||||
@ -8,6 +8,8 @@ var is_building = false
|
||||
|
||||
var build_start_pos = null
|
||||
|
||||
signal room_built
|
||||
|
||||
func _ready():
|
||||
add_child(place)
|
||||
|
||||
@ -16,17 +18,18 @@ func _input(event):
|
||||
|
||||
func _on_build_toggle(toggled_on):
|
||||
build_enabled = toggled_on
|
||||
if not toggled_on:
|
||||
place.clear_selection()
|
||||
|
||||
func toggle_building(event):
|
||||
func start_build(event):
|
||||
is_building = event.button_mask
|
||||
|
||||
func _on_area_3d_input_event(_camera, event, event_position, _normal, _shade_id):
|
||||
|
||||
# Checks input events from the mouse plane
|
||||
#Checks input events from the mouse planex
|
||||
|
||||
if event.is_action_pressed("select") && build_enabled:
|
||||
build_start_pos = event_position
|
||||
toggle_building(event)
|
||||
start_build(event)
|
||||
place.draw_tile_click(build_start_pos)
|
||||
|
||||
if is_building:
|
||||
@ -35,16 +38,13 @@ func _on_area_3d_input_event(_camera, event, event_position, _normal, _shade_id)
|
||||
place.init_select_drag(build_start_pos, build_mouse_pos)
|
||||
|
||||
if not event.button_mask:
|
||||
toggle_building(event)
|
||||
start_build(event)
|
||||
place.end_select_drag()
|
||||
|
||||
func _on_cancel_button_pressed() -> void:
|
||||
place.clear_selection()
|
||||
|
||||
|
||||
func _on_build_button_pressed() -> void:
|
||||
place.build_selection(true)
|
||||
|
||||
|
||||
func _on_destroy_button_pressed() -> void:
|
||||
place.build_selection(false)
|
||||
func _on_confirm_button_pressed() -> void:
|
||||
if place.build_allowed:
|
||||
place.build_selection(true)
|
||||
is_building = false
|
||||
emit_signal("room_built")
|
||||
else:
|
||||
pass
|
||||
|
||||
@ -5,7 +5,7 @@
|
||||
[sub_resource type="BoxShape3D" id="BoxShape3D_rcbs8"]
|
||||
size = Vector3(256, 0, 256)
|
||||
|
||||
[sub_resource type="PrismMesh" id="PrismMesh_rcbs8"]
|
||||
[sub_resource type="CapsuleMesh" id="CapsuleMesh_vil6d"]
|
||||
|
||||
[node name="PlaceManager" type="Node3D"]
|
||||
script = ExtResource("1_rcbs8")
|
||||
@ -17,6 +17,6 @@ transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 128, 0, 128)
|
||||
shape = SubResource("BoxShape3D_rcbs8")
|
||||
|
||||
[node name="MeshInstance3D" type="MeshInstance3D" parent="FloorPlane"]
|
||||
mesh = SubResource("PrismMesh_rcbs8")
|
||||
mesh = SubResource("CapsuleMesh_vil6d")
|
||||
|
||||
[connection signal="input_event" from="FloorPlane" to="." method="_on_area_3d_input_event"]
|
||||
|
||||
@ -2,9 +2,34 @@ extends Node3D
|
||||
|
||||
var id = null
|
||||
|
||||
var type = 2
|
||||
var _debug_sel_mode = {
|
||||
1: "not selected",
|
||||
2: "room select",
|
||||
3: "build select",
|
||||
4: "invalid select"
|
||||
}
|
||||
|
||||
var is_selected = false
|
||||
var _debug_con_mode = {
|
||||
1: "non interactalble",
|
||||
2: "closed",
|
||||
3: "open",
|
||||
4: "built",
|
||||
5: "reinforced",
|
||||
6: "under construction"
|
||||
}
|
||||
|
||||
var _debug_face_mode = {
|
||||
1: "none",
|
||||
2: "full",
|
||||
3: "partial",
|
||||
4: "door"
|
||||
}
|
||||
|
||||
# list of objects contained within
|
||||
|
||||
var construction_mode = 0
|
||||
|
||||
var selection_mode = 0
|
||||
|
||||
var orange = preload("res://tiles/base_tile/orange.tres")
|
||||
var gray = preload("res://tiles/base_tile/gray.tres")
|
||||
@ -12,33 +37,83 @@ var red = preload("res://tiles/base_tile/red.tres")
|
||||
var blue = preload("res://tiles/base_tile/blue.tres")
|
||||
var lightblue = preload("res://tiles/base_tile/lightblue.tres")
|
||||
|
||||
# tiles are 'buildable area' or not. non-buildable tiles are used as normal, but not chanegd by player
|
||||
var faces = {
|
||||
"floor": null,
|
||||
"north": null,
|
||||
"east": null,
|
||||
"south": null,
|
||||
"west": null
|
||||
}
|
||||
|
||||
# buildable are tiles need five total faces. If a face doesn't exist, it's assumed to be open space.
|
||||
func _ready():
|
||||
if type == 0:
|
||||
pass
|
||||
pass
|
||||
|
||||
func invalid_this_tile():
|
||||
pass
|
||||
|
||||
|
||||
func select_this_tile(b):
|
||||
is_selected = b
|
||||
|
||||
if b:
|
||||
$WallMesh.set_material_override(lightblue)
|
||||
$FloorMesh.set_material_override(blue)
|
||||
else:
|
||||
$WallMesh.set_material_override(gray)
|
||||
$FloorMesh.set_material_override(null)
|
||||
func update(sel_mode: int = 0, con_mode: int = 0):
|
||||
|
||||
func build_this_tile(b):
|
||||
if b:
|
||||
type = 1
|
||||
$WallMesh.visible = false
|
||||
$FloorMesh.visible = true
|
||||
else:
|
||||
type = 0
|
||||
$WallMesh.visible = true
|
||||
$FloorMesh.visible = false
|
||||
if sel_mode:
|
||||
if sel_mode != selection_mode:
|
||||
|
||||
selection_mode = sel_mode
|
||||
|
||||
if sel_mode == 1:
|
||||
# not selected
|
||||
$Floor/FloorMesh.set_material_overlay(null)
|
||||
|
||||
elif sel_mode == 2:
|
||||
# room selection
|
||||
for i in $Walls.get_children():
|
||||
i.Mesh.set_material_override(orange)
|
||||
|
||||
elif sel_mode == 3:
|
||||
# build selection
|
||||
$Floor/FloorMesh.set_material_overlay(lightblue)
|
||||
#for i in $Walls.get_children():
|
||||
#i.Mesh.set_material_override(blue)
|
||||
|
||||
elif sel_mode == 4:
|
||||
# invalid selection
|
||||
$Floor/FloorMesh.set_material_overlay(orange)
|
||||
#for i in $Walls.get_children():
|
||||
#i.set_material_override(red)
|
||||
else:
|
||||
pass
|
||||
|
||||
if con_mode:
|
||||
if con_mode != construction_mode:
|
||||
|
||||
construction_mode = con_mode
|
||||
|
||||
if con_mode == 1:
|
||||
# non-interactable
|
||||
$Label3D.text = "1"
|
||||
pass
|
||||
|
||||
elif con_mode == 2:
|
||||
# closed
|
||||
$Label3D.text = "2"
|
||||
$Floor/FloorMesh.set_material_override(gray)
|
||||
pass
|
||||
|
||||
elif con_mode == 3:
|
||||
# open
|
||||
pass
|
||||
|
||||
elif con_mode == 4:
|
||||
# built
|
||||
$Label3D.text = "4"
|
||||
$Floor/FloorMesh.set_material_override(null)
|
||||
pass
|
||||
|
||||
elif con_mode == 5:
|
||||
# reinforced
|
||||
pass
|
||||
|
||||
elif con_mode == 6:
|
||||
# under construction
|
||||
pass
|
||||
|
||||
else:
|
||||
pass
|
||||
|
||||
@ -1,21 +1,27 @@
|
||||
[gd_scene load_steps=6 format=3 uid="uid://gs6yynwvvot2"]
|
||||
[gd_scene load_steps=3 format=3 uid="uid://gs6yynwvvot2"]
|
||||
|
||||
[ext_resource type="Script" uid="uid://jqjcr7dxjnbt" path="res://tiles/base_tile/tile.gd" id="1_v7x5k"]
|
||||
[ext_resource type="PlaneMesh" uid="uid://bis4hdushjnjm" path="res://tiles/base_tile/base_floor.tres" id="2_ipr02"]
|
||||
[ext_resource type="Material" uid="uid://nkwjhj76xffi" path="res://tiles/base_tile/red.tres" id="3_h0a52"]
|
||||
[ext_resource type="Material" uid="uid://cm5lg0k4vihh3" path="res://tiles/base_tile/gray.tres" id="3_tmpem"]
|
||||
|
||||
[sub_resource type="BoxMesh" id="BoxMesh_sbkyc"]
|
||||
|
||||
[node name="Tile" type="Node3D"]
|
||||
script = ExtResource("1_v7x5k")
|
||||
|
||||
[node name="FloorMesh" type="MeshInstance3D" parent="."]
|
||||
visible = false
|
||||
mesh = ExtResource("2_ipr02")
|
||||
surface_material_override/0 = ExtResource("3_h0a52")
|
||||
[node name="Floor" type="Node3D" parent="."]
|
||||
|
||||
[node name="WallMesh" type="MeshInstance3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0.5, 0)
|
||||
mesh = SubResource("BoxMesh_sbkyc")
|
||||
surface_material_override/0 = ExtResource("3_tmpem")
|
||||
[node name="FloorMesh" type="MeshInstance3D" parent="Floor"]
|
||||
transform = Transform3D(1, 0, 0, 0, 1, 0, 0, 0, 1, 0.5, 0, 0.5)
|
||||
mesh = ExtResource("2_ipr02")
|
||||
skeleton = NodePath("../..")
|
||||
|
||||
[node name="Walls" type="Node" parent="."]
|
||||
|
||||
[node name="NorthWall" type="Node3D" parent="Walls"]
|
||||
|
||||
[node name="EastWall" type="Node3D" parent="Walls"]
|
||||
|
||||
[node name="SouthWall" type="Node3D" parent="Walls"]
|
||||
|
||||
[node name="WestWall" type="Node3D" parent="Walls"]
|
||||
|
||||
[node name="Label3D" type="Label3D" parent="."]
|
||||
transform = Transform3D(1, 0, 0, 0, 0.0668138, 0.997765, 0, -0.997765, 0.0668138, 0.341829, 0.0223614, 0.130147)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user