Skip to content

Commit

Permalink
TDraw: 修复多视口下的 draw_timer 问题
Browse files Browse the repository at this point in the history
  • Loading branch information
LaneSun committed Mar 8, 2024
1 parent 070c6d4 commit edc5352
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 28 deletions.
3 changes: 3 additions & 0 deletions lib/sekai/sekai_item.gsm.gd
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ func _draw() -> void:
func get_time() -> float:
return _time

func reset_time(time := 0.0) -> void:
_time = time

func get_delta_time() -> float:
return _t_delta

Expand Down
49 changes: 33 additions & 16 deletions lib/sekai/traits/drawer/t_draw.gd
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,36 @@ var props := {
&"draw_data": {},
&"cur_draw": &"",
&"cur_draw_variant": 0,
&"draw_timer": 0.0, # FIXME
&"draw_flip_h": false,
&"on_draw_end": Prop.Stack(), # TODO

&"draw/reset": func (ctx: LisperContext, this: Mono) -> void:
var items := this.getp(&"layer") as Dictionary
for item in items.values():
if item != null:
this.setp(&"draw_timer", item.get_time()),
item.reset_time(),
&"draw/restick": func (ctx: LisperContext, this: Mono) -> void:
var cur_draw = this.getp(&"cur_draw")
if cur_draw == &"": return
var draw = this.getp(&"draw_data")[cur_draw]
if draw[0] == &"diverse":
draw = draw[1][this.getp(&"cur_draw_variant")]
if draw[0] == &"sticky":
var timeout := draw[2] as float
var items := this.getp(&"layer") as Dictionary
for item in items.values():
if item != null:
this.setp(&"draw_timer", item.get_time() + timeout),
while draw[0] != &"sticky":
match draw[0]:
&"diverse":
draw = draw[1][this.getp(&"cur_draw_variant")]
continue
&"layers":
for d in draw[1]:
if d[0] == &"sticky":
draw = d
break
return
_:
return
var timeout := draw[2] as float
var items := this.getp(&"layer") as Dictionary
for item in items.values():
if item != null:
item.reset_time(-timeout),
&"draw/to": func (ctx: LisperContext, this: Mono, draw_id: StringName) -> void:
this.setp(&"cur_draw", draw_id),
&"draw/reset_to": func (ctx: LisperContext, this: Mono, draw_id: StringName) -> void:
Expand Down Expand Up @@ -57,26 +66,34 @@ const TILE_MAP = [
]

static func on_draw(ctx: LisperContext, this: Mono, ctrl: SekaiControl, item: SekaiItem) -> void:
var pos := Vector2(this.position.x, this.position.y - this.position.z * item.ratio_yz)
var cur_draw = this.getp(&"cur_draw")
if cur_draw == &"": return
var draw = this.getp(&"draw_data")[cur_draw]
if draw[0] == &"diverse":
draw = draw[1][this.getp(&"cur_draw_variant")]
_on_draw(ctx, this, item, this.getp(&"draw_data")[cur_draw])

static func _on_draw(ctx: LisperContext, this: Mono, item: SekaiItem, draw: Array) -> void:
match draw[0]:
&"layers":
for d in draw[1]:
_on_draw(ctx, this, item, d)
return
&"diverse":
_on_draw(ctx, this, item, draw[1][this.getp(&"cur_draw_variant")])
return
var texture = this.getp(&"asserts")[draw[1]]
var pos := Vector2(this.position.x, this.position.y - this.position.z)
var frame
match draw[0]:
&"static":
frame = draw[2]
&"fixed":
var timeout := draw[2] as float
var t := item.get_time() - this.getp(&"draw_timer") as float
var t := item.get_time()
var frames := draw[3] as Array
var frame_idx := frames.size() * fposmod(t / timeout, 1) as int
frame = frames[frame_idx]
&"sticky":
var timeout := draw[2] as float
var t := item.get_time() - this.getp(&"draw_timer") as float
var t := item.get_time()
var frames := draw[3] as Array
var frame_idx := clampi(frames.size() * (t / timeout + 1) as int, 0, frames.size() - 1)
frame = frames[frame_idx]
Expand Down
22 changes: 10 additions & 12 deletions lib/sekai/traits/drawer/t_draw_static.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ var props := {
const TILE_MAP := TDraw.TILE_MAP

static func draw_handle(ctx: LisperContext, this: Mono, draw: Array) -> void:
if draw[0] == &"layers":
for d in draw[1]:
draw_handle(ctx, this, d)
return
if draw[0] == &"diverse":
draw_handle(ctx, this, draw[1][this.getp(&"cur_draw_variant")])
return
match draw[0]:
&"layers":
for d in draw[1]:
draw_handle(ctx, this, d)
return
&"diverse":
draw_handle(ctx, this, draw[1][this.getp(&"cur_draw_variant")])
return
var texture = this.getp(&"asserts")[draw[1]]
var pos := Vector2(this.position.x, this.position.y - this.position.z)
match draw[0]:
Expand All @@ -49,12 +50,10 @@ static func draw_handle(ctx: LisperContext, this: Mono, draw: Array) -> void:
&"fixed":
var timeout := draw[2] as float
var frames := draw[3] as Array
var timer := this.getp(&"draw_timer") as float
if this.getp(&"draw_flip_h"):
this.puts_on_draw([
&"0:draw_static", func (ctx: LisperContext, this: Mono, ctrl: SekaiControl, item: SekaiItem) -> void:
var t := (item.get_time() - timer) as float
var frame_idx := lerpf(0.0, (frames.size() as float), fmod(t, timeout) / timeout) as int
var frame_idx := lerpf(0.0, (frames.size() as float), fmod(item.get_time(), timeout) / timeout) as int
var frame = frames[frame_idx]
item.pen_set_transform(Transform2D(0, Vector2(-1, 1), 0, pos + frame[0].position + frame[0].size / 2))
item.pen_draw_texture_region(texture, Rect2(-frame[0].size / 2, frame[0].size), frame[1])
Expand All @@ -63,8 +62,7 @@ static func draw_handle(ctx: LisperContext, this: Mono, draw: Array) -> void:
else:
this.puts_on_draw([
&"0:draw_static", func (ctx: LisperContext, this: Mono, ctrl: SekaiControl, item: SekaiItem) -> void:
var t := (item.get_time() - timer) as float
var frame_idx := lerpf(0.0, (frames.size() as float), fmod(t, timeout) / timeout) as int
var frame_idx := lerpf(0.0, (frames.size() as float), fmod(item.get_time(), timeout) / timeout) as int
var frame = frames[frame_idx]
item.pen_draw_texture_region(texture, Rect2(pos + frame[0].position, frame[0].size), frame[1])
])
Expand Down
1 change: 1 addition & 0 deletions test-next/define/实体/kami/ui/main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ placeholder_text = "过滤"
unique_name_in_owner = true
layout_mode = 2
size_flags_vertical = 3
mouse_force_pass_scroll_events = false

[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer5/HSplitContainer/VBoxContainer"]
layout_mode = 2
Expand Down

0 comments on commit edc5352

Please sign in to comment.