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

@@ -6,20 +6,22 @@
#
#===============================================================================
class UIControls::BaseControl < BitmapSprite
attr_reader :value
# attr_accessor :disabled # TODO: Make use of this.
attr_reader :value
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
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