Anim Editor: added FoeFlip property, Space to play, S to swap sides, P to show/hide property lines for selected particle

This commit is contained in:
Maruno17
2024-04-18 22:35:15 +01:00
parent 15033d6114
commit 4480def33c
23 changed files with 264 additions and 161 deletions

View File

@@ -475,6 +475,7 @@ class AnimationEditor::Canvas < Sprite
spr.zoom_y = values[:zoom_y] / 100.0
spr.angle = values[:angle]
spr.mirror = values[:flip]
spr.mirror = !spr.mirror if relative_to_index >= 0 && relative_to_index.odd? && particle[:foe_flip]
spr.blend_type = values[:blending]
# Set color and tone
spr.color.set(values[:color_red], values[:color_green], values[:color_blue], values[:color_alpha])

View File

@@ -5,9 +5,9 @@ class AnimationEditor::PlayControls < UIControls::ControlsContainer
attr_reader :slowdown, :looping
ROW_HEIGHT = 28
PLAY_BUTTON_X = 241
PLAY_BUTTON_Y = 13
PLAY_BUTTON_SIZE = 22
PLAY_BUTTON_X = 231
PLAY_BUTTON_Y = 3
PLAY_BUTTON_SIZE = 42
LOOP_BUTTON_X = PLAY_BUTTON_X + PLAY_BUTTON_SIZE + 12
LOOP_BUTTON_Y = 16
LOOP_BUTTON_SIZE = 16
@@ -34,7 +34,8 @@ class AnimationEditor::PlayControls < UIControls::ControlsContainer
end
def dispose
@bitmaps.each { |b| b&.dispose }
@bitmaps.each_value { |b| b&.dispose }
@bitmaps.clear
super
end
@@ -43,12 +44,12 @@ class AnimationEditor::PlayControls < UIControls::ControlsContainer
def generate_button_bitmaps
@bitmaps = {}
play_button = Bitmap.new(PLAY_BUTTON_SIZE, PLAY_BUTTON_SIZE)
(PLAY_BUTTON_SIZE - 2).times do |j|
play_button.fill_rect(PLAY_BUTTON_SIZE / 4, j + 1, (j >= (PLAY_BUTTON_SIZE - 2) / 2) ? PLAY_BUTTON_SIZE - j : j + 3, 1, ICON_COLOR)
(PLAY_BUTTON_SIZE - 10).times do |j|
play_button.fill_rect(11, j + 5, (j >= (PLAY_BUTTON_SIZE - 10) / 2) ? PLAY_BUTTON_SIZE - j - 4 : j + 7, 1, ICON_COLOR)
end
@bitmaps[:play_button] = play_button
stop_button = Bitmap.new(PLAY_BUTTON_SIZE, PLAY_BUTTON_SIZE)
stop_button.fill_rect(4, 4, PLAY_BUTTON_SIZE - 8, PLAY_BUTTON_SIZE - 8, ICON_COLOR)
stop_button.fill_rect(8, 8, PLAY_BUTTON_SIZE - 16, PLAY_BUTTON_SIZE - 16, ICON_COLOR)
@bitmaps[:stop_button] = stop_button
# Loop button
play_once_button = Bitmap.new(LOOP_BUTTON_SIZE, LOOP_BUTTON_SIZE)
@@ -79,6 +80,22 @@ class AnimationEditor::PlayControls < UIControls::ControlsContainer
end
def add_play_controls
# Slowdown label
duration_label = UIControls::Label.new(200, ROW_HEIGHT, self.viewport, _INTL("Slowdown factor"))
duration_label.x = SLOWDOWN_BUTTON_X + (SLOWDOWN_FACTORS.length * (SLOWDOWN_BUTTON_WIDTH + SLOWDOWN_BUTTON_SPACING) / 2)
duration_label.x -= (duration_label.text_width / 2) + 5
duration_label.y = SLOWDOWN_LABEL_Y
@controls.push([:slowdown_label, duration_label])
# Slowdown factor buttons
SLOWDOWN_FACTORS.each_with_index do |value, i|
button = UIControls::Button.new(SLOWDOWN_BUTTON_WIDTH, ROW_HEIGHT, self.viewport, value.to_s)
button.set_fixed_size
button.x = SLOWDOWN_BUTTON_X + ((SLOWDOWN_BUTTON_WIDTH + SLOWDOWN_BUTTON_SPACING) * i)
button.y = SLOWDOWN_BUTTON_Y
button.set_interactive_rects
button.set_highlighted if value == @slowdown
@controls.push([("slowdown" + value.to_s).to_sym, button])
end
# Play button
play_button = UIControls::BitmapButton.new(PLAY_BUTTON_X, PLAY_BUTTON_Y, self.viewport, @bitmaps[:play_button])
play_button.set_interactive_rects
@@ -98,22 +115,6 @@ class AnimationEditor::PlayControls < UIControls::ControlsContainer
unloop_button.set_interactive_rects
unloop_button.visible = false if !@looping
@controls.push([:unloop, unloop_button])
# Slowdown label
duration_label = UIControls::Label.new(200, ROW_HEIGHT, self.viewport, _INTL("Slowdown factor"))
duration_label.x = SLOWDOWN_BUTTON_X + (SLOWDOWN_FACTORS.length * (SLOWDOWN_BUTTON_WIDTH + SLOWDOWN_BUTTON_SPACING) / 2)
duration_label.x -= (duration_label.text_width / 2) + 5
duration_label.y = SLOWDOWN_LABEL_Y
@controls.push([:slowdown_label, duration_label])
# Slowdown factor buttons
SLOWDOWN_FACTORS.each_with_index do |value, i|
button = UIControls::Button.new(SLOWDOWN_BUTTON_WIDTH, ROW_HEIGHT, self.viewport, value.to_s)
button.set_fixed_size
button.x = SLOWDOWN_BUTTON_X + ((SLOWDOWN_BUTTON_WIDTH + SLOWDOWN_BUTTON_SPACING) * i)
button.y = SLOWDOWN_BUTTON_Y
button.set_interactive_rects
button.set_highlighted if value == @slowdown
@controls.push([("slowdown" + value.to_s).to_sym, button])
end
# Duration label
duration_label = UIControls::Label.new(200, ROW_HEIGHT, self.viewport, _INTL("Duration"))
duration_label.x = DURATION_TEXT_X - (duration_label.text_width / 2)

View File

@@ -175,7 +175,8 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
@particle_line_sprite.dispose
@controls.each { |c| c[1].dispose }
@controls.clear
@bitmaps.each { |b| b&.dispose }
@bitmaps.each_value { |b| b&.dispose }
@bitmaps.clear
dispose_listed_sprites
@list_viewport.dispose
@commands_bg_viewport.dispose
@@ -433,16 +434,16 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
#-----------------------------------------------------------------------------
def calculate_duration
@duration = AnimationPlayer::Helper.get_duration(@particles)
@duration += DURATION_BUFFER
end
def calculate_all_commands_and_durations
calculate_duration
calculate_all_commands
end
def calculate_duration
@duration = AnimationPlayer::Helper.get_duration(@particles)
@duration += DURATION_BUFFER
end
def calculate_all_commands
@commands = {}
@particles.each_with_index do |particle, index|
@@ -1024,13 +1025,13 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
def update_input
# Left/right to change current keyframe
if Input.repeat?(Input::LEFT)
if Input.triggerex?(:LEFT) || Input.repeatex?(:LEFT)
if @keyframe > 0
@keyframe -= 1
scroll_to_keyframe(@keyframe)
set_changed
end
elsif Input.repeat?(Input::RIGHT)
elsif Input.triggerex?(:RIGHT) || Input.repeatex?(:RIGHT)
if @keyframe < @duration - 1
@keyframe += 1
scroll_to_keyframe(@keyframe)
@@ -1038,7 +1039,7 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
end
end
# Up/down to change selected particle
if Input.repeat?(Input::UP)
if Input.triggerex?(:UP) || Input.repeatex?(:UP)
if @row_index > 0
loop do
@row_index -= 1
@@ -1047,7 +1048,7 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
scroll_to_row(@row_index)
set_changed
end
elsif Input.repeat?(Input::DOWN)
elsif Input.triggerex?(:DOWN) || Input.repeatex?(:DOWN)
if @row_index < @particle_list.length - 1
old_row_index = @row_index
loop do
@@ -1064,6 +1065,18 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
end
end
end
if Input.triggerex?(:P)
idx_particle = @particle_list[@row_index]
idx_particle = idx_particle[0] if idx_particle.is_a?(Array)
if @row_index >= 0 && @particles[idx_particle][:name] != "SE"
if @expanded_particles.include?(idx_particle) # Contract
@expanded_particles.delete(idx_particle)
else # Expand
@expanded_particles.push(idx_particle)
end
set_particles(@particles)
end
end
# Mouse scroll wheel
mouse_x, mouse_y = mouse_pos
if mouse_x && mouse_y