添加弹出框,修复鉴定

This commit is contained in:
TsubakiLoL 2024-11-18 11:13:00 +08:00
parent 834e5f76fd
commit 2e11493610
6 changed files with 111 additions and 4 deletions

View File

@ -0,0 +1,10 @@
extends PanelContainer
func set_text(str:String):
$Label.text=str
func _on_timer_timeout() -> void:
self.queue_free()
pass # Replace with function body.

View File

@ -0,0 +1,11 @@
extends CanvasLayer
@onready var toast_tscn=preload("res://autoload/toast/tscn/toast.tscn")
# Called when the node enters the scene tree for the first time.
func popup(str:String):
var new_toast=toast_tscn.instantiate()
$pos/VBoxContainer.add_child(new_toast)
new_toast.set_text(str)
pass

View File

@ -0,0 +1,49 @@
[gd_scene load_steps=4 format=3 uid="uid://35qxfxq6dnpk"]
[ext_resource type="Script" path="res://autoload/toast/script/toast.gd" id="1_53rag"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_1eytc"]
bg_color = Color(1, 1, 1, 1)
border_width_left = 10
border_width_top = 10
border_width_right = 10
border_width_bottom = 10
border_color = Color(0, 0, 0, 1)
border_blend = true
corner_radius_top_left = 10
corner_radius_top_right = 10
corner_radius_bottom_right = 10
corner_radius_bottom_left = 10
shadow_size = 2
[sub_resource type="LabelSettings" id="LabelSettings_i4wv3"]
font_size = 30
outline_size = 14
outline_color = Color(0, 0, 0, 1)
[node name="toast" type="PanelContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
size_flags_horizontal = 3
size_flags_vertical = 8
mouse_filter = 2
theme_override_styles/panel = SubResource("StyleBoxFlat_1eytc")
script = ExtResource("1_53rag")
[node name="Label" type="Label" parent="."]
layout_mode = 2
size_flags_vertical = 1
text = "这是一条通知"
label_settings = SubResource("LabelSettings_i4wv3")
horizontal_alignment = 1
vertical_alignment = 1
autowrap_mode = 3
[node name="Timer" type="Timer" parent="."]
one_shot = true
autostart = true
[connection signal="timeout" from="Timer" to="." method="_on_timer_timeout"]

View File

@ -0,0 +1,31 @@
[gd_scene load_steps=2 format=3 uid="uid://psgvivswjxvb"]
[ext_resource type="Script" path="res://autoload/toast/script/toast_root.gd" id="1_fss3d"]
[node name="toast_root" type="CanvasLayer"]
script = ExtResource("1_fss3d")
[node name="pos" type="Control" parent="."]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
mouse_filter = 2
[node name="VBoxContainer" type="VBoxContainer" parent="pos"]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.394
anchor_top = 0.239
anchor_right = 0.609
anchor_bottom = 0.877
offset_left = 0.111969
offset_top = 0.127991
offset_right = 0.431946
offset_bottom = -0.296021
grow_horizontal = 2
grow_vertical = 0
mouse_filter = 2
alignment = 2

View File

@ -22,6 +22,7 @@ Global="*res://autoload/global/tscn/global.tscn"
SceneManager="*res://autoload/scene_manager/tscn/scene_manager.tscn"
Bgm="*res://autoload/BGM/tscn/bgm.tscn"
Database="*res://autoload/database/tscn/database.tscn"
Toast="*res://autoload/toast/tscn/toast_root.tscn"
[display]

View File

@ -32,9 +32,9 @@ func set_data(_data:Dictionary):
%multi_pre.hide()
%single.show()
%single_name.text=data["name"]
single_judge_name=CharacterTool.get_name_by_attribute_key(data["attribute_name"])
single_judge_name=data["attribute_name"]
single_judge_value=data["attribute_value"]
%indetification_value.text=single_judge_name+":"+str(single_judge_value)
%indetification_value.text=CharacterTool.get_name_by_attribute_key(data["attribute_name"])+":"+str(single_judge_value)
var apped_item_data:Array=[]
#从背包中寻找可用item
func search_bag():
@ -84,30 +84,35 @@ func _on_single_start_pressed() -> void:
var character_dt=CharacterTool.get_character_use_identification_card(character_data,apped_item_data)
var res=judge_single_identification(character_dt)
if res:
Toast.popup("鉴定成功!")
for i in judge_success_triger:
Global.call_triger(i["type"],i["data"])
else:
Toast.popup("鉴定失败!")
for i in judge_fail_trigtr:
Global.call_triger(i["type"],i["data"])
#清空触发器
judge_success_triger=[]
judge_fail_trigtr=[]
print("鉴定结果"+str(res))
hide()
pass # Replace with function body.
#鉴定算法
func judge_single_identification(character_dt:Dictionary)->bool:
#Toast.popup("角色鉴定属性名:"+single_judge_name)
var attribute_value=CharacterTool.get_character_attribute(character_dt,single_judge_name)
#Toast.popup("角色值:"+str(attribute_value))
if attribute_value is float:
var percent=(attribute_value-single_judge_value)/30
var rand=randf()
#Toast.popup("鉴定概率:"+str(percent*100)+"%")
if rand<percent:
return true
else:
return false
else:
#Toast.popup("不存在对应的属性!")
return false