Implemented list control and basic animation-choosing screen for editor

This commit is contained in:
Maruno17
2023-08-31 23:03:47 +01:00
parent 1041883992
commit d4077875a4
7 changed files with 367 additions and 59 deletions

View File

@@ -9,11 +9,19 @@ class AnimationEditorLoadScreen
ANIMATIONS_LIST_WIDTH = 300
ANIMATIONS_LIST_HEIGHT = 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
@viewport = Viewport.new(0, 0, AnimationEditor::WINDOW_WIDTH, AnimationEditor::WINDOW_HEIGHT)
generate_list
@viewport = Viewport.new(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT)
@viewport.z = 99999
@screen_bitmap = BitmapSprite.new(AnimationEditor::WINDOW_WIDTH, AnimationEditor::WINDOW_HEIGHT, @viewport)
@screen_bitmap = BitmapSprite.new(WINDOW_WIDTH, WINDOW_HEIGHT, @viewport)
draw_editor_background
@load_animation_id = nil
create_controls
end
def dispose
@@ -21,32 +29,86 @@ class AnimationEditorLoadScreen
@viewport.dispose
end
def generate_list
@animations = []
# TODO: Look through GameData to populate @animations; below is temporary.
# There will be separate arrays for move animations, common animations
# and overworld animations. The move animations one will primarily be
# a list of moves that have any animations, with the actual GameData
# animations being in a sub-array for each move.
67.times { |i| @animations.push([i, "Animation #{i + 1}"]) }
end
def draw_editor_background
# Fill the whole screen with black
@screen_bitmap.bitmap.fill_rect(
0, 0, AnimationEditor::WINDOW_WIDTH, AnimationEditor::WINDOW_HEIGHT, Color.black
)
# Fill the whole screen with white
@screen_bitmap.bitmap.fill_rect(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, Color.black)
# Outline around animations list
@screen_bitmap.bitmap.outline_rect(
ANIMATIONS_LIST_X - 3, ANIMATIONS_LIST_Y - 3,
ANIMATIONS_LIST_WIDTH + 6, ANIMATIONS_LIST_HEIGHT + 6, Color.white
)
@screen_bitmap.bitmap.outline_rect(
ANIMATIONS_LIST_X - 2, ANIMATIONS_LIST_Y - 2,
ANIMATIONS_LIST_WIDTH + 4, ANIMATIONS_LIST_HEIGHT + 4, Color.black
)
@screen_bitmap.bitmap.outline_rect(
ANIMATIONS_LIST_X - 1, ANIMATIONS_LIST_Y - 1,
ANIMATIONS_LIST_WIDTH + 2, ANIMATIONS_LIST_HEIGHT + 2, Color.white
)
# Fill the animations list with white
@screen_bitmap.bitmap.fill_rect(
ANIMATIONS_LIST_X, ANIMATIONS_LIST_Y, ANIMATIONS_LIST_WIDTH, ANIMATIONS_LIST_HEIGHT, Color.white
)
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
# @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 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.
repaint
end
def repaint
@controls.each { |ctrl| ctrl[1].repaint }
end
def update
# TODO: Update the controls (animations list, Load button, etc.).
# 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
@@ -56,15 +118,20 @@ class AnimationEditorLoadScreen
Graphics.update
Input.update
update
if !inputting_text
break if Input.trigger?(Input::BACK)
end
# Open editor with animation
# TODO: If the Load button is pressed while an animation is selected.
if Input.trigger?(Input::USE)
# TODO: Add animation to be edited as an argument.
if @load_animation_id
# Open editor with animation
# TODO: Add animation to be edited as an argument. This will be
# GameData::Animation.get(@load_animation_id).to_hash.
echoln "Anim number #{@load_animation_id}: #{@animations[@load_animation_id][1]}"
screen = AnimationEditor.new
screen.run
@load_animation_id = nil
# TODO: Regenerate @animations in case the edited animation changed its
# name/move/version. Reapply @animations to @list and the sublist
# (this should invalidate them).
repaint
elsif !inputting_text
break if Input.trigger?(Input::BACK)
end
end
dispose