Remove MultiLineText as gosu natively supports newlines, Update Text to correctly calculate its height, call super in button_down/button_up to support gosu's fullscreen toggle, added Window.text_input = nil to GameState to prevent fustrating bugs that stem from forgetting to set it back to nil.

This commit is contained in:
2019-03-31 17:34:24 -05:00
parent 74a3631111
commit cc97077b0f
6 changed files with 15 additions and 72 deletions

View File

@@ -13,7 +13,6 @@ require_relative "cyberarm_engine/background"
require_relative "cyberarm_engine/objects/text"
require_relative "cyberarm_engine/objects/timer"
require_relative "cyberarm_engine/objects/multi_line_text"
require_relative "cyberarm_engine/ui/theme"
require_relative "cyberarm_engine/ui/event"

View File

@@ -48,10 +48,12 @@ module CyberarmEngine
end
def button_down(id)
super
current_state.button_down(id) if current_state
end
def button_up(id)
super
current_state.button_up(id) if current_state
end

View File

@@ -36,7 +36,7 @@ module CyberarmEngine
setup
@debug_text = MultiLineText.new("", color: @debug_color, y: @position.y-(self.height*self.scale), z: 9999)
@debug_text = Text.new("", color: @debug_color, y: @position.y-(self.height*self.scale), z: 9999)
@debug_text.x = @position.x
if @radius == 0 || @radius == nil
@radius = options[:radius] ? options[:radius] : defined?(@image.width) ? ((@image.width+@image.height)/4)*scale : 1
@@ -121,11 +121,11 @@ module CyberarmEngine
end
def width
@image ? @image.width : 0
@image ? @image.width * self.scale : 0
end
def height
@image ? @image.height : 0
@image ? @image.height * self.scale : 0
end
def pause

View File

@@ -9,6 +9,7 @@ module CyberarmEngine
@options = options
@game_objects = []
@global_pause = false
$window.text_input = nil unless options[:preserve_text_input]
@down_keys = {}

View File

@@ -1,67 +0,0 @@
module CyberarmEngine
class MultiLineText
attr_accessor :options, :x, :y, :width, :height
def initialize(text, options={})
@texts = []
text.split("\n").each_with_index do |line, i|
_options = options
_options[:y]+=_options[:size]
@texts << Text.new(line, _options)
end
@options = options
@x = @texts.first ? @texts.first.x : 0
@y = @texts.first ? @texts.first.y : 0
@width = 0
@height = 0
calculate_boundry
end
def draw
@texts.each(&:draw)
end
def text
string = ""
@texts.each {|t| string << t.text}
return string
end
def text=(text)
if text.lines.count < @texts.count
range = ((@texts.count - @text.lines.count)-1)..@texts.count-1
p range
@texts.slice!(range)
end
text.split("\n").each_with_index do |line, i|
if @texts[i]
@texts[i].text = line
else
@texts << Text.new(line, @options)
end
end
self.y = @y
calculate_boundry
end
def x=(int)
@x = int
@texts.each {|t| t.x = int}
end
def y=(int)
@y = int
@texts.each_with_index {|t, i| t.y=int+(i*t.size)}
end
def calculate_boundry
@width = 0
@height= 0
@texts.each {|t| @width = t.width if t.width > @width}
@texts.each {|t| @height+=t.height}
end
end
end

View File

@@ -67,7 +67,7 @@ module CyberarmEngine
end
def height
textobject.height
@text.lines.count * textobject.height
end
def draw
@@ -91,6 +91,14 @@ module CyberarmEngine
@textobject.draw_markup(@text, @x, @y, @z, @factor_x, @factor_y, @color)
end
def alpha=(n)
@color = Gosu::Color.new(@color.red, @color.green, @color.blue, n)
end
def alpha
@color.alpha
end
def update; end
end
end