Tidied up TODO comments, misc tweaks to Anim Editor

This commit is contained in:
Maruno17
2023-12-03 23:47:38 +00:00
parent b4e7b765d1
commit 2f231a25bb
203 changed files with 813 additions and 852 deletions

View File

@@ -1,16 +1,6 @@
#===============================================================================
# Controls are arranged in a list in self's bitmap. Each control is given an
# area of size "self's bitmap's width" x LINE_SPACING to draw itself in.
# TODO: The act of "capturing" a control makes other controls in this container
# not update themselves, i.e. they won't colour themselves with a hover
# highlight if the mouse happens to move over it while another control is
# captured. Is there a better way of dealing with this? I'm leaning
# towards the control itself deciding if it's captured, and it being
# treated as uncaptured once it says its value has changed, but I think
# this would require manually telling all other controls in this container
# that something else is captured and they shouldn't show a hover
# highlight when updated (perhaps as a parameter in def update), which I
# don't think is ideal.
#===============================================================================
class UIControls::ControlsContainer
attr_reader :x, :y
@@ -171,11 +161,6 @@ class UIControls::ControlsContainer
return if !@visible
# Update controls
if @captured
# TODO: Ideally all controls will be updated here, if only to redraw
# themselves if they happen to be invalidated somehow. But that
# involves telling each control whether any other control is busy,
# to ensure that they don't show their hover colours or anything,
# which is fiddly and I'm not sure if it's the best approach.
@captured.update
@captured = nil if !@captured.busy?
else

View File

@@ -10,6 +10,7 @@ class UIControls::BaseControl < BitmapSprite
TEXT_COLOR = Color.black
TEXT_SIZE = 18 # Default is 22 if size isn't explicitly set
TEXT_OFFSET_Y = 5
HOVER_COLOR = Color.cyan # For clickable area when hovering over it
CAPTURE_COLOR = Color.pink # For area you clicked in but aren't hovering over
DISABLED_COLOR = Color.gray
@@ -19,7 +20,6 @@ class UIControls::BaseControl < BitmapSprite
super(width, height, viewport)
self.bitmap.font.color = TEXT_COLOR
self.bitmap.font.size = TEXT_SIZE
@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
@@ -51,10 +51,7 @@ class UIControls::BaseControl < BitmapSprite
return false if !@interactions || @interactions.empty?
mouse_x, mouse_y = mouse_pos
return false if !mouse_x || !mouse_y
@interactions.each_pair do |area, rect|
return true if rect.contains?(mouse_x, mouse_y)
end
return false
return @interactions.any? { |area, rect| rect.contains?(mouse_x, mouse_y) }
end
#-----------------------------------------------------------------------------
@@ -84,7 +81,7 @@ class UIControls::BaseControl < BitmapSprite
@invalid = true
end
# Makes the control no longer invalid.
# Makes the control no longer invalid. Called after repainting.
def validate
@invalid = false
end
@@ -125,7 +122,6 @@ class UIControls::BaseControl < BitmapSprite
end
def refresh
# Paint over control to erase contents (intentionally not using self.bitmap.clear)
self.bitmap.clear
draw_area_highlight
end
@@ -194,10 +190,8 @@ class UIControls::BaseControl < BitmapSprite
# Updates the logic on the control, invalidating it if necessary.
def update
return if !self.visible
return if disabled? && !busy?
return if disabled? && !busy? # This control still works if it becomes disabled while using it
update_hover_highlight
# Detect a mouse press/release
if @interactions && !@interactions.empty?
if Input.trigger?(Input::MOUSELEFT)
@@ -206,6 +200,5 @@ class UIControls::BaseControl < BitmapSprite
on_mouse_release
end
end
end
end

View File

@@ -4,9 +4,6 @@
class UIControls::Label < UIControls::BaseControl
attr_reader :text
LABEL_END_X = 80
TEXT_OFFSET_Y = 5
def initialize(width, height, viewport, text)
super(width, height, viewport)
@text = text
@@ -27,8 +24,10 @@ class UIControls::Label < UIControls::BaseControl
super
if @header
draw_text_centered(self.bitmap, 0, TEXT_OFFSET_Y, width, @text)
# 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)
self.bitmap.fill_rect((width - text_size.width) / 2, TEXT_OFFSET_Y + text_size.height,
text_size.width, 1, TEXT_COLOR)
else
draw_text(self.bitmap, 4, TEXT_OFFSET_Y, @text)
end

View File

@@ -1,20 +1,18 @@
#===============================================================================
# TODO: Support selecting part of the text by remembering the initial
# cursor position and using it and the current cursor position to
# decide which characters are selected. Maybe? Note that this method
# is only triggered upon the initial mouse press, and isn't repeated
# while it's still held down.
#
#===============================================================================
class UIControls::TextBox < UIControls::BaseControl
attr_accessor :box_width
TEXT_BOX_X = 2
TEXT_BOX_WIDTH = 200
TEXT_BOX_HEIGHT = 24
TEXT_BOX_PADDING = 4 # Gap between sides of text box and text
TEXT_OFFSET_Y = 5
def initialize(width, height, viewport, value = "")
super(width, height, viewport)
@value = value
@box_width = TEXT_BOX_WIDTH
@cursor_pos = -1
@display_pos = 0
@cursor_timer = nil
@@ -22,9 +20,13 @@ class UIControls::TextBox < UIControls::BaseControl
@blacklist = []
end
def value
return @value.dup
end
def value=(new_value)
return if @value == new_value
@value = new_value
@value = new_value.dup
invalidate
end
@@ -59,7 +61,7 @@ class UIControls::TextBox < UIControls::BaseControl
def set_interactive_rects
@text_box_rect = Rect.new(TEXT_BOX_X, (height - TEXT_BOX_HEIGHT) / 2,
[TEXT_BOX_WIDTH, width].min, TEXT_BOX_HEIGHT)
[@box_width, width - (TEXT_BOX_X * 2)].min, TEXT_BOX_HEIGHT)
@interactions = {
:text_box => @text_box_rect
}

View File

@@ -1,6 +1,5 @@
#===============================================================================
# TODO: Is there a better knob design than a big black rectangle? I'd rather
# it not be a different colour.
#
#===============================================================================
class UIControls::NumberSlider < UIControls::BaseControl
attr_reader :min_value
@@ -14,7 +13,6 @@ class UIControls::NumberSlider < UIControls::BaseControl
SLIDER_LENGTH = 128
PLUS_X = SLIDER_X + SLIDER_LENGTH + SLIDER_PADDING
VALUE_X = PLUS_X + PLUS_MINUS_SIZE + 5
TEXT_OFFSET_Y = 5
def initialize(width, height, viewport, min_value, max_value, value)
super(width, height, viewport)

View File

@@ -4,8 +4,8 @@
class UIControls::Button < UIControls::BaseControl
BUTTON_X = 2
BUTTON_Y = 2
BUTTON_PADDING = 10
BUTTON_HEIGHT = 28
BUTTON_PADDING = 10 # Used when @fixed_size is false
BUTTON_HEIGHT = 28 # Used when @fixed_size is false
# TODO: This will also depend on the font size.
TEXT_BASE_OFFSET_Y = 18 # Text is centred vertically in the button
@@ -20,6 +20,7 @@ class UIControls::Button < UIControls::BaseControl
end
def set_interactive_rects
@interactions&.clear
button_width = (@fixed_size) ? width - (BUTTON_X * 2) : self.bitmap.text_size(@text).width + (BUTTON_PADDING * 2)
button_height = (@fixed_size) ? height - (2 * BUTTON_Y) : BUTTON_HEIGHT
button_height = [button_height, height - (2 * BUTTON_Y)].min
@@ -29,10 +30,10 @@ class UIControls::Button < UIControls::BaseControl
}
end
# TODO: This won't change the button's size. This is probably okay.
def set_text(val)
return if @text == val
@text = val
set_interactive_rects if !@fixed_size
invalidate
end
@@ -60,12 +61,14 @@ class UIControls::Button < UIControls::BaseControl
self.bitmap.outline_rect(@button_rect.x, @button_rect.y,
@button_rect.width, @button_rect.height,
self.bitmap.font.color)
# TODO: Make buttons look more different to text boxes?
# shade = self.bitmap.font.color.clone
# shade.alpha = 96
# self.bitmap.outline_rect(@button_rect.x + 1, @button_rect.y + 1,
# @button_rect.width - 2, @button_rect.height - 2,
# shade, 3)
# 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
self.bitmap.outline_rect(@button_rect.x + 2, @button_rect.y + 2,
@button_rect.width - 4, @button_rect.height - 4,
shade, 1)
end
# Draw button text
draw_text_centered(self.bitmap, @button_rect.x,
@button_rect.y + (@button_rect.height - TEXT_BASE_OFFSET_Y) / 2,

View File

@@ -1,11 +1,5 @@
#===============================================================================
# TODO: Do I need to split self's bitmap into two (one for highlights and one
# for text)? This would be to reduce lag caused by redrawing text even if
# you're just waving the mouse over the control. There doesn't seem to be
# any lag at the moment with a tall list.
# TODO: Make a viewport for the list, and allow scrolling positions halfway
# through a line? Nah.
# TODO: This control cannot be disabled.
#
#===============================================================================
class UIControls::List < UIControls::BaseControl
LIST_X = 0

View File

@@ -2,22 +2,23 @@
#
#===============================================================================
class UIControls::DropdownList < UIControls::BaseControl
attr_accessor :box_width
attr_accessor :max_rows
TEXT_BOX_X = 2
TEXT_BOX_WIDTH = 200
TEXT_BOX_HEIGHT = 24
TEXT_BOX_PADDING = 4 # Gap between sides of text box and text
TEXT_OFFSET_Y = 5
MAX_LIST_ROWS = 8
attr_accessor :max_rows
# NOTE: options is a hash: keys are symbols, values are display names.
def initialize(width, height, viewport, options, value)
# NOTE: options is a hash: keys are symbols, values are display names.
super(width, height, viewport)
@options = options
@value = value
@options = options
@value = value
@box_width = TEXT_BOX_WIDTH
@toggling_dropdown_list = false
@max_rows = MAX_LIST_ROWS
@max_rows = MAX_LIST_ROWS
end
def dispose
@@ -33,7 +34,7 @@ class UIControls::DropdownList < UIControls::BaseControl
def set_interactive_rects
@button_rect = Rect.new(TEXT_BOX_X, (height - TEXT_BOX_HEIGHT) / 2,
[TEXT_BOX_WIDTH, width].min, TEXT_BOX_HEIGHT)
[@box_width, width - (TEXT_BOX_X * 2)].min, TEXT_BOX_HEIGHT)
@interactions = {
:button => @button_rect
}

View File

@@ -1,7 +1,5 @@
#===============================================================================
# TODO: Make the slider a separate sprite that moves, instead of redrawing this
# sprite's bitmap whenever it moves? Intended to reduce lag. There doesn't
# seem to be any lag at the moment with a tall scrollbar.
#
#===============================================================================
class UIControls::Scrollbar < UIControls::BaseControl
SLIDER_WIDTH = 16
@@ -122,9 +120,6 @@ class UIControls::Scrollbar < UIControls::BaseControl
return if !self.visible
super
if @captured_area == :slider
# TODO: Have a display y position for the slider bar which is in pixels,
# and round it to the nearest row when setting @top_row? This is
# just to make the slider bar movement smoother.
mouse_x, mouse_y = mouse_pos
return if !mouse_x || !mouse_y
long_coord = (@horizontal) ? mouse_x : mouse_y