Anim Editor: added dark colour scheme

This commit is contained in:
Maruno17
2024-05-13 20:32:20 +01:00
parent 5495bf565c
commit 63309a2ae9
19 changed files with 526 additions and 236 deletions

View File

@@ -1,2 +1,140 @@
#===============================================================================
# Container module for control classes.
#===============================================================================
module UIControls; end
#===============================================================================
#
#===============================================================================
module UIControls::StyleMixin
COLOR_SCHEMES = {
:dark => {
:background_color => Color.new(32, 32, 32),
:text_color => Color.white,
:disabled_text_color => Color.new(96, 96, 96),
:line_color => Color.white,
:disabled_fill_color => Color.new(128, 128, 128),
:hover_color => Color.new(64, 80, 80),
:capture_color => Color.new(224, 32, 96),
:highlight_color => Color.new(160, 128, 16),
# Sidebars
# :delete_icon_color => Color.new(248, 96, 96), # Unchanged
# Checkbox
:checked_color => Color.new(32, 160, 32),
:unchecked_color => Color.new(160, 160, 160),
# ParticleList
# :position_line_color => Color.new(248, 96, 96), # Unchanged
:after_end_bg_color => Color.new(80, 80, 80),
:se_background_color => Color.new(160, 160, 160),
:property_background_color => Color.new(96, 96, 96),
# ParticleList and Canvas
:focus_colors => {
:foreground => Color.new(80, 112, 248), # Blue
:midground => Color.new(80, 112, 248), # Blue
:background => Color.new(80, 112, 248), # Blue
:user => Color.new(32, 192, 32), # Green
:target => Color.new(192, 32, 32), # Red
:user_and_target => Color.new(192, 192, 32), # Yellow
:user_side_foreground => Color.new(80, 208, 208), # Cyan
:user_side_background => Color.new(80, 208, 208), # Cyan
:target_side_foreground => Color.new(80, 208, 208), # Cyan
:target_side_background => Color.new(80, 208, 208) # Cyan
}
}
}
FOCUS_COLORS = {
:foreground => Color.new(128, 160, 248), # Blue
:midground => Color.new(128, 160, 248), # Blue
:background => Color.new(128, 160, 248), # Blue
:user => Color.new(64, 224, 64), # Green
:target => Color.new(224, 64, 64), # Red
:user_and_target => Color.new(224, 224, 64), # Yellow
:user_side_foreground => Color.new(128, 224, 224), # Cyan
:user_side_background => Color.new(128, 224, 224), # Cyan
:target_side_foreground => Color.new(128, 224, 224), # Cyan
:target_side_background => Color.new(128, 224, 224) # Cyan
}
def color_scheme_options
return {
:light => _INTL("Light"),
:dark => _INTL("Dark")
}
end
#-----------------------------------------------------------------------------
def background_color
return get_color_scheme_color_for_element(:background_color, Color.white)
end
def semi_transparent_color
return get_color_scheme_color_for_element(:semi_transparent_color, Color.new(0, 0, 0, 128))
end
#-----------------------------------------------------------------------------
def text_color
return get_color_scheme_color_for_element(:text_color, Color.black)
end
def disabled_text_color
return get_color_scheme_color_for_element(:disabled_text_color, Color.new(160, 160, 160))
end
def text_size
return 18 # Default is 22 if size isn't explicitly set
end
def line_color
return get_color_scheme_color_for_element(:line_color, Color.black)
end
def delete_icon_color
return get_color_scheme_color_for_element(:delete_icon_color, Color.new(248, 96, 96))
end
#-----------------------------------------------------------------------------
def disabled_fill_color
return get_color_scheme_color_for_element(:disabled_fill_color, Color.gray)
end
def hover_color
return get_color_scheme_color_for_element(:hover_color, Color.new(224, 255, 255))
end
def capture_color
return get_color_scheme_color_for_element(:capture_color, Color.new(255, 64, 128))
end
def highlight_color
return get_color_scheme_color_for_element(:highlight_color, Color.new(224, 192, 32))
end
#-----------------------------------------------------------------------------
def color_scheme=(value)
return if @color_scheme == value
@color_scheme = value
self.bitmap.font.color = text_color
self.bitmap.font.size = text_size
invalidate if self.respond_to?(:invalidate)
end
def get_color_scheme_color_for_element(element, default)
if COLOR_SCHEMES[@color_scheme] && COLOR_SCHEMES[@color_scheme][element]
return COLOR_SCHEMES[@color_scheme][element]
end
return default
end
def focus_color(focus)
if COLOR_SCHEMES[@color_scheme] && COLOR_SCHEMES[@color_scheme][:focus_colors] &&
COLOR_SCHEMES[@color_scheme][:focus_colors][focus]
return COLOR_SCHEMES[@color_scheme][:focus_colors][focus]
end
return FOCUS_COLORS[focus] || Color.magenta
end
end

View File

@@ -14,7 +14,10 @@ class UIControls::ControlsContainer
OFFSET_FROM_LABEL_X = 100
OFFSET_FROM_LABEL_Y = 0
include UIControls::StyleMixin
def initialize(x, y, width, height, right_margin = 0)
self.color_scheme = :light
@viewport = Viewport.new(x, y, width, height)
@viewport.z = 99999
@x = x
@@ -45,6 +48,15 @@ class UIControls::ControlsContainer
repaint if @visible
end
def color_scheme=(value)
return if @color_scheme == value
@color_scheme = value
if @controls
@controls.each { |c| c[1].color_scheme = value }
repaint
end
end
#-----------------------------------------------------------------------------
def busy?
@@ -215,6 +227,7 @@ class UIControls::ControlsContainer
def add_control_at(id, control, x, y)
control.x = x
control.y = y
control.color_scheme = @color_scheme
control.set_interactive_rects
@controls.push([id, control])
repaint

View File

@@ -5,18 +5,13 @@ class UIControls::BaseControl < BitmapSprite
attr_reader :value
attr_accessor :disabled
TEXT_COLOR = Color.black
TEXT_SIZE = 18 # Default is 22 if size isn't explicitly set
TEXT_OFFSET_Y = 5
HOVER_COLOR = Color.new(224, 255, 255) # For clickable area when hovering over it; light blue
CAPTURE_COLOR = Color.new(255, 64, 128) # For area you clicked in but aren't hovering over; hot pink
DISABLED_COLOR = Color.gray
DISABLED_COLOR_DARK = Color.new(128, 128, 128)
TEXT_OFFSET_Y = 5
include UIControls::StyleMixin
def initialize(width, height, viewport)
super(width, height, viewport)
self.bitmap.font.color = TEXT_COLOR
self.bitmap.font.size = TEXT_SIZE
self.color_scheme = :light
@disabled = false
@hover_area = nil # Is a symbol from the keys for @interactions if the mouse is hovering over that interaction
@captured_area = nil # Is a symbol from the keys for @interactions (or :none) if this control is clicked in
@@ -138,11 +133,11 @@ class UIControls::BaseControl < BitmapSprite
if !@captured_area || @hover_area == @captured_area
# Draw mouse hover over area highlight
rect = @interactions[@hover_area]
self.bitmap.fill_rect(rect.x, rect.y, rect.width, rect.height, HOVER_COLOR) if rect
self.bitmap.fill_rect(rect.x, rect.y, rect.width, rect.height, hover_color) if rect
elsif @captured_area
# Draw captured area highlight
rect = @interactions[@captured_area]
self.bitmap.fill_rect(rect.x, rect.y, rect.width, rect.height, CAPTURE_COLOR) if rect
self.bitmap.fill_rect(rect.x, rect.y, rect.width, rect.height, capture_color) if rect
end
end

View File

@@ -35,7 +35,7 @@ class UIControls::Label < UIControls::BaseControl
# Draw underline
text_size = self.bitmap.text_size(@text)
self.bitmap.fill_rect((width - text_size.width) / 2, TEXT_OFFSET_Y + text_size.height,
text_size.width, 1, TEXT_COLOR)
text_size.width, 1, line_color)
else
draw_text(self.bitmap, 4, TEXT_OFFSET_Y, @text)
end

View File

@@ -6,8 +6,6 @@ class UIControls::Checkbox < UIControls::BaseControl
CHECKBOX_WIDTH = 40
CHECKBOX_HEIGHT = 24
CHECKBOX_FILL_SIZE = CHECKBOX_HEIGHT - 4
UNCHECKED_COLOR = Color.gray
CHECKED_COLOR = Color.new(48, 192, 48) # Darkish green
def initialize(width, height, viewport, value = false)
super(width, height, viewport)
@@ -22,6 +20,14 @@ class UIControls::Checkbox < UIControls::BaseControl
invalidate
end
def checked_color
return get_color_scheme_color_for_element(:checked_color, Color.new(48, 192, 48))
end
def unchecked_color
return get_color_scheme_color_for_element(:unchecked_color, Color.gray)
end
#-----------------------------------------------------------------------------
def set_interactive_rects
@@ -40,24 +46,23 @@ class UIControls::Checkbox < UIControls::BaseControl
if disabled?
self.bitmap.fill_rect(@checkbox_rect.x, @checkbox_rect.y,
@checkbox_rect.width, @checkbox_rect.height,
DISABLED_COLOR)
disabled_fill_color)
end
# Draw checkbox outline
self.bitmap.outline_rect(@checkbox_rect.x, @checkbox_rect.y,
@checkbox_rect.width, @checkbox_rect.height,
self.bitmap.font.color)
line_color)
# Draw checkbox fill
if @value # If checked
self.bitmap.fill_rect(@checkbox_rect.x + @checkbox_rect.width - CHECKBOX_FILL_SIZE - 2, @checkbox_rect.y + 2,
CHECKBOX_FILL_SIZE, CHECKBOX_FILL_SIZE, (disabled?) ? DISABLED_COLOR_DARK : CHECKED_COLOR)
self.bitmap.outline_rect(@checkbox_rect.x + @checkbox_rect.width - CHECKBOX_FILL_SIZE - 2, @checkbox_rect.y + 2,
CHECKBOX_FILL_SIZE, CHECKBOX_FILL_SIZE, self.bitmap.font.color)
box_x = (@value) ? @checkbox_rect.width - CHECKBOX_FILL_SIZE - 2 : 2
if disabled?
box_color = disabled_text_color
else
self.bitmap.fill_rect(@checkbox_rect.x + 2, @checkbox_rect.y + 2,
CHECKBOX_FILL_SIZE, CHECKBOX_FILL_SIZE, (disabled?) ? DISABLED_COLOR_DARK : UNCHECKED_COLOR)
self.bitmap.outline_rect(@checkbox_rect.x + 2, @checkbox_rect.y + 2,
CHECKBOX_FILL_SIZE, CHECKBOX_FILL_SIZE, self.bitmap.font.color)
box_color = (@value) ? checked_color : unchecked_color
end
self.bitmap.fill_rect(@checkbox_rect.x + box_x, @checkbox_rect.y + 2,
CHECKBOX_FILL_SIZE, CHECKBOX_FILL_SIZE, box_color)
self.bitmap.outline_rect(@checkbox_rect.x + box_x, @checkbox_rect.y + 2,
CHECKBOX_FILL_SIZE, CHECKBOX_FILL_SIZE, line_color)
end
#-----------------------------------------------------------------------------

View File

@@ -167,7 +167,7 @@ class UIControls::TextBox < UIControls::BaseControl
return if !@cursor_shown || @cursor_pos < 0
cursor_y_offset = ((height - TEXT_BOX_HEIGHT) / 2) + 2
cursor_height = height - (cursor_y_offset * 2)
bitmap.fill_rect(cursor_x, cursor_y_offset, 2, cursor_height, self.bitmap.font.color)
bitmap.fill_rect(cursor_x, cursor_y_offset, 2, cursor_height, text_color)
end
def refresh
@@ -176,12 +176,12 @@ class UIControls::TextBox < UIControls::BaseControl
if disabled?
self.bitmap.fill_rect(@text_box_rect.x, @text_box_rect.y,
@text_box_rect.width, @text_box_rect.height,
DISABLED_COLOR)
disabled_fill_color)
end
# Draw text box outline
self.bitmap.outline_rect(@text_box_rect.x, @text_box_rect.y,
@text_box_rect.width, @text_box_rect.height,
self.bitmap.font.color)
line_color)
# Draw value
char_x = @text_box_rect.x + TEXT_BOX_PADDING
last_char_index = @display_pos
@@ -199,16 +199,17 @@ class UIControls::TextBox < UIControls::BaseControl
# Draw cursor at end
draw_cursor(char_x - 1) if @cursor_pos == @value.to_s.length
# Draw left/right arrows to indicate more text beyond the text box sides
arrow_color = (disabled?) ? disabled_text_color : text_color
if @display_pos > 0
bitmap.fill_rect(@text_box_rect.x, (height / 2) - 4, 1, 8, Color.white)
bitmap.fill_rect(@text_box_rect.x, (height / 2) - 4, 1, 8, background_color)
5.times do |i|
bitmap.fill_rect(@text_box_rect.x - 2 + i, (height / 2) - (i + 1), 1, 2 * (i + 1), self.bitmap.font.color)
bitmap.fill_rect(@text_box_rect.x - 2 + i, (height / 2) - (i + 1), 1, 2 * (i + 1), arrow_color)
end
end
if last_char_index < @value.to_s.length - 1
bitmap.fill_rect(@text_box_rect.x + @text_box_rect.width - 1, (height / 2) - 4, 1, 8, Color.white)
bitmap.fill_rect(@text_box_rect.x + @text_box_rect.width - 1, (height / 2) - 4, 1, 8, background_color)
5.times do |i|
bitmap.fill_rect(@text_box_rect.x + @text_box_rect.width + 1 - i, (height / 2) - (i + 1), 1, 2 * (i + 1), self.bitmap.font.color)
bitmap.fill_rect(@text_box_rect.x + @text_box_rect.width + 1 - i, (height / 2) - (i + 1), 1, 2 * (i + 1), arrow_color)
end
end
end

View File

@@ -62,7 +62,7 @@ class UIControls::NumberSlider < UIControls::BaseControl
# the mouse doesn't need to be on the slider to change this control's value
if @captured_area == :slider
rect = @interactions[@captured_area]
self.bitmap.fill_rect(rect.x, rect.y, rect.width, rect.height, HOVER_COLOR) if rect
self.bitmap.fill_rect(rect.x, rect.y, rect.width, rect.height, hover_color) if rect
else
super
end
@@ -70,14 +70,14 @@ class UIControls::NumberSlider < UIControls::BaseControl
def refresh
super
button_color = (disabled?) ? DISABLED_COLOR : self.bitmap.font.color
button_color = (disabled?) ? disabled_text_color : text_color
# Draw minus button
self.bitmap.fill_rect(@minus_rect.x + 2, @minus_rect.y + (@minus_rect.height / 2) - 2, @minus_rect.width - 4, 4, button_color)
# Draw slider bar
self.bitmap.fill_rect(SLIDER_X, (self.height / 2) - 1, SLIDER_LENGTH, 2, self.bitmap.font.color)
self.bitmap.fill_rect(SLIDER_X, (self.height / 2) - 1, SLIDER_LENGTH, 2, text_color)
# Draw notches on slider bar
5.times do |i|
self.bitmap.fill_rect(SLIDER_X - 1 + (i * SLIDER_LENGTH / 4), (self.height / 2) - 2, 2, 4, self.bitmap.font.color)
self.bitmap.fill_rect(SLIDER_X - 1 + (i * SLIDER_LENGTH / 4), (self.height / 2) - 2, 2, 4, text_color)
end
# Draw slider knob
fraction = (self.value - self.min_value) / (self.max_value.to_f - self.min_value)

View File

@@ -73,7 +73,7 @@ class UIControls::NumberTextBox < UIControls::TextBox
def refresh
super
button_color = (disabled?) ? DISABLED_COLOR : self.bitmap.font.color
button_color = (disabled?) ? disabled_text_color : text_color
# Draw minus button
self.bitmap.fill_rect(@minus_rect.x + 2, @minus_rect.y + (@minus_rect.height / 2) - 2, @minus_rect.width - 4, 4, button_color)
# Draw plus button

View File

@@ -7,7 +7,6 @@ class UIControls::Button < UIControls::BaseControl
BUTTON_PADDING = 10 # Used when @fixed_size is false
BUTTON_HEIGHT = 28 # Used when @fixed_size is false
TEXT_BASE_OFFSET_Y = 18 # Text is centred vertically in the button
HIGHLIGHT_COLOR = Color.new(224, 192, 32) # Dark yellow
def initialize(width, height, viewport, text = "")
super(width, height, viewport)
@@ -82,21 +81,21 @@ class UIControls::Button < UIControls::BaseControl
# Draw highligted colour
self.bitmap.fill_rect(@button_rect.x, @button_rect.y,
@button_rect.width, @button_rect.height,
HIGHLIGHT_COLOR)
highlight_color)
elsif disabled?
# Draw disabled colour
self.bitmap.fill_rect(@button_rect.x, @button_rect.y,
@button_rect.width, @button_rect.height,
DISABLED_COLOR)
disabled_fill_color)
end
# Draw button outline
self.bitmap.outline_rect(@button_rect.x, @button_rect.y,
@button_rect.width, @button_rect.height,
self.bitmap.font.color)
line_color)
# Draw inner grey ring that shows this is a button rather than a text box
if !disabled?
shade = self.bitmap.font.color.clone
shade.alpha = 64
shade = line_color.clone
shade.alpha = (shade.red > 128) ? 160 : 64
self.bitmap.outline_rect(@button_rect.x + 2, @button_rect.y + 2,
@button_rect.width - 4, @button_rect.height - 4,
shade, 1)

View File

@@ -6,7 +6,6 @@ class UIControls::List < UIControls::BaseControl
ROW_HEIGHT = 24
TEXT_PADDING_X = 4
TEXT_OFFSET_Y = 3
SELECTED_ROW_COLOR = Color.new(216, 192, 32) # Dark yellow
def initialize(width, height, viewport, values = [])
super(width, height, viewport)
@@ -14,6 +13,7 @@ class UIControls::List < UIControls::BaseControl
width - UIControls::Scrollbar::SLIDER_WIDTH - BORDER_THICKNESS, BORDER_THICKNESS,
height - (BORDER_THICKNESS * 2), viewport
)
@scrollbar.color_scheme = @color_scheme
@scrollbar.set_interactive_rects
@scrollbar.range = ROW_HEIGHT
@scrollbar.z = self.z + 1
@@ -51,6 +51,15 @@ class UIControls::List < UIControls::BaseControl
@scrollbar.visible = new_val
end
def color_scheme=(value)
return if @color_scheme == value
@color_scheme = value
self.bitmap.font.color = text_color
self.bitmap.font.size = text_size
@scrollbar&.color_scheme = value
invalidate if self.respond_to?(:invalidate)
end
# Each value in @values is an array: [id, text].
def values=(new_vals)
@values = new_vals
@@ -131,7 +140,7 @@ class UIControls::List < UIControls::BaseControl
if rect
rect_y = rect.y
rect_y -= @top_row * ROW_HEIGHT if @hover_area.is_a?(Integer)
self.bitmap.fill_rect(rect.x, rect_y, rect.width, rect.height, HOVER_COLOR)
self.bitmap.fill_rect(rect.x, rect_y, rect.width, rect.height, hover_color)
end
end
@@ -143,7 +152,7 @@ class UIControls::List < UIControls::BaseControl
def refresh
super
# Draw control outline
self.bitmap.outline_rect(0, 0, width, height, Color.black)
self.bitmap.outline_rect(0, 0, width, height, line_color)
# Draw text options
@values.each_with_index do |val, i|
next if i < @top_row || i >= @top_row + @rows_count
@@ -152,11 +161,11 @@ class UIControls::List < UIControls::BaseControl
@interactions[i].x,
@interactions[i].y - (@top_row * ROW_HEIGHT),
@interactions[i].width, @interactions[i].height,
SELECTED_ROW_COLOR
highlight_color
)
end
txt = (val.is_a?(Array)) ? val[1] : val.to_s
text_color = TEXT_COLOR
old_text_color = self.bitmap.font.color
if txt[/^\\c\[([0-9]+)\]/i]
text_colors = [
[ 0, 112, 248], [120, 184, 232], # 1 Blue
@@ -181,7 +190,7 @@ class UIControls::List < UIControls::BaseControl
@interactions[i].x + TEXT_PADDING_X,
@interactions[i].y + TEXT_OFFSET_Y - (@top_row * ROW_HEIGHT),
txt)
self.bitmap.font.color = TEXT_COLOR
self.bitmap.font.color = old_text_color
end
end

View File

@@ -63,12 +63,15 @@ class UIControls::DropdownList < UIControls::BaseControl
@dropdown_menu_bg.x = self.x + @button_rect.x
@dropdown_menu_bg.y = self.y + @button_rect.y + @button_rect.height
@dropdown_menu_bg.z = self.z + 1
@dropdown_menu_bg.bitmap.fill_rect(0, 0, @dropdown_menu_bg.width, @dropdown_menu_bg.height, Color.white)
@dropdown_menu_bg.bitmap.font.color = text_color
@dropdown_menu_bg.bitmap.font.size = text_size
@dropdown_menu_bg.bitmap.fill_rect(0, 0, @dropdown_menu_bg.width, @dropdown_menu_bg.height, background_color)
# Create menu
@dropdown_menu = UIControls::List.new(@button_rect.width, menu_height, self.viewport, @options)
@dropdown_menu.x = @dropdown_menu_bg.x
@dropdown_menu.y = @dropdown_menu_bg.y
@dropdown_menu.z = self.z + 2
@dropdown_menu.color_scheme = @color_scheme
@dropdown_menu.set_interactive_rects
@dropdown_menu.repaint
end
@@ -95,23 +98,24 @@ class UIControls::DropdownList < UIControls::BaseControl
if disabled?
self.bitmap.fill_rect(@button_rect.x, @button_rect.y,
@button_rect.width, @button_rect.height,
DISABLED_COLOR)
disabled_fill_color)
end
# Draw button outline
self.bitmap.outline_rect(@button_rect.x, @button_rect.y,
@button_rect.width, @button_rect.height,
self.bitmap.font.color)
line_color)
# Draw value
draw_text(self.bitmap, @button_rect.x + TEXT_BOX_PADDING, TEXT_OFFSET_Y, @options[@value] || "???")
# Draw down arrow
arrow_area_x = @button_rect.x + @button_rect.width - @button_rect.height + 1
arrow_area_width = @button_rect.height - 2
arrow_color = (disabled?) ? disabled_text_color : text_color
self.bitmap.fill_rect(arrow_area_x, @button_rect.y + 1, arrow_area_width, arrow_area_width,
(@hover_area && @captured_area != :button) ? HOVER_COLOR : Color.white)
(@hover_area && @captured_area != :button) ? hover_color : background_color)
6.times do |i|
self.bitmap.fill_rect(arrow_area_x + (arrow_area_width / 2) - 5 + i,
@button_rect.y + (arrow_area_width / 2) - 1 + i,
11 - (2 * i), 1, (disabled?) ? DISABLED_COLOR_DARK : self.bitmap.font.color)
11 - (2 * i), 1, arrow_color)
end
end

View File

@@ -59,12 +59,13 @@ class UIControls::TextBoxDropdownList < UIControls::TextBox
@dropdown_menu_bg.x = self.x + @text_box_rect.x
@dropdown_menu_bg.y = self.y + @text_box_rect.y + @text_box_rect.height
@dropdown_menu_bg.z = self.z + 1
@dropdown_menu_bg.bitmap.fill_rect(0, 0, @dropdown_menu_bg.width, @dropdown_menu_bg.height, Color.white)
@dropdown_menu_bg.bitmap.fill_rect(0, 0, @dropdown_menu_bg.width, @dropdown_menu_bg.height, background_color)
# Create menu
@dropdown_menu = UIControls::List.new(@text_box_rect.width + @button_rect.width, menu_height, self.viewport, @options)
@dropdown_menu.x = @dropdown_menu_bg.x
@dropdown_menu.y = @dropdown_menu_bg.y
@dropdown_menu.z = self.z + 2
@dropdown_menu.color_scheme = @color_scheme
@dropdown_menu.set_interactive_rects
@dropdown_menu.repaint
end
@@ -83,10 +84,10 @@ class UIControls::TextBoxDropdownList < UIControls::TextBox
def draw_area_highlight
highlight_color = nil
if @captured_area == :text_box && !@hover_area && Input.press?(Input::MOUSELEFT)
highlight_color = CAPTURE_COLOR
highlight_color = capture_color
elsif !@captured_area && [:text_box, :button].include?(@hover_area)
# Draw mouse hover over area highlight
highlight_color = HOVER_COLOR
highlight_color = hover_color
end
return if !highlight_color
[:text_box, :button].each do |area|
@@ -102,21 +103,22 @@ class UIControls::TextBoxDropdownList < UIControls::TextBox
if disabled?
self.bitmap.fill_rect(@button_rect.x, @button_rect.y,
@button_rect.width, @button_rect.height,
DISABLED_COLOR)
disabled_fill_color)
end
# Draw button outline
self.bitmap.outline_rect(@button_rect.x, @button_rect.y,
@button_rect.width, @button_rect.height,
self.bitmap.font.color)
line_color)
# Draw down arrow
arrow_area_x = @button_rect.x + @button_rect.width - @button_rect.height + 1
arrow_area_width = @button_rect.height - 2
arrow_color = (disabled?) ? disabled_text_color : text_color
# self.bitmap.fill_rect(arrow_area_x, @button_rect.y + 1, arrow_area_width, arrow_area_width,
# (@hover_area && @captured_area != :button) ? HOVER_COLOR : Color.white)
# (@hover_area && @captured_area != :button) ? hover_color : background_color)
6.times do |i|
self.bitmap.fill_rect(arrow_area_x + (arrow_area_width / 2) - 5 + i,
@button_rect.y + (arrow_area_width / 2) - 1 + i,
11 - (2 * i), 1, (disabled?) ? DISABLED_COLOR_DARK : self.bitmap.font.color)
11 - (2 * i), 1, arrow_color)
end
end

View File

@@ -7,9 +7,6 @@ class UIControls::Scrollbar < UIControls::BaseControl
SLIDER_WIDTH = 16
WIDTH_PADDING = 0
SCROLL_DISTANCE = 16
TRAY_COLOR = Color.white
SLIDER_COLOR = Color.black
GRAB_COLOR = HOVER_COLOR # Cyan
def initialize(x, y, size, viewport, horizontal = false, always_visible = false)
if horizontal
@@ -90,14 +87,14 @@ class UIControls::Scrollbar < UIControls::BaseControl
super
return if !self.visible
# Draw the tray
self.bitmap.fill_rect(@slider_tray.x, @slider_tray.y, @slider_tray.width, @slider_tray.height, TRAY_COLOR)
self.bitmap.fill_rect(@slider_tray.x, @slider_tray.y, @slider_tray.width, @slider_tray.height, background_color)
# Draw the slider
if @slider_size < @tray_size
bar_color = SLIDER_COLOR
if @slider_size < @tray_size && !disabled?
if @captured_area == :slider || (!@captured_area && @hover_area == :slider)
bar_color = GRAB_COLOR
bar_color = hover_color
else
bar_color = text_color
end
bar_color = DISABLED_COLOR if disabled?
self.bitmap.fill_rect(@slider.x, @slider.y, @slider.width, @slider.height, bar_color)
end
end

View File

@@ -1,3 +1,34 @@
#===============================================================================
#
#===============================================================================
class AnimationEditor
module AnimationEditor::SettingsMixin
def load_settings
if File.file?(DEBUG_SETTINGS_FILE_PATH)
@settings = SaveData.get_data_from_file(DEBUG_SETTINGS_FILE_PATH)[:anim_editor]
else
@settings = {
:color_scheme => :light,
:side_sizes => [1, 1], # Player's side, opposing side
:user_index => 0, # 0, 2, 4
:target_indices => [1], # There must be at least one valid target
:user_opposes => false,
:canvas_bg => "indoor1",
# NOTE: These sprite names are also used in Pokemon.play_cry and so
# should be a species ID (being a string is fine).
:user_sprite_name => "DRAGONITE",
:target_sprite_name => "CHARIZARD"
}
end
end
def save_settings
data = { :anim_editor => @settings }
File.open(DEBUG_SETTINGS_FILE_PATH, "wb") { |file| Marshal.dump(data, file) }
end
end
end
#===============================================================================
#
#===============================================================================
@@ -102,6 +133,9 @@ class AnimationEditor
"./debug_settings.rxdata"
end
include AnimationEditor::SettingsMixin
include UIControls::StyleMixin
#-----------------------------------------------------------------------------
def initialize(anim_id, anim)
@@ -116,6 +150,7 @@ class AnimationEditor
initialize_components
@captured = nil
set_components_contents
self.color_scheme = @settings[:color_scheme]
refresh
end
@@ -130,28 +165,39 @@ class AnimationEditor
def initialize_bitmaps
# Background for main editor
@screen_bitmap = BitmapSprite.new(WINDOW_WIDTH, WINDOW_HEIGHT, @viewport)
@screen_bitmap.z = -100
if !@screen_bitmap
@screen_bitmap = BitmapSprite.new(WINDOW_WIDTH, WINDOW_HEIGHT, @viewport)
@screen_bitmap.z = -100
end
# Semi-transparent black overlay to dim the screen while a pop-up window is open
@pop_up_bg_bitmap = BitmapSprite.new(WINDOW_WIDTH, WINDOW_HEIGHT, @pop_up_viewport)
@pop_up_bg_bitmap.z = -100
@pop_up_bg_bitmap.visible = false
if !@pop_up_bg_bitmap
@pop_up_bg_bitmap = BitmapSprite.new(WINDOW_WIDTH, WINDOW_HEIGHT, @pop_up_viewport)
@pop_up_bg_bitmap.z = -100
@pop_up_bg_bitmap.visible = false
end
# Bitmaps for "delete this property change" buttons in the side pane
@delete_bitmap = Bitmap.new(16, 16)
@delete_disabled_bitmap = Bitmap.new(16, 16)
if !@delete_bitmap
@delete_bitmap = Bitmap.new(16, 16)
@delete_disabled_bitmap = Bitmap.new(16, 16)
end
@delete_bitmap.clear
@delete_disabled_bitmap.clear
icon_color = delete_icon_color
disabled_icon_color = disabled_text_color
14.times do |i|
case i
when 0, 13 then wid = 3
when 1, 12 then wid = 4
else wid = 5
end
@delete_bitmap.fill_rect([i - 1, 1].max, i + 1, wid, 1, Color.new(248, 96, 96))
@delete_bitmap.fill_rect([i - 1, 1].max, 14 - i, wid, 1, Color.new(248, 96, 96))
@delete_disabled_bitmap.fill_rect([i - 1, 1].max, i + 1, wid, 1, Color.new(160, 160, 160))
@delete_disabled_bitmap.fill_rect([i - 1, 1].max, 14 - i, wid, 1, Color.new(160, 160, 160))
@delete_bitmap.fill_rect([i - 1, 1].max, i + 1, wid, 1, icon_color)
@delete_bitmap.fill_rect([i - 1, 1].max, 14 - i, wid, 1, icon_color)
@delete_disabled_bitmap.fill_rect([i - 1, 1].max, i + 1, wid, 1, disabled_icon_color)
@delete_disabled_bitmap.fill_rect([i - 1, 1].max, 14 - i, wid, 1, disabled_icon_color)
end
# Editor settings button bitmap
@editor_settings_bitmap = Bitmap.new(18, 18)
@editor_settings_bitmap = Bitmap.new(18, 18) if !@editor_settings_bitmap
@editor_settings_bitmap.clear
settings_array = [
0, 0, 0, 0, 0, 0, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 1, 1,
@@ -163,12 +209,13 @@ class AnimationEditor
0, 1, 1, 1, 1, 1, 1, 0, 0,
1, 1, 1, 1, 1, 1, 0, 0, 0
]
icon_color = text_color
settings_array.length.times do |i|
next if settings_array[i] == 0
@editor_settings_bitmap.fill_rect(i % 9, i / 9, 1, 1, Color.black)
@editor_settings_bitmap.fill_rect(17 - (i % 9), i / 9, 1, 1, Color.black)
@editor_settings_bitmap.fill_rect(i % 9, 17 - (i / 9), 1, 1, Color.black)
@editor_settings_bitmap.fill_rect(17 - (i % 9), 17 - (i / 9), 1, 1, Color.black)
@editor_settings_bitmap.fill_rect(i % 9, i / 9, 1, 1, icon_color)
@editor_settings_bitmap.fill_rect(17 - (i % 9), i / 9, 1, 1, icon_color)
@editor_settings_bitmap.fill_rect(i % 9, 17 - (i / 9), 1, 1, icon_color)
@editor_settings_bitmap.fill_rect(17 - (i % 9), 17 - (i / 9), 1, 1, icon_color)
end
# Draw in these bitmaps
draw_editor_background
@@ -243,29 +290,6 @@ class AnimationEditor
return @components[:particle_list].particle_index
end
def load_settings
if File.file?(DEBUG_SETTINGS_FILE_PATH)
@settings = SaveData.get_data_from_file(DEBUG_SETTINGS_FILE_PATH)[:anim_editor]
else
@settings = {
:side_sizes => [1, 1], # Player's side, opposing side
:user_index => 0, # 0, 2, 4
:target_indices => [1], # There must be at least one valid target
:user_opposes => false,
:canvas_bg => "indoor1",
# NOTE: These sprite names are also used in Pokemon.play_cry and so
# should be a species ID (being a string is fine).
:user_sprite_name => "DRAGONITE",
:target_sprite_name => "CHARIZARD"
}
end
end
def save_settings
data = { :anim_editor => @settings }
File.open(DEBUG_SETTINGS_FILE_PATH, "wb") { |file| Marshal.dump(data, file) }
end
def save
AnimationEditor::ParticleDataHelper.optimize_all_particles(@anim[:particles])
GameData::Animation.register(@anim, @anim_id)
@@ -281,6 +305,17 @@ class AnimationEditor
save_settings
end
def color_scheme=(value)
return if @color_scheme == value
@color_scheme = value
return if !@components
initialize_bitmaps
@components.each do |component|
component[1].color_scheme = value if component[1].respond_to?("color_scheme=")
end
refresh
end
#-----------------------------------------------------------------------------
# Returns the animation's name for display in the menu bar and elsewhere.
@@ -383,6 +418,7 @@ class AnimationEditor
def set_editor_settings_contents
editor_settings = @components[:editor_settings]
editor_settings.add_header_label(:header, _INTL("Editor settings"))
editor_settings.add_labelled_dropdown_list(:color_scheme, _INTL("Color scheme"), color_scheme_options, :light)
editor_settings.add_labelled_dropdown_list(:side_size_1, _INTL("Side sizes"), {
1 => "1",
2 => "2",
@@ -490,19 +526,21 @@ class AnimationEditor
#-----------------------------------------------------------------------------
def draw_editor_background
bg_color = background_color
contrast_color = line_color
# Fill the whole screen with white
@screen_bitmap.bitmap.fill_rect(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, Color.white)
@screen_bitmap.bitmap.fill_rect(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, bg_color)
# Outline around elements
@screen_bitmap.bitmap.border_rect(CANVAS_X, CANVAS_Y, CANVAS_WIDTH, CANVAS_HEIGHT,
BORDER_THICKNESS, Color.white, Color.black)
BORDER_THICKNESS, bg_color, contrast_color)
@screen_bitmap.bitmap.border_rect(PLAY_CONTROLS_X, PLAY_CONTROLS_Y, PLAY_CONTROLS_WIDTH, PLAY_CONTROLS_HEIGHT,
BORDER_THICKNESS, Color.white, Color.black)
BORDER_THICKNESS, bg_color, contrast_color)
@screen_bitmap.bitmap.border_rect(SIDE_PANE_X, SIDE_PANE_Y, SIDE_PANE_WIDTH, SIDE_PANE_HEIGHT,
BORDER_THICKNESS, Color.white, Color.black)
BORDER_THICKNESS, bg_color, contrast_color)
@screen_bitmap.bitmap.border_rect(PARTICLE_LIST_X, PARTICLE_LIST_Y, PARTICLE_LIST_WIDTH, PARTICLE_LIST_HEIGHT,
BORDER_THICKNESS, Color.white, Color.black)
BORDER_THICKNESS, bg_color, contrast_color)
# Make the pop-up background semi-transparent
@pop_up_bg_bitmap.bitmap.fill_rect(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, Color.new(0, 0, 0, 128))
@pop_up_bg_bitmap.bitmap.fill_rect(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT, semi_transparent_color)
end
#-----------------------------------------------------------------------------
@@ -706,6 +744,9 @@ class AnimationEditor
end
when :editor_settings
case property
when :color_scheme
@settings[:color_scheme] = value
self.color_scheme = value
when :side_size_1
old_val = @settings[:side_sizes][0]
@settings[:side_sizes][0] = value
@@ -943,6 +984,13 @@ class AnimationEditor
@components[:particle_list].set_particles(@anim[:particles])
refresh
end
elsif Input.triggerex?(:C)
options = color_scheme_options.keys
this_index = options.index(@color_scheme || :light) || 0
new_index = (this_index + 1) % options.length
@settings[:color_scheme] = options[new_index]
self.color_scheme = @settings[:color_scheme]
save_settings
end
end

View File

@@ -2,19 +2,22 @@
#
#===============================================================================
class AnimationEditor
def create_pop_up_window(width, height)
ret = BitmapSprite.new(width + (BORDER_THICKNESS * 2),
height + (BORDER_THICKNESS * 2), @pop_up_viewport)
ret.x = (WINDOW_WIDTH - ret.width) / 2
ret.y = (WINDOW_HEIGHT - ret.height) / 2
ret.z = -1
ret.bitmap.font.color = Color.black
ret.bitmap.font.size = 18
def create_pop_up_window(width, height, ret = nil)
if !ret
ret = BitmapSprite.new(width + (BORDER_THICKNESS * 2),
height + (BORDER_THICKNESS * 2), @pop_up_viewport)
ret.x = (WINDOW_WIDTH - ret.width) / 2
ret.y = (WINDOW_HEIGHT - ret.height) / 2
ret.z = -1
end
ret.bitmap.clear
ret.bitmap.font.color = text_color
ret.bitmap.font.size = text_size
# Draw pop-up box border
ret.bitmap.border_rect(BORDER_THICKNESS, BORDER_THICKNESS, width, height,
BORDER_THICKNESS, Color.white, Color.black)
BORDER_THICKNESS, background_color, line_color)
# Fill pop-up box with white
ret.bitmap.fill_rect(BORDER_THICKNESS, BORDER_THICKNESS, width, height, Color.white)
ret.bitmap.fill_rect(BORDER_THICKNESS, BORDER_THICKNESS, width, height, background_color)
return ret
end
@@ -35,6 +38,7 @@ class AnimationEditor
btn.x += MESSAGE_BOX_BUTTON_WIDTH * i
btn.y = msg_bitmap.y + msg_bitmap.height - MESSAGE_BOX_BUTTON_HEIGHT - MESSAGE_BOX_SPACING
btn.set_fixed_size
btn.color_scheme = @color_scheme
btn.set_interactive_rects
buttons.push([option[0], btn])
end
@@ -130,6 +134,7 @@ class AnimationEditor
editor_settings.visible = true
# Set control values
refresh_component(:editor_settings)
editor_settings.get_control(:color_scheme).value = @settings[:color_scheme] || :light
editor_settings.get_control(:side_size_1).value = @settings[:side_sizes][0]
editor_settings.get_control(:side_size_2).value = @settings[:side_sizes][1]
editor_settings.get_control(:user_index).value = @settings[:user_index]
@@ -148,6 +153,7 @@ class AnimationEditor
break if editor_settings.values.keys.include?(:close)
editor_settings.values.each_pair do |property, value|
apply_changed_value(:editor_settings, property, value)
create_pop_up_window(ANIM_PROPERTIES_WIDTH, ANIM_PROPERTIES_HEIGHT, bg_bitmap)
end
editor_settings.clear_changed
end
@@ -222,7 +228,7 @@ class AnimationEditor
bg_bitmap.bitmap.outline_rect(BORDER_THICKNESS + list.x + list.width + 6,
BORDER_THICKNESS + list.y,
GRAPHIC_CHOOSER_PREVIEW_SIZE + 4, GRAPHIC_CHOOSER_PREVIEW_SIZE + 4,
Color.black)
line_color)
preview_sprite = Sprite.new(@pop_up_viewport)
preview_sprite.x = graphic_chooser.x + list.x + list.width + 8 + (GRAPHIC_CHOOSER_PREVIEW_SIZE / 2)
preview_sprite.y = graphic_chooser.y + list.y + 2 + (GRAPHIC_CHOOSER_PREVIEW_SIZE / 2)
@@ -251,7 +257,7 @@ class AnimationEditor
preview_bitmap = AnimatedBitmap.new(folder + fname)
bg_bitmap.bitmap.fill_rect(BORDER_THICKNESS + list.x + list.width + 8, BORDER_THICKNESS + list.y + 2,
GRAPHIC_CHOOSER_PREVIEW_SIZE, GRAPHIC_CHOOSER_PREVIEW_SIZE,
Color.white)
background_color)
next if !preview_bitmap
sprite.bitmap = preview_bitmap.bitmap
zoom = [[GRAPHIC_CHOOSER_PREVIEW_SIZE.to_f / preview_bitmap.width,

View File

@@ -44,7 +44,11 @@ class AnimationEditor::AnimationSelector
MESSAGE_BOX_BUTTON_HEIGHT = 32
MESSAGE_BOX_SPACING = 16
include AnimationEditor::SettingsMixin
include UIControls::StyleMixin
def initialize
load_settings
@animation_type = 0 # 0=move, 1=common
@filter_text = ""
@quit = false
@@ -52,6 +56,7 @@ class AnimationEditor::AnimationSelector
initialize_viewports
initialize_bitmaps
initialize_controls
self.color_scheme = @settings[:color_scheme]
refresh
end
@@ -132,11 +137,21 @@ class AnimationEditor::AnimationSelector
#-----------------------------------------------------------------------------
def color_scheme=(value)
return if @color_scheme == value
@color_scheme = value
draw_editor_background
@components.color_scheme = value
refresh
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.white)
@screen_bitmap.bitmap.fill_rect(0, 0, AnimationEditor::WINDOW_WIDTH, AnimationEditor::WINDOW_HEIGHT, background_color)
# Make the pop-up background semi-transparent
@pop_up_bg_bitmap.bitmap.fill_rect(0, 0, AnimationEditor::WINDOW_WIDTH, AnimationEditor::WINDOW_HEIGHT, Color.new(0, 0, 0, 128))
@pop_up_bg_bitmap.bitmap.fill_rect(0, 0, AnimationEditor::WINDOW_WIDTH, AnimationEditor::WINDOW_HEIGHT, semi_transparent_color)
end
#-----------------------------------------------------------------------------
@@ -147,13 +162,13 @@ class AnimationEditor::AnimationSelector
ret.x = (AnimationEditor::WINDOW_WIDTH - ret.width) / 2
ret.y = (AnimationEditor::WINDOW_HEIGHT - ret.height) / 2
ret.z = -1
ret.bitmap.font.color = Color.black
ret.bitmap.font.size = 18
ret.bitmap.font.color = text_color
ret.bitmap.font.size = text_size
# Draw pop-up box border
ret.bitmap.border_rect(BORDER_THICKNESS, BORDER_THICKNESS, width, height,
BORDER_THICKNESS, Color.white, Color.black)
BORDER_THICKNESS, background_color, line_color)
# Fill pop-up box with white
ret.bitmap.fill_rect(BORDER_THICKNESS, BORDER_THICKNESS, width, height, Color.white)
ret.bitmap.fill_rect(BORDER_THICKNESS, BORDER_THICKNESS, width, height, background_color)
return ret
end
@@ -174,6 +189,7 @@ class AnimationEditor::AnimationSelector
btn.x += MESSAGE_BOX_BUTTON_WIDTH * i
btn.y = msg_bitmap.y + msg_bitmap.height - MESSAGE_BOX_BUTTON_HEIGHT - MESSAGE_BOX_SPACING
btn.set_fixed_size
btn.color_scheme = @color_scheme
btn.set_interactive_rects
buttons.push([option[0], btn])
end
@@ -351,6 +367,8 @@ class AnimationEditor::AnimationSelector
if anim_id
screen = AnimationEditor.new(anim_id, GameData::Animation.get(anim_id).clone_as_hash)
screen.run
load_settings
self.color_scheme = @settings[:color_scheme]
generate_full_lists
end
when :copy
@@ -379,6 +397,17 @@ class AnimationEditor::AnimationSelector
refresh
end
def update_input
if Input.triggerex?(:C)
options = color_scheme_options.keys
this_index = options.index(@color_scheme || :light) || 0
new_index = (this_index + 1) % options.length
@settings[:color_scheme] = options[new_index]
self.color_scheme = @settings[:color_scheme]
save_settings
end
end
def update
@components.update
if @components.changed?
@@ -394,6 +423,7 @@ class AnimationEditor::AnimationSelector
apply_list_filter
refresh
end
update_input if !@components.busy?
end
def run

View File

@@ -19,6 +19,8 @@ class AnimationEditor::Canvas < Sprite
FRAME_SIZE = 48
PARTICLE_FRAME_COLOR = Color.new(0, 0, 0, 64)
include UIControls::StyleMixin
def initialize(viewport, anim, settings)
super(viewport)
@anim = anim
@@ -156,6 +158,14 @@ class AnimationEditor::Canvas < Sprite
return true
end
def color_scheme=(value)
return if @color_scheme == value
@color_scheme = value
self.bitmap.font.color = text_color
self.bitmap.font.size = text_size
refresh
end
def selected_particle=(val)
return if @selected_particle == val
@selected_particle = val
@@ -543,8 +553,7 @@ class AnimationEditor::Canvas < Sprite
def refresh_particle_frame
return if !show_particle_sprite?(@selected_particle)
focus = @anim[:particles][@selected_particle][:focus]
frame_color = AnimationEditor::ParticleList::CONTROL_BG_COLORS[focus] || Color.magenta
frame_color = focus_color(@anim[:particles][@selected_particle][:focus])
@sel_frame_bitmap.outline_rect(1, 1, @sel_frame_bitmap.width - 2, @sel_frame_bitmap.height - 2, frame_color)
update_selected_particle_frame
end

View File

@@ -22,7 +22,6 @@ class AnimationEditor::PlayControls < UIControls::ControlsContainer
DURATION_LABEL_Y = SLOWDOWN_LABEL_Y
DURATION_VALUE_Y = ROW_HEIGHT
SLOWDOWN_FACTORS = [1, 2, 4, 6, 8]
ICON_COLOR = Color.black
def initialize(x, y, width, height, viewport)
super(x, y, width, height)
@@ -42,23 +41,25 @@ class AnimationEditor::PlayControls < UIControls::ControlsContainer
#-----------------------------------------------------------------------------
def generate_button_bitmaps
@bitmaps = {}
play_button = Bitmap.new(PLAY_BUTTON_SIZE, PLAY_BUTTON_SIZE)
@bitmaps = {} if !@bitmaps
icon_color = text_color
@bitmaps[:play_button] = Bitmap.new(PLAY_BUTTON_SIZE, PLAY_BUTTON_SIZE) if !@bitmaps[:play_button]
@bitmaps[:play_button].clear
(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)
@bitmaps[: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(8, 8, PLAY_BUTTON_SIZE - 16, PLAY_BUTTON_SIZE - 16, ICON_COLOR)
@bitmaps[:stop_button] = stop_button
@bitmaps[:stop_button] = Bitmap.new(PLAY_BUTTON_SIZE, PLAY_BUTTON_SIZE) if !@bitmaps[:stop_button]
@bitmaps[:stop_button].clear
@bitmaps[:stop_button].fill_rect(8, 8, PLAY_BUTTON_SIZE - 16, PLAY_BUTTON_SIZE - 16, icon_color)
# Loop button
play_once_button = Bitmap.new(LOOP_BUTTON_SIZE, LOOP_BUTTON_SIZE)
play_once_button.fill_rect(1, 7, 11, 2, ICON_COLOR)
play_once_button.fill_rect(8, 5, 2, 6, ICON_COLOR)
play_once_button.fill_rect(10, 6, 1, 4, ICON_COLOR)
play_once_button.fill_rect(13, 1, 2, 14, ICON_COLOR)
@bitmaps[:play_once_button] = play_once_button
looping_button = Bitmap.new(LOOP_BUTTON_SIZE, LOOP_BUTTON_SIZE)
@bitmaps[:play_once_button] = Bitmap.new(LOOP_BUTTON_SIZE, LOOP_BUTTON_SIZE) if !@bitmaps[:play_once_button]
@bitmaps[:play_once_button].clear
@bitmaps[:play_once_button].fill_rect(1, 7, 11, 2, icon_color)
@bitmaps[:play_once_button].fill_rect(8, 5, 2, 6, icon_color)
@bitmaps[:play_once_button].fill_rect(10, 6, 1, 4, icon_color)
@bitmaps[:play_once_button].fill_rect(13, 1, 2, 14, icon_color)
@bitmaps[:looping_button] = Bitmap.new(LOOP_BUTTON_SIZE, LOOP_BUTTON_SIZE) if !@bitmaps[:looping_button]
@bitmaps[:looping_button].clear
[0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0,
0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0,
@@ -74,9 +75,8 @@ class AnimationEditor::PlayControls < UIControls::ControlsContainer
0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0].each_with_index do |val, i|
next if val == 0
looping_button.fill_rect(1 + (i % 14), 1 + (i / 14), 1, 1, ICON_COLOR)
@bitmaps[:looping_button].fill_rect(1 + (i % 14), 1 + (i / 14), 1, 1, icon_color)
end
@bitmaps[:looping_button] = looping_button
end
def add_play_controls
@@ -143,6 +143,16 @@ class AnimationEditor::PlayControls < UIControls::ControlsContainer
refresh
end
def color_scheme=(value)
return if @color_scheme == value
@color_scheme = value
generate_button_bitmaps
if @controls
@controls.each { |c| c[1].color_scheme = value }
repaint
end
end
#-----------------------------------------------------------------------------
def prepare_to_play_animation

View File

@@ -23,22 +23,6 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
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
PROPERTY_BG_COLOR = Color.new(224, 224, 224)
CONTROL_BG_COLORS = {
:foreground => Color.new(128, 160, 248), # Blue
:midground => Color.new(128, 160, 248), # Blue
:background => Color.new(128, 160, 248), # Blue
:user => Color.new(64, 224, 64), # Green
:target => Color.new(224, 64, 64), # Red
:user_and_target => Color.new(224, 224, 64), # Yellow
:user_side_foreground => Color.new(128, 224, 224), # Cyan
:user_side_background => Color.new(128, 224, 224), # Cyan
:target_side_foreground => Color.new(128, 224, 224), # Cyan
:target_side_background => Color.new(128, 224, 224) # Cyan
}
SE_CONTROL_BG_COLOR = Color.gray
TIME_AFTER_ANIMATION_COLOR = Color.new(160, 160, 160)
POSITION_LINE_COLOR = Color.new(248, 96, 96)
attr_reader :keyframe # The selected keyframe
attr_reader :values
@@ -116,20 +100,26 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
@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.color = text_color
@timeline_sprite.bitmap.font.size = TIMELINE_TEXT_SIZE
end
def initialize_selection_bitmaps
# 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, POSITION_LINE_COLOR)
if !@position_sprite
@position_sprite = BitmapSprite.new(3, height - UIControls::Scrollbar::SLIDER_WIDTH - VIEWPORT_SPACING, @position_viewport)
@position_sprite.ox = @position_sprite.width / 2
end
@position_sprite.bitmap.clear
@position_sprite.bitmap.fill_rect(0, 0, @position_sprite.bitmap.width, @position_sprite.bitmap.height, position_line_color)
# Selected particle line sprite
@particle_line_sprite = BitmapSprite.new(@position_viewport.rect.width, 3, @commands_viewport)
@particle_line_sprite.z = -10
@particle_line_sprite.oy = @particle_line_sprite.height / 2
@particle_line_sprite.bitmap.fill_rect(0, 0, @particle_line_sprite.bitmap.width, @particle_line_sprite.bitmap.height, POSITION_LINE_COLOR)
if !@particle_line_sprite
@particle_line_sprite = BitmapSprite.new(@position_viewport.rect.width, 3, @commands_viewport)
@particle_line_sprite.z = -10
@particle_line_sprite.oy = @particle_line_sprite.height / 2
end
@particle_line_sprite.bitmap.clear
@particle_line_sprite.bitmap.fill_rect(0, 0, @particle_line_sprite.bitmap.width, @particle_line_sprite.bitmap.height, position_line_color)
end
def initialize_controls
@@ -147,23 +137,22 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
end
def generate_button_bitmaps
@bitmaps = {}
add_button = Bitmap.new(12, 12)
add_button.fill_rect(1, 5, 10, 2, TEXT_COLOR)
add_button.fill_rect(5, 1, 2, 10, TEXT_COLOR)
@bitmaps[:add_button] = add_button
up_button = Bitmap.new(12, 12)
@bitmaps = {} if !@bitmaps
@bitmaps[:add_button] = Bitmap.new(12, 12) if !@bitmaps[:add_button]
@bitmaps[:add_button].clear
@bitmaps[:add_button].fill_rect(1, 5, 10, 2, text_color)
@bitmaps[:add_button].fill_rect(5, 1, 2, 10, text_color)
@bitmaps[:up_button] = Bitmap.new(12, 12) if !@bitmaps[:up_button]
@bitmaps[:up_button].clear
5.times do |i|
up_button.fill_rect(1 + i, 7 - i, 1, (i == 0) ? 2 : 3, TEXT_COLOR)
up_button.fill_rect(10 - i, 7 - i, 1, (i == 0) ? 2 : 3, TEXT_COLOR)
@bitmaps[:up_button].fill_rect(1 + i, 7 - i, 1, (i == 0) ? 2 : 3, text_color)
@bitmaps[:up_button].fill_rect(10 - i, 7 - i, 1, (i == 0) ? 2 : 3, text_color)
end
@bitmaps[:up_button] = up_button
down_button = Bitmap.new(12, 12)
@bitmaps[:down_button] = Bitmap.new(12, 12) if !@bitmaps[:down_button]
5.times do |i|
down_button.fill_rect(1 + i, 2 + i + (i == 0 ? 1 : 0), 1, (i == 0) ? 2 : 3, TEXT_COLOR)
down_button.fill_rect(10 - i, 2 + i + (i == 0 ? 1 : 0), 1, (i == 0) ? 2 : 3, TEXT_COLOR)
@bitmaps[:down_button].fill_rect(1 + i, 2 + i + (i == 0 ? 1 : 0), 1, (i == 0) ? 2 : 3, text_color)
@bitmaps[:down_button].fill_rect(10 - i, 2 + i + (i == 0 ? 1 : 0), 1, (i == 0) ? 2 : 3, text_color)
end
@bitmaps[:down_button] = down_button
end
def dispose
@@ -195,6 +184,39 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
#-----------------------------------------------------------------------------
def position_line_color
return get_color_scheme_color_for_element(:position_line_color, Color.new(248, 96, 96))
end
def after_end_bg_color
return get_color_scheme_color_for_element(:after_end_bg_color, Color.new(160, 160, 160))
end
def se_background_color
return get_color_scheme_color_for_element(:se_background_color, Color.gray)
end
def property_background_color
return get_color_scheme_color_for_element(:property_background_color, Color.new(224, 224, 224))
end
def color_scheme=(value)
return if @color_scheme == value
@color_scheme = value
return if !@bitmaps
draw_control_background
initialize_selection_bitmaps
generate_button_bitmaps
self.bitmap.font.color = text_color
self.bitmap.font.size = text_size
@list_scrollbar.color_scheme = value
@time_scrollbar.color_scheme = value
@timeline_sprite.bitmap.font.color = text_color
@controls.each { |c| c[1].color_scheme = value }
@list_sprites.each { |spr| spr.bitmap.font.color = text_color }
invalidate
end
def duration
return [@duration - DURATION_BUFFER, 0].max
end
@@ -342,18 +364,18 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
@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_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_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_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
@@ -559,10 +581,10 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
def draw_control_background
self.bitmap.clear
# 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)
self.bitmap.fill_rect(0, TIMELINE_HEIGHT, width, VIEWPORT_SPACING, line_color)
self.bitmap.fill_rect(LIST_WIDTH, 0, VIEWPORT_SPACING, height, line_color)
self.bitmap.fill_rect(0, height - UIControls::Scrollbar::SLIDER_WIDTH - VIEWPORT_SPACING, width, VIEWPORT_SPACING, line_color)
self.bitmap.fill_rect(width - UIControls::Scrollbar::SLIDER_WIDTH - VIEWPORT_SPACING, 0, VIEWPORT_SPACING, height, line_color)
end
#-----------------------------------------------------------------------------
@@ -582,26 +604,26 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
draw_x = TIMELINE_LEFT_BUFFER + (dur * KEYFRAME_SPACING) - @left_pos
greyed_width = @time_bg_sprite.width - draw_x
if greyed_width > 0
@time_bg_sprite.bitmap.fill_rect(draw_x, 0, greyed_width, @time_bg_sprite.height, TIME_AFTER_ANIMATION_COLOR)
@time_bg_sprite.bitmap.fill_rect(draw_x, TIMELINE_HEIGHT, greyed_width, VIEWPORT_SPACING, Color.black)
@time_bg_sprite.bitmap.fill_rect(draw_x, 0, greyed_width, @time_bg_sprite.height, after_end_bg_color)
@time_bg_sprite.bitmap.fill_rect(draw_x, TIMELINE_HEIGHT, greyed_width, VIEWPORT_SPACING, line_color)
end
# Draw hover highlight
if !controls_busy?
hover_color = nil
this_hover_color = nil
if @captured_keyframe && !@captured_row
if @hover_keyframe && @hover_keyframe == @captured_keyframe && !@hover_row
hover_color = HOVER_COLOR
this_hover_color = hover_color
else
hover_color = CAPTURE_COLOR
this_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)
KEYFRAME_SPACING, TIMELINE_HEIGHT - 1, this_hover_color)
elsif !@captured_keyframe && !@captured_row && @hover_keyframe && !@hover_row
hover_color = HOVER_COLOR
this_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)
KEYFRAME_SPACING, TIMELINE_HEIGHT - 1, this_hover_color)
end
end
# Draw timeline markings
@@ -613,7 +635,7 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
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)
@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
@@ -644,11 +666,11 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
box_x += LIST_INDENT if is_property
# Get the background color
if particle_data[:name] == "SE"
bg_color = SE_CONTROL_BG_COLOR
bg_color = se_background_color
elsif is_property
bg_color = PROPERTY_BG_COLOR
bg_color = property_background_color
else
bg_color = CONTROL_BG_COLORS[@particles[p_index][:focus]] || Color.magenta
bg_color = focus_color(@particles[p_index][:focus])
end
# Draw hover highlight
if !controls_busy? && !@captured_keyframe
@@ -657,21 +679,21 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
if @captured_row == index
if !@hover_keyframe && @hover_row && @hover_row == index &&
@captured_row_button && @hover_row_button == @captured_row_button
hover_color = HOVER_COLOR
this_hover_color = hover_color
else
hover_color = CAPTURE_COLOR
this_hover_color = capture_color
end
end
elsif @hover_row && @hover_row == index && !@hover_keyframe
hover_color = HOVER_COLOR
this_hover_color = hover_color
end
if hover_color
if this_hover_color
case @captured_row_button || @hover_row_button
when :expand
spr.bitmap.fill_rect(EXPAND_BUTTON_X, (ROW_HEIGHT - EXPAND_BUTTON_WIDTH + 1) / 2,
EXPAND_BUTTON_WIDTH, EXPAND_BUTTON_WIDTH, hover_color)
EXPAND_BUTTON_WIDTH, EXPAND_BUTTON_WIDTH, this_hover_color)
when :row
spr.bitmap.fill_rect(box_x, ROW_SPACING, spr.width - box_x, spr.height - ROW_SPACING, hover_color)
spr.bitmap.fill_rect(box_x, ROW_SPACING, spr.width - box_x, spr.height - ROW_SPACING, this_hover_color)
end
end
end
@@ -684,12 +706,14 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
draw_text(spr.bitmap, box_x + 4, 3, @particles[p_index][:name] || "Unnamed")
end
# Draw expand/collapse arrow or dotted lines
icon_color = text_color
dotted_color = line_color
if is_property
6.times do |j|
spr.bitmap.fill_rect(10, j * 2, 1, 1, Color.black)
spr.bitmap.fill_rect(10, j * 2, 1, 1, dotted_color)
end
9.times do |i|
spr.bitmap.fill_rect(10 + (i * 2), 12, 1, 1, Color.black)
spr.bitmap.fill_rect(10 + (i * 2), 12, 1, 1, dotted_color)
end
elsif @expanded_particles.include?(p_index)
# Draw down-pointing arrow
@@ -697,7 +721,7 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
j = (i == 0 || i == 10) ? 1 : 0
h = [2, 4, 5, 6, 7, 8, 7, 6, 5, 4, 2][i]
h = ((i > 5) ? 10 - i : i) + 3 - j
spr.bitmap.fill_rect(5 + i, 9 + j, 1, h, Color.black)
spr.bitmap.fill_rect(5 + i, 9 + j, 1, h, icon_color)
end
elsif particle_data[:name] != "SE"
# Draw right-pointing arrow
@@ -705,13 +729,13 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
i = (j == 0 || j == 10) ? 1 : 0
w = [2, 4, 5, 6, 7, 8, 7, 6, 5, 4, 2][j]
w = ((j > 5) ? 10 - j : j) + 3 - i
spr.bitmap.fill_rect(7 + i, 7 + j, w, 1, Color.black)
spr.bitmap.fill_rect(7 + i, 7 + j, w, 1, icon_color)
end
end
# Draw dotted line leading to the next property line
if @particle_list[index + 1]&.is_a?(Array)
5.times do |j|
spr.bitmap.fill_rect(10, 14 + (j * 2), 1, 1, Color.black)
spr.bitmap.fill_rect(10, 14 + (j * 2), 1, 1, dotted_color)
end
end
end
@@ -725,11 +749,11 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
particle_data = @particles[p_index]
# Get the background color
if particle_data[:name] == "SE"
bg_color = SE_CONTROL_BG_COLOR
bg_color = se_background_color
elsif is_property
bg_color = PROPERTY_BG_COLOR
bg_color = property_background_color
else
bg_color = CONTROL_BG_COLORS[@particles[p_index][:focus]] || Color.magenta
bg_color = focus_color(@particles[p_index][:focus])
end
# Get visibilities of particle for each keyframe
visible_cmds = @visibilities[p_index]
@@ -741,7 +765,7 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
bg_spr.bitmap.fill_rect(draw_x, ROW_SPACING, KEYFRAME_SPACING, ROW_HEIGHT - ROW_SPACING, bg_color)
end
# Draw hover highlight
hover_color = nil
this_hover_color = nil
if !controls_busy?
earlier_captured_keyframe = @captured_keyframe
later_captured_keyframe = (earlier_captured_keyframe || -1) + 1
@@ -754,30 +778,30 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
if @captured_row && @captured_keyframe
if @captured_row == index && i >= earlier_captured_keyframe && i < later_captured_keyframe
if @hover_row && @hover_row == index && @hover_keyframe && i >= earlier_hovered_keyframe && i < later_hovered_keyframe
hover_color = HOVER_COLOR
this_hover_color = hover_color
else
hover_color = CAPTURE_COLOR
this_hover_color = capture_color
end
end
elsif !@captured_row && !@captured_keyframe && @hover_row && @hover_keyframe &&
@hover_row == index && i >= earlier_hovered_keyframe && i < later_hovered_keyframe
hover_color = HOVER_COLOR
this_hover_color = hover_color
end
end
if hover_color
if this_hover_color
if is_property
bg_spr.bitmap.fill_rect(draw_x, 2, KEYFRAME_SPACING, ROW_HEIGHT - 3, hover_color)
bg_spr.bitmap.fill_rect(draw_x, 2, KEYFRAME_SPACING, ROW_HEIGHT - 3, this_hover_color)
else
bg_spr.bitmap.fill_rect(draw_x - (KEYFRAME_SPACING / 2), 2, KEYFRAME_SPACING, ROW_HEIGHT - 3, hover_color)
bg_spr.bitmap.fill_rect(draw_x - (KEYFRAME_SPACING / 2), 2, KEYFRAME_SPACING, ROW_HEIGHT - 3, this_hover_color)
end
end
next if i >= @duration - DURATION_BUFFER
outline_color = Color.black
outline_color = line_color
case visible_cmds[i]
when 1 # Particle is visible
# Draw outline
if is_property
outline_color = CONTROL_BG_COLORS[@particles[p_index][:focus]] || Color.magenta
outline_color = focus_color(@particles[p_index][:focus])
end
bg_spr.bitmap.fill_rect(draw_x, ROW_SPACING, KEYFRAME_SPACING, 1, outline_color) # Top
bg_spr.bitmap.fill_rect(draw_x, ROW_HEIGHT - 1, KEYFRAME_SPACING, 1, outline_color) # Bottom
@@ -822,7 +846,7 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
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)
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(
@@ -832,7 +856,7 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
INTERP_LINE_HEIGHT,
cmds[i][0] > 0, # Increases or decreases
cmds[i][1], # Interpolation type
TEXT_COLOR
text_color
)
end
end
@@ -849,7 +873,7 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
INTERP_LINE_HEIGHT,
cmds[i][0] > 0, # Increases or decreases
cmds[i][1], # Interpolation type
TEXT_COLOR
text_color
)
end
end