Added selectable gui elements
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user