Add dialouge boxes/tooltips (#10)
- [x] Update objects so they know when the mouse is on them - [x] Remove testing code - [x] Add into the producers - [x] Add into the consumer - [x] Standardize fonts --------- Co-authored-by: leah <leah@hintonclan.org> Reviewed-on: #10
This commit was merged in pull request #10.
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
# 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
|
||||
Reference in New Issue
Block a user