From 8bf6b1444668cf7c7cb78308b0ed548fb69234d8 Mon Sep 17 00:00:00 2001 From: bionickatana Date: Sun, 14 Jun 2026 22:11:20 -0600 Subject: [PATCH] Updated consumer with text --- consumer.rb | 26 ++++++++++++++++++++++++-- main.rb | 2 +- producer.rb | 4 +--- 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/consumer.rb b/consumer.rb index ee4be68..18750e9 100644 --- a/consumer.rb +++ b/consumer.rb @@ -1,9 +1,16 @@ ## Nathan Hinton ## A number consumer that will create numbers when an extractor is placed on it. +require './dialouge_box.rb' + CONSUMER_DEBUG = false BORDER = 2 SIZE = 3 +HOVER_TIME = 500 # ms + +TASKS = [ + "Collect 10 1's" +] class Consumer attr_reader :draw_x, :draw_y @@ -19,6 +26,10 @@ class Consumer @image = Gosu.render((SIZE * @box_size) - (2 * BORDER), (SIZE * @box_size) - (2 * BORDER)) { Gosu.draw_rect(0, 0, (SIZE * @box_size) - (2 * BORDER), (SIZE * @box_size) - (2 * BORDER), Gosu::Color::GREEN, 0) } + @task_index = 0 + @tooltip_timer = 0 + @tooltip = DialougeBox.new(@x, @y, WIDTH, HEIGHT, TASKS[@task_index]) + puts 'made tooltip for consumer' end # Consumes numbers created @@ -26,11 +37,21 @@ class Consumer # @param camera_x [Integer] The camera X position # @param camera_y [Integer] The camera Y position # @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_y = (((((@screen_height / @box_size.to_f) / 2.0) + (@y - camera_y) * camera_zoom) * @box_size) + BORDER * camera_zoom) @camera_zoom = camera_zoom - + if 0 < mouse_x - @draw_x && mouse_x - @draw_x < (SIZE * @box_size * @camera_zoom) && 0 < mouse_y - @draw_y && mouse_y - @draw_y < (SIZE * @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 # Draw the consumer. Uses the camera x and y to shift where it should draw @@ -39,5 +60,6 @@ class Consumer puts "Drawing at #{@x - camera_x}, #{@y - camera_y}" end @image.draw(@draw_x, @draw_y, 0, @camera_zoom, @camera_zoom) + @tooltip.draw() end end diff --git a/main.rb b/main.rb index 8ece34a..230211c 100644 --- a/main.rb +++ b/main.rb @@ -197,7 +197,7 @@ class NumFactory < Gosu::Window end @consumers.each do |consumer| - consumer.update(delta_mult, @camera_x, @camera_y, @camera_zoom) + consumer.update(delta_mult, @camera_x, @camera_y, @camera_zoom, self.mouse_x, self.mouse_y) end @dialouges.each do |dialouge| dialouge.update(0, 0, newtext: "My new text is: #{delta_mult}") diff --git a/producer.rb b/producer.rb index 781736e..c5434f6 100644 --- a/producer.rb +++ b/producer.rb @@ -3,7 +3,6 @@ require './dialouge_box.rb' - PRODUCER_DEBUG = false BORDER = 2 HOVER_TIME = 500 # ms @@ -31,7 +30,6 @@ class Producer } @tooltip = DialougeBox.new(@x, @y, WIDTH, HEIGHT, "Produces #{@rate} number per second") - puts @tooltip.methods.sort end # Creates numbers depending on the rate. This is done with knowing that the @@ -46,8 +44,8 @@ class Producer @draw_y = (((((@screen_height / @box_size.to_f) / 2.0) + (@y - camera_y) * camera_zoom) * @box_size) + BORDER * 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) + puts 'mouse in consumer' @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)