Compare commits

...

2 Commits

Author SHA1 Message Date
bionickatana f8d69be2ad created dialouge boxes for the producers 2026-06-14 20:36:01 -06:00
bionickatana 1b1696becd Fixed scrolling speed issue 2026-06-14 20:35:45 -06:00
3 changed files with 61 additions and 33 deletions
+34 -24
View File
@@ -4,47 +4,57 @@
TEXT_SIZE = 20 TEXT_SIZE = 20
TEXT_MARGIN = 3 TEXT_MARGIN = 3
class DialougeBox class DialougeBox
attr_accessor :show
def initialize(parent_x, parent_y, screen_width, screen_height, text) 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 @text = text
line_count = text.split("\n").length @longest_line = ((@text.split("\n").map { |ss| ss.length}.max) / 3).to_i
@line_count = @text.split("\n").length
@x = parent_x @x = parent_x
@y = parent_y @y = parent_y
@show = false
@screen_width = screen_width @screen_width = screen_width
@screen_height = screen_height @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( Gosu.draw_rect(
@x, 0,
@y, 0,
(((TEXT_MARGIN * 2) + TEXT_SIZE) * longest_line) + @x, (((TEXT_MARGIN * 2) + TEXT_SIZE) * @longest_line) + @x,
((TEXT_SIZE + TEXT_MARGIN) * line_count) + @y, ((TEXT_SIZE + TEXT_MARGIN) * @line_count) + @y,
Gosu::Color.new(0xC0, 0xFF, 0xFF, 0xFF), Gosu::Color.new(0xC0, 0xFF, 0xFF, 0xFF),
0, 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 end
def update(newtext: nil) def update(x, y, camera_zoom, newtext: nil)
if !newtext.nil? if !newtext.nil?
longest_line = ((newtext.split("\n").map { |ss| ss.length}.max) / 3.5).to_i @text = newtext
line_count = newtext.split("\n").length @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( @image = Gosu.render(((TEXT_MARGIN * 2) + TEXT_SIZE) * @longest_line, (TEXT_SIZE + TEXT_MARGIN) * @line_count) {
@x, Gosu.draw_rect(
@y, 0,
(((TEXT_MARGIN * 2) + TEXT_SIZE) * longest_line) + @x, 0,
((TEXT_SIZE + TEXT_MARGIN) * line_count) + @y, (((TEXT_MARGIN * 2) + TEXT_SIZE) * @longest_line) + @x,
Gosu::Color.new(0xC0, 0xFF, 0xFF, 0xFF), ((TEXT_SIZE + TEXT_MARGIN) * @line_count) + @y,
0, Gosu::Color.new(0xC0, 0xFF, 0xFF, 0xFF),
) 0,
Gosu::Image.from_text(newtext, TEXT_SIZE).draw(TEXT_MARGIN + @x, TEXT_MARGIN + @y) )
} Gosu::Image.from_text(newtext, TEXT_SIZE).draw(TEXT_MARGIN, TEXT_MARGIN)
}
end end
@camera_zoom = camera_zoom
@x = x
@y = y
end end
def draw() 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
end end
+7 -7
View File
@@ -44,7 +44,7 @@ class NumFactory < Gosu::Window
@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!") @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] @dialouges = []
# Load from file or initialize a new game # Load from file or initialize a new game
begin begin
@@ -168,15 +168,15 @@ class NumFactory < Gosu::Window
### CAMERA ### ### CAMERA ###
# Move the camera if needed # Move the camera if needed
if self.mouse_x < CAMERA_MOVE_RANGE if self.mouse_x < CAMERA_MOVE_RANGE
@camera_x -= ([(CAMERA_MOVE_SPEED * ((CAMERA_MOVE_RANGE - self.mouse_x ) / 5)).to_i, CAMERA_MOVE_MAX_SPEED].min * delta_mult) @camera_x -= ([(CAMERA_MOVE_SPEED * ((CAMERA_MOVE_RANGE - self.mouse_x ) / 5)), CAMERA_MOVE_MAX_SPEED].min * delta_mult)
elsif self.mouse_x > WIDTH - CAMERA_MOVE_RANGE elsif self.mouse_x > WIDTH - CAMERA_MOVE_RANGE
@camera_x += ([(CAMERA_MOVE_SPEED * ((CAMERA_MOVE_RANGE - (WIDTH - self.mouse_x) ) / 2)).to_i, CAMERA_MOVE_MAX_SPEED].min * delta_mult) @camera_x += ([(CAMERA_MOVE_SPEED * ((CAMERA_MOVE_RANGE - (WIDTH - self.mouse_x + 1)) / 5)), CAMERA_MOVE_MAX_SPEED].min * delta_mult)
end end
if self.mouse_y < CAMERA_MOVE_RANGE if self.mouse_y < CAMERA_MOVE_RANGE
@camera_y -= ([(CAMERA_MOVE_SPEED * ((CAMERA_MOVE_RANGE - self.mouse_y ) / 2)).to_i, CAMERA_MOVE_MAX_SPEED].min * delta_mult) @camera_y -= ([(CAMERA_MOVE_SPEED * ((CAMERA_MOVE_RANGE - self.mouse_y ) / 5)), CAMERA_MOVE_MAX_SPEED].min * delta_mult)
elsif self.mouse_y > HEIGHT - CAMERA_MOVE_RANGE elsif self.mouse_y > HEIGHT - CAMERA_MOVE_RANGE
@camera_y += ([(CAMERA_MOVE_SPEED * ((CAMERA_MOVE_RANGE - (HEIGHT - (self.mouse_y + 1)) ) / 2)).to_i, CAMERA_MOVE_MAX_SPEED].min * delta_mult) @camera_y += ([(CAMERA_MOVE_SPEED * ((CAMERA_MOVE_RANGE - (HEIGHT - (self.mouse_y + 1)) ) / 5)), CAMERA_MOVE_MAX_SPEED].min * delta_mult)
end end
# Prevent camera from leaving the screen # Prevent camera from leaving the screen
@@ -187,7 +187,7 @@ class NumFactory < Gosu::Window
### ITEMS ### ### ITEMS ###
@producers.each do |producer| @producers.each do |producer|
producer.update(delta_mult, @camera_x, @camera_y, @camera_zoom) producer.update(delta_mult, @camera_x, @camera_y, @camera_zoom, self.mouse_x, self.mouse_y)
end end
@belts.each do |belt| @belts.each do |belt|
@@ -198,7 +198,7 @@ class NumFactory < Gosu::Window
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| @dialouges.each do |dialouge|
dialouge.update(newtext: "My new text is: #{delta_mult}") dialouge.update(0, 0, newtext: "My new text is: #{delta_mult}")
end end
end end
+20 -2
View File
@@ -1,8 +1,13 @@
## Nathan Hinton ## Nathan Hinton
## A number producer that will create numbers when an extractor is placed on it. ## A number producer that will create numbers when an extractor is placed on it.
require './dialouge_box.rb'
PRODUCER_DEBUG = false PRODUCER_DEBUG = false
BORDER = 2 BORDER = 2
HOVER_TIME = 500 # ms
class Producer class Producer
attr_reader :draw_x, :draw_y attr_reader :draw_x, :draw_y
@@ -25,6 +30,8 @@ class Producer
Gosu::Image.from_text("#{@number}", 20).draw(5, 5, 1) Gosu::Image.from_text("#{@number}", 20).draw(5, 5, 1)
} }
@tooltip = DialougeBox.new(@x, @y, WIDTH, HEIGHT, "This is a string\nof test text!")
puts @tooltip.methods.sort
end end
# Creates numbers depending on the rate. This is done with knowing that the # Creates numbers depending on the rate. This is done with knowing that the
@@ -34,11 +41,21 @@ class Producer
# @param camera_x [Integer] The camera X position # @param camera_x [Integer] The camera X position
# @param camera_y [Integer] The camera Y position # @param camera_y [Integer] The camera Y position
# @param camera_zoom [Float] The camera zoom # @param camera_zoom [Float] The camera zoom
def update(delta_mult, camera_x, camera_y, camera_zoom) def update(delta_mult, camera_x, camera_y, camera_zoom, mouse_x, mouse_y)
@draw_x = (((((@screen_width / @box_size.to_f) / 2.0) + (@x - camera_x) * camera_zoom) * @box_size) + BORDER * camera_zoom) @draw_x = (((((@screen_width / @box_size.to_f) / 2.0) + (@x - camera_x) * camera_zoom) * @box_size) + BORDER * camera_zoom)
@draw_y = (((((@screen_height / @box_size.to_f) / 2.0) + (@y - camera_y) * camera_zoom) * @box_size) + BORDER * camera_zoom) @draw_y = (((((@screen_height / @box_size.to_f) / 2.0) + (@y - camera_y) * camera_zoom) * @box_size) + BORDER * camera_zoom)
@camera_zoom = camera_zoom @camera_zoom = camera_zoom
if 0 < mouse_x - @draw_x && mouse_x - @draw_x < (@box_size * @camera_zoom) && 0 < mouse_y - @draw_y && mouse_y - @draw_y < (@box_size * @camera_zoom)
@tooltip_timer += 60.0 * delta_mult
puts @tooltip_timer
if @tooltip_timer > HOVER_TIME
@tooltip.show = true
@tooltip.update(@draw_x, @draw_y, @camera_zoom)
end
else
@tooltip_timer = 0
@tooltip.show = false
end
end end
# Draw the producer. Uses the camera x and y to shift where it should draw # Draw the producer. Uses the camera x and y to shift where it should draw
@@ -47,5 +64,6 @@ class Producer
puts "Drawing at #{@x - camera_x}, #{@y - camera_y}" puts "Drawing at #{@x - camera_x}, #{@y - camera_y}"
end end
@image.draw(@draw_x, @draw_y, 0, @camera_zoom, @camera_zoom) @image.draw(@draw_x, @draw_y, 0, @camera_zoom, @camera_zoom)
@tooltip.draw()
end end
end end