created dialouge boxes for the producers
This commit is contained in:
+34
-24
@@ -4,47 +4,57 @@
|
||||
TEXT_SIZE = 20
|
||||
TEXT_MARGIN = 3
|
||||
class DialougeBox
|
||||
attr_accessor :show
|
||||
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
|
||||
@text = text
|
||||
@longest_line = ((@text.split("\n").map { |ss| ss.length}.max) / 3).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) {
|
||||
@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,
|
||||
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).draw(TEXT_MARGIN + @x, TEXT_MARGIN + @y)
|
||||
Gosu::Image.from_text(text, TEXT_SIZE).draw(TEXT_MARGIN, TEXT_MARGIN)
|
||||
}
|
||||
end
|
||||
|
||||
def update(newtext: nil)
|
||||
def update(x, y, camera_zoom, 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)
|
||||
}
|
||||
@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).draw(TEXT_MARGIN, TEXT_MARGIN)
|
||||
}
|
||||
end
|
||||
@camera_zoom = camera_zoom
|
||||
@x = x
|
||||
@y = y
|
||||
end
|
||||
|
||||
def draw()
|
||||
@image.draw(@x, @y, 0)
|
||||
if @show
|
||||
puts "Drawing tooltip at #{@x}, #{@y}"
|
||||
@image.draw(@x, @y, 0, @camera_zoom, @camera_zoom)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user