mirror of
https://github.com/infinitefusion/infinitefusion-e18.git
synced 2025-12-07 21:24:59 +00:00
Anim Editor: improved NumberTextBox entry, added "FoeInvertX/Y" particle properties, tidied up
This commit is contained in:
@@ -1,6 +1,3 @@
|
||||
# TODO: Add indicator of whether the control's value is "lerping" between frames
|
||||
# (use yellow somehow?).
|
||||
|
||||
#===============================================================================
|
||||
#
|
||||
#===============================================================================
|
||||
|
||||
@@ -25,8 +25,8 @@ class UIControls::TextBox < UIControls::BaseControl
|
||||
end
|
||||
|
||||
def value=(new_value)
|
||||
return if @value == new_value
|
||||
@value = new_value.dup
|
||||
return if @value.to_s == new_value.to_s
|
||||
@value = new_value.to_s.dup
|
||||
invalidate
|
||||
end
|
||||
|
||||
@@ -39,6 +39,7 @@ class UIControls::TextBox < UIControls::BaseControl
|
||||
end
|
||||
|
||||
def delete_at(index)
|
||||
@value = @value.to_s
|
||||
@value.slice!(index)
|
||||
@cursor_pos -= 1 if @cursor_pos > index
|
||||
@cursor_timer = System.uptime
|
||||
|
||||
@@ -22,46 +22,28 @@ class UIControls::NumberTextBox < UIControls::TextBox
|
||||
end
|
||||
|
||||
def value=(new_value)
|
||||
old_val = @value
|
||||
old_val = @value.to_i
|
||||
@value = new_value.to_i.clamp(self.min_value, self.max_value)
|
||||
self.invalidate if @value != old_val
|
||||
invalidate if @value != old_val
|
||||
end
|
||||
|
||||
def min_value=(new_min)
|
||||
return if new_min == @min_value
|
||||
@min_value = new_min
|
||||
@value = @value.clamp(self.min_value, self.max_value)
|
||||
self.invalidate
|
||||
@value = @value.to_i.clamp(self.min_value, self.max_value)
|
||||
invalidate
|
||||
end
|
||||
|
||||
def max_value=(new_max)
|
||||
return if new_max == @max_value
|
||||
@max_value = new_max
|
||||
@value = @value.clamp(self.min_value, self.max_value)
|
||||
self.invalidate
|
||||
end
|
||||
|
||||
def insert_char(ch, index = -1)
|
||||
old_val = @value
|
||||
if @value == 0
|
||||
@value = ch.to_i
|
||||
else
|
||||
self.value = @value.to_s.insert((index >= 0) ? index : @cursor_pos, ch).to_i
|
||||
end
|
||||
return if @value == old_val
|
||||
@cursor_pos += 1
|
||||
@cursor_pos = @cursor_pos.clamp(0, @value.to_s.length)
|
||||
@cursor_timer = System.uptime
|
||||
@cursor_shown = true
|
||||
@value = @value.to_i.clamp(self.min_value, self.max_value)
|
||||
invalidate
|
||||
end
|
||||
|
||||
def delete_at(index)
|
||||
new_val = @value.to_s
|
||||
new_val.slice!(index)
|
||||
self.value = new_val.to_i
|
||||
@cursor_pos -= 1 if @cursor_pos > index
|
||||
@cursor_pos = @cursor_pos.clamp(0, @value.to_s.length)
|
||||
def insert_char(ch, index = -1)
|
||||
@value = @value.to_s.insert((index >= 0) ? index : @cursor_pos, ch)
|
||||
@cursor_pos += 1
|
||||
@cursor_timer = System.uptime
|
||||
@cursor_shown = true
|
||||
invalidate
|
||||
@@ -81,6 +63,13 @@ class UIControls::NumberTextBox < UIControls::TextBox
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
def reset_interaction
|
||||
super
|
||||
self.value = @value # Turn value back into a number and clamp it
|
||||
end
|
||||
|
||||
#-----------------------------------------------------------------------------
|
||||
|
||||
def refresh
|
||||
super
|
||||
button_color = (disabled?) ? DISABLED_COLOR : self.bitmap.font.color
|
||||
@@ -104,8 +93,8 @@ class UIControls::NumberTextBox < UIControls::TextBox
|
||||
elsif @captured_area
|
||||
@initial_value = @value
|
||||
else
|
||||
set_changed if @initial_value && @value != @initial_value
|
||||
reset_interaction
|
||||
set_changed if @initial_value && @value != @initial_value
|
||||
end
|
||||
end
|
||||
|
||||
@@ -114,15 +103,21 @@ class UIControls::NumberTextBox < UIControls::TextBox
|
||||
Input.gets.each_char do |ch|
|
||||
case ch
|
||||
when "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"
|
||||
if (@value.to_s == "-0" && @cursor_pos > 1) ||
|
||||
(@value.to_s == "0" && @cursor_pos > 0)
|
||||
@value = @value.to_s.chop
|
||||
@cursor_pos -= 1
|
||||
end
|
||||
insert_char(ch)
|
||||
ret = true
|
||||
when "-", "+"
|
||||
if @value > 0 && @min_value < 0 && ch == "-"
|
||||
insert_char(ch, 0) # Add a negative sign at the start
|
||||
ret = true
|
||||
elsif @value < 0
|
||||
@value = @value.to_s
|
||||
if @value[0] == "-"
|
||||
delete_at(0) # Remove the negative sign
|
||||
ret = true
|
||||
elsif ch == "-"
|
||||
insert_char(ch, 0) # Add a negative sign at the start
|
||||
ret = true
|
||||
end
|
||||
next
|
||||
end
|
||||
|
||||
@@ -6,7 +6,6 @@ class UIControls::Button < UIControls::BaseControl
|
||||
BUTTON_Y = 2
|
||||
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
|
||||
HIGHLIGHT_COLOR = Color.new(224, 192, 32) # Dark yellow
|
||||
|
||||
|
||||
Reference in New Issue
Block a user