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
|
||||||
@@ -7,6 +7,7 @@ require 'yaml'
|
|||||||
|
|
||||||
require './producer.rb'
|
require './producer.rb'
|
||||||
require './consumer.rb'
|
require './consumer.rb'
|
||||||
|
require './dialouge_box.rb'
|
||||||
|
|
||||||
# Viewport resolution
|
# Viewport resolution
|
||||||
WIDTH = Gosu::screen_width
|
WIDTH = Gosu::screen_width
|
||||||
@@ -42,6 +43,9 @@ class NumFactory < Gosu::Window
|
|||||||
@camera_x_zoom_offset = WIDTH.to_f / (@camera_boxes * BOX_SIZE * 2).to_f
|
@camera_x_zoom_offset = WIDTH.to_f / (@camera_boxes * BOX_SIZE * 2).to_f
|
||||||
@camera_y_zoom_offset = HEIGHT.to_f / (@camera_boxes * BOX_SIZE * 2).to_f
|
@camera_y_zoom_offset = HEIGHT.to_f / (@camera_boxes * BOX_SIZE * 2).to_f
|
||||||
|
|
||||||
|
@dd = DialougeBox.new(0, 0, WIDTH, HEIGHT, "This is a really really really really really really really really really really string\nof test text!")
|
||||||
|
@dialouges = [@dd]
|
||||||
|
|
||||||
# Load from file or initialize a new game
|
# Load from file or initialize a new game
|
||||||
begin
|
begin
|
||||||
game_save_data = YAML.load_file("#{GAME_SAVE_DIRECTORY}/positions.yaml")
|
game_save_data = YAML.load_file("#{GAME_SAVE_DIRECTORY}/positions.yaml")
|
||||||
@@ -193,6 +197,10 @@ class NumFactory < Gosu::Window
|
|||||||
@consumers.each do |consumer|
|
@consumers.each do |consumer|
|
||||||
consumer.update(delta_mult, @camera_x, @camera_y, @camera_zoom)
|
consumer.update(delta_mult, @camera_x, @camera_y, @camera_zoom)
|
||||||
end
|
end
|
||||||
|
@dialouges.each do |dialouge|
|
||||||
|
dialouge.update(newtext: "My new text is: #{delta_mult}")
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
## Called when OS wants to update window.
|
## Called when OS wants to update window.
|
||||||
@@ -225,6 +233,11 @@ class NumFactory < Gosu::Window
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@dialouges.each do |dialouge|
|
||||||
|
dialouge.draw()
|
||||||
|
end
|
||||||
|
|
||||||
Gosu::Image.from_text("#{width}, #{height}", 20).draw(1600, 0, 1)
|
Gosu::Image.from_text("#{width}, #{height}", 20).draw(1600, 0, 1)
|
||||||
Gosu::Image.from_text("#{mouse_x}, #{mouse_y}", 20).draw(1600, 100, 1)
|
Gosu::Image.from_text("#{mouse_x}, #{mouse_y}", 20).draw(1600, 100, 1)
|
||||||
Gosu::Image.from_text("Tick time: #{((Time.now() - @tick_time).to_f * 1000).to_i}", 20).draw(1600, 25, 1)
|
Gosu::Image.from_text("Tick time: #{((Time.now() - @tick_time).to_f * 1000).to_i}", 20).draw(1600, 25, 1)
|
||||||
|
|||||||
Reference in New Issue
Block a user