武器切换

master
chendian 2 years ago
parent ae8b17fc4f
commit 89e6e00aae

File diff suppressed because one or more lines are too long

@ -1,4 +1,4 @@
[gd_scene load_steps=18 format=3 uid="uid://126wph4owvoy"]
[gd_scene load_steps=17 format=3 uid="uid://126wph4owvoy"]
[ext_resource type="Texture2D" uid="uid://cwhu1ec03t3c8" path="res://resource/ui/hud/headbar_hp_empty.png" id="1_flgf6"]
[ext_resource type="Script" path="res://script/ui/hud/hud_page.gd" id="1_t7dgf"]
@ -9,7 +9,6 @@
[ext_resource type="Script" path="res://script/ui/hud/lock_item.gd" id="5_usy8x"]
[ext_resource type="Texture2D" uid="uid://dx2vp753yvh4y" path="res://render/texture/shape/lock.png" id="6_hmslt"]
[ext_resource type="Script" path="res://script/ui/hud/weapon_item.gd" id="7_3g1k3"]
[ext_resource type="PackedScene" uid="uid://chi3x0mugaiu4" path="res://resource/ui/hud/weapon_item.tscn" id="8_nlmif"]
[ext_resource type="Shader" path="res://render/shader/loading.gdshader" id="9_lv4gd"]
[sub_resource type="Animation" id="Animation_ikdwl"]
@ -133,35 +132,12 @@ libraries = {
[node name="WeaponItem" type="Control" parent="HudPage"]
anchors_preset = 0
offset_left = 56.0
offset_top = 304.0
offset_top = 296.0
offset_right = 88.0
offset_bottom = 336.0
offset_bottom = 328.0
pivot_offset = Vector2(16, 16)
script = ExtResource("7_3g1k3")
[node name="Weapon1" parent="HudPage/WeaponItem" instance=ExtResource("8_nlmif")]
layout_mode = 1
[node name="Weapon2" parent="HudPage/WeaponItem" instance=ExtResource("8_nlmif")]
layout_mode = 1
offset_left = -48.0
offset_right = -16.0
[node name="Weapon3" parent="HudPage/WeaponItem" instance=ExtResource("8_nlmif")]
layout_mode = 1
offset_left = -16.0
offset_right = 16.0
[node name="Weapon4" parent="HudPage/WeaponItem" instance=ExtResource("8_nlmif")]
layout_mode = 1
offset_left = 16.0
offset_right = 48.0
[node name="Weapon5" parent="HudPage/WeaponItem" instance=ExtResource("8_nlmif")]
layout_mode = 1
offset_left = 48.0
offset_right = 80.0
[node name="HeadBarPage" type="Control" parent="."]
layout_mode = 3
anchors_preset = 0

@ -1,8 +1,8 @@
[gd_scene load_steps=4 format=3 uid="uid://chi3x0mugaiu4"]
[ext_resource type="Texture2D" uid="uid://7138jsp4yabf" path="res://resource/ui/hud/weapon_slot.png" id="1_3hxat"]
[ext_resource type="Script" path="res://script/ui/hud/weapon_item_sub.gd" id="1_y2xym"]
[ext_resource type="Texture2D" uid="uid://ksw3dvkdv6ud" path="res://resource/ui/icon/long.png" id="2_88p8f"]
[ext_resource type="Script" path="res://script/ui/hud/weapon_item_sub.gd" id="1_si20m"]
[ext_resource type="Texture2D" uid="uid://7138jsp4yabf" path="res://resource/ui/hud/weapon_slot.png" id="2_cxs45"]
[ext_resource type="Texture2D" uid="uid://ksw3dvkdv6ud" path="res://resource/ui/icon/long.png" id="3_i0fx0"]
[node name="Weapon" type="Control"]
layout_mode = 3
@ -18,7 +18,7 @@ offset_bottom = 16.0
grow_horizontal = 2
grow_vertical = 2
pivot_offset = Vector2(16, 16)
script = ExtResource("1_y2xym")
script = ExtResource("1_si20m")
[node name="WeaponSlot" type="TextureRect" parent="."]
layout_mode = 1
@ -33,7 +33,7 @@ offset_right = 16.0
offset_bottom = 16.0
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("1_3hxat")
texture = ExtResource("2_cxs45")
[node name="WeaponIcon" type="TextureRect" parent="."]
layout_mode = 1
@ -48,4 +48,4 @@ offset_right = 32.0
offset_bottom = 32.0
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("2_88p8f")
texture = ExtResource("3_i0fx0")

@ -18,4 +18,5 @@ const level_loading_min_time : float = 0.5
const level_loading_control_time : float = 0.2
#ui
const weapon_hide_duration : float = 2
const weapon_hide_duration : float = 2.0
const weapon_anime_duration : float = 0.1

@ -25,6 +25,8 @@ func _process(delta):
trigger_buff_effect(buff_info,"second")
buff_info.duration += delta
if buff_info.duration >= buff_info.duration_max:
buff_info.duration = buff_info.duration_max
trigger_buff_effect(buff_info,"update")
remove_buff(buff_name)
else:
trigger_buff_effect(buff_info,"update")
@ -125,6 +127,14 @@ func on_update_stun_recover(rate):
if status.stun == 0:
remove_buff("stun_recover")
func on_update_weapon_index_change(rate):character.set_status("weapon_index_change_rate",rate)
func on_end_weapon_index_change(rate):
var weapon_index = status.weapon_index + status.weapon_index_change_dir
var weapon_len = len(status.weapon_list)
weapon_index = (weapon_index%weapon_len+weapon_len)%weapon_len
character.set_status("weapon_index",weapon_index)
character.set_status("weapon_index_change_dir",0)
#表现
func on_start_freeze(rate):status.is_pause = true
func on_end_freeze(rate):status.is_pause = false

@ -18,6 +18,7 @@ func _ready():
add_weapon(load("res://config/weapon/long.tres"))
add_weapon(load("res://config/weapon/short.tres"))
add_weapon(load("res://config/weapon/fist.tres"))
add_weapon(load("res://config/weapon/chain.tres"))
func _process(delta):
update_input_alive(delta)
@ -116,8 +117,12 @@ func add_weapon(weapon:WeaponCfg):
status.emit_status("weapon_list")
status.set_status("weapon_index",0)
func weapon_index_change(value:int):
if status.weapon_list:
var target_index = status.weapon_index + value
target_index = target_index % len(status.weapon_list)
status.set_status("weapon_index",target_index)
func weapon_index_change(dir:int):
if not status.weapon_list:
return
if status.weapon_index_change_dir:
return
if abs(dir) != 1:
return
status.set_status("weapon_index_change_dir",dir)
character.add_buff("weapon_index_change",Setting.weapon_anime_duration)

@ -70,6 +70,8 @@ class_name Status
@export var break_level : Enum.EBreakLevel #打断等级
@export var weapon_list = [] #武器列表
@export var weapon_index : int #当前武器下标
@export var weapon_index_change_dir : int #武器下标操作变化方向
@export var weapon_index_change_rate : float #武器下标操作变化进度
@export_category("动画触发器")
@export var trigger_jump : bool #跳跃

@ -1,33 +1,77 @@
extends Control
@onready var weapon_item_list = [$Weapon1,$Weapon2,$Weapon3,$Weapon4,$Weapon5]
@onready var weapon_scene = preload("res://scene/ui/item/weapon_item.tscn")
var duration : float
var item_layout_offset_x : int = 32
var item_layout_offset_y : int = 16
var weapon_item_list = []
var weapon_list : Array
var weapon_index : int
var weapon_index_dir : int
var weapon_index_rate : float
var hide_duration : float
func _process(delta):
if visible:
duration -= delta
if duration <= 0:
visible = false
if not visible:
return
if weapon_index_dir:
item_lerp(weapon_index_dir,weapon_index_rate)
hide_duration = Setting.weapon_hide_duration
return
item_lerp(weapon_index_dir,1)
hide_duration -= delta
if hide_duration <= 0:
for item in weapon_item_list:
remove_child(item)
weapon_item_list.clear()
visible = false
var weapon_list : Array
var weapon_index_list = [0,0,0,0,0]
func on_weapon_list_changed(list:Array):
weapon_list = list
func on_weapon_index_changed(index:int):
for i in range(5):
weapon_index_list[i] = (i + index + len(weapon_list) - 2) % len(weapon_list)
update_weapon()
func update_weapon():
if visible:
pass
else:
for i in range(5):
var weapon_item_sub = weapon_item_list[i] as WeaponItemSub
var weapon_cfg = weapon_list[weapon_index_list[i]] as WeaponCfg
weapon_item_sub.set_texture(weapon_cfg.icon)
func on_weapon_list_changed(list:Array):weapon_list = list
func on_weapon_index_changed(index:int):weapon_index = index
func on_weapon_index_change_rate_changed(rate:float):weapon_index_rate = rate
func on_weapon_index_change_dir_changed(dir:int):
weapon_index_dir = dir
if not weapon_index_dir:
return
if not visible:
visible = true
duration = Setting.weapon_hide_duration
for i in range(5):append()
else:
if dir > 0:
push_back()
pop_front()
else:
push_front()
pop_back()
hide_duration = Setting.weapon_hide_duration
func append():weapon_item_list.append(create_weapon_item(len(weapon_item_list)-2+weapon_index_dir))
func push_front():weapon_item_list.push_front(create_weapon_item(-2+weapon_index_dir))
func push_back():weapon_item_list.push_back(create_weapon_item(2+weapon_index_dir))
func pop_front():remove_child(weapon_item_list.pop_front())
func pop_back():remove_child(weapon_item_list.pop_back())
func create_weapon_item(offset:int)->WeaponItemSub:
var weapon_count = len(weapon_list)
var index = ((weapon_index + offset) % weapon_count + weapon_count) % weapon_count
var weapon_item_sub = weapon_scene.instantiate() as WeaponItemSub
var weapon_cfg = weapon_list[index] as WeaponCfg
add_child(weapon_item_sub)
weapon_item_sub.set_texture(weapon_cfg.icon)
return weapon_item_sub
func item_lerp(dir:int,rate:float):
for i in range(len(weapon_item_list)):
var item = weapon_item_list[i] as WeaponItemSub
var target_index = i-2
var index = target_index+dir
var pos_from = get_item_pos(index)
var pos_to = get_item_pos(target_index)
var alpha_from = 1 if abs(index)<=1 else 0
var alpha_to = 1 if abs(target_index)<=1 else 0
item.position = lerp(pos_from,pos_to,rate)
item.update_alpha(alpha_from,alpha_to,rate)
func get_item_pos(offset:int):
return Vector2(item_layout_offset_x*offset,item_layout_offset_y if offset else 0)

@ -1,7 +1,12 @@
extends Control
class_name WeaponItemSub
@onready var icon_rect = $WeaponIcon as TextureRect
func set_texture(value:Texture2D):
icon_rect.texture = value
$WeaponIcon.texture = value
func update_alpha(alpha_from:float,alpha_to:float,rate:float):
var alpha = lerp(alpha_from,alpha_to,rate)
$WeaponIcon.modulate = Color(1,1,1,alpha)
$WeaponSlot.modulate = Color(1,1,1,alpha)

Loading…
Cancel
Save