Anim Editor: Particle spawner tweaks

This commit is contained in:
Maruno17
2024-05-04 22:20:05 +01:00
parent dba28332f2
commit 8aacfe491f
10 changed files with 119 additions and 551 deletions

View File

@@ -533,9 +533,10 @@ AnimationEditor::SidePanes.add_property(:particle_pane, :random_frame_max, {
AnimationEditor::SidePanes.add_property(:particle_pane, :spawner, {
:new => proc { |pane, editor|
values = {
:none => _INTL("None"),
:random_direction => _INTL("Random direction"),
:random_direction_gravity => _INTL("Random direction gravity")
:none => _INTL("None"),
:random_direction => _INTL("Random direction"),
:random_direction_gravity => _INTL("Random dir. with gravity"),
:random_up_direction_gravity => _INTL("Random up dir. gravity")
}
pane.add_labelled_dropdown_list(:spawner, _INTL("Spawner"), values, :none)
}
@@ -552,6 +553,12 @@ AnimationEditor::SidePanes.add_property(:particle_pane, :spawn_quantity, {
else
control.enable
end
},
:apply_value => proc { |value, editor|
AnimationEditor::SidePanes.get_pane(:particle_pane)[:apply_value].call(:spawn_quantity, value, editor)
editor.components[:particle_list].change_particle_commands(editor.particle_index)
editor.components[:play_controls].duration = editor.components[:particle_list].duration
editor.refresh
}
})

View File

@@ -64,7 +64,8 @@ module AnimationEditor::ParticleDataHelper
end
# Used to determine which keyframes the particle is visible in, which is
# indicated in the timeline by a coloured bar.
# indicated in the timeline by a coloured bar. 0=not visible, 1=visible,
# 2=visible because of spawner delay.
# NOTE: Particles are assumed to be not visible at the start of the
# animation, and automatically become visible when the particle has
# its first command. This does not apply to the "User" and "Target"
@@ -75,8 +76,8 @@ module AnimationEditor::ParticleDataHelper
raise _INTL("Couldn't get default value for property {1} for particle {2}.",
property, particle[:name])
end
value = GameData::Animation::PARTICLE_KEYFRAME_DEFAULT_VALUES[:visible]
value = true if ["User", "Target", "SE"].include?(particle[:name])
value = GameData::Animation::PARTICLE_KEYFRAME_DEFAULT_VALUES[:visible] ? 1 : 0
value = 1 if ["User", "Target", "SE"].include?(particle[:name])
ret = []
if !["User", "Target", "SE"].include?(particle[:name])
earliest = duration
@@ -84,15 +85,31 @@ module AnimationEditor::ParticleDataHelper
next if !value.is_a?(Array) || value.empty?
earliest = value[0][0] if earliest > value[0][0]
end
ret[earliest] = true
ret[earliest] = 1
end
if particle[:visible]
particle[:visible].each { |cmd| ret[cmd[0]] = cmd[2] }
particle[:visible].each { |cmd| ret[cmd[0]] = (cmd[2]) ? 1 : 0 }
end
duration.times do |i|
value = ret[i] if !ret[i].nil?
ret[i] = value
end
qty = particle[:spawn_quantity] || 1 if particle[:spawner] && particle[:spawner] != :none
if (particle[:spawner] || :none) != :none
qty = particle[:spawn_quantity] || 1
delay = AnimationPlayer::Helper.get_particle_delay(particle, qty - 1)
if delay > 0
count = -1
duration.times do |i|
if ret[i] == 1 # Visible
count = 0
elsif ret[i] == 0 && count >= 0 && count < delay # Not visible and within delay
ret[i] = 2
count += 1
end
end
end
end
return ret
end

View File

@@ -518,7 +518,7 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
end
sprites_need_changing = ensure_sprites
if @duration != old_duration || sprites_need_changing
@keyframe = @keyframe.clamp(0, @duration - 1)
@keyframe = @keyframe.clamp(-1, @duration - 1)
@row_index = @row_index.clamp(0, @particle_list.length - 1)
create_sprites
end
@@ -737,7 +737,7 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
each_visible_keyframe do |i|
draw_x = TIMELINE_LEFT_BUFFER + (i * KEYFRAME_SPACING) - @left_pos
# Draw bg
if i < @duration - DURATION_BUFFER && visible_cmds[i]
if i < @duration - DURATION_BUFFER && visible_cmds[i] == 1
bg_spr.bitmap.fill_rect(draw_x, ROW_SPACING, KEYFRAME_SPACING, ROW_HEIGHT - ROW_SPACING, bg_color)
end
# Draw hover highlight
@@ -772,19 +772,39 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
end
end
next if i >= @duration - DURATION_BUFFER
next if !visible_cmds[i]
# Draw outline
outline_color = Color.black
if is_property
outline_color = CONTROL_BG_COLORS[@particles[p_index][:focus]] || Color.magenta
end
bg_spr.bitmap.fill_rect(draw_x, ROW_SPACING, KEYFRAME_SPACING, 1, outline_color) # Top
bg_spr.bitmap.fill_rect(draw_x, ROW_HEIGHT - 1, KEYFRAME_SPACING, 1, outline_color) # Bottom
if i <= 0 || !visible_cmds[i - 1]
bg_spr.bitmap.fill_rect(draw_x, ROW_SPACING, 1, ROW_HEIGHT - ROW_SPACING, outline_color) # Left
end
if i == @duration - DURATION_BUFFER - 1 || (i < @duration - 1 && !visible_cmds[i + 1])
bg_spr.bitmap.fill_rect(draw_x + KEYFRAME_SPACING, ROW_SPACING, 1, ROW_HEIGHT - ROW_SPACING, outline_color) # Right
case visible_cmds[i]
when 1 # Particle is visible
# Draw outline
if is_property
outline_color = CONTROL_BG_COLORS[@particles[p_index][:focus]] || Color.magenta
end
bg_spr.bitmap.fill_rect(draw_x, ROW_SPACING, KEYFRAME_SPACING, 1, outline_color) # Top
bg_spr.bitmap.fill_rect(draw_x, ROW_HEIGHT - 1, KEYFRAME_SPACING, 1, outline_color) # Bottom
if i <= 0 || visible_cmds[i - 1] != 1
bg_spr.bitmap.fill_rect(draw_x, ROW_SPACING, 1, ROW_HEIGHT - ROW_SPACING, outline_color) # Left
end
if i == @duration - DURATION_BUFFER - 1 || (i < @duration - 1 && visible_cmds[i + 1] != 1)
bg_spr.bitmap.fill_rect(draw_x + KEYFRAME_SPACING, ROW_SPACING, 1, ROW_HEIGHT - ROW_SPACING, outline_color) # Right
end
when 2 # Particle is a spawner and delays its particles into this frame
if !is_property
# Draw dotted outline
KEYFRAME_SPACING.times do |j|
next if j.odd?
bg_spr.bitmap.fill_rect(draw_x + j, ROW_SPACING, 1, 1, outline_color) # Top
bg_spr.bitmap.fill_rect(draw_x + j, ROW_HEIGHT - 1, 1, 1, outline_color) # Bottom
end
(ROW_HEIGHT - ROW_SPACING).times do |j|
next if j.odd?
if i <= 0 || visible_cmds[i - 1] != 2
bg_spr.bitmap.fill_rect(draw_x, ROW_SPACING + j, 1, 1, outline_color) # Left
end
if i == @duration - DURATION_BUFFER - 1 || (i < @duration - 1 && visible_cmds[i + 1] != 2)
bg_spr.bitmap.fill_rect(draw_x + KEYFRAME_SPACING, ROW_SPACING + j, 1, 1, outline_color) # Right
end
end
end
end
end
end
@@ -1027,7 +1047,7 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
def update_input
# Left/right to change current keyframe
if Input.triggerex?(:LEFT) || Input.repeatex?(:LEFT)
if @keyframe > 0
if @keyframe >= 0
@keyframe -= 1
scroll_to_keyframe(@keyframe)
set_changed