forked from bionickatana/number_factory
96fa6d3c62
Updated consumer with text
60 lines
1.8 KiB
Ruby
60 lines
1.8 KiB
Ruby
# Nathan Hinotn
|
|
# Creates a simple dialouge box that can be spawned from any location
|
|
|
|
TEXT_SIZE = 20
|
|
TEXT_MARGIN = 3
|
|
class DialougeBox
|
|
attr_accessor :show
|
|
def initialize(parent_x, parent_y, screen_width, screen_height, text)
|
|
@text = text
|
|
@longest_line = ((@text.split("\n").map { |ss| ss.length}.max) / 2.25).to_i
|
|
@line_count = @text.split("\n").length
|
|
|
|
@x = parent_x
|
|
@y = parent_y
|
|
@show = false
|
|
@screen_width = screen_width
|
|
@screen_height = screen_height
|
|
@image = Gosu.render(((TEXT_MARGIN * 2) + TEXT_SIZE) * @longest_line, (TEXT_SIZE + TEXT_MARGIN) * @line_count) {
|
|
Gosu.draw_rect(
|
|
0,
|
|
0,
|
|
(((TEXT_MARGIN * 2) + TEXT_SIZE) * @longest_line) + @x,
|
|
((TEXT_SIZE + TEXT_MARGIN) * @line_count) + @y,
|
|
Gosu::Color.new(0xC0, 0xFF, 0xFF, 0xFF),
|
|
0,
|
|
)
|
|
Gosu::Image.from_text(text, TEXT_SIZE, font: FONT_PATH).draw(TEXT_MARGIN, TEXT_MARGIN)
|
|
}
|
|
end
|
|
|
|
def update(x, y, camera_zoom, newtext: nil)
|
|
if !newtext.nil?
|
|
@text = newtext
|
|
@longest_line = ((@text.split("\n").map { |ss| ss.length}.max) / 3.5).to_i
|
|
@line_count = @text.split("\n").length
|
|
|
|
@image = Gosu.render(((TEXT_MARGIN * 2) + TEXT_SIZE) * @longest_line, (TEXT_SIZE + TEXT_MARGIN) * @line_count) {
|
|
Gosu.draw_rect(
|
|
0,
|
|
0,
|
|
(((TEXT_MARGIN * 2) + TEXT_SIZE) * @longest_line) + @x,
|
|
((TEXT_SIZE + TEXT_MARGIN) * @line_count) + @y,
|
|
Gosu::Color.new(0xC0, 0xFF, 0xFF, 0xFF),
|
|
0,
|
|
)
|
|
Gosu::Image.from_text(newtext, TEXT_SIZE, font: FONT_PATH).draw(TEXT_MARGIN, TEXT_MARGIN)
|
|
}
|
|
end
|
|
@camera_zoom = camera_zoom
|
|
@x = x
|
|
@y = y
|
|
end
|
|
|
|
def draw()
|
|
if @show
|
|
@image.draw(@x, @y, 0, @camera_zoom, @camera_zoom)
|
|
end
|
|
end
|
|
end
|