Delete mode
This commit is contained in:
parent
1c20d54651
commit
c566936cfc
3 changed files with 48 additions and 4 deletions
|
@ -50,6 +50,17 @@ plc_rotate_up={
|
||||||
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"key_label":0,"unicode":114,"location":0,"echo":false,"script":null)
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"key_label":0,"unicode":114,"location":0,"echo":false,"script":null)
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
plc_rotate_down={
|
||||||
|
"deadzone": 1.0,
|
||||||
|
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":16,"position":Vector2(239, 1),"global_position":Vector2(243, 38),"factor":1.0,"button_index":5,"canceled":false,"pressed":true,"double_click":false,"script":null)
|
||||||
|
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":true,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":82,"key_label":0,"unicode":82,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
plc_remove_toggle={
|
||||||
|
"deadzone": 0.2,
|
||||||
|
"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":81,"key_label":0,"unicode":113,"location":0,"echo":false,"script":null)
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
[layer_names]
|
[layer_names]
|
||||||
|
|
||||||
|
|
|
@ -38,5 +38,12 @@ func get_at(point : Vector2) -> Structure:
|
||||||
return null
|
return null
|
||||||
return structures[index]
|
return structures[index]
|
||||||
|
|
||||||
|
func destroy_at(point : Vector2) -> void:
|
||||||
|
var index = building_zone.indexify_global_point(point)
|
||||||
|
if index == -1:
|
||||||
|
return
|
||||||
|
structures[index].queue_free()
|
||||||
|
structures[index] = null
|
||||||
|
|
||||||
func is_point_occupied(point : Vector2) -> bool:
|
func is_point_occupied(point : Vector2) -> bool:
|
||||||
return get_at(point) != null
|
return get_at(point) != null
|
||||||
|
|
|
@ -3,13 +3,31 @@ extends Node2D
|
||||||
## Currently held structure
|
## Currently held structure
|
||||||
var held_construction : Structure
|
var held_construction : Structure
|
||||||
var selected_prototype : Prototype
|
var selected_prototype : Prototype
|
||||||
|
var delete_mode : bool = false
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
GuiEventBus.construction_selected.connect(on_construction_selected)
|
GuiEventBus.construction_selected.connect(on_construction_selected)
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
func _input(event: InputEvent) -> void:
|
||||||
if held_construction == null:
|
|
||||||
|
if event.is_action_pressed("plc_remove_toggle"):
|
||||||
|
delete_mode = not delete_mode
|
||||||
|
if held_construction:
|
||||||
|
held_construction.queue_free()
|
||||||
|
selected_prototype = null
|
||||||
|
|
||||||
|
if event.is_action_pressed("plc_place") and delete_mode:
|
||||||
|
print(delete_mode)
|
||||||
|
var zone : PlacementZone = try_get_zone(global_position)
|
||||||
|
if zone != null and zone.grid_controller.is_point_occupied(global_position):
|
||||||
|
zone.grid_controller.destroy_at(global_position)
|
||||||
|
|
||||||
|
if event.is_action_pressed("plc_cancel") and delete_mode:
|
||||||
|
delete_mode = false
|
||||||
|
|
||||||
|
if held_construction == null or delete_mode:
|
||||||
return
|
return
|
||||||
|
|
||||||
if event.is_action_pressed("plc_place"):
|
if event.is_action_pressed("plc_place"):
|
||||||
var zone = try_get_zone(held_construction.global_position)
|
var zone = try_get_zone(held_construction.global_position)
|
||||||
if zone != null and held_construction.try_place(zone):
|
if zone != null and held_construction.try_place(zone):
|
||||||
|
@ -17,15 +35,22 @@ func _input(event: InputEvent) -> void:
|
||||||
held_construction = selected_prototype.scene.instantiate()
|
held_construction = selected_prototype.scene.instantiate()
|
||||||
add_child(held_construction)
|
add_child(held_construction)
|
||||||
held_construction.set_facing(facing)
|
held_construction.set_facing(facing)
|
||||||
|
|
||||||
if event.is_action_pressed("plc_rotate_up"):
|
if event.is_action_pressed("plc_rotate_up"):
|
||||||
if held_construction != null:
|
if held_construction != null:
|
||||||
held_construction.cycle_up_facing()
|
held_construction.cycle_up_facing()
|
||||||
|
|
||||||
|
if event.is_action_pressed("plc_rotate_down"):
|
||||||
|
if held_construction != null:
|
||||||
|
held_construction.cycle_down_facing()
|
||||||
|
|
||||||
if event.is_action_pressed("plc_cancel"):
|
if event.is_action_pressed("plc_cancel"):
|
||||||
held_construction.queue_free()
|
held_construction.queue_free()
|
||||||
selected_prototype = null
|
selected_prototype = null
|
||||||
|
|
||||||
func on_construction_selected(constructible : Prototype):
|
func on_construction_selected(constructible : Prototype):
|
||||||
|
if delete_mode:
|
||||||
|
return
|
||||||
if held_construction:
|
if held_construction:
|
||||||
held_construction.queue_free()
|
held_construction.queue_free()
|
||||||
held_construction = constructible.scene.instantiate()
|
held_construction = constructible.scene.instantiate()
|
||||||
|
@ -34,9 +59,10 @@ func on_construction_selected(constructible : Prototype):
|
||||||
|
|
||||||
|
|
||||||
func _process(_delta: float) -> void:
|
func _process(_delta: float) -> void:
|
||||||
if held_construction == null:
|
|
||||||
return
|
|
||||||
var mouse_pos = get_global_mouse_position()
|
var mouse_pos = get_global_mouse_position()
|
||||||
|
if held_construction == null:
|
||||||
|
global_position = mouse_pos
|
||||||
|
return
|
||||||
var zone = try_get_zone(mouse_pos)
|
var zone = try_get_zone(mouse_pos)
|
||||||
if zone and held_construction.can_be_placed(zone):
|
if zone and held_construction.can_be_placed(zone):
|
||||||
global_position = zone.get_placement_position(mouse_pos)
|
global_position = zone.get_placement_position(mouse_pos)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue