weapon display
This commit is contained in:
parent
553f8ea77a
commit
8fadd143c3
26 changed files with 491 additions and 46 deletions
|
|
@ -23,7 +23,7 @@ var slots: Dictionary[StringName,WeaponSubStateMachine] = {
|
|||
}
|
||||
|
||||
signal switched_to(state: WeaponSubStateMachine)
|
||||
signal slots_updated(slots: Dictionary[StringName,WeaponSubStateMachine])
|
||||
signal slots_updated(current_slot: StringName,slots: Dictionary[StringName,StringName])
|
||||
signal ammo_updated(ammo: int, remaining_ammo: int)
|
||||
|
||||
func _ready() -> void:
|
||||
|
|
@ -33,6 +33,12 @@ func _ready() -> void:
|
|||
player_input.switch_weapon.connect(switch)
|
||||
player_input.alternate_state.connect(alternate_state)
|
||||
player_input.switch_firemode.connect(switch_mode)
|
||||
|
||||
await get_tree().process_frame
|
||||
await get_tree().process_frame
|
||||
|
||||
notify_slots_updated()
|
||||
on_ammo_updated()
|
||||
|
||||
func get_speed_modifier() -> float:
|
||||
if current_state == null:
|
||||
|
|
@ -51,7 +57,8 @@ func add(state: WeaponSubStateMachine, slot: StringName) -> void:
|
|||
add_child(state, true)
|
||||
|
||||
slots[slot] = state
|
||||
slots_updated.emit(slots)
|
||||
|
||||
notify_slots_updated()
|
||||
|
||||
if current_state == null:
|
||||
current_state = state
|
||||
|
|
@ -60,17 +67,6 @@ func add(state: WeaponSubStateMachine, slot: StringName) -> void:
|
|||
await get_tree().process_frame
|
||||
await get_tree().process_frame
|
||||
state._enter()
|
||||
|
||||
|
||||
func process_spawned_weapon(weapon_node: Node):
|
||||
var weapon = weapon_node as WeaponSubStateMachine
|
||||
|
||||
slots[weapon.slot] = weapon
|
||||
slots_updated.emit(slots)
|
||||
|
||||
if current_state == null:
|
||||
current_state = weapon
|
||||
ammo_updated.emit(current_state.ammo,current_state.remaining_ammo)
|
||||
|
||||
func get_empty_ability_slot() -> StringName:
|
||||
if slots["ability_first"] == null:
|
||||
|
|
@ -95,6 +91,7 @@ func switch(to: StringName, exit: bool = true):
|
|||
|
||||
ammo_updated.emit(current_state.ammo,current_state.remaining_ammo)
|
||||
switched_to.emit(current_state)
|
||||
notify_slots_updated()
|
||||
|
||||
func return_to_previous(exit: bool = true):
|
||||
if last_slot != "":
|
||||
|
|
@ -108,7 +105,7 @@ func drop_current():
|
|||
func drop(weapon: WeaponSubStateMachine) -> void:
|
||||
if not is_multiplayer_authority():
|
||||
return
|
||||
if slots.find_key(weapon) == "knife":
|
||||
if slots.find_key(weapon) in ["knife","ability_first","ability_second","ability_third"]:
|
||||
return
|
||||
|
||||
var dropped_weapon: DroppableWeapon = Registry.weapons[weapon.registry_entry].dropped_scene.instantiate()
|
||||
|
|
@ -122,7 +119,7 @@ func drop(weapon: WeaponSubStateMachine) -> void:
|
|||
$"../PickupRange".start_temp_ignore()
|
||||
|
||||
slots[slots.find_key(weapon)] = null
|
||||
slots_updated.emit(slots)
|
||||
notify_slots_updated()
|
||||
weapon.queue_free()
|
||||
return_to_previous(false)
|
||||
|
||||
|
|
@ -152,6 +149,25 @@ func on_ammo_updated() -> void:
|
|||
func remote_ammo_update(ammo: int, remaining_ammo: int):
|
||||
ammo_updated.emit(ammo,remaining_ammo)
|
||||
|
||||
func notify_slots_updated():
|
||||
var display_slots: Dictionary[StringName,StringName] = {}
|
||||
for key in slots.keys():
|
||||
if slots[key] == null:
|
||||
display_slots[key] = ""
|
||||
else:
|
||||
display_slots[key] = slots[key].registry_entry
|
||||
var current_slot: StringName = ""
|
||||
var found = slots.find_key(current_state)
|
||||
if found:
|
||||
current_slot = found
|
||||
|
||||
remote_update_slots.rpc(current_slot,display_slots)
|
||||
slots_updated.emit(current_slot,display_slots)
|
||||
|
||||
@rpc
|
||||
func remote_update_slots(current_slot: StringName, update_slots: Dictionary[StringName,StringName]):
|
||||
slots_updated.emit(current_slot, update_slots)
|
||||
|
||||
func disable() -> void:
|
||||
disabled = true
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue