forked from bionickatana/number_factory
Added test dialouge boxes
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
# Nathan Hinotn
|
||||
# Creates a simple dialouge box that can be spawned from any location
|
||||
|
||||
TEXT_SIZE = 20
|
||||
TEXT_MARGIN = 3
|
||||
class DialougeBox
|
||||
def initialize(parent_x, parent_y, screen_width, screen_height, text)
|
||||
longest_line = ((text.split("\n").map { |ss| ss.length}.max) / 3.5).to_i
|
||||
line_count = text.split("\n").length
|
||||
|
||||
@x = parent_x
|
||||
@y = parent_y
|
||||
@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(
|
||||
@x,
|
||||
@y,
|
||||
(((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).draw(TEXT_MARGIN + @x, TEXT_MARGIN + @y)
|
||||
}
|
||||
end
|
||||
|
||||
def update(newtext: nil)
|
||||
if !newtext.nil?
|
||||
longest_line = ((newtext.split("\n").map { |ss| ss.length}.max) / 3.5).to_i
|
||||
line_count = newtext.split("\n").length
|
||||
|
||||
@image = Gosu.render(((TEXT_MARGIN * 2) + TEXT_SIZE) * longest_line, (TEXT_SIZE + TEXT_MARGIN) * line_count) {
|
||||
Gosu.draw_rect(
|
||||
@x,
|
||||
@y,
|
||||
(((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).draw(TEXT_MARGIN + @x, TEXT_MARGIN + @y)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def draw()
|
||||
@image.draw(@x, @y, 0)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user