diff --git a/assets/images/cursor.png b/assets/images/cursor.png new file mode 100644 index 0000000..c5dbb41 Binary files /dev/null and b/assets/images/cursor.png differ diff --git a/assets/images/cursor.xcf b/assets/images/cursor.xcf new file mode 100644 index 0000000..d210f87 Binary files /dev/null and b/assets/images/cursor.xcf differ diff --git a/assets/images/delete.png b/assets/images/delete.png new file mode 100644 index 0000000..35ad042 Binary files /dev/null and b/assets/images/delete.png differ diff --git a/assets/images/delete.xcf b/assets/images/delete.xcf new file mode 100644 index 0000000..394260f Binary files /dev/null and b/assets/images/delete.xcf differ diff --git a/assets/images/extrtactor.png b/assets/images/extractor.png similarity index 100% rename from assets/images/extrtactor.png rename to assets/images/extractor.png diff --git a/assets/images/extrtactor.xcf b/assets/images/extractor.xcf similarity index 100% rename from assets/images/extrtactor.xcf rename to assets/images/extractor.xcf diff --git a/main.rb b/main.rb index a8a98f2..2006e21 100644 --- a/main.rb +++ b/main.rb @@ -33,11 +33,15 @@ CAMERA_MIN_ZOOM = 16 # Boxes across CAMERA_MAX_ZOOM = 80 # Boxes across class NumFactory < Gosu::Window + attr_accessor :current_tool + def initialize super WIDTH, HEIGHT, :fullscreen => true self.caption = "Number factory" @background_color = Gosu::Color::BLUE + @cursor_image = Gosu::Image.new('assets/images/cursor.png') + @cursor = @cursor_image @camera_x = 0 @camera_y = 0 @@ -46,7 +50,13 @@ class NumFactory < Gosu::Window @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 - @ui = UI.new(WIDTH, HEIGHT) + @ui = UI.new(self, WIDTH, HEIGHT) + @current_tool = nil + @extractor_image = Gosu::Image.new('assets/images/extractor.png') + @belt_image = Gosu::Image.new('assets/images/belt.png') + @adder_image = Gosu::Image.new('assets/images/adder.png') + @delete_image = Gosu::Image.new('assets/images/delete.png') + @dialouges = [ #DialougeBox.new(0, 5, BOX_SIZE, BOX_SIZE, WIDTH, HEIGHT, 'this is some really good test text!', BOX_SIZE, 500) ] @@ -125,7 +135,11 @@ class NumFactory < Gosu::Window end - + # Disable cursor in the window + def needs_cursor? + false + end + def button_down(id) if id == Gosu::KB_ESCAPE close @@ -158,6 +172,9 @@ class NumFactory < Gosu::Window @camera_zoom = WIDTH.to_f / (@camera_boxes * BOX_SIZE).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 + elsif id == Gosu::KB_G + @cursor = @cursor_image + @current_tool = nil else super end @@ -224,8 +241,29 @@ class NumFactory < Gosu::Window consumer.update(delta_mult, @camera_x, @camera_y, @camera_zoom, self.mouse_x, self.mouse_y, mouse_used) end - @dialouges.each do |dialouge| - dialouge.update(delta_mult, @camera_zoom, self.mouse_x, self.mouse_y) + if !mouse_used + @dialouges.each do |dialouge| + dialouge.update(delta_mult, @camera_zoom, self.mouse_x, self.mouse_y) + end + end + + case @current_tool + when 'delete' + @cursor = @delete_image + @cursor_offset = @delete_image.height + #break + when 'belt' + @cursor = @belt_image + @cursor_offset = @belt_image.height + #break + when 'adder' + @cursor = @adder_image + @cursor_offset = @adder_image.height + #break + when 'extractor' + @cursor = @extractor_image + @cursor_offset = @extractor_image.height + #break end end @@ -278,6 +316,12 @@ class NumFactory < Gosu::Window Gosu::Image.from_text("Camera location: #{@camera_x}, #{@camera_y}", 20, font: FONT_PATH).draw(1600, 200, 1) Gosu::Image.from_text("Camera zoom: #{@camera_zoom}, #{@camera_x_zoom_offset}", 20, font: FONT_PATH).draw(1600, 225, 1) Gosu::Image.from_text("Camera viewport: (#{@camera_min_x}, #{@camera_min_y}) to (#{@camera_max_x}, #{@camera_max_y})", 20, font: FONT_PATH).draw(1600, 250, 1) + + if @cursor == @cursor_image + @cursor.draw(self.mouse_x - 16, self.mouse_y - 16, 10) + else + @cursor.draw(self.mouse_x - @cursor_offset, self.mouse_y - @cursor_offset, 10, BOX_SIZE / 32.0 * @camera_zoom, BOX_SIZE / 32.0 * @camera_zoom) + end end end diff --git a/ui.rb b/ui.rb index 8039b4e..1a83e3a 100644 --- a/ui.rb +++ b/ui.rb @@ -8,12 +8,19 @@ class UI # Setup for the UI # @param width [Integer] Width of screen in pixels # @param height [Integer] Height of the screen in pixels - def initialize(width, height) + def initialize(parent, width, height) + @parent = parent @width = width @height = height @tool_selector = [] @toolbar_width = width / 2 @toolbar_height = height / 9 + @tool_info = [ + ['extractor', 96], + ['belt', 32], + ['adder', 64], + ['delete', 32], + ] @tool_selector_image = Gosu.render(@toolbar_width, @toolbar_height) { Gosu.draw_rect( 0, @@ -22,15 +29,48 @@ class UI @toolbar_height, Gosu::Color.new(0xC0, 0xFF, 0xFF, 0xFF), 0) - Gosu::Image.from_text('tool selector', TEXT_SIZE, font: FONT_PATH).draw(TEXT_MARGIN, TEXT_MARGIN) + # Loop through the tools: + @tool_info.each_with_index do |path, idx| + Gosu::Image.new("assets/images/#{path[0]}.png").draw( + idx * (@toolbar_height + 2), + 2, + 0, + (@toolbar_height / path[1].to_f), + (@toolbar_height / path[1].to_f), + ) + end + } @x = (@width / 2) - (@toolbar_width / 2) @y = @height - @toolbar_height - + @mouse_down_last_update = false end def update(mouse_x, mouse_y) - false + managed = false + # Only check if we are clicking + if Gosu.button_down?(Gosu::MS_LEFT) + if !@mouse_down_last_update + puts 'mouse clicked' + @mouse_down_last_update = true + # Check if we are in the right y area: + if mouse_y > @y + # Check if we are within the right zone + mouse_x_inset = mouse_x - @x + if 0 < mouse_x_inset && mouse_x_inset < @toolbar_width + managed = true + item_index = mouse_x_inset / (@toolbar_height + 2) + if item_index < @tool_info.length + @parent.current_tool = @tool_info[item_index][0] + puts "Selected item!" + end + end + end + end + else + @mouse_down_last_update = false + end + return managed end def draw()