Fleshing out animation editor's code

This commit is contained in:
Maruno17
2023-10-23 22:36:43 +01:00
parent 7031698d85
commit 340983e765
14 changed files with 810 additions and 282 deletions

View File

@@ -25,24 +25,32 @@ class AnimationEditor
WINDOW_WIDTH = AnimationEditorLoadScreen::WINDOW_WIDTH
WINDOW_HEIGHT = AnimationEditorLoadScreen::WINDOW_HEIGHT
TOP_BAR_HEIGHT = 30
BORDER_THICKNESS = 4
CANVAS_X = BORDER_THICKNESS
CANVAS_Y = 32 + BORDER_THICKNESS
CANVAS_Y = TOP_BAR_HEIGHT + BORDER_THICKNESS
CANVAS_WIDTH = Settings::SCREEN_WIDTH
CANVAS_HEIGHT = Settings::SCREEN_HEIGHT
PLAY_CONTROLS_X = CANVAS_X
PLAY_CONTROLS_Y = CANVAS_Y + CANVAS_HEIGHT + (BORDER_THICKNESS * 2)
PLAY_CONTROLS_WIDTH = CANVAS_WIDTH
PLAY_CONTROLS_HEIGHT = 64 - (BORDER_THICKNESS * 2)
SIDE_PANE_X = CANVAS_X + CANVAS_WIDTH + (BORDER_THICKNESS * 2)
SIDE_PANE_Y = CANVAS_Y
SIDE_PANE_WIDTH = WINDOW_WIDTH - SIDE_PANE_X - BORDER_THICKNESS
SIDE_PANE_HEIGHT = CANVAS_HEIGHT + (32 * 2)
PARTICLE_LIST_X = 0
SIDE_PANE_HEIGHT = CANVAS_HEIGHT + PLAY_CONTROLS_HEIGHT + (BORDER_THICKNESS * 2)
PARTICLE_LIST_X = BORDER_THICKNESS
PARTICLE_LIST_Y = SIDE_PANE_Y + SIDE_PANE_HEIGHT + (BORDER_THICKNESS * 2)
PARTICLE_LIST_WIDTH = WINDOW_WIDTH
PARTICLE_LIST_HEIGHT = WINDOW_HEIGHT - PARTICLE_LIST_Y
PARTICLE_LIST_WIDTH = WINDOW_WIDTH - (BORDER_THICKNESS * 2)
PARTICLE_LIST_HEIGHT = WINDOW_HEIGHT - PARTICLE_LIST_Y - BORDER_THICKNESS
def initialize(anim_id, anim)
@anim_id = anim_id
@anim = anim
@particle = -1
@viewport = Viewport.new(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT)
@viewport.z = 99999
@screen_bitmap = BitmapSprite.new(WINDOW_WIDTH, WINDOW_HEIGHT, @viewport)
@@ -53,9 +61,12 @@ class AnimationEditor
@canvas.y = CANVAS_Y
@canvas.bitmap = RPG::Cache.load_bitmap("Graphics/Battlebacks/", "field_bg")
# Side panes
@keyframe_particle_pane = UIControls::ControlsContainer.new(SIDE_PANE_X, SIDE_PANE_Y, SIDE_PANE_WIDTH, SIDE_PANE_HEIGHT)
@commands_pane = UIControls::ControlsContainer.new(SIDE_PANE_X, SIDE_PANE_Y, SIDE_PANE_WIDTH, SIDE_PANE_HEIGHT)
@se_pane = UIControls::ControlsContainer.new(SIDE_PANE_X, SIDE_PANE_Y, SIDE_PANE_WIDTH, SIDE_PANE_HEIGHT)
@particle_pane = UIControls::ControlsContainer.new(SIDE_PANE_X, SIDE_PANE_Y, SIDE_PANE_WIDTH, SIDE_PANE_HEIGHT)
@keyframe_pane = UIControls::ControlsContainer.new(SIDE_PANE_X, SIDE_PANE_Y, SIDE_PANE_WIDTH, SIDE_PANE_HEIGHT)
# TODO: Make more side panes for:
# - colour/tone editor (accessed from keyframe_particle_pane via a
# - colour/tone editor (accessed from commands_pane via a
# button; has Apply/Cancel buttons to only apply all its values at
# the end of editing them, although canvas will be updated in real
# time to show the changes)
@@ -66,6 +77,10 @@ class AnimationEditor
# shake, etc.)
# - keyframe properties (shift all later particle commands forward/
# backward).
# Play controls
@play_controls = UIControls::AnimationPlayControls.new(
PLAY_CONTROLS_X, PLAY_CONTROLS_Y, PLAY_CONTROLS_WIDTH, PLAY_CONTROLS_HEIGHT, @viewport
)
# Timeline/particle list
@particle_list = UIControls::AnimationParticleList.new(
PARTICLE_LIST_X, PARTICLE_LIST_Y, PARTICLE_LIST_WIDTH, PARTICLE_LIST_HEIGHT, @viewport
@@ -74,13 +89,18 @@ class AnimationEditor
@captured = nil
set_side_panes_contents
set_particle_list_contents
set_play_controls_contents
refresh
end
def dispose
@screen_bitmap.dispose
@canvas.dispose
@keyframe_particle_pane.dispose
@commands_pane.dispose
@se_pane.dispose
@particle_pane.dispose
@keyframe_pane.dispose
@play_controls.dispose
@particle_list.dispose
@viewport.dispose
end
@@ -95,55 +115,93 @@ class AnimationEditor
#-----------------------------------------------------------------------------
def set_keyframe_particle_pane_contents
# TODO: Move these properties to a new side pane for particle properties
# (ones that don't change during the animation).
@keyframe_particle_pane.add_labelled_text_box(:name, "Name", "Untitled")
# @keyframe_particle_pane.add_labelled_dropdown_list(:focus, "Focus", {
# :user => "User",
# :target => "Target",
# :user_and_target => "User and target",
# :screen => "Screen"
# }, :user)
# TODO: Make sure the IDs for these controls all match up to particle
# properties that can change during the animation.
@keyframe_particle_pane.add_labelled_value_box(:x, "X", -128, CANVAS_WIDTH + 128, 64)
@keyframe_particle_pane.add_labelled_value_box(:y, "Y", -128, CANVAS_HEIGHT + 128, 96)
@keyframe_particle_pane.add_labelled_value_box(:zoom_x, "Zoom X", 0, 1000, 100)
@keyframe_particle_pane.add_labelled_value_box(:zoom_y, "Zoom Y", 0, 1000, 100)
@keyframe_particle_pane.add_labelled_checkbox(:visible, "Visible", true)
@keyframe_particle_pane.add_labelled_slider(:opacity, "Opacity", 0, 255, 255)
@keyframe_particle_pane.add_labelled_value_box(:angle, "Angle", -1080, 1080, 0)
@keyframe_particle_pane.add_labelled_checkbox(:flip, "Flip", false)
@keyframe_particle_pane.add_labelled_dropdown_list(:priority, "Priority", { # TODO: Include sub-priority.
:behind_all => "Behind all",
:behind_user => "Behind user",
:above_user => "In front of user",
:above_all => "In front of everything"
}, :above_user)
@keyframe_particle_pane.add_labelled_button(:color, "Color", "Edit")
@keyframe_particle_pane.add_labelled_button(:tone, "Tone", "Edit")
@keyframe_particle_pane.add_labelled_button(:graphic, "Graphic", "Change")
# :frame (related to graphic)
# :blending
def set_commands_pane_contents
# :frame (related to graphic) - If the graphic is user's sprite/target's
# sprite, make this instead a choice of front/back/same as the main sprite/
# opposite of the main sprite. Probably need two controls in the same space
# and refresh_commands_pane makes the appropriate one visible.
@commands_pane.add_labelled_value_box(:x, _INTL("X"), -128, CANVAS_WIDTH + 128, 64)
@commands_pane.add_labelled_value_box(:y, _INTL("Y"), -128, CANVAS_HEIGHT + 128, 96)
@commands_pane.add_labelled_checkbox(:visible, _INTL("Visible"), true)
@commands_pane.add_labelled_slider(:opacity, _INTL("Opacity"), 0, 255, 255)
@commands_pane.add_labelled_value_box(:zoom_x, _INTL("Zoom X"), 0, 1000, 100)
@commands_pane.add_labelled_value_box(:zoom_y, _INTL("Zoom Y"), 0, 1000, 100)
@commands_pane.add_labelled_value_box(:angle, _INTL("Angle"), -1080, 1080, 0)
@commands_pane.add_labelled_checkbox(:flip, _INTL("Flip"), false)
@commands_pane.add_labelled_dropdown_list(:blending, _INTL("Blending"), {
0 => _INTL("None"),
1 => _INTL("Additive"),
2 => _INTL("Subtractive")
}, 0)
@commands_pane.add_labelled_button(:color_tone, _INTL("Color/Tone"), _INTL("Edit"))
# @commands_pane.add_labelled_dropdown_list(:priority, _INTL("Priority"), { # TODO: Include sub-priority.
# :behind_all => _INTL("Behind all"),
# :behind_user => _INTL("Behind user"),
# :above_user => _INTL("In front of user"),
# :above_all => _INTL("In front of everything")
# }, :above_user)
# :sub_priority
# @commands_pane.add_labelled_button(:masking, _INTL("Masking"), _INTL("Edit"))
# TODO: Add buttons that shift all commands from the current keyframe and
# later forwards/backwards in time?
end
def set_se_pane_contents
# TODO: A list containing all SE files that play this keyframe. Lists SE,
# user cry and target cry.
@se_pane.add_button(:add, _INTL("Add"))
@se_pane.add_button(:edit, _INTL("Edit"))
@se_pane.add_button(:delete, _INTL("Delete"))
end
def set_particle_pane_contents
# TODO: Name should blacklist certain names ("User", "Target", "SE") and
# should be disabled if the value is one of those.
@particle_pane.add_labelled_text_box(:name, _INTL("Name"), _INTL("Untitled"))
# TODO: Graphic should show the graphic's name alongside a "Change" button.
# New kind of control that is a label plus a button?
@particle_pane.add_labelled_button(:graphic, _INTL("Graphic"), _INTL("Change"))
@particle_pane.add_labelled_dropdown_list(:focus, _INTL("Focus"), {
:user => _INTL("User"),
:target => _INTL("Target"),
:user_and_target => _INTL("User and target"),
:screen => _INTL("Screen")
}, :user)
# FlipIfFoe
# RotateIfFoe
# Delete button (if not "User"/"Target"/"SE")
# Duplicate button
# Shift all command timings by X keyframes (text box and button)
# Move particle up/down the list?
end
def set_keyframe_pane_contents
@keyframe_pane.add_label(:temp, _INTL("Keyframe pane"))
# TODO: Various command-shifting options.
end
def set_side_panes_contents
set_keyframe_particle_pane_contents
set_commands_pane_contents
set_se_pane_contents
set_particle_pane_contents
set_keyframe_pane_contents
end
def set_particle_list_contents
@particle_list.set_particles(@anim[:particles])
end
def set_play_controls_contents
@play_controls.duration = @particle_list.duration
end
#-----------------------------------------------------------------------------
def draw_editor_background
# Fill the whole screen with black
@screen_bitmap.bitmap.fill_rect(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, Color.black)
# Fill the top bar with white
@screen_bitmap.bitmap.fill_rect(0, 0, WINDOW_WIDTH, TOP_BAR_HEIGHT, Color.white)
# Outline around canvas
@screen_bitmap.bitmap.outline_rect(CANVAS_X - 3, CANVAS_Y - 3, CANVAS_WIDTH + 6, CANVAS_HEIGHT + 6, Color.white)
@screen_bitmap.bitmap.outline_rect(CANVAS_X - 2, CANVAS_Y - 2, CANVAS_WIDTH + 4, CANVAS_HEIGHT + 4, Color.black)
@@ -154,22 +212,31 @@ class AnimationEditor
@screen_bitmap.bitmap.outline_rect(SIDE_PANE_X - 1, SIDE_PANE_Y - 1, SIDE_PANE_WIDTH + 2, SIDE_PANE_HEIGHT + 2, Color.white)
# Fill the side pane with white
@screen_bitmap.bitmap.fill_rect(SIDE_PANE_X, SIDE_PANE_Y, SIDE_PANE_WIDTH, SIDE_PANE_HEIGHT, Color.white)
# Outline around play controls
@screen_bitmap.bitmap.outline_rect(PLAY_CONTROLS_X - 3, PLAY_CONTROLS_Y - 3, PLAY_CONTROLS_WIDTH + 6, PLAY_CONTROLS_HEIGHT + 6, Color.white)
@screen_bitmap.bitmap.outline_rect(PLAY_CONTROLS_X - 2, PLAY_CONTROLS_Y - 2, PLAY_CONTROLS_WIDTH + 4, PLAY_CONTROLS_HEIGHT + 4, Color.black)
@screen_bitmap.bitmap.outline_rect(PLAY_CONTROLS_X - 1, PLAY_CONTROLS_Y - 1, PLAY_CONTROLS_WIDTH + 2, PLAY_CONTROLS_HEIGHT + 2, Color.white)
# Fill the play controls with white
@screen_bitmap.bitmap.fill_rect(PLAY_CONTROLS_X, PLAY_CONTROLS_Y, PLAY_CONTROLS_WIDTH, PLAY_CONTROLS_HEIGHT, Color.white)
# Outline around timeline/particle list
@screen_bitmap.bitmap.outline_rect(PARTICLE_LIST_X - 3, PARTICLE_LIST_Y - 3, PARTICLE_LIST_WIDTH + 6, PARTICLE_LIST_HEIGHT + 6, Color.white)
@screen_bitmap.bitmap.outline_rect(PARTICLE_LIST_X - 2, PARTICLE_LIST_Y - 2, PARTICLE_LIST_WIDTH + 4, PARTICLE_LIST_HEIGHT + 4, Color.black)
@screen_bitmap.bitmap.outline_rect(PARTICLE_LIST_X - 1, PARTICLE_LIST_Y - 1, PARTICLE_LIST_WIDTH + 2, PARTICLE_LIST_HEIGHT + 2, Color.white)
end
def refresh_keyframe_particle_pane
if !keyframe || keyframe < 0 || !particle_index || particle_index < 0 ||
!@anim[:particles][particle_index]
@keyframe_particle_pane.visible = false
def refresh_canvas
end
def refresh_commands_pane
if keyframe < 0 || particle_index < 0 || !@anim[:particles][particle_index] ||
@anim[:particles][particle_index][:name] == "SE"
@commands_pane.visible = false
else
@keyframe_particle_pane.visible = true
@commands_pane.visible = true
new_vals = AnimationEditor::ParticleDataHelper.get_all_keyframe_particle_values(@anim[:particles][particle_index], keyframe)
# TODO: Need to do something special for :color, :tone and :graphic/:frame
# which all have button controls.
@keyframe_particle_pane.controls.each do |ctrl|
# TODO: Need to do something special for :color, :tone and :frame which
# all have button controls.
@commands_pane.controls.each do |ctrl|
next if !new_vals.include?(ctrl[0])
ctrl[1].value = new_vals[ctrl[0]][0] if ctrl[1].respond_to?("value=")
# TODO: new_vals[ctrl[0]][1] is whether the value is being interpolated,
@@ -178,15 +245,58 @@ class AnimationEditor
end
end
def refresh_se_pane
if keyframe < 0 || particle_index < 0 || !@anim[:particles][particle_index] ||
@anim[:particles][particle_index][:name] != "SE"
@se_pane.visible = false
else
@se_pane.visible = true
# TODO: Set list of SEs, activate/deactivate buttons accordingly.
end
end
def refresh_particle_pane
if keyframe >= 0 || particle_index < 0
@particle_pane.visible = false
else
@particle_pane.visible = true
new_vals = AnimationEditor::ParticleDataHelper.get_all_particle_values(@anim[:particles][particle_index])
@particle_pane.controls.each do |ctrl|
next if !new_vals.include?(ctrl[0])
ctrl[1].value = new_vals[ctrl[0]] if ctrl[1].respond_to?("value=")
end
# TODO: Disable the name and graphic controls for "User"/"Target".
end
end
def refresh_keyframe_pane
if keyframe < 0 || particle_index >= 0
@keyframe_pane.visible = false
else
@keyframe_pane.visible = true
end
end
def refresh_particle_list
@particle_list.refresh
end
def refresh_play_controls
@play_controls.refresh
end
def refresh
# Set canvas display
refresh_canvas
# Set all side pane controls to values from animation
refresh_keyframe_particle_pane
refresh_commands_pane
refresh_se_pane
refresh_particle_pane
refresh_keyframe_pane
# Set particle list's contents
refresh_particle_list
# Set play controls' information
refresh_play_controls
end
#-----------------------------------------------------------------------------
@@ -197,23 +307,96 @@ class AnimationEditor
# double-clicking to add particle, deleting particle.
end
def update_keyframe_particle_pane
@keyframe_particle_pane.update
@captured = :keyframe_particle_pane if @keyframe_particle_pane.busy?
if @keyframe_particle_pane.changed?
def update_commands_pane
return if !@commands_pane.visible
@commands_pane.update
if @commands_pane.busy?
@captured = [@commands_pane, :update_commands_pane]
end
if @commands_pane.changed?
# TODO: Make undo/redo snapshot.
values = @keyframe_particle_pane.values
# TODO: Apply vals to the animation data, unless the changed control is a
# button (its value will be true), in which case run some special
# code. Maybe this special code should be passed to/run in the
# control as a proc instead, and the button control can be given a
# value like any other control? Probably not.
echoln values
if values[:color]
elsif values[:tone]
elsif values[:graphic]
values = @commands_pane.values
values.each_pair do |property, value|
case property
when :color_tone # Button
# TODO: Open the colour/tone side pane.
else
particle = @anim[:particles][particle_index]
new_cmds = AnimationEditor::ParticleDataHelper.add_command(particle, property, keyframe, value)
if new_cmds
particle[property] = new_cmds
else
particle.delete(property)
end
@particle_list.change_particle_commands(particle_index)
@play_controls.duration = @particle_list.duration
refresh_commands_pane
end
end
@keyframe_particle_pane.clear_changed
@commands_pane.clear_changed
end
end
def update_se_pane
return if !@se_pane.visible
@se_pane.update
if @se_pane.busy?
@captured = [@se_pane, :update_se_pane]
end
# TODO: Enable the "Edit" and "Delete" controls only if an SE is selected.
if @se_pane.changed?
# TODO: Make undo/redo snapshot.
values = @se_pane.values
values.each_pair do |property, value|
case property
when :add # Button
when :edit # Button
when :delete # Button
else
particle = @anim[:particles][particle_index]
end
end
@se_pane.clear_changed
end
end
def update_particle_pane
return if !@particle_pane.visible
@particle_pane.update
if @particle_pane.busy?
@captured = [@particle_pane, :update_particle_pane]
end
if @particle_pane.changed?
# TODO: Make undo/redo snapshot.
values = @particle_pane.values
values.each_pair do |property, value|
case property
when :graphic # Button
# TODO: Open the graphic chooser pop-up window.
else
particle = @anim[:particles][particle_index]
new_cmds = AnimationEditor::ParticleDataHelper.set_property(particle, property, value)
@particle_list.change_particle(particle_index)
refresh_particle_pane
end
end
@particle_pane.clear_changed
end
end
def update_keyframe_pane
return if !@keyframe_pane.visible
@keyframe_pane.update
if @keyframe_pane.busy?
@captured = [@keyframe_pane, :update_keyframe_pane]
end
if @keyframe_pane.changed?
# TODO: Make undo/redo snapshot.
values = @keyframe_pane.values
values.each_pair do |property, value|
# TODO: Stuff here once I decide what controls to add.
end
@keyframe_pane.clear_changed
end
end
@@ -221,34 +404,44 @@ class AnimationEditor
old_keyframe = keyframe
old_particle_index = particle_index
@particle_list.update
@captured = :particle_list if @particle_list.busy?
if @particle_list.busy?
@captured = [@particle_list, :update_particle_list]
end
if @particle_list.changed?
refresh_keyframe_particle_pane if keyframe != old_keyframe || particle_index != old_particle_index
refresh if keyframe != old_keyframe || particle_index != old_particle_index
# TODO: Lots of stuff here.
@particle_list.clear_changed
end
@particle_list.repaint
end
def update_play_controls
@play_controls.update
@play_controls.repaint
if @play_controls.busy?
@captured = [@play_controls, :update_play_controls]
end
# TODO: Will the play controls ever signal themselves as changed? I don't
# think so.
if @play_controls.changed?
@play_controls.clear_changed
end
@play_controls.repaint
end
def update
if @captured
# TODO: There must be a better way to do this.
case @captured
when :canvas
update_canvas
@captured = nil if !@canvas.busy?
when :keyframe_particle_pane
update_keyframe_particle_pane
@captured = nil if !@keyframe_particle_pane.busy?
when :particle_list
update_particle_list
@captured = nil if !@particle_list.busy?
end
else
update_canvas
update_keyframe_particle_pane
update_particle_list
self.send(@captured[1])
@captured = nil if !@captured[0].busy?
return
end
update_canvas
update_commands_pane
update_se_pane
update_particle_pane
update_keyframe_pane
update_particle_list
update_play_controls
end
#-----------------------------------------------------------------------------