mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-07 21:24:59 +00:00
Rearranged and renamed Animation Editor-related script files
This commit is contained in:
469
Data/Scripts/904_Anim Editor/001_AnimationEditor.rb
Normal file
469
Data/Scripts/904_Anim Editor/001_AnimationEditor.rb
Normal file
@@ -0,0 +1,469 @@
|
||||
# TODO: Should I split this code into visual and mechanical classes, a la the
|
||||
# other UI screens?
|
||||
#===============================================================================
|
||||
# TODO: Need a way to recognise when text is being input into something
|
||||
# (Input.text_input) and disable all keyboard shortcuts if so. If only
|
||||
# this class has keyboard shortcuts in it, then it should be okay already.
|
||||
# TODO: When creating a new particle, blacklist the names "User", "Target" and
|
||||
# "SE". Make particles with those names undeletable.
|
||||
# TODO: Remove the particle named "Target" if the animation's focus is changed
|
||||
# to one that doesn't include a target, and vice versa. Do the same for
|
||||
# "User".
|
||||
# TODO: Things that need pop-up windows (draws a semi-transparent grey over the
|
||||
# whole screen behind the window):
|
||||
# - graphic picker
|
||||
# - SE file picker
|
||||
# - animation properties (Move/OppMove/Common/OppCommon, move, version,
|
||||
# extra name, target, filepath, flags, etc.)
|
||||
# - editor settings (theme, canvas BG graphics, user/target graphics,
|
||||
# display of canvas particle boxes, etc.)
|
||||
# TODO: While playing the animation, draw a semi-transparent grey over the
|
||||
# screen except for the canvas and playback controls. Can't edit anything
|
||||
# while it's playing.
|
||||
#===============================================================================
|
||||
class AnimationEditor
|
||||
WINDOW_WIDTH = Settings::SCREEN_WIDTH + (32 * 10)
|
||||
WINDOW_HEIGHT = Settings::SCREEN_HEIGHT + (32 * 10)
|
||||
|
||||
TOP_BAR_HEIGHT = 30
|
||||
|
||||
BORDER_THICKNESS = 4
|
||||
CANVAS_X = 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 + 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 - (BORDER_THICKNESS * 2)
|
||||
PARTICLE_LIST_HEIGHT = WINDOW_HEIGHT - PARTICLE_LIST_Y - BORDER_THICKNESS
|
||||
|
||||
def initialize(anim_id, anim)
|
||||
@anim_id = anim_id
|
||||
@anim = anim
|
||||
# Viewports
|
||||
@viewport = Viewport.new(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT)
|
||||
@viewport.z = 99999
|
||||
@canvas_viewport = Viewport.new(CANVAS_X, CANVAS_Y, CANVAS_WIDTH, CANVAS_HEIGHT)
|
||||
@canvas_viewport.z = @viewport.z
|
||||
# Background sprite
|
||||
@screen_bitmap = BitmapSprite.new(WINDOW_WIDTH, WINDOW_HEIGHT, @viewport)
|
||||
draw_editor_background
|
||||
# Canvas
|
||||
@canvas = AnimationEditor::Canvas.new(@canvas_viewport)
|
||||
# Play controls
|
||||
@play_controls = AnimationEditor::PlayControls.new(
|
||||
PLAY_CONTROLS_X, PLAY_CONTROLS_Y, PLAY_CONTROLS_WIDTH, PLAY_CONTROLS_HEIGHT, @viewport
|
||||
)
|
||||
# Side panes
|
||||
@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 @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)
|
||||
# - effects particle properties (depends on keyframe; for screen
|
||||
# shake, etc.)
|
||||
# Timeline/particle list
|
||||
@particle_list = AnimationEditor::ParticleList.new(
|
||||
PARTICLE_LIST_X, PARTICLE_LIST_Y, PARTICLE_LIST_WIDTH, PARTICLE_LIST_HEIGHT, @viewport
|
||||
)
|
||||
@particle_list.set_interactive_rects
|
||||
@captured = nil
|
||||
set_canvas_contents
|
||||
set_side_panes_contents
|
||||
set_particle_list_contents
|
||||
set_play_controls_contents
|
||||
refresh
|
||||
end
|
||||
|
||||
def dispose
|
||||
@screen_bitmap.dispose
|
||||
@canvas.dispose
|
||||
@commands_pane.dispose
|
||||
@se_pane.dispose
|
||||
@particle_pane.dispose
|
||||
@keyframe_pane.dispose
|
||||
@play_controls.dispose
|
||||
@particle_list.dispose
|
||||
@viewport.dispose
|
||||
@canvas_viewport.dispose
|
||||
end
|
||||
|
||||
def keyframe
|
||||
return @particle_list.keyframe
|
||||
end
|
||||
|
||||
def particle_index
|
||||
return @particle_list.particle_index
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
def set_canvas_contents
|
||||
@canvas.bg_name = "indoor1"
|
||||
end
|
||||
|
||||
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_number_text_box(:x, _INTL("X"), -128, CANVAS_WIDTH + 128, 64)
|
||||
@commands_pane.add_labelled_number_text_box(:y, _INTL("Y"), -128, CANVAS_HEIGHT + 128, 96)
|
||||
@commands_pane.add_labelled_checkbox(:visible, _INTL("Visible"), true)
|
||||
@commands_pane.add_labelled_number_slider(:opacity, _INTL("Opacity"), 0, 255, 255)
|
||||
@commands_pane.add_labelled_number_text_box(:zoom_x, _INTL("Zoom X"), 0, 1000, 100)
|
||||
@commands_pane.add_labelled_number_text_box(:zoom_y, _INTL("Zoom Y"), 0, 1000, 100)
|
||||
@commands_pane.add_labelled_number_text_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_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)
|
||||
@screen_bitmap.bitmap.outline_rect(CANVAS_X - 1, CANVAS_Y - 1, CANVAS_WIDTH + 2, CANVAS_HEIGHT + 2, Color.white)
|
||||
# Outline around side pane
|
||||
@screen_bitmap.bitmap.outline_rect(SIDE_PANE_X - 3, SIDE_PANE_Y - 3, SIDE_PANE_WIDTH + 6, SIDE_PANE_HEIGHT + 6, Color.white)
|
||||
@screen_bitmap.bitmap.outline_rect(SIDE_PANE_X - 2, SIDE_PANE_Y - 2, SIDE_PANE_WIDTH + 4, SIDE_PANE_HEIGHT + 4, Color.black)
|
||||
@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_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
|
||||
@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 :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,
|
||||
# which should be indicated somehow in ctrl[1].
|
||||
end
|
||||
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_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
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
def update_canvas
|
||||
@canvas.update
|
||||
# TODO: Detect and apply changes made in canvas, e.g. moving particle,
|
||||
# double-clicking to add particle, deleting particle.
|
||||
end
|
||||
|
||||
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 = @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
|
||||
@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
|
||||
|
||||
def update_particle_list
|
||||
old_keyframe = keyframe
|
||||
old_particle_index = particle_index
|
||||
@particle_list.update
|
||||
if @particle_list.busy?
|
||||
@captured = [@particle_list, :update_particle_list]
|
||||
end
|
||||
if @particle_list.changed?
|
||||
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
|
||||
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
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
def run
|
||||
Input.text_input = false
|
||||
loop do
|
||||
inputting_text = Input.text_input
|
||||
Graphics.update
|
||||
Input.update
|
||||
update
|
||||
if !inputting_text
|
||||
if Input.trigger?(Input::BACK)
|
||||
# TODO: Ask to save/discard changes.
|
||||
# TODO: When saving, add animation to GameData and rewrite animation's
|
||||
# parent PBS file (which could include multiple animations).
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
dispose
|
||||
end
|
||||
end
|
||||
172
Data/Scripts/904_Anim Editor/010_AnimationSelector.rb
Normal file
172
Data/Scripts/904_Anim Editor/010_AnimationSelector.rb
Normal file
@@ -0,0 +1,172 @@
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
class AnimationEditor::AnimationSelector
|
||||
ANIMATIONS_LIST_X = 4
|
||||
ANIMATIONS_LIST_Y = 4
|
||||
ANIMATIONS_LIST_WIDTH = 300
|
||||
ANIMATIONS_LIST_HEIGHT = AnimationEditor::WINDOW_HEIGHT - (ANIMATIONS_LIST_Y * 2)
|
||||
|
||||
LOAD_BUTTON_WIDTH = 200
|
||||
LOAD_BUTTON_HEIGHT = 48
|
||||
LOAD_BUTTON_X = ANIMATIONS_LIST_WIDTH + 100
|
||||
LOAD_BUTTON_Y = ANIMATIONS_LIST_Y + (ANIMATIONS_LIST_HEIGHT / 2) - (LOAD_BUTTON_HEIGHT / 2)
|
||||
|
||||
def initialize
|
||||
generate_list
|
||||
@viewport = Viewport.new(0, 0, AnimationEditor::WINDOW_WIDTH, AnimationEditor::WINDOW_HEIGHT)
|
||||
@viewport.z = 99999
|
||||
@screen_bitmap = BitmapSprite.new(AnimationEditor::WINDOW_WIDTH, AnimationEditor::WINDOW_HEIGHT, @viewport)
|
||||
draw_editor_background
|
||||
@load_animation_id = nil
|
||||
create_controls
|
||||
end
|
||||
|
||||
def dispose
|
||||
@screen_bitmap.dispose
|
||||
@viewport.dispose
|
||||
end
|
||||
|
||||
# TODO: Make separate arrays for move and common animations. Group animations
|
||||
# for the same move/common animation together somehow to be listed in
|
||||
# the main list - individual animations are shown in the secondary list.
|
||||
# The display names will need improving accordingly. Usage of
|
||||
# @animations in this class will need redoing.
|
||||
def generate_list
|
||||
@animations = []
|
||||
GameData::Animation.keys.each do |id|
|
||||
anim = GameData::Animation.get(id)
|
||||
if anim.version > 0
|
||||
name = "#{anim.type}: #{anim.move} (#{anim.version}) - #{anim.name}"
|
||||
else
|
||||
name = "#{anim.type}: #{anim.move} - #{anim.name}"
|
||||
end
|
||||
@animations.push([id, name])
|
||||
end
|
||||
# TODO: For scrollbar testing purposes.
|
||||
rand(400).times do |i|
|
||||
@animations.push([42 + i, "Extra animation #{i + 1}"])
|
||||
end
|
||||
end
|
||||
|
||||
def draw_editor_background
|
||||
# Fill the whole screen with white
|
||||
@screen_bitmap.bitmap.fill_rect(0, 0, AnimationEditor::WINDOW_WIDTH, AnimationEditor::WINDOW_HEIGHT, Color.black)
|
||||
# Outline around animations list
|
||||
areas = [
|
||||
[ANIMATIONS_LIST_X, ANIMATIONS_LIST_Y, ANIMATIONS_LIST_WIDTH, ANIMATIONS_LIST_HEIGHT],
|
||||
[LOAD_BUTTON_X, LOAD_BUTTON_Y, LOAD_BUTTON_WIDTH, LOAD_BUTTON_HEIGHT]
|
||||
]
|
||||
areas.each do |area|
|
||||
# Draw outlines around area
|
||||
@screen_bitmap.bitmap.outline_rect(area[0] - 3, area[1] - 3, area[2] + 6, area[3] + 6, Color.white)
|
||||
@screen_bitmap.bitmap.outline_rect(area[0] - 2, area[1] - 2, area[2] + 4, area[3] + 4, Color.black)
|
||||
@screen_bitmap.bitmap.outline_rect(area[0] - 1, area[1] - 1, area[2] + 2, area[3] + 2, Color.white)
|
||||
# Fill the area with white
|
||||
# TODO: This line was quoted out previously, and I'm not sure why.
|
||||
@screen_bitmap.bitmap.fill_rect(area[0], area[1], area[2], area[3], Color.white)
|
||||
end
|
||||
end
|
||||
|
||||
def create_controls
|
||||
@controls = {}
|
||||
# TODO: Buttons to toggle between listing moves that have animations, and
|
||||
# common animations (and overworld animations).
|
||||
# Animations list
|
||||
@list = UIControls::List.new(ANIMATIONS_LIST_WIDTH, ANIMATIONS_LIST_HEIGHT, @viewport, @animations)
|
||||
@list.x = ANIMATIONS_LIST_X
|
||||
@list.y = ANIMATIONS_LIST_Y
|
||||
@controls[:list] = @list
|
||||
# TODO: A secondary list for displaying all the animations related to the
|
||||
# selected move. For common anims/overworld anims, this will only ever
|
||||
# list one animation. The first animation listed in here will be
|
||||
# selected by default.
|
||||
# TODO: Filter text box for @list's contents. Applies the filter upon every
|
||||
# change to the text box's value. Perhaps it should only do so after
|
||||
# 0.5 seconds of non-typing. What exactly should the filter be applied
|
||||
# to? Animation's name, move's name (if there is one), what else?
|
||||
# TODO: Filter dropdown list to pick a move type? Other filter options?
|
||||
# "Load animation" button
|
||||
@load_button = UIControls::Button.new(LOAD_BUTTON_WIDTH, LOAD_BUTTON_HEIGHT, @viewport, "Load animation")
|
||||
@load_button.x = LOAD_BUTTON_X
|
||||
@load_button.y = LOAD_BUTTON_Y
|
||||
@load_button.set_fixed_size
|
||||
@load_button.set_interactive_rects
|
||||
@controls[:load] = @load_button
|
||||
# TODO: "New animation" button, "Delete animation" button, "Duplicate
|
||||
# animation" button.
|
||||
repaint
|
||||
end
|
||||
|
||||
def repaint
|
||||
@controls.each { |ctrl| ctrl[1].repaint }
|
||||
end
|
||||
|
||||
def update
|
||||
# Update all controls
|
||||
if @captured
|
||||
@captured.update
|
||||
@captured = nil if !@captured.busy?
|
||||
else
|
||||
@controls.each do |ctrl|
|
||||
ctrl[1].update
|
||||
@captured = ctrl[1] if ctrl[1].busy?
|
||||
end
|
||||
end
|
||||
# Check for changes in controls
|
||||
@list.clear_changed if @list.changed? # We don't need @list's value now
|
||||
if @load_button.changed?
|
||||
# TODO: This will need to get the animation ID from the sublist instead.
|
||||
@load_animation_id = @list.value
|
||||
@load_button.clear_changed
|
||||
end
|
||||
repaint # Only repaints if needed
|
||||
end
|
||||
|
||||
def run
|
||||
Input.text_input = false
|
||||
loop do
|
||||
inputting_text = Input.text_input
|
||||
Graphics.update
|
||||
Input.update
|
||||
update
|
||||
# Open editor with animation
|
||||
@load_animation_id = 2 # TODO: For quickstart testing purposes.
|
||||
if @load_animation_id
|
||||
screen = AnimationEditor.new(@load_animation_id, GameData::Animation.get(@load_animation_id).clone_as_hash)
|
||||
screen.run
|
||||
@load_animation_id = nil
|
||||
break # TODO: For quickstart testing purposes.
|
||||
# Refresh list of animations, in case the edited one changed its type,
|
||||
# move, version or name
|
||||
generate_list
|
||||
@list.values = @animations
|
||||
repaint
|
||||
next
|
||||
end
|
||||
# Typing text into a text box; don't want key presses to trigger anything
|
||||
next if inputting_text
|
||||
# Inputs
|
||||
break if Input.trigger?(Input::BACK)
|
||||
end
|
||||
dispose
|
||||
end
|
||||
end
|
||||
|
||||
#===============================================================================
|
||||
# Add to Debug menu.
|
||||
#===============================================================================
|
||||
MenuHandlers.add(:debug_menu, :use_pc, {
|
||||
"name" => _INTL("New Animation Editor"),
|
||||
"parent" => :main,
|
||||
"description" => _INTL("Open the new animation editor."),
|
||||
"effect" => proc {
|
||||
Graphics.resize_screen(AnimationEditor::WINDOW_WIDTH, AnimationEditor::WINDOW_HEIGHT)
|
||||
pbSetResizeFactor(1)
|
||||
screen = AnimationEditor::AnimationSelector.new
|
||||
screen.run
|
||||
Graphics.resize_screen(Settings::SCREEN_WIDTH, Settings::SCREEN_HEIGHT)
|
||||
pbSetResizeFactor($PokemonSystem.screensize)
|
||||
$game_map&.autoplay
|
||||
}
|
||||
})
|
||||
214
Data/Scripts/904_Anim Editor/901_ParticleDataHelper.rb
Normal file
214
Data/Scripts/904_Anim Editor/901_ParticleDataHelper.rb
Normal file
@@ -0,0 +1,214 @@
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
module AnimationEditor::ParticleDataHelper
|
||||
module_function
|
||||
|
||||
def get_duration(particles)
|
||||
ret = 0
|
||||
particles.each do |p|
|
||||
p.each_pair do |cmd, val|
|
||||
next if !val.is_a?(Array) || val.length == 0
|
||||
max = val.last[0] + val.last[1] # Keyframe + duration
|
||||
ret = max if ret < max
|
||||
end
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def get_keyframe_particle_value(particle, frame, property)
|
||||
if !GameData::Animation::PARTICLE_KEYFRAME_DEFAULT_VALUES.include?(property)
|
||||
raise _INTL("Couldn't get default value for property {1} for particle {2}.",
|
||||
property, particle[:name])
|
||||
end
|
||||
ret = [GameData::Animation::PARTICLE_KEYFRAME_DEFAULT_VALUES[property], false]
|
||||
if particle[property]
|
||||
# NOTE: The commands are already in keyframe order, so we can just run
|
||||
# through them in order, applying their changes until we reach
|
||||
# frame.
|
||||
particle[property].each do |cmd|
|
||||
break if cmd[0] > frame # Command is in the future; no more is needed
|
||||
break if cmd[0] == frame && cmd[1] > 0 # Start of a "MoveXYZ" command; won't have changed yet
|
||||
if cmd[0] + cmd[1] <= frame # Command has finished; use its end value
|
||||
ret[0] = cmd[2]
|
||||
next
|
||||
end
|
||||
# In a "MoveXYZ" command; need to interpolate
|
||||
ret[0] = lerp(ret[0], cmd[2], cmd[1], cmd[0], frame).to_i
|
||||
ret[1] = true # Interpolating
|
||||
break
|
||||
end
|
||||
end
|
||||
# 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"
|
||||
# particles, which start the animation visible.
|
||||
if property == :visible
|
||||
first_cmd = (["User", "Target"].include?(particle[:name])) ? 0 : -1
|
||||
first_visible_cmd = -1
|
||||
particle.each_pair do |prop, value|
|
||||
next if !value.is_a?(Array) || value.length == 0
|
||||
first_cmd = value[0][0] if first_cmd < 0 || first_cmd > value[0][0]
|
||||
first_visible_cmd = value[0][0] if prop == :visible && (first_visible_cmd < 0 || first_visible_cmd > value[0][0])
|
||||
end
|
||||
ret[0] = true if first_cmd >= 0 && first_cmd <= frame &&
|
||||
(first_visible_cmd < 0 || frame < first_visible_cmd)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def get_all_keyframe_particle_values(particle, frame)
|
||||
ret = {}
|
||||
GameData::Animation::PARTICLE_KEYFRAME_DEFAULT_VALUES.each_pair do |prop, default|
|
||||
ret[prop] = get_keyframe_particle_value(particle, frame, prop)
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def get_all_particle_values(particle)
|
||||
ret = {}
|
||||
GameData::Animation::PARTICLE_DEFAULT_VALUES.each_pair do |prop, default|
|
||||
ret[prop] = particle[prop] || default
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
# TODO: Generalise this to any property?
|
||||
# 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"
|
||||
# particles, which start the animation visible. They do NOT become
|
||||
# invisible automatically after their last command.
|
||||
def get_timeline_particle_visibilities(particle, duration)
|
||||
if !GameData::Animation::PARTICLE_KEYFRAME_DEFAULT_VALUES.include?(:visible)
|
||||
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])
|
||||
ret = []
|
||||
if particle[:visible]
|
||||
particle[:visible].each { |cmd| ret[cmd[0]] = cmd[2] }
|
||||
end
|
||||
duration.times do |i|
|
||||
value = ret[i] if !ret[i].nil?
|
||||
ret[i] = value
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
# Returns an array indicating where command diamonds and duration lines should
|
||||
# be drawn in the AnimationEditor::ParticleList.
|
||||
def get_particle_commands_timeline(particle)
|
||||
ret = []
|
||||
durations = []
|
||||
particle.each_pair do |prop, val|
|
||||
next if !val.is_a?(Array)
|
||||
val.each do |cmd|
|
||||
ret[cmd[0]] = true
|
||||
if cmd[1] > 0
|
||||
ret[cmd[0] + cmd[1]] = true
|
||||
durations.push([cmd[0], cmd[1]])
|
||||
end
|
||||
end
|
||||
end
|
||||
return ret, durations
|
||||
end
|
||||
|
||||
# Returns an array, whose indexes are keyframes, where the values in the array
|
||||
# are commands. A keyframe's value can be one of these:
|
||||
# 0 - SetXYZ
|
||||
# [+/- duration, interpolation type] --- MoveXYZ (duration's sign is whether
|
||||
# it makes the value higher or lower)
|
||||
def get_particle_property_commands_timeline(particle, commands, property)
|
||||
return nil if !commands || commands.length == 0
|
||||
if particle[:name] == "SE"
|
||||
ret = []
|
||||
commands.each { |cmd| ret[cmd[0]] = 0 }
|
||||
return ret
|
||||
end
|
||||
if !GameData::Animation::PARTICLE_KEYFRAME_DEFAULT_VALUES.include?(property)
|
||||
raise _INTL("No default value for property {1} in PARTICLE_KEYFRAME_DEFAULT_VALUES.", property)
|
||||
end
|
||||
ret = []
|
||||
val = GameData::Animation::PARTICLE_KEYFRAME_DEFAULT_VALUES[property]
|
||||
commands.each do |cmd|
|
||||
if cmd[1] > 0 # MoveXYZ
|
||||
dur = cmd[1]
|
||||
dur *= -1 if cmd[2] < val
|
||||
# TODO: Support multiple interpolation types here (will be cmd[3]).
|
||||
ret[cmd[0]] = [dur, cmd[3] || :linear]
|
||||
ret[cmd[0] + cmd[1]] = 0
|
||||
else # SetXYZ
|
||||
ret[cmd[0]] = 0
|
||||
end
|
||||
val = cmd[2] # New actual value
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
def set_property(particle, property, value)
|
||||
particle[property] = value
|
||||
end
|
||||
|
||||
def add_command(particle, property, frame, value)
|
||||
# Split particle[property] into values and interpolation arrays
|
||||
set_points = [] # All SetXYZ commands (the values thereof)
|
||||
end_points = [] # End points of MoveXYZ commands (the values thereof)
|
||||
interps = [] # Interpolation type from a keyframe to the next point
|
||||
if particle && particle[property]
|
||||
particle[property].each do |cmd|
|
||||
if cmd[1] == 0 # SetXYZ
|
||||
set_points[cmd[0]] = cmd[2]
|
||||
else
|
||||
interps[cmd[0]] = cmd[3] || :linear
|
||||
end_points[cmd[0] + cmd[1]] = cmd[2]
|
||||
end
|
||||
end
|
||||
end
|
||||
# Add new command to points (may replace an existing command)
|
||||
interp = :none
|
||||
(frame + 1).times do |i|
|
||||
interp = :none if set_points[i] || end_points[i]
|
||||
interp = interps[i] if interps[i]
|
||||
end
|
||||
interps[frame] = interp if interp != :none
|
||||
set_points[frame] = value
|
||||
# Convert points and interps back into particle[property]
|
||||
ret = []
|
||||
if !GameData::Animation::PARTICLE_KEYFRAME_DEFAULT_VALUES.include?(property)
|
||||
raise _INTL("Couldn't get default value for property {1}.", property)
|
||||
end
|
||||
val = GameData::Animation::PARTICLE_KEYFRAME_DEFAULT_VALUES[property]
|
||||
val = true if property == :visible && ["User", "Target", "SE"].include?(particle[:name])
|
||||
length = [set_points.length, end_points.length].max
|
||||
length.times do |i|
|
||||
if !set_points[i].nil? && set_points[i] != val
|
||||
ret.push([i, 0, set_points[i]])
|
||||
val = set_points[i]
|
||||
end
|
||||
if interps[i] && interps[i] != :none
|
||||
((i + 1)..length).each do |j|
|
||||
next if set_points[j].nil? && end_points[j].nil?
|
||||
if set_points[j].nil?
|
||||
break if end_points[j] == val
|
||||
ret.push([i, j - i, end_points[j], interps[i]])
|
||||
val = end_points[j]
|
||||
end_points[j] = nil
|
||||
else
|
||||
break if set_points[j] == val
|
||||
ret.push([i, j - i, set_points[j], interps[i]])
|
||||
val = set_points[j]
|
||||
set_points[j] = nil
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
return (ret.empty?) ? nil : ret
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,43 @@
|
||||
#===============================================================================
|
||||
# TODO
|
||||
#===============================================================================
|
||||
class AnimationEditor::Canvas < Sprite
|
||||
attr_reader :bg_name
|
||||
|
||||
def initialize(viewport)
|
||||
super
|
||||
@bg_val = ""
|
||||
# TODO: Add a second bg sprite for screen shake purposes.
|
||||
player_base_pos = Battle::Scene.pbBattlerPosition(0)
|
||||
@player_base = IconSprite.new(*player_base_pos, viewport)
|
||||
@player_base.z = 1
|
||||
foe_base_pos = Battle::Scene.pbBattlerPosition(1)
|
||||
@foe_base = IconSprite.new(*foe_base_pos, viewport)
|
||||
@foe_base.z = 1
|
||||
@message_bar_sprite = Sprite.new(viewport)
|
||||
@message_bar_sprite.z = 999
|
||||
end
|
||||
|
||||
def dispose
|
||||
@message_bar_sprite.dispose
|
||||
@player_base.dispose
|
||||
@foe_base.dispose
|
||||
super
|
||||
end
|
||||
|
||||
def bg_name=(val)
|
||||
return if @bg_name == val
|
||||
@bg_name = val
|
||||
# TODO: Come up with a better way to define the base filenames, based on
|
||||
# which files actually exist.
|
||||
self.bitmap = RPG::Cache.load_bitmap("Graphics/Battlebacks/", @bg_name + "_bg")
|
||||
@player_base.setBitmap("Graphics/Battlebacks/" + @bg_name + "_base0")
|
||||
@player_base.ox = @player_base.bitmap.width / 2
|
||||
@player_base.oy = @player_base.bitmap.height
|
||||
@foe_base.setBitmap("Graphics/Battlebacks/" + @bg_name + "_base1")
|
||||
@foe_base.ox = @foe_base.bitmap.width / 2
|
||||
@foe_base.oy = @foe_base.bitmap.height / 2
|
||||
@message_bar_sprite.bitmap = RPG::Cache.load_bitmap("Graphics/Battlebacks/", @bg_name + "_message")
|
||||
@message_bar_sprite.y = Settings::SCREEN_HEIGHT - @message_bar_sprite.height
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,27 @@
|
||||
#===============================================================================
|
||||
# TODO
|
||||
#===============================================================================
|
||||
class AnimationEditor::PlayControls < UIControls::BaseControl
|
||||
TEXT_OFFSET_Y = 5
|
||||
|
||||
def initialize(x, y, width, height, viewport)
|
||||
super(width, height, viewport)
|
||||
self.x = x
|
||||
self.y = y
|
||||
@duration = 0
|
||||
end
|
||||
|
||||
def duration=(new_val)
|
||||
return if @duration == new_val
|
||||
@duration = new_val
|
||||
refresh
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
def refresh
|
||||
super
|
||||
draw_text(self.bitmap, 12, TEXT_OFFSET_Y + 14, _INTL("Play controls not added yet!"))
|
||||
draw_text(self.bitmap, width - 134, TEXT_OFFSET_Y, _INTL("Total length: {1}s", @duration / 20.0))
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,776 @@
|
||||
#===============================================================================
|
||||
# TODO: Would be nice to make command sprites wider than their viewport and
|
||||
# change @commands_viewport's ox to @left_pos, similar to how the vertical
|
||||
# scrollbar works, i.e. every visible @commands_sprites isn't redrawn each
|
||||
# time the horizontal scrollbar changes.
|
||||
#===============================================================================
|
||||
class AnimationEditor::ParticleList < UIControls::BaseControl
|
||||
VIEWPORT_SPACING = 1
|
||||
TIMELINE_HEIGHT = 24 - VIEWPORT_SPACING
|
||||
LIST_X = 0
|
||||
LIST_Y = TIMELINE_HEIGHT + VIEWPORT_SPACING
|
||||
LIST_WIDTH = 150 - VIEWPORT_SPACING
|
||||
COMMANDS_X = LIST_WIDTH + VIEWPORT_SPACING
|
||||
COMMANDS_Y = LIST_Y
|
||||
|
||||
ROW_HEIGHT = 24
|
||||
DIAMOND_SIZE = 3
|
||||
TIMELINE_LEFT_BUFFER = DIAMOND_SIZE + 1 # Allows diamonds at keyframe 0 to be drawn fully
|
||||
TIMELINE_TEXT_SIZE = 16
|
||||
KEYFRAME_SPACING = 20
|
||||
INTERP_LINE_HEIGHT = KEYFRAME_SPACING - ((DIAMOND_SIZE * 2) + 3)
|
||||
INTERP_LINE_Y = (ROW_HEIGHT / 2) - (INTERP_LINE_HEIGHT / 2)
|
||||
DURATION_BUFFER = 20 # Extra keyframes shown after the animation's end
|
||||
CONTROL_BG_COLORS = {
|
||||
:user => Color.new(96, 248, 96), # Green
|
||||
:target => Color.new(248, 96, 96), # Red
|
||||
:user_and_target => Color.new(248, 248, 96), # Yellow
|
||||
:screen => Color.new(128, 160, 248) # Blue
|
||||
}
|
||||
SE_CONTROL_BG = Color.gray
|
||||
|
||||
attr_reader :keyframe # The selected keyframe
|
||||
|
||||
def initialize(x, y, width, height, viewport)
|
||||
super(width, height, viewport)
|
||||
self.x = x
|
||||
self.y = y
|
||||
draw_control_background
|
||||
# Create viewports
|
||||
@list_viewport = Viewport.new(
|
||||
x + LIST_X, y + LIST_Y, LIST_WIDTH, height - LIST_Y - UIControls::Scrollbar::SLIDER_WIDTH - VIEWPORT_SPACING
|
||||
)
|
||||
@list_viewport.z = self.viewport.z + 1
|
||||
@commands_bg_viewport = Viewport.new(
|
||||
x + COMMANDS_X, y + COMMANDS_Y,
|
||||
width - COMMANDS_X - UIControls::Scrollbar::SLIDER_WIDTH - VIEWPORT_SPACING, @list_viewport.rect.height
|
||||
)
|
||||
@commands_bg_viewport.z = self.viewport.z + 1
|
||||
@position_viewport = Viewport.new(@commands_bg_viewport.rect.x, y, @commands_bg_viewport.rect.width, height)
|
||||
@position_viewport.z = self.viewport.z + 2
|
||||
@commands_viewport = Viewport.new(@commands_bg_viewport.rect.x, @commands_bg_viewport.rect.y,
|
||||
@commands_bg_viewport.rect.width, @commands_bg_viewport.rect.height)
|
||||
@commands_viewport.z = self.viewport.z + 3
|
||||
# Create scrollbar
|
||||
@list_scrollbar = UIControls::Scrollbar.new(
|
||||
x + width - UIControls::Scrollbar::SLIDER_WIDTH, @commands_bg_viewport.rect.y,
|
||||
@commands_bg_viewport.rect.height, self.viewport, false, true
|
||||
)
|
||||
@list_scrollbar.set_interactive_rects
|
||||
@time_scrollbar = UIControls::Scrollbar.new(
|
||||
@commands_bg_viewport.rect.x, y + height - UIControls::Scrollbar::SLIDER_WIDTH,
|
||||
@commands_bg_viewport.rect.width, self.viewport, true, true
|
||||
)
|
||||
@time_scrollbar.set_interactive_rects
|
||||
# Timeline bitmap sprite
|
||||
@timeline_sprite = BitmapSprite.new(@commands_viewport.rect.width, TIMELINE_HEIGHT, self.viewport)
|
||||
@timeline_sprite.x = @commands_viewport.rect.x
|
||||
@timeline_sprite.y = self.y
|
||||
@timeline_sprite.bitmap.font.color = TEXT_COLOR
|
||||
@timeline_sprite.bitmap.font.size = TIMELINE_TEXT_SIZE
|
||||
# Position line sprite
|
||||
@position_sprite = BitmapSprite.new(3, height - UIControls::Scrollbar::SLIDER_WIDTH - VIEWPORT_SPACING, @position_viewport)
|
||||
@position_sprite.ox = @position_sprite.width / 2
|
||||
@position_sprite.bitmap.fill_rect(0, 0, @position_sprite.bitmap.width, @position_sprite.bitmap.height, Color.red)
|
||||
# List sprites and commands sprites
|
||||
@list_sprites = []
|
||||
@commands_bg_sprites = []
|
||||
@commands_sprites = []
|
||||
# Scrollbar positions
|
||||
@left_pos = 0
|
||||
@top_pos = 0
|
||||
@duration = 0
|
||||
# Selected things
|
||||
@keyframe = 0
|
||||
@row_index = 0
|
||||
# Particle information to display (one row each)
|
||||
@particles = [] # Reference to particle data from the editor scene
|
||||
@expanded_particles = [0] # Each element is index in @particles
|
||||
@particle_list = [] # Each element is index in @particles or [index, property]
|
||||
@visibilities = [] # Per particle
|
||||
@commands = {}
|
||||
end
|
||||
|
||||
def draw_control_background
|
||||
self.bitmap.clear
|
||||
# Background
|
||||
self.bitmap.fill_rect(0, 0, width, height, Color.white)
|
||||
# Separator lines
|
||||
self.bitmap.fill_rect(0, TIMELINE_HEIGHT, width, VIEWPORT_SPACING, Color.black)
|
||||
self.bitmap.fill_rect(LIST_WIDTH, 0, VIEWPORT_SPACING, height, Color.black)
|
||||
self.bitmap.fill_rect(0, height - UIControls::Scrollbar::SLIDER_WIDTH - VIEWPORT_SPACING, width, VIEWPORT_SPACING, Color.black)
|
||||
self.bitmap.fill_rect(width - UIControls::Scrollbar::SLIDER_WIDTH - VIEWPORT_SPACING, 0, VIEWPORT_SPACING, height, Color.black)
|
||||
end
|
||||
|
||||
def dispose_listed_sprites
|
||||
@list_sprites.each { |p| p&.dispose }
|
||||
@list_sprites.clear
|
||||
@commands_bg_sprites.each { |p| p&.dispose }
|
||||
@commands_bg_sprites.clear
|
||||
@commands_sprites.each { |p| p&.dispose }
|
||||
@commands_sprites.clear
|
||||
end
|
||||
|
||||
def dispose
|
||||
@list_scrollbar.dispose
|
||||
@time_scrollbar.dispose
|
||||
@timeline_sprite.dispose
|
||||
@position_sprite.dispose
|
||||
dispose_listed_sprites
|
||||
@list_viewport.dispose
|
||||
@commands_bg_viewport.dispose
|
||||
@commands_viewport.dispose
|
||||
end
|
||||
|
||||
def duration
|
||||
return [@duration - DURATION_BUFFER, 0].max
|
||||
end
|
||||
|
||||
def particle_index
|
||||
ret = @particle_list[@row_index]
|
||||
return (ret.is_a?(Array)) ? ret[0] : ret
|
||||
end
|
||||
|
||||
def left_pos=(val)
|
||||
old_val = @left_pos
|
||||
total_width = (@duration * KEYFRAME_SPACING) + TIMELINE_LEFT_BUFFER + 1
|
||||
if total_width <= @commands_viewport.rect.width
|
||||
@left_pos = 0
|
||||
else
|
||||
@left_pos = val
|
||||
@left_pos = @left_pos.clamp(0, total_width - @commands_viewport.rect.width)
|
||||
end
|
||||
if @left_pos != old_val
|
||||
refresh_position_line
|
||||
invalidate_time
|
||||
end
|
||||
end
|
||||
|
||||
def top_pos=(val)
|
||||
old_val = @top_pos
|
||||
total_height = (@particle_list.length * ROW_HEIGHT) + 1
|
||||
if total_height <= @list_viewport.rect.height
|
||||
@top_pos = 0
|
||||
else
|
||||
@top_pos = val
|
||||
@top_pos = @top_pos.clamp(0, total_height - @list_viewport.rect.height)
|
||||
end
|
||||
@list_viewport.oy = @top_pos
|
||||
@commands_bg_viewport.oy = @top_pos
|
||||
@commands_viewport.oy = @top_pos
|
||||
if @top_pos != old_val
|
||||
invalidate_rows
|
||||
@old_top_pos = old_val
|
||||
end
|
||||
end
|
||||
|
||||
def set_particles(particles)
|
||||
@particles = particles
|
||||
calculate_all_commands_and_durations
|
||||
create_sprites
|
||||
end
|
||||
|
||||
def create_sprites
|
||||
# Fill in @particle_list with indices from @particles
|
||||
@particle_list.clear
|
||||
@particles.length.times do |i|
|
||||
@particle_list.push(i)
|
||||
next if !@expanded_particles.include?(i)
|
||||
@particles[i].each_pair do |property, value|
|
||||
@particle_list.push([i, property]) if value.is_a?(Array)
|
||||
end
|
||||
end
|
||||
# Dispose of and clear all existing list/commands sprites
|
||||
dispose_listed_sprites
|
||||
# Create new sprites for each particle (1x list and 2x commands)
|
||||
@particle_list.length.times do
|
||||
list_sprite = BitmapSprite.new(@list_viewport.rect.width, ROW_HEIGHT, @list_viewport)
|
||||
list_sprite.y = @list_sprites.length * ROW_HEIGHT
|
||||
list_sprite.bitmap.font.color = TEXT_COLOR
|
||||
list_sprite.bitmap.font.size = TEXT_SIZE
|
||||
@list_sprites.push(list_sprite)
|
||||
commands_bg_sprite = BitmapSprite.new(@commands_viewport.rect.width, ROW_HEIGHT, @commands_bg_viewport)
|
||||
commands_bg_sprite.y = @commands_bg_sprites.length * ROW_HEIGHT
|
||||
commands_bg_sprite.bitmap.font.color = TEXT_COLOR
|
||||
commands_bg_sprite.bitmap.font.size = TEXT_SIZE
|
||||
@commands_bg_sprites.push(commands_bg_sprite)
|
||||
commands_sprite = BitmapSprite.new(@commands_viewport.rect.width, ROW_HEIGHT, @commands_viewport)
|
||||
commands_sprite.y = @commands_sprites.length * ROW_HEIGHT
|
||||
commands_sprite.bitmap.font.color = TEXT_COLOR
|
||||
commands_sprite.bitmap.font.size = TEXT_SIZE
|
||||
@commands_sprites.push(commands_sprite)
|
||||
end
|
||||
# Set scrollbars to the correct lengths
|
||||
@list_scrollbar.range = (@particle_list.length * ROW_HEIGHT) + 1
|
||||
@time_scrollbar.range = (@duration * KEYFRAME_SPACING) + TIMELINE_LEFT_BUFFER + 1
|
||||
self.left_pos = @left_pos
|
||||
self.top_pos = @top_pos
|
||||
# Redraw all sprites
|
||||
invalidate
|
||||
end
|
||||
|
||||
def set_interactive_rects
|
||||
@list_rect = Rect.new(0, TIMELINE_HEIGHT, LIST_WIDTH - 1, @list_viewport.rect.height)
|
||||
@timeline_rect = Rect.new(LIST_WIDTH, 0, width - LIST_WIDTH - UIControls::Scrollbar::SLIDER_WIDTH - 1, TIMELINE_HEIGHT - 1)
|
||||
@commands_rect = Rect.new(LIST_WIDTH, TIMELINE_HEIGHT, @timeline_rect.width, @list_rect.height)
|
||||
@interactions = {
|
||||
:list => @list_rect,
|
||||
:timeline => @timeline_rect,
|
||||
:commands => @commands_rect
|
||||
}
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
def invalid?
|
||||
return @invalid || @invalid_time || @invalid_rows || @invalid_commands
|
||||
end
|
||||
|
||||
def invalidate_time
|
||||
@invalid_time = true
|
||||
end
|
||||
|
||||
def invalidate_rows
|
||||
@invalid_rows = true
|
||||
end
|
||||
|
||||
def invalidate_commands
|
||||
@invalid_commands = true
|
||||
end
|
||||
|
||||
def validate
|
||||
super
|
||||
@invalid_time = false
|
||||
@invalid_rows = false
|
||||
@invalid_commands = false
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
def calculate_duration
|
||||
# TODO: Refresh lots of things if the duration changed (e.g. SE command
|
||||
# line).
|
||||
@duration = AnimationEditor::ParticleDataHelper.get_duration(@particles)
|
||||
@duration += DURATION_BUFFER
|
||||
end
|
||||
|
||||
# TODO: Call this only from set_particles and when changes are made to
|
||||
# @particles by the main editor scene. If we can be specific about which
|
||||
# particle was changed, recalculate only that particle's commands.
|
||||
def calculate_all_commands_and_durations
|
||||
calculate_duration
|
||||
calculate_all_commands
|
||||
end
|
||||
|
||||
def calculate_all_commands
|
||||
@commands = {}
|
||||
@particles.each_with_index do |particle, index|
|
||||
calculate_commands_for_particle(index)
|
||||
end
|
||||
end
|
||||
|
||||
def calculate_commands_for_particle(index)
|
||||
# TODO: Delete everything from @commands that includes index.
|
||||
overall_commands = []
|
||||
@particles[index].each_pair do |property, value|
|
||||
next if !value.is_a?(Array)
|
||||
cmds = AnimationEditor::ParticleDataHelper.get_particle_property_commands_timeline(@particles[index], value, property)
|
||||
@commands[[index, property]] = cmds
|
||||
cmds.each_with_index do |cmd, i|
|
||||
next if !cmd
|
||||
overall_commands[i] = (cmd.is_a?(Array)) ? cmd.clone : cmd
|
||||
end
|
||||
end
|
||||
@commands[index] = overall_commands
|
||||
# Calculate visibilities for every keyframe
|
||||
@visibilities[index] = AnimationEditor::ParticleDataHelper.get_timeline_particle_visibilities(
|
||||
@particles[index], @duration - DURATION_BUFFER
|
||||
)
|
||||
end
|
||||
|
||||
# Returns whether the sprites need replacing due to the addition or
|
||||
# subtraction of one.
|
||||
def ensure_sprites
|
||||
# TODO: Check through @particle_list to ensure only ones are shown which
|
||||
# correspond to something in @particles.
|
||||
# Go through all @particles to ensure there are sprites for each of them
|
||||
missing = false
|
||||
@particles.each_with_index do |particle, index|
|
||||
if @particle_list.none? { |value| next !value.is_a?(Array) && value == index }
|
||||
missing = true
|
||||
break
|
||||
end
|
||||
next if !@expanded_particles.include?(index)
|
||||
particle.each_pair do |property, value|
|
||||
next if !value.is_a?(Array)
|
||||
if @particle_list.none? { |value| next value.is_a?(Array) && value[0] == index && value[1] == property }
|
||||
missing = true
|
||||
break
|
||||
end
|
||||
end
|
||||
break if missing
|
||||
end
|
||||
return true if missing
|
||||
# Go through all sprites to ensure there are none for a particle or
|
||||
# particle/property that don't exist
|
||||
excess = false
|
||||
@particle_list.each do |value|
|
||||
if value.is_a?(Array)
|
||||
excess = true if !@particles[value[0]] || !@particles[value[0]][value[1]] ||
|
||||
@particles[value[0]][value[1]].empty?
|
||||
else
|
||||
excess = true if !@particles[value]
|
||||
end
|
||||
break if excess
|
||||
end
|
||||
return excess
|
||||
end
|
||||
|
||||
# Called when a change is made to a particle's commands.
|
||||
def change_particle_commands(index)
|
||||
old_duration = @duration
|
||||
calculate_duration
|
||||
if @duration != old_duration
|
||||
calculate_all_commands
|
||||
else
|
||||
calculate_commands_for_particle(index)
|
||||
end
|
||||
sprites_need_changing = ensure_sprites
|
||||
if @duration != old_duration || sprites_need_changing
|
||||
@keyframe = @keyframe.clamp(0, @duration - 1)
|
||||
@row_index = @row_index.clamp(0, @particle_list.length - 1)
|
||||
create_sprites
|
||||
end
|
||||
invalidate
|
||||
end
|
||||
|
||||
# Called when a change is made to a particle's general properties.
|
||||
def change_particle(index)
|
||||
invalidate_rows
|
||||
end
|
||||
|
||||
# TODO: Methods that will show/hide individual property rows for a given
|
||||
# @particles index.
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
def each_visible_keyframe(early_start = false)
|
||||
full_width = @commands_viewport.rect.width
|
||||
start_keyframe = ((@left_pos - TIMELINE_LEFT_BUFFER) / KEYFRAME_SPACING)
|
||||
start_keyframe = 0 if start_keyframe < 0
|
||||
start_keyframe -= 1 if early_start && start_keyframe > 0 # For drawing long timestamps
|
||||
end_keyframe = (@left_pos + full_width / KEYFRAME_SPACING)
|
||||
(start_keyframe..end_keyframe).each { |i| yield i }
|
||||
end
|
||||
|
||||
def each_visible_particle
|
||||
full_height = @list_viewport.rect.height
|
||||
start_row = @top_pos / ROW_HEIGHT
|
||||
end_row = (@top_pos + full_height) / ROW_HEIGHT
|
||||
if @old_top_pos
|
||||
old_start_row = @old_top_pos / ROW_HEIGHT
|
||||
old_end_row = (@old_top_pos + full_height) / ROW_HEIGHT
|
||||
(start_row..end_row).each { |i| yield i if !(old_start_row..old_end_row).include?(i) }
|
||||
else
|
||||
(start_row..end_row).each { |i| yield i }
|
||||
end
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
def property_display_name(property)
|
||||
return {
|
||||
:frame => _INTL("Graphic frame"),
|
||||
:blending => _INTL("Blending"),
|
||||
:flip => _INTL("Flip"),
|
||||
:x => _INTL("X"),
|
||||
:y => _INTL("Y"),
|
||||
:zoom_x => _INTL("Zoom X"),
|
||||
:zoom_y => _INTL("Zoom Y"),
|
||||
:angle => _INTL("Angle"),
|
||||
:visible => _INTL("Visible"),
|
||||
:opacity => _INTL("Opacity")
|
||||
}[property] || property.capitalize
|
||||
end
|
||||
|
||||
def repaint
|
||||
@list_scrollbar.repaint if @list_scrollbar.invalid?
|
||||
@time_scrollbar.repaint if @time_scrollbar.invalid?
|
||||
super if invalid?
|
||||
end
|
||||
|
||||
def refresh_timeline
|
||||
@timeline_sprite.bitmap.clear
|
||||
# Draw hover highlight
|
||||
hover_color = nil
|
||||
if @captured_keyframe && !@captured_row
|
||||
if @hover_keyframe && @hover_keyframe == @captured_keyframe && !@hover_row
|
||||
hover_color = HOVER_COLOR
|
||||
else
|
||||
hover_color = CAPTURE_COLOR
|
||||
end
|
||||
draw_x = TIMELINE_LEFT_BUFFER + (@captured_keyframe * KEYFRAME_SPACING) - @left_pos
|
||||
@timeline_sprite.bitmap.fill_rect(draw_x - (KEYFRAME_SPACING / 2), 0,
|
||||
KEYFRAME_SPACING, TIMELINE_HEIGHT - 1, hover_color)
|
||||
elsif !@captured_keyframe && !@captured_row && @hover_keyframe && !@hover_row
|
||||
hover_color = HOVER_COLOR
|
||||
draw_x = TIMELINE_LEFT_BUFFER + (@hover_keyframe * KEYFRAME_SPACING) - @left_pos
|
||||
@timeline_sprite.bitmap.fill_rect(draw_x - (KEYFRAME_SPACING / 2), 0,
|
||||
KEYFRAME_SPACING, TIMELINE_HEIGHT - 1, hover_color)
|
||||
end
|
||||
# Draw timeline markings
|
||||
each_visible_keyframe(true) do |i|
|
||||
draw_x = TIMELINE_LEFT_BUFFER + (i * KEYFRAME_SPACING) - @left_pos
|
||||
line_height = 6
|
||||
if (i % 20) == 0
|
||||
line_height = TIMELINE_HEIGHT - 2
|
||||
elsif (i % 5) == 0
|
||||
line_height = TIMELINE_HEIGHT / 2
|
||||
end
|
||||
@timeline_sprite.bitmap.fill_rect(draw_x, TIMELINE_HEIGHT - line_height, 1, line_height, TEXT_COLOR)
|
||||
draw_text(@timeline_sprite.bitmap, draw_x + 1, 0, (i / 20.0).to_s) if (i % 5) == 0
|
||||
end
|
||||
end
|
||||
|
||||
def refresh_position_line
|
||||
@position_sprite.visible = (@keyframe >= 0)
|
||||
if @keyframe >= 0
|
||||
@position_sprite.x = TIMELINE_LEFT_BUFFER + (@keyframe * KEYFRAME_SPACING) - @left_pos
|
||||
end
|
||||
end
|
||||
|
||||
# TODO: Add indicator that this is selected (if so).
|
||||
def refresh_particle_list_sprite(index)
|
||||
spr = @list_sprites[index]
|
||||
return if !spr
|
||||
spr.bitmap.clear
|
||||
box_x = (@particle_list[index].is_a?(Array)) ? 16 : 0
|
||||
# Get the background color
|
||||
p_index = (@particle_list[index].is_a?(Array)) ? @particle_list[index][0] : @particle_list[index]
|
||||
particle_data = @particles[p_index]
|
||||
if particle_data[:name] == "SE"
|
||||
bg_color = SE_CONTROL_BG
|
||||
else
|
||||
bg_color = CONTROL_BG_COLORS[@particles[@particle_list[index][0]][:focus]] || Color.magenta
|
||||
end
|
||||
# Draw hover highlight
|
||||
hover_color = nil
|
||||
if @captured_row && !@captured_keyframe
|
||||
if @captured_row == index
|
||||
if @hover_row && @hover_row == index && !@hover_keyframe
|
||||
hover_color = HOVER_COLOR
|
||||
else
|
||||
hover_color = CAPTURE_COLOR
|
||||
end
|
||||
end
|
||||
elsif !@captured_row && !@captured_keyframe && @hover_row && @hover_row == index && !@hover_keyframe
|
||||
hover_color = HOVER_COLOR
|
||||
end
|
||||
spr.bitmap.fill_rect(box_x, 1, spr.width - box_x, spr.height - 1, hover_color) if hover_color
|
||||
# Draw outline
|
||||
spr.bitmap.outline_rect(box_x, 1, spr.width - box_x, spr.height - 1, bg_color, 2)
|
||||
# Draw text
|
||||
if @particle_list[index].is_a?(Array)
|
||||
draw_text(spr.bitmap, box_x + 4, 0, "→") # ►
|
||||
draw_text(spr.bitmap, box_x + 4 + 17, 3, property_display_name(@particle_list[index][1]))
|
||||
else
|
||||
draw_text(spr.bitmap, 4, 3, @particles[p_index][:name] || "Unnamed")
|
||||
end
|
||||
end
|
||||
|
||||
def refresh_particle_commands_bg_sprites(index)
|
||||
bg_spr = @commands_bg_sprites[index]
|
||||
return if !bg_spr
|
||||
bg_spr.bitmap.clear
|
||||
p_index = (@particle_list[index].is_a?(Array)) ? @particle_list[index][0] : @particle_list[index]
|
||||
particle_data = @particles[p_index]
|
||||
# Get the background color
|
||||
if particle_data[:name] == "SE"
|
||||
bg_color = SE_CONTROL_BG
|
||||
else
|
||||
bg_color = CONTROL_BG_COLORS[@particles[@particle_list[index][0]][:focus]] || Color.magenta
|
||||
end
|
||||
# Get visibilities of particle for each keyframe
|
||||
visible_cmds = @visibilities[p_index]
|
||||
# Draw background for visible parts of the particle
|
||||
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]
|
||||
bg_spr.bitmap.fill_rect(draw_x, 1, KEYFRAME_SPACING, ROW_HEIGHT - 2, bg_color)
|
||||
end
|
||||
# Draw hover highlight
|
||||
hover_color = nil
|
||||
if @captured_row && @captured_keyframe
|
||||
if @captured_row == index && @captured_keyframe == i
|
||||
if @hover_row && @hover_row == index && @hover_keyframe && @hover_keyframe == i
|
||||
hover_color = HOVER_COLOR
|
||||
else
|
||||
hover_color = CAPTURE_COLOR
|
||||
end
|
||||
end
|
||||
elsif !@captured_row && !@captured_keyframe &&
|
||||
@hover_row && @hover_row == index && @hover_keyframe && @hover_keyframe == i
|
||||
hover_color = HOVER_COLOR
|
||||
end
|
||||
bg_spr.bitmap.fill_rect(draw_x - (KEYFRAME_SPACING / 2), 2, KEYFRAME_SPACING, ROW_HEIGHT - 3, hover_color) if hover_color
|
||||
next if i >= @duration - DURATION_BUFFER
|
||||
next if !visible_cmds[i]
|
||||
# Draw outline
|
||||
bg_spr.bitmap.fill_rect(draw_x, 1, KEYFRAME_SPACING, 1, Color.black) # Top
|
||||
bg_spr.bitmap.fill_rect(draw_x, ROW_HEIGHT - 1, KEYFRAME_SPACING, 1, Color.black) # Bottom
|
||||
if i <= 0 || !visible_cmds[i - 1]
|
||||
bg_spr.bitmap.fill_rect(draw_x, 1, 1, ROW_HEIGHT - 1, Color.black) # Left
|
||||
end
|
||||
if i == @duration - DURATION_BUFFER - 1 || (i < @duration - 1 && !visible_cmds[i + 1])
|
||||
bg_spr.bitmap.fill_rect(draw_x + KEYFRAME_SPACING, 1, 1, ROW_HEIGHT - 1, Color.black) # Right
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def refresh_particle_commands_sprite(index)
|
||||
spr = @commands_sprites[index]
|
||||
return if !spr
|
||||
spr.bitmap.clear
|
||||
cmds = @commands[@particle_list[index]]
|
||||
return if !cmds
|
||||
# Draw command diamonds
|
||||
first_keyframe = -1
|
||||
each_visible_keyframe do |i|
|
||||
first_keyframe = i if first_keyframe < 0
|
||||
next if !cmds[i]
|
||||
draw_x = TIMELINE_LEFT_BUFFER + (i * KEYFRAME_SPACING) - @left_pos
|
||||
# Draw command diamond
|
||||
spr.bitmap.fill_diamond(draw_x, ROW_HEIGHT / 2, DIAMOND_SIZE, TEXT_COLOR)
|
||||
# Draw interpolation line
|
||||
if cmds[i].is_a?(Array)
|
||||
spr.bitmap.draw_interpolation_line(
|
||||
draw_x + DIAMOND_SIZE + 2,
|
||||
INTERP_LINE_Y,
|
||||
cmds[i][0].abs * KEYFRAME_SPACING - ((DIAMOND_SIZE * 2) + 3),
|
||||
INTERP_LINE_HEIGHT,
|
||||
cmds[i][0] > 0, # Increases or decreases
|
||||
cmds[i][1], # Interpolation type
|
||||
TEXT_COLOR
|
||||
)
|
||||
end
|
||||
end
|
||||
# Draw any interpolation lines that start before the first visible keyframe
|
||||
if first_keyframe > 0
|
||||
(0...first_keyframe).each do |i|
|
||||
next if !cmds[i] || !cmds[i].is_a?(Array)
|
||||
next if i + cmds[i][0].abs < first_keyframe
|
||||
draw_x = TIMELINE_LEFT_BUFFER + (i * KEYFRAME_SPACING) - @left_pos
|
||||
spr.bitmap.draw_interpolation_line(
|
||||
draw_x + DIAMOND_SIZE + 2,
|
||||
INTERP_LINE_Y,
|
||||
cmds[i][0].abs * KEYFRAME_SPACING - ((DIAMOND_SIZE * 2) + 3),
|
||||
INTERP_LINE_HEIGHT,
|
||||
cmds[i][0] > 0, # Increases or decreases
|
||||
cmds[i][1], # Interpolation type
|
||||
TEXT_COLOR
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def refresh
|
||||
draw_area_highlight
|
||||
refresh_timeline if @invalid || @invalid_time
|
||||
each_visible_particle do |i|
|
||||
refresh_particle_list_sprite(i) if @invalid || @invalid_rows
|
||||
refresh_particle_commands_bg_sprites(i)
|
||||
refresh_particle_commands_sprite(i)
|
||||
end
|
||||
@old_top_pos = nil # For refreshing only rows that became visible via using vertical scrollbar
|
||||
end
|
||||
|
||||
# Does nothing, because area highlights are drawn in other sprites rather than
|
||||
# this one.
|
||||
def draw_area_highlight; end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
def get_interactive_element_at_mouse
|
||||
ret = nil
|
||||
mouse_x, mouse_y = mouse_pos
|
||||
return ret if !mouse_x || !mouse_y
|
||||
@interactions.each_pair do |area, rect|
|
||||
next if !rect.contains?(mouse_x, mouse_y)
|
||||
ret = area
|
||||
case area
|
||||
when :list
|
||||
new_hover_row = (mouse_y + @top_pos - rect.y) / ROW_HEIGHT
|
||||
break if new_hover_row >= @particle_list.length
|
||||
listed_element = @particle_list[new_hover_row]
|
||||
p_index = listed_element.is_a?(Array) ? listed_element[0] : listed_element
|
||||
break if @particles[p_index][:name] == "SE"
|
||||
ret = [area, nil, new_hover_row]
|
||||
when :timeline
|
||||
new_hover_keyframe = (mouse_x + @left_pos - rect.x - TIMELINE_LEFT_BUFFER + (KEYFRAME_SPACING / 2) - 1) / KEYFRAME_SPACING
|
||||
break if new_hover_keyframe < 0 || new_hover_keyframe >= @duration
|
||||
ret = [area, new_hover_keyframe, nil]
|
||||
when :commands
|
||||
new_hover_row = (mouse_y + @top_pos - rect.y) / ROW_HEIGHT
|
||||
new_hover_keyframe = (mouse_x + @left_pos - rect.x - TIMELINE_LEFT_BUFFER + (KEYFRAME_SPACING / 2) - 1) / KEYFRAME_SPACING
|
||||
break if new_hover_row >= @particle_list.length
|
||||
break if new_hover_keyframe < 0 || new_hover_keyframe >= @duration
|
||||
ret = [area, new_hover_keyframe, new_hover_row]
|
||||
end
|
||||
break
|
||||
end
|
||||
return ret
|
||||
end
|
||||
|
||||
def on_mouse_press
|
||||
return if @captured_area
|
||||
hover_element = get_interactive_element_at_mouse
|
||||
if hover_element.is_a?(Array)
|
||||
@captured_area = hover_element[0]
|
||||
@captured_keyframe = hover_element[1]
|
||||
@captured_row = hover_element[2]
|
||||
end
|
||||
end
|
||||
|
||||
def on_mouse_release
|
||||
return if !@captured_area # Wasn't captured to begin with
|
||||
# Change this control's value
|
||||
hover_element = get_interactive_element_at_mouse
|
||||
if hover_element.is_a?(Array)
|
||||
if @captured_area == hover_element[0] &&
|
||||
@captured_keyframe == hover_element[1] &&
|
||||
@captured_row == hover_element[2]
|
||||
if @captured_row && @particle_list[@captured_row].is_a?(Array)
|
||||
# TODO: If I want to be able to select individual property rows and/or
|
||||
# diamonds, I shouldn't have this line.
|
||||
@captured_row = @particle_list.index(@particle_list[@captured_row][0])
|
||||
end
|
||||
set_changed if @keyframe != @captured_keyframe || @row_index != @captured_row
|
||||
@keyframe = @captured_keyframe || -1
|
||||
@row_index = @captured_row || -1
|
||||
end
|
||||
end
|
||||
@captured_keyframe = nil
|
||||
@captured_row = nil
|
||||
super # Make this control not busy again
|
||||
end
|
||||
|
||||
def on_right_mouse_release
|
||||
# TODO: Toggle interpolation line at mouse's position. Should this also have
|
||||
# a def on_right_mouse_press and @right_captured_whatever?
|
||||
end
|
||||
|
||||
def update_hover_highlight
|
||||
# Remove the hover highlight if there are no interactions for this control
|
||||
# or if the mouse is off-screen
|
||||
mouse_x, mouse_y = mouse_pos
|
||||
if !@interactions || @interactions.empty? || !mouse_x || !mouse_y
|
||||
invalidate if @hover_area
|
||||
@hover_area = nil
|
||||
@hover_keyframe = nil
|
||||
@hover_row = nil
|
||||
return
|
||||
end
|
||||
# Check each interactive area for whether the mouse is hovering over it, and
|
||||
# set @hover_area accordingly
|
||||
hover_element = get_interactive_element_at_mouse
|
||||
if hover_element.is_a?(Array)
|
||||
invalidate if @hover_area != hover_element[0] # Moved to a different region
|
||||
case hover_element[0]
|
||||
when :list
|
||||
invalidate_rows if @hover_row != hover_element[2]
|
||||
when :timeline
|
||||
invalidate_time if @hover_keyframe != hover_element[1]
|
||||
when :commands
|
||||
invalidate_commands if @hover_row != hover_element[2] ||
|
||||
@hover_keyframe != hover_element[1]
|
||||
end
|
||||
@hover_area = hover_element[0]
|
||||
@hover_keyframe = hover_element[1]
|
||||
@hover_row = hover_element[2]
|
||||
elsif hover_element
|
||||
if @hover_area == hover_element
|
||||
case @hover_area
|
||||
when :list
|
||||
invalidate_rows if @hover_row
|
||||
when :timeline
|
||||
invalidate_time if @hover_keyframe
|
||||
when :commands
|
||||
invalidate_commands if @hover_keyframe || @hover_row
|
||||
end
|
||||
else # Moved to a different region
|
||||
invalidate
|
||||
end
|
||||
@hover_area = hover_element
|
||||
@hover_keyframe = nil
|
||||
@hover_row = nil
|
||||
else
|
||||
invalidate if @hover_area
|
||||
@hover_area = nil
|
||||
@hover_keyframe = nil
|
||||
@hover_row = nil
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
return if !self.visible
|
||||
@list_scrollbar.update
|
||||
@time_scrollbar.update
|
||||
super
|
||||
# Refresh sprites if a scrollbar has been moved
|
||||
self.left_pos = @time_scrollbar.position
|
||||
self.top_pos = @list_scrollbar.position
|
||||
# Update the current keyframe line's position
|
||||
refresh_position_line
|
||||
|
||||
if Input.release?(Input::MOUSERIGHT)
|
||||
on_right_mouse_release
|
||||
end
|
||||
|
||||
# TODO: This is testing code, and should be replaced by clicking on the
|
||||
# timeline or a command sprite. Maybe keep it after all? If so,
|
||||
# probably change left/right to <>, and also move the scrollbar(s) to
|
||||
# keep the "cursor" on-screen.
|
||||
if Input.repeat?(Input::LEFT)
|
||||
if @keyframe > 0
|
||||
@keyframe -= 1
|
||||
set_changed
|
||||
end
|
||||
elsif Input.repeat?(Input::RIGHT)
|
||||
if @keyframe < @duration - 1
|
||||
@keyframe += 1
|
||||
set_changed
|
||||
end
|
||||
# TODO: If this is to be kept, @row_index should be changed by potentially
|
||||
# more than 1, so that @particle_list[@row_index] is an integer and
|
||||
# not an array.
|
||||
# elsif Input.repeat?(Input::UP)
|
||||
# if @row_index > 0
|
||||
# @row_index -= 1
|
||||
# set_changed
|
||||
# end
|
||||
# elsif Input.repeat?(Input::DOWN)
|
||||
# if @row_index < @particles.length - 1
|
||||
# @row_index += 1
|
||||
# set_changed
|
||||
# end
|
||||
end
|
||||
|
||||
# Mouse scroll wheel
|
||||
mouse_x, mouse_y = mouse_pos
|
||||
if mouse_x && mouse_y
|
||||
if @interactions[:list].contains?(mouse_x, mouse_y) ||
|
||||
@interactions[:commands].contains?(mouse_x, mouse_y)
|
||||
wheel_v = Input.scroll_v
|
||||
if wheel_v > 0 # Scroll up
|
||||
@list_scrollbar.slider_top -= UIControls::Scrollbar::SCROLL_DISTANCE
|
||||
self.top_pos = @list_scrollbar.position
|
||||
elsif wheel_v < 0 # Scroll down
|
||||
@list_scrollbar.slider_top += UIControls::Scrollbar::SCROLL_DISTANCE
|
||||
self.top_pos = @list_scrollbar.position
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user