9.24上午

This commit is contained in:
TsubakiLoL 2024-09-24 11:59:54 +08:00
parent 67a6671d04
commit eb9933afbd
26 changed files with 390 additions and 45 deletions

View File

@ -165,7 +165,7 @@ func set_now_scene(scene_id:String):
now_game_data["now_scene"]=scene_id
var now_game_flow:GameFlow
func get_now_character_data():
return now_game_data["character_data"]
return now_game_data["character_data"].duplicate()
func _ready() -> void:
load_texture_data()
load_script_data()
@ -231,6 +231,15 @@ func load_npc_data():
for i in dictionary.keys():
dictionary[i]["id"]=i
npc_data=dictionary
func load_card_data():
var file=FileAccess.open(card_json_path,FileAccess.READ)
var str=file.get_as_text()
var dictionary:Dictionary=JSON.parse_string(str)
for i in dictionary.keys():
dictionary[i]["id"]=i
card_data=dictionary
pass
func get_texture(id:String):
if texture_data.has(id):
return texture_data[id]
@ -277,3 +286,9 @@ func get_npc_data(id:String):
else:
return null
pass
func get_card_data(id:String):
if card_data.has(id):
var dictionary:Dictionary=card_data[id]
return dictionary.duplicate()
else:
return null

View File

@ -0,0 +1,29 @@
extends Node
class_name State
@onready var timer=Timer.new()
@onready var root=get_node("..") as StateMachine
func _ready():
timer.set_one_shot(true)
self.add_child(timer)
timer.timeout.connect(Callable(self,"time_out"))
func enter_state(n):
pass
func update_state(delta):
pass
func update_state_phy(delta):
pass
func exit_state():
pass
func change_to_state(state_name:String,s=0):
root.change_state(state_name,s)
pass
func time_out():
pass
func get_player():
return root.player
func process_message(type:String,n):
pass

View File

@ -0,0 +1,45 @@
extends Node
##状态机根节点类
class_name StateMachine
##状态机进入时候的状态
@export var init_state:NodePath="stable_1"##进入时的状态
@export var owner_player:NodePath="stable_1"##拥有此状态机的节点路径
@onready var state_list=get_children() ##所拥有的状态节点的数组
@onready var state_now:State=get_node(init_state) ##当前的状态节点
@onready var player =get_node(owner_player) ##通过角色路径获取到的节点
func _ready():
set_process(false)
##启动状态机
func launch():
state_now=get_node(init_state)
state_now.enter_state(1)
set_process(true)
func _process(delta):
if state_now:
state_now.update_state(delta)
func _physics_process(delta):
if state_now:
state_now.update_state_phy(delta)
##判断n节点是否在状态机节点所拥有的状态中
func is_in_list(n)->bool:
if n in state_list:
return true
return false
##将状态节点切换为n,并调用对应的init stable方法和exit stable方法,传入s
func change_state(n:String,s):
var change_to=get_node(n)
if change_to&&is_in_list(change_to)&&state_now!=change_to:
state_now.exit_state()
state_now=change_to
state_now.enter_state(s)
##获取当前状态的状态名
func get_state_name()->String:
return self.state_now.state_name
func get_state(state_name:String):
return self.get_node(state_name)
func send_message(type:String,n=0):
if state_now!=null:
state_now.process_message(type,n)
pass

View File

@ -1,6 +1,13 @@
class_name TimeTool
static func is_leap_year(year:int)->bool:
if year%4==0 and year%100!=0:
return true
elif year%400==0:
return true
else:
return false
static func is_in_date(data:Dictionary,now_time:Dictionary)->bool:
var from_time:Dictionary

View File

@ -1,5 +1,6 @@
{
"card_01":{
"name":"测试卡01"
"name":"测试卡01",
"icon":"?"
}
}

View File

@ -1,8 +1,8 @@
{
"test_character_01":{
"character":{
"name":"朱雀院椿(测试)",
"name":"朱雀院椿(测试1)",
"head":"test_character_tsubaki_head",
"star":3,
"skin":[
@ -86,8 +86,9 @@
},
"test_character_02":{
"character":{
"name":"朱雀院椿(测试)",
"name":"朱雀院椿(测试2)",
"star":3,
"head":"test_character_tsubaki_head",
"skin":[
{
"name":"皮肤1",
@ -176,7 +177,7 @@
"test_character_02":{
"test_character_03":{
"character":{
"name":"朱雀院椿(NPC)",
"star":3,
@ -260,7 +261,7 @@
}
]
},
"test_character_02":{
"test_character_04":{
"character":{
"name":"朱雀院椿(测试)",
"star":3,

View File

@ -3,5 +3,7 @@
"test_scene":"res://test/texture/test_scene.png",
"test_character":"res://test/texture/test_character.png",
"test_character_tsubaki":"res://test/texture/tsubaki_1.png",
"tower":"res://test/texture/test_tower.jpg"
"test_character_tsubaki_head":"res://test/texture/tsubaki_head.png",
"tower":"res://test/texture/test_tower.jpg",
"?":"res://res/ui/ui_025_adventure_mode/tuceng353.png"
}

View File

@ -0,0 +1,72 @@
shader_type canvas_item;
uniform vec4 color : source_color = vec4(1.0);
uniform float width : hint_range(0, 10) = 1.0;
uniform int pattern : hint_range(0, 2) = 0; // diamond, circle, square
uniform bool inside = false;
uniform bool add_margins = true; // only useful when inside is false
uniform vec2 number_of_images = vec2(1.0); // number of horizontal and vertical images in the sprite sheet
uniform bool open_flashing;
uniform vec4 flashing_color:source_color=vec4(1,1,1,1);
void vertex() {
if (add_margins) {
VERTEX += sign(VERTEX) * width; // replace `sign(VERTEX)` by `sign(VERTEX * 2.0 - 1.0)` if not centered
}
}
bool hasContraryNeighbour(vec2 uv, vec2 texture_pixel_size, vec2 image_top_left, vec2 image_bottom_right, sampler2D texture) {
for (float i = -ceil(width); i <= ceil(width); i++) {
float x = abs(i) > width ? width * sign(i) : i;
float offset;
if (pattern == 0) {
offset = width - abs(x);
} else if (pattern == 1) {
offset = floor(sqrt(pow(width + 0.5, 2) - x * x));
} else if (pattern == 2) {
offset = width;
}
for (float j = -ceil(offset); j <= ceil(offset); j++) {
float y = abs(j) > offset ? offset * sign(j) : j;
vec2 xy = uv + texture_pixel_size * vec2(x, y);
if ((xy != clamp(xy, image_top_left, image_bottom_right) || texture(texture, xy).a <= 0.0) == inside) {
return true;
}
}
}
return false;
}
void fragment() {
if(!open_flashing){
vec2 uv = UV;
vec2 image_top_left = floor(uv * number_of_images) / number_of_images;
vec2 image_bottom_right = image_top_left + vec2(1.0) / number_of_images;
if (add_margins) {
vec2 texture_pixel_size = vec2(1.0) / (vec2(1.0) / TEXTURE_PIXEL_SIZE + vec2(width * 2.0) * number_of_images);
uv = (uv - texture_pixel_size * width - image_top_left) * TEXTURE_PIXEL_SIZE / texture_pixel_size + image_top_left;
if (uv != clamp(uv, image_top_left, image_bottom_right)) {
COLOR.a = 0.0;
} else {
COLOR = texture(TEXTURE, uv);
}
} else {
COLOR = texture(TEXTURE, uv);
}
if ((COLOR.a > 0.0) == inside && hasContraryNeighbour(uv, TEXTURE_PIXEL_SIZE, image_top_left, image_bottom_right, TEXTURE)) {
COLOR.rgb = inside ? mix(COLOR.rgb, color.rgb, color.a) : color.rgb;
COLOR.a += (1.0 - COLOR.a) * color.a;
}
}
else{
COLOR.rgb=flashing_color.rgb;
}
}

26
scene/card.gd Normal file
View File

@ -0,0 +1,26 @@
extends Control
@onready var state_machine: StateMachine = $state_machine
@onready var fight_card: TextureRect = $fight_card
func _on_fight_card_mouse_entered() -> void:
state_machine.send_message("mouse_enter")
pass # Replace with function body.
func _on_fight_card_mouse_exited() -> void:
state_machine.send_message("mouse_exit")
pass # Replace with function body.
func up():
pass
var last_scale_tween:Tween
func scale_to(sc:float):
if last_scale_tween!=null:
last_scale_tween.kill()
last_scale_tween=get_tree().create_tween()
last_scale_tween.tween_property(fight_card,"scale",Vector2(sc,sc),0.1)

46
scene/card.tscn Normal file
View File

@ -0,0 +1,46 @@
[gd_scene load_steps=10 format=3 uid="uid://8a2mwnnmnecl"]
[ext_resource type="PackedScene" uid="uid://chowelwcfnsxs" path="res://scene/fight_card.tscn" id="1_nmkht"]
[ext_resource type="Script" path="res://scene/card.gd" id="1_wc0x3"]
[ext_resource type="Script" path="res://scene/card_state_machine/root.gd" id="3_k5t40"]
[ext_resource type="Script" path="res://scene/card_state_machine/getting.gd" id="4_8qagf"]
[ext_resource type="Script" path="res://scene/card_state_machine/idle.gd" id="4_p2uoy"]
[ext_resource type="Script" path="res://scene/card_state_machine/focus.gd" id="6_3e38c"]
[ext_resource type="Script" path="res://scene/card_state_machine/selected.gd" id="7_ugr71"]
[ext_resource type="Script" path="res://scene/card_state_machine/queue.gd" id="8_y4vrd"]
[ext_resource type="Script" path="res://scene/card_state_machine/exe.gd" id="9_40m88"]
[node name="card" type="Control"]
layout_mode = 3
anchors_preset = 0
script = ExtResource("1_wc0x3")
[node name="fight_card" parent="." instance=ExtResource("1_nmkht")]
layout_mode = 0
pivot_offset = Vector2(94, 125)
[node name="state_machine" type="Node" parent="."]
script = ExtResource("3_k5t40")
init_state = NodePath("idle")
owner_player = NodePath("..")
[node name="getting" type="Node" parent="state_machine"]
script = ExtResource("4_8qagf")
[node name="idle" type="Node" parent="state_machine"]
script = ExtResource("4_p2uoy")
[node name="focus" type="Node" parent="state_machine"]
script = ExtResource("6_3e38c")
[node name="selected" type="Node" parent="state_machine"]
script = ExtResource("7_ugr71")
[node name="queue" type="Node" parent="state_machine"]
script = ExtResource("8_y4vrd")
[node name="exe" type="Node" parent="state_machine"]
script = ExtResource("9_40m88")
[connection signal="mouse_entered" from="fight_card" to="." method="_on_fight_card_mouse_entered"]
[connection signal="mouse_exited" from="fight_card" to="." method="_on_fight_card_mouse_exited"]

View File

@ -0,0 +1 @@
extends State

View File

@ -0,0 +1,11 @@
extends State
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass

View File

@ -0,0 +1,11 @@
extends State
# Called when the node enters the scene tree for the first time.
func _ready() -> void:
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass

View File

@ -0,0 +1,16 @@
extends State
func enter_state(n):
pass
func update_state(delta):
pass
func update_state_phy(delta):
pass
func exit_state():
pass
func time_out():
pass
func process_message(type:String,n):
pass

View File

@ -0,0 +1 @@
extends State

View File

@ -0,0 +1 @@
extends StateMachine

View File

@ -0,0 +1 @@
extends State

View File

@ -25,7 +25,7 @@ var data:Dictionary={
signal pressed(data,node,is_select)
func _on_tool_button_pressed() -> void:
is_selected=!is_selected
pressed.emit(data,self,is_selected)
pressed.emit(data.duplicate(),self,is_selected)
pass # Replace with function body.
func _ready() -> void:

View File

@ -77,30 +77,31 @@ metadata/_edit_use_anchors_ = true
[node name="ToolButton" parent="TextureRect" instance=ExtResource("5_cxbtq")]
layout_mode = 1
[node name="hbox" type="HBoxContainer" parent="."]
layout_mode = 0
anchor_left = 0.0260417
anchor_top = 0.45463
anchor_right = 0.871875
anchor_bottom = 0.686111
theme_override_constants/separation = 59
metadata/_edit_use_anchors_ = true
[node name="fight_character_card" parent="hbox" instance=ExtResource("6_5ixhk")]
layout_mode = 2
[node name="fight_character_card2" parent="hbox" instance=ExtResource("6_5ixhk")]
layout_mode = 2
[node name="hbox2" type="HBoxContainer" parent="."]
[node name="character_card_add_pos" type="HBoxContainer" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.141146
anchor_left = 0.0260417
anchor_top = 0.45463
anchor_right = 0.984896
anchor_bottom = 0.686111
theme_override_constants/separation = 20
metadata/_edit_use_anchors_ = true
[node name="fight_character_card" parent="character_card_add_pos" instance=ExtResource("6_5ixhk")]
layout_mode = 2
[node name="fight_character_card2" parent="character_card_add_pos" instance=ExtResource("6_5ixhk")]
layout_mode = 2
[node name="enermy_card_add_pos" type="HBoxContainer" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.0260417
anchor_right = 0.986979
anchor_bottom = 0.231481
theme_override_constants/separation = 59
theme_override_constants/separation = 20
alignment = 2
metadata/_edit_use_anchors_ = true
[node name="fight_enermy_card" parent="hbox2" instance=ExtResource("7_fjnhq")]
[node name="fight_enermy_card" parent="enermy_card_add_pos" instance=ExtResource("7_fjnhq")]
layout_mode = 2

11
scene/fight_card.gd Normal file
View File

@ -0,0 +1,11 @@
extends TextureRect
@onready var n: Label = $n
@onready var icon: TextureRect = $icon
var data:Dictionary
func set_card(id:String):
data=Global.get_card_data(id)
icon.texture=Global.get_texture(data["icon"])
n.text=data["name"]
pass

View File

@ -1,47 +1,54 @@
[gd_scene load_steps=5 format=3 uid="uid://chowelwcfnsxs"]
[gd_scene load_steps=6 format=3 uid="uid://chowelwcfnsxs"]
[ext_resource type="Texture2D" uid="uid://bac5i5fhd7acq" path="res://res/ui/ui_026_fight/tuceng285.png" id="1_2g5f6"]
[ext_resource type="Texture2D" uid="uid://d4geq35efgqon" path="res://res/ui/ui_026_fight/tuceng286.png" id="2_2gbqn"]
[ext_resource type="Script" path="res://scene/fight_card.gd" id="2_nlhl0"]
[ext_resource type="Texture2D" uid="uid://vhxdnd5qvcpv" path="res://res/ui/ui_025_adventure_mode/tuceng353.png" id="3_obhg4"]
[ext_resource type="PackedScene" uid="uid://bdlo2wn4qnygv" path="res://scene/tool/tool_button.tscn" id="4_0y613"]
[sub_resource type="ShaderMaterial" id="ShaderMaterial_i0euk"]
[node name="fight_card" type="TextureRect"]
offset_right = 189.0
offset_bottom = 250.0
material = SubResource("ShaderMaterial_i0euk")
offset_left = -94.0
offset_top = -125.0
offset_right = 95.0
offset_bottom = 125.0
texture = ExtResource("1_2g5f6")
expand_mode = 3
script = ExtResource("2_nlhl0")
[node name="TextureRect" type="TextureRect" parent="."]
show_behind_parent = true
clip_children = 2
light_mask = 9
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
texture = ExtResource("2_2gbqn")
expand_mode = 1
metadata/_edit_use_anchors_ = true
[node name="TextureRect2" type="TextureRect" parent="."]
[node name="icon" type="TextureRect" parent="."]
layout_mode = 0
anchor_left = 0.153439
anchor_top = 0.152
anchor_right = 0.89418
anchor_bottom = 0.724
mouse_filter = 2
texture = ExtResource("3_obhg4")
expand_mode = 1
stretch_mode = 5
metadata/_edit_use_anchors_ = true
[node name="Label" type="Label" parent="."]
[node name="n" type="Label" parent="."]
layout_mode = 0
offset_top = 225.0
offset_right = 189.0
offset_bottom = 250.0
anchor_top = 0.9
anchor_right = 1.0
anchor_bottom = 1.0
text = "道具卡"
horizontal_alignment = 1
[node name="ToolButton" parent="." instance=ExtResource("4_0y613")]
layout_mode = 1
metadata/_edit_use_anchors_ = true

View File

@ -0,0 +1,4 @@
extends TextureRect
@onready var n: Label = $TextureRect/n
@onready var icon: TextureRect = $TextureRect/TextureRect2/icon

View File

@ -1,6 +1,7 @@
[gd_scene load_steps=8 format=3 uid="uid://braadtw2q0x6u"]
[gd_scene load_steps=9 format=3 uid="uid://braadtw2q0x6u"]
[ext_resource type="Texture2D" uid="uid://cn2q8k4s3bxiu" path="res://res/ui/ui_026_fight/juxing744_1.png" id="1_oi31c"]
[ext_resource type="Script" path="res://scene/fight_character_card.gd" id="2_berqc"]
[ext_resource type="Texture2D" uid="uid://by6vl56taeyd2" path="res://res/ui/ui_026_fight/tuceng285_2.png" id="2_evh5s"]
[ext_resource type="Texture2D" uid="uid://d4geq35efgqon" path="res://res/ui/ui_026_fight/tuceng286.png" id="3_kujn5"]
[ext_resource type="Texture2D" uid="uid://li8e5ntlgcpg" path="res://res/ui/ui_003_select/test.png" id="4_srllr"]
@ -15,6 +16,7 @@ size_flags_horizontal = 0
size_flags_vertical = 3
texture = ExtResource("1_oi31c")
expand_mode = 3
script = ExtResource("2_berqc")
[node name="TextureRect" type="TextureRect" parent="."]
layout_mode = 1
@ -36,7 +38,7 @@ grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("3_kujn5")
[node name="TextureRect" type="TextureRect" parent="TextureRect/TextureRect2"]
[node name="icon" type="TextureRect" parent="TextureRect/TextureRect2"]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
@ -47,7 +49,7 @@ texture = ExtResource("4_srllr")
expand_mode = 1
stretch_mode = 6
[node name="Label" type="Label" parent="TextureRect"]
[node name="n" type="Label" parent="TextureRect"]
layout_mode = 0
anchor_top = 0.884
anchor_right = 1.0

View File

@ -23,7 +23,7 @@ func _ready() -> void:
Global.time_changed.connect(update_date)
Global.now_game_flow=self
var character_data=Global.get_now_character_data()
character_texture.texture=Global.get_texture(character_data["character"]["skin"][character_data["character"]["skin_now_use"]]["card_face"])
character_texture.texture=Global.get_texture(character_data["character"]["head"])
character_name.text=character_data["character"]["name"]
func set_scene(id:String):
scene_data=Global.get_scene_data(id)

Binary file not shown.

After

Width:  |  Height:  |  Size: 156 KiB

View File

@ -0,0 +1,34 @@
[remap]
importer="texture"
type="CompressedTexture2D"
uid="uid://cbyjecdxr6mup"
path="res://.godot/imported/tsubaki_head.png-d616098088dd0e77c7cef770671f8f93.ctex"
metadata={
"vram_texture": false
}
[deps]
source_file="res://test/texture/tsubaki_head.png"
dest_files=["res://.godot/imported/tsubaki_head.png-d616098088dd0e77c7cef770671f8f93.ctex"]
[params]
compress/mode=0
compress/high_quality=false
compress/lossy_quality=0.7
compress/hdr_compression=1
compress/normal_map=0
compress/channel_pack=0
mipmaps/generate=false
mipmaps/limit=-1
roughness/mode=0
roughness/src_normal=""
process/fix_alpha_border=true
process/premult_alpha=false
process/normal_map_invert_y=false
process/hdr_as_srgb=false
process/hdr_clamp_exposure=false
process/size_limit=0
detect_3d/compress_to=1