UIControls can be disabled, added blacklist to TextBox control

This commit is contained in:
Maruno17
2023-11-29 23:39:10 +00:00
parent 973b93a524
commit 5553218507
13 changed files with 116 additions and 69 deletions

View File

@@ -7,19 +7,21 @@
#===============================================================================
class UIControls::BaseControl < BitmapSprite
attr_reader :value
# attr_accessor :disabled # TODO: Make use of this.
attr_accessor :disabled
TEXT_COLOR = Color.black
TEXT_SIZE = 18 # Default is 22 if size isn't explicitly set
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
DISABLED_COLOR_DARK = Color.new(128, 128, 128)
def initialize(width, height, viewport)
super(width, height, viewport)
self.bitmap.font.color = TEXT_COLOR
self.bitmap.font.size = TEXT_SIZE
# @disabled = false # TODO: Make use of this.
@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
clear_changed
@@ -58,6 +60,22 @@ class UIControls::BaseControl < BitmapSprite
#-----------------------------------------------------------------------------
def disabled?
return @disabled
end
def disable
return if disabled?
@disabled = true
invalidate
end
def enable
return if !disabled?
@disabled = false
invalidate
end
def invalid?
return @invalid
end
@@ -177,8 +195,7 @@ class UIControls::BaseControl < BitmapSprite
# Updates the logic on the control, invalidating it if necessary.
def update
return if !self.visible
# TODO: Disabled control stuff.
# return if self.disabled
return if disabled? && !busy?
update_hover_highlight

View File

@@ -33,6 +33,12 @@ class UIControls::Checkbox < UIControls::BaseControl
def refresh
super
# Draw disabled colour
if disabled?
self.bitmap.fill_rect(@checkbox_rect.x, @checkbox_rect.y,
@checkbox_rect.width, @checkbox_rect.height,
DISABLED_COLOR)
end
# Draw checkbox outline
self.bitmap.outline_rect(@checkbox_rect.x, @checkbox_rect.y,
@checkbox_rect.width, @checkbox_rect.height,
@@ -40,12 +46,12 @@ class UIControls::Checkbox < UIControls::BaseControl
# 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, CHECKED_COLOR)
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)
else
self.bitmap.fill_rect(@checkbox_rect.x + 2, @checkbox_rect.y + 2,
CHECKBOX_FILL_SIZE, CHECKBOX_FILL_SIZE, UNCHECKED_COLOR)
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)
end

View File

@@ -4,8 +4,6 @@
# 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.
# TODO: Add a blacklist array. Can't type in any values in this array. Disable
# this control if @value is in this array.
#===============================================================================
class UIControls::TextBox < UIControls::BaseControl
TEXT_BOX_X = 2
@@ -21,6 +19,7 @@ class UIControls::TextBox < UIControls::BaseControl
@display_pos = 0
@cursor_timer = nil
@cursor_shown = false
@blacklist = []
end
def value=(new_value)
@@ -53,6 +52,11 @@ class UIControls::TextBox < UIControls::BaseControl
invalidate
end
def set_blacklist(*list)
@blacklist = list
invalidate
end
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)
@@ -63,6 +67,12 @@ class UIControls::TextBox < UIControls::BaseControl
#-----------------------------------------------------------------------------
def disabled?
val = (@value.respond_to?("strip!")) ? @value.strip : @value
return true if @blacklist.include?(val)
return super
end
def busy?
return @cursor_pos >= 0 if @captured_area == :text_box
return super
@@ -157,6 +167,12 @@ class UIControls::TextBox < UIControls::BaseControl
def refresh
super
# Draw disabled colour
if disabled?
self.bitmap.fill_rect(@text_box_rect.x, @text_box_rect.y,
@text_box_rect.width, @text_box_rect.height,
DISABLED_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,
@@ -204,6 +220,7 @@ class UIControls::TextBox < UIControls::BaseControl
invalidate
else
@value.strip! if @value.respond_to?("strip!")
@value = @initial_value if disabled?
set_changed if @initial_value && @value != @initial_value
reset_interaction
end
@@ -224,6 +241,7 @@ class UIControls::TextBox < UIControls::BaseControl
# Released mouse button outside of text box, or initially clicked outside of
# text box; end interaction with this control
@value.strip! if @value.respond_to?("strip!")
@value = @initial_value if disabled?
set_changed if @initial_value && @value != @initial_value
reset_interaction
super # Make this control not busy again
@@ -252,6 +270,7 @@ class UIControls::TextBox < UIControls::BaseControl
if Input.triggerex?(:RETURN) || Input.repeatex?(:RETURN) ||
Input.triggerex?(:KP_ENTER) || Input.repeatex?(:KP_ENTER)
@value.strip! if @value.respond_to?("strip!")
@value = @initial_value if disabled?
set_changed if @initial_value && @value != @initial_value
reset_interaction
@captured_area = nil
@@ -274,8 +293,6 @@ class UIControls::TextBox < UIControls::BaseControl
def update
return if !self.visible
super
# TODO: Disabled control stuff.
# return if self.disabled
# Make the cursor flash
if @captured_area == :text_box
cursor_to_show = ((System.uptime - @cursor_timer) / 0.35).to_i.even?

View File

@@ -1,5 +1,6 @@
#===============================================================================
#
# 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
@@ -15,10 +16,6 @@ class UIControls::NumberSlider < UIControls::BaseControl
VALUE_X = PLUS_X + PLUS_MINUS_SIZE + 5
TEXT_OFFSET_Y = 5
# TODO: Is there a better knob design than a big black rectangle? I'd rather
# it not be a different colour.
SLIDER_KNOB_COLOR = Color.black
def initialize(width, height, viewport, min_value, max_value, value)
super(width, height, viewport)
@min_value = min_value
@@ -72,8 +69,9 @@ class UIControls::NumberSlider < UIControls::BaseControl
def refresh
super
button_color = (disabled?) ? DISABLED_COLOR : self.bitmap.font.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, self.bitmap.font.color)
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)
# Draw notches on slider bar
@@ -83,10 +81,10 @@ class UIControls::NumberSlider < UIControls::BaseControl
# Draw slider knob
fraction = (self.value - self.min_value) / (self.max_value.to_f - self.min_value)
knob_x = (SLIDER_LENGTH * fraction).to_i
self.bitmap.fill_rect(SLIDER_X + knob_x - 4, (self.height / 2) - 6, 8, 12, SLIDER_KNOB_COLOR)
self.bitmap.fill_rect(SLIDER_X + knob_x - 4, (self.height / 2) - 6, 8, 12, button_color)
# Draw plus button
self.bitmap.fill_rect(@plus_rect.x + 2, @plus_rect.y + (@plus_rect.height / 2) - 2, @plus_rect.width - 4, 4, self.bitmap.font.color)
self.bitmap.fill_rect(@plus_rect.x + (@plus_rect.width / 2) - 2, @plus_rect.y + 2, 4, @plus_rect.height - 4, self.bitmap.font.color)
self.bitmap.fill_rect(@plus_rect.x + 2, @plus_rect.y + (@plus_rect.height / 2) - 2, @plus_rect.width - 4, 4, button_color)
self.bitmap.fill_rect(@plus_rect.x + (@plus_rect.width / 2) - 2, @plus_rect.y + 2, 4, @plus_rect.height - 4, button_color)
# Draw value text
draw_text(self.bitmap, VALUE_X, TEXT_OFFSET_Y, self.value.to_s)
end
@@ -108,8 +106,6 @@ class UIControls::NumberSlider < UIControls::BaseControl
def update
return if !self.visible
super
# TODO: Disabled control stuff.
# return if self.disabled
case @captured_area
when :minus
# Constant decrement of value while pressing the minus button

View File

@@ -78,11 +78,12 @@ class UIControls::NumberTextBox < UIControls::TextBox
def refresh
super
button_color = (disabled?) ? DISABLED_COLOR : self.bitmap.font.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, self.bitmap.font.color)
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
self.bitmap.fill_rect(@plus_rect.x + 2, @plus_rect.y + (@plus_rect.height / 2) - 2, @plus_rect.width - 4, 4, self.bitmap.font.color)
self.bitmap.fill_rect(@plus_rect.x + (@plus_rect.width / 2) - 2, @plus_rect.y + 2, 4, @plus_rect.height - 4, self.bitmap.font.color)
self.bitmap.fill_rect(@plus_rect.x + 2, @plus_rect.y + (@plus_rect.height / 2) - 2, @plus_rect.width - 4, 4, button_color)
self.bitmap.fill_rect(@plus_rect.x + (@plus_rect.width / 2) - 2, @plus_rect.y + 2, 4, @plus_rect.height - 4, button_color)
end
#-----------------------------------------------------------------------------

View File

@@ -50,6 +50,12 @@ class UIControls::Button < UIControls::BaseControl
def refresh
super
# Draw disabled colour
if disabled?
self.bitmap.fill_rect(@button_rect.x, @button_rect.y,
@button_rect.width, @button_rect.height,
DISABLED_COLOR)
end
# Draw button outline
self.bitmap.outline_rect(@button_rect.x, @button_rect.y,
@button_rect.width, @button_rect.height,

View File

@@ -5,6 +5,7 @@
# 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
@@ -217,8 +218,6 @@ class UIControls::List < UIControls::BaseControl
return if !self.visible
@scrollbar.update
super
# TODO: Disabled control stuff.
# return if self.disabled
# Refresh the list's position if changed by moving the scrollbar
self.top_row = (@scrollbar.position.to_f / ROW_HEIGHT).round
# Set the selected row to the row the mouse is over, if clicked on

View File

@@ -81,10 +81,16 @@ class UIControls::DropdownList < UIControls::BaseControl
def refresh
@dropdown_menu&.refresh
super
# Draw disabled colour
if disabled?
self.bitmap.fill_rect(@button_rect.x, @button_rect.y,
@button_rect.width, @button_rect.height,
DISABLED_COLOR)
end
# Draw button outline
self.bitmap.outline_rect(@button_rect.x, @button_rect.y,
@button_rect.width, @button_rect.height,
Color.black)
self.bitmap.font.color)
# Draw value
draw_text(self.bitmap, @button_rect.x + TEXT_BOX_PADDING, TEXT_OFFSET_Y, @options[@value] || "???")
# Draw down arrow
@@ -95,7 +101,7 @@ class UIControls::DropdownList < UIControls::BaseControl
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, Color.black)
11 - (2 * i), 1, (disabled?) ? DISABLED_COLOR_DARK : self.bitmap.font.color)
end
end

View File

@@ -87,6 +87,7 @@ class UIControls::Scrollbar < UIControls::BaseControl
if @captured_area == :slider || (!@captured_area && @hover_area == :slider)
bar_color = GRAB_COLOR
end
bar_color = DISABLED_COLOR if disabled?
self.bitmap.fill_rect(@slider.x, @slider.y, @slider.width, @slider.height, bar_color)
end
end
@@ -120,8 +121,6 @@ class UIControls::Scrollbar < UIControls::BaseControl
def update
return if !self.visible
super
# TODO: Disabled control stuff.
# return if self.disabled
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
@@ -141,7 +140,7 @@ class UIControls::Scrollbar < UIControls::BaseControl
self.slider_top = @slider_top + ((@tray_size - @slider_size) / 4.0).ceil
end
end
else
elsif !disabled?
mouse_x, mouse_y = mouse_pos
if mouse_x && mouse_y && @interactions[:slider_tray].contains?(mouse_x, mouse_y)
wheel_v = Input.scroll_v

View File

@@ -242,17 +242,9 @@ module GameData
ret = @particles[index][SUB_SCHEMA[key][0]] if SUB_SCHEMA[key]
ret = nil if ret == false || (ret.is_a?(Array) && ret.length == 0) || ret == ""
case key
when "Focus"
# The User and Target particles are hardcoded to only have their
# corresponding foci, so they don't need writing to PBS
if ["User", "Target"].include?(@particles[index][:name])
ret = nil
elsif ret
ret = SUB_SCHEMA[key][2].key(ret)
end
when "graphic"
# The User and Target particles have hardcoded graphics, so they don't
# need writing to PBS
when "Graphic", "Focus"
# The User and Target particles have hardcoded graphics/foci, so they
# don't need writing to PBS
ret = nil if ["User", "Target"].include?(@particles[index][:name])
when "Play"
# TODO: Turn volume/pitch of 100 into nil.

View File

@@ -8,8 +8,6 @@
# "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,
@@ -213,11 +211,8 @@ class AnimationEditor
def set_particle_pane_contents
particle_pane = @components[:particle_pane]
particle_pane.add_header_label(:header, _INTL("Edit particle properties"))
# 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_text_box(:name, _INTL("Name"), "")
particle_pane.get_control(:name).set_blacklist("User", "Target", "SE")
particle_pane.add_labelled_label(:graphic_name, _INTL("Graphic"), "")
particle_pane.add_labelled_button(:graphic, "", _INTL("Change"))
particle_pane.add_labelled_dropdown_list(:focus, _INTL("Focus"), {
@@ -327,7 +322,6 @@ class AnimationEditor
# which should be indicated somehow in ctrl[1].
end
when :se_pane
# TODO: Activate/deactivate Edit/Delete buttons accordingly.
se_particle = @anim[:particles].select { |p| p[:name] == "SE" }[0]
kyfrm = keyframe
# Populate list of files
@@ -346,7 +340,16 @@ class AnimationEditor
end
list.sort! { |a, b| a[1].downcase <=> b[1].downcase }
component.get_control(:list).values = list
# Enable/disable the "Edit" and "Delete" buttons
if list.length > 0 && component.get_control(:list).value
component.get_control(:edit).enable
component.get_control(:delete).enable
else
component.get_control(:edit).disable
component.get_control(:delete).disable
end
when :particle_pane
# Display particle's graphic's name
new_vals = AnimationEditor::ParticleDataHelper.get_all_particle_values(@anim[:particles][particle_index])
component.controls.each do |ctrl|
next if !new_vals.include?(ctrl[0])
@@ -365,7 +368,14 @@ class AnimationEditor
}
graphic_name = graphic_override_names[graphic_name] if graphic_override_names[graphic_name]
component.get_control(:graphic_name).label = graphic_name
# TODO: Disable the name, graphic and focus controls for "User"/"Target".
# Enable/disable the Graphic and Focus controls for "User"/"Target"
if ["User", "Target"].include?(@anim[:particles][particle_index][:name])
component.get_control(:graphic).disable
component.get_control(:focus).disable
else
component.get_control(:graphic).enable
component.get_control(:focus).enable
end
end
end
@@ -394,7 +404,7 @@ class AnimationEditor
save
when :name
# TODO: Open the animation properties pop-up window.
echoln "animation name clicked"
echoln "Animation's name button clicked"
end
when :canvas
# TODO: Detect and apply changes made in canvas, e.g. moving particle,
@@ -403,6 +413,7 @@ class AnimationEditor
case property
when :color_tone # Button
# TODO: Open the colour/tone side pane.
echoln "Color/Tone button clicked"
else
particle = @anim[:particles][particle_index]
new_cmds = AnimationEditor::ParticleDataHelper.add_command(particle, property, keyframe, value)
@@ -417,6 +428,8 @@ class AnimationEditor
end
when :se_pane
case property
when :list # List
refresh_component(:se_pane)
when :add # Button
new_file, new_volume, new_pitch = choose_audio_file("", 100, 100)
if new_file != ""
@@ -451,8 +464,6 @@ class AnimationEditor
@components[:play_controls].duration = @components[:particle_list].duration
refresh_component(:se_pane)
end
else
# particle = @anim[:particles][particle_index]
end
when :particle_pane
case property
@@ -474,7 +485,7 @@ class AnimationEditor
# TODO: Stuff here once I decide what controls to add.
when :particle_list
# refresh if keyframe != old_keyframe || particle_index != old_particle_index
# TODO: Lots of stuff here.
# TODO: Lots of stuff here when buttons are added to it.
when :play_controls
# TODO: Will the play controls ever signal themselves as changed? I don't
# think so.
@@ -515,13 +526,10 @@ class AnimationEditor
def run
Input.text_input = false
loop do
# TODO: Do we need to check for Input.text_input? I think just checking
# @captured != nil will suffice.
inputting_text = Input.text_input
Graphics.update
Input.update
update
if !inputting_text && @captured.nil? && @quit
if @captured.nil? && @quit
case message(_INTL("Do you want to save changes to the animation?"),
[:yes, _INTL("Yes")], [:no, _INTL("No")], [:cancel, _INTL("Cancel")])
when :yes

View File

@@ -450,7 +450,7 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
if particle_data[:name] == "SE"
bg_color = SE_CONTROL_BG
else
bg_color = CONTROL_BG_COLORS[@particles[@particle_list[index][0]][:focus]] || Color.magenta
bg_color = CONTROL_BG_COLORS[@particles[p_index][:focus]] || Color.magenta
end
# Draw hover highlight
hover_color = nil
@@ -487,7 +487,7 @@ class AnimationEditor::ParticleList < UIControls::BaseControl
if particle_data[:name] == "SE"
bg_color = SE_CONTROL_BG
else
bg_color = CONTROL_BG_COLORS[@particles[@particle_list[index][0]][:focus]] || Color.magenta
bg_color = CONTROL_BG_COLORS[@particles[p_index][:focus]] || Color.magenta
end
# Get visibilities of particle for each keyframe
visible_cmds = @visibilities[p_index]

View File

@@ -41,9 +41,9 @@ class AnimationEditor::MenuBar < UIControls::ControlsContainer
i = @controls.length
control_x = (add_offset ? @row_count - 1 : @row_count) * MENU_BUTTON_WIDTH
control_x = @width - control.width if control.width == NAME_BUTTON_WIDTH
@control_rects[i] = Rect.new(control_x, 0, control.width, control.height)
control.x = @control_rects[i].x + (add_offset ? OFFSET_FROM_LABEL_X : 0)
control.y = @control_rects[i].y + (add_offset ? OFFSET_FROM_LABEL_Y : 0)
control_y = 0
control.x = control_x + (add_offset ? OFFSET_FROM_LABEL_X : 0)
control.y = control_y + (add_offset ? OFFSET_FROM_LABEL_Y : 0)
control.set_interactive_rects
@controls[i] = [id, control]
@row_count += 1 if !add_offset