Skip to content

Commit

Permalink
add:任务栏
Browse files Browse the repository at this point in the history
  • Loading branch information
tuzhanhong committed Feb 27, 2024
1 parent 6305f01 commit 7731041
Showing 12 changed files with 237 additions and 4 deletions.
5 changes: 5 additions & 0 deletions project.godot
Original file line number Diff line number Diff line change
@@ -168,6 +168,11 @@ kami_zoom_reset={
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":true,"meta_pressed":false,"button_mask":4,"position":Vector2(130, 11),"global_position":Vector2(796, 392),"factor":1.0,"button_index":3,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}
task_toggle={
"deadzone": 0.5,
"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":84,"key_label":0,"unicode":116,"echo":false,"script":null)
]
}

[input_devices]

2 changes: 1 addition & 1 deletion test-next/define/实体/human.gd
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@ func do_merge(sets: Array[Dictionary]) -> Array[Dictionary]:
merge_traits(sets, [
有背包, 有快捷栏, 有精力,
可控制, 交互主体,
UI快捷栏, UI物品栏, UI合成台, UI状态栏,
UI快捷栏, UI物品栏, UI合成台, UI状态栏, UI任务栏,
主次行为输入,
一般控制输入, 一般交互输入,
])
9 changes: 8 additions & 1 deletion test-next/define/实体/traits/一般控制输入.gd
Original file line number Diff line number Diff line change
@@ -26,10 +26,16 @@ var props := {
# @params: SekaiControl
&"on_inventory_toggle": Prop.Stack({
&"0:一般控制": func (ctx: LisperContext, this: Mono, ctrl: SekaiControl) -> void:
print("open")
await this.callmRSU(ctx, &"inventory/toggle", ctrl),
}),

# 开关任务栏
# @params: SekaiControl
&"on_task_toggle": Prop.Stack({
&"0:一般控制": func (ctx: LisperContext, this: Mono, ctrl: SekaiControl) -> void:
await this.callmRSU(ctx, &"task/toggle", ctrl),
}),



#--------------------------------------------------------------------------#
@@ -46,6 +52,7 @@ var props := {
&"slot_4": await this.applyc(ctx, &"on_slot_select", [ctrl, 3])
&"slot_5": await this.applyc(ctx, &"on_slot_select", [ctrl, 4])
&"inventory_toggle": await this.applyc(ctx, &"on_inventory_toggle", [ctrl])
&"task_toggle": await this.applyc(ctx, &"on_task_toggle", [ctrl])
pass,
}),
}
32 changes: 32 additions & 0 deletions test-next/define/实体/ui/任务栏.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class_name UI任务栏 extends MonoTrait

var id := &"UI任务栏"
var requires := [&"ui"]

var props := {
#
# 方法
#

# 打开任务栏
&"task/toggle": func (ctx: LisperContext, this: Mono, ctrl: SekaiControl) -> void:
if await this.applymRSU(ctx, &"ui/toggle", [ctrl, &"task"]) != null:
this.emitmRSUY(ctx, &"control/block")
else:
this.emitc(ctx, &"on_task_closed")
this.emitmRSUY(ctx, &"control/unblock")
var node = this.applymRSUY(ctx, &"ui/get", [ctrl, &"slots"])
pass,

#
# 信号
#

# 任务栏被关闭时触发
&"on_task_closed": Prop.Stack(),

#--------------------------------------------------------------------------#
&"ui_data": {
&"task": preload("任务栏/task.tscn"),
},
}
31 changes: 31 additions & 0 deletions test-next/define/实体/ui/任务栏/task.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
extends Control

var this: Mono
var context: LisperContext
var control: SekaiControl

func _ready() -> void:
draw_task()

func _enter_tree() -> void:
this.putsB.call_deferred(&"on_input", [&"0:UI任务栏", _on_input])

func _exit_tree() -> void:
this.delsB(&"on_input", &"0:UI任务栏")

func _on_input(ctx: LisperContext, this: Mono, ctrl: SekaiControl, sets: InputSet) -> void:
if sets.pressings.has(&"task_toggle"): await this.callmRSU(ctx, &"task/toggle", ctrl)

func draw_task():
var tasks = await sekai.gikou.callm(context, &"taskm/get_by_status", 0)
for task in tasks.values():
var name = task["data"]["name"]
var desc = task["data"]["desc"]
var node = TaskButton.new()
node.text = name
node.desc = desc
node.connect("press", _on_button_pressed)
%CraftList.add_child(node)

func _on_button_pressed(desc: String):
$describe.text = desc
80 changes: 80 additions & 0 deletions test-next/define/实体/ui/任务栏/task.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
[gd_scene load_steps=7 format=3 uid="uid://dxfigiu78vxil"]

[ext_resource type="Texture2D" uid="uid://dh0fifljiutht" path="res://test-next/define/实体/ui/任务栏/任务书.png" id="1_cs245"]
[ext_resource type="Script" path="res://test-next/define/实体/ui/任务栏/task.gd" id="2_i7b1d"]
[ext_resource type="Texture2D" uid="uid://ciy146m8dp43d" path="res://test-next/define/实体/ui/合成台/拖动条.png" id="3_xvfrj"]
[ext_resource type="Texture2D" uid="uid://coct8kk3p6ce" path="res://test-next/define/实体/ui/合成台/拖动闲置.png" id="4_bnu4i"]
[ext_resource type="Texture2D" uid="uid://7qy76xr4b1do" path="res://test-next/define/实体/ui/合成台/拖动点击.png" id="5_44h56"]
[ext_resource type="Script" path="res://test-next/define/实体/ui/合成台/scroll.gd" id="6_46hpq"]

[node name="Task" type="TextureRect"]
anchors_preset = 8
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
offset_left = -255.0
offset_top = -224.0
offset_right = 256.0
offset_bottom = 96.0
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("1_cs245")
expand_mode = 3
stretch_mode = 4
script = ExtResource("2_i7b1d")

[node name="scrollBar" type="TextureRect" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.412916
anchor_top = 0.15625
anchor_right = 0.430528
anchor_bottom = 0.78125
texture = ExtResource("3_xvfrj")
metadata/_edit_use_anchors_ = true

[node name="scroll" type="TextureButton" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.398453
anchor_top = 0.152174
anchor_right = 0.437137
anchor_bottom = 0.220497
offset_left = -1.08622e-05
offset_right = 1.22303
offset_bottom = 1.22976
keep_pressed_outside = true
texture_normal = ExtResource("4_bnu4i")
texture_pressed = ExtResource("5_44h56")
script = ExtResource("6_46hpq")
y_max = 235
y_min = 50

[node name="list" type="ScrollContainer" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.0841487
anchor_top = 0.146875
anchor_right = 0.389432
anchor_bottom = 0.771875
vertical_scroll_mode = 3
metadata/_edit_use_anchors_ = true

[node name="CraftList" type="VBoxContainer" parent="list"]
unique_name_in_owner = true
layout_mode = 2
size_flags_horizontal = 3

[node name="describe" type="Label" parent="."]
layout_mode = 1
anchors_preset = -1
anchor_left = 0.549902
anchor_top = 0.134375
anchor_right = 0.917808
anchor_bottom = 0.496875
offset_left = 1.33976e-05
offset_right = -1.07714e-05
autowrap_mode = 1
text_overrun_behavior = 1
metadata/_edit_use_anchors_ = true
11 changes: 11 additions & 0 deletions test-next/define/实体/ui/任务栏/task_button.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class_name TaskButton extends Button

signal press(desc)

var desc: String

func _ready():
self.pressed.connect(self._on_pressed)

func _on_pressed():
emit_signal("press", desc)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions test-next/define/实体/ui/任务栏/任务书.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://dh0fifljiutht"
path="res://.godot/imported/任务书.png-d670ce3c0c8acbdd6272c752157d3be7.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://test-next/define/实体/ui/任务栏/任务书.png"
dest_files=["res://.godot/imported/任务书.png-d670ce3c0c8acbdd6272c752157d3be7.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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions test-next/define/实体/ui/任务栏/任务图标.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://d2mkilxqpouix"
path="res://.godot/imported/任务图标.png-420747cfc0dca53e705f4f34d88b2a71.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://test-next/define/实体/ui/任务栏/任务图标.png"
dest_files=["res://.godot/imported/任务图标.png-420747cfc0dca53e705f4f34d88b2a71.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
3 changes: 1 addition & 2 deletions test-next/define/实体/ui/合成台/craft.gd
Original file line number Diff line number Diff line change
@@ -52,8 +52,7 @@ func get_craft_list():
if item == null:
continue
var need_num = record["need"][id]
# mock
var need_ref = 3000
var need_ref = item.ref
craft_list[ref]["needs"] = {}
craft_list[ref]["needs"][need_ref] = {}
craft_list[ref]["needs"][need_ref]["num"] = need_num

0 comments on commit 7731041

Please sign in to comment.