Added selectable gui elements
This commit is contained in:
Binary file not shown.
|
After Width: | Height: | Size: 832 B |
Binary file not shown.
Binary file not shown.
|
After Width: | Height: | Size: 550 B |
Binary file not shown.
|
Before Width: | Height: | Size: 434 B After Width: | Height: | Size: 434 B |
@@ -33,11 +33,15 @@ CAMERA_MIN_ZOOM = 16 # Boxes across
|
|||||||
CAMERA_MAX_ZOOM = 80 # Boxes across
|
CAMERA_MAX_ZOOM = 80 # Boxes across
|
||||||
|
|
||||||
class NumFactory < Gosu::Window
|
class NumFactory < Gosu::Window
|
||||||
|
attr_accessor :current_tool
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
super WIDTH, HEIGHT, :fullscreen => true
|
super WIDTH, HEIGHT, :fullscreen => true
|
||||||
self.caption = "Number factory"
|
self.caption = "Number factory"
|
||||||
|
|
||||||
@background_color = Gosu::Color::BLUE
|
@background_color = Gosu::Color::BLUE
|
||||||
|
@cursor_image = Gosu::Image.new('assets/images/cursor.png')
|
||||||
|
@cursor = @cursor_image
|
||||||
|
|
||||||
@camera_x = 0
|
@camera_x = 0
|
||||||
@camera_y = 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_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
|
||||||
|
|
||||||
@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 = [
|
@dialouges = [
|
||||||
#DialougeBox.new(0, 5, BOX_SIZE, BOX_SIZE, WIDTH, HEIGHT, 'this is some really good test text!', BOX_SIZE, 500)
|
#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
|
end
|
||||||
|
|
||||||
|
# Disable cursor in the window
|
||||||
|
def needs_cursor?
|
||||||
|
false
|
||||||
|
end
|
||||||
|
|
||||||
def button_down(id)
|
def button_down(id)
|
||||||
if id == Gosu::KB_ESCAPE
|
if id == Gosu::KB_ESCAPE
|
||||||
close
|
close
|
||||||
@@ -158,6 +172,9 @@ class NumFactory < Gosu::Window
|
|||||||
@camera_zoom = WIDTH.to_f / (@camera_boxes * BOX_SIZE).to_f
|
@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_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
|
||||||
|
elsif id == Gosu::KB_G
|
||||||
|
@cursor = @cursor_image
|
||||||
|
@current_tool = nil
|
||||||
else
|
else
|
||||||
super
|
super
|
||||||
end
|
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)
|
consumer.update(delta_mult, @camera_x, @camera_y, @camera_zoom, self.mouse_x, self.mouse_y, mouse_used)
|
||||||
end
|
end
|
||||||
|
|
||||||
@dialouges.each do |dialouge|
|
if !mouse_used
|
||||||
dialouge.update(delta_mult, @camera_zoom, self.mouse_x, self.mouse_y)
|
@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
|
||||||
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 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 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)
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -8,12 +8,19 @@ class UI
|
|||||||
# Setup for the UI
|
# Setup for the UI
|
||||||
# @param width [Integer] Width of screen in pixels
|
# @param width [Integer] Width of screen in pixels
|
||||||
# @param height [Integer] Height of the 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
|
@width = width
|
||||||
@height = height
|
@height = height
|
||||||
@tool_selector = []
|
@tool_selector = []
|
||||||
@toolbar_width = width / 2
|
@toolbar_width = width / 2
|
||||||
@toolbar_height = height / 9
|
@toolbar_height = height / 9
|
||||||
|
@tool_info = [
|
||||||
|
['extractor', 96],
|
||||||
|
['belt', 32],
|
||||||
|
['adder', 64],
|
||||||
|
['delete', 32],
|
||||||
|
]
|
||||||
@tool_selector_image = Gosu.render(@toolbar_width, @toolbar_height) {
|
@tool_selector_image = Gosu.render(@toolbar_width, @toolbar_height) {
|
||||||
Gosu.draw_rect(
|
Gosu.draw_rect(
|
||||||
0,
|
0,
|
||||||
@@ -22,15 +29,48 @@ class UI
|
|||||||
@toolbar_height,
|
@toolbar_height,
|
||||||
Gosu::Color.new(0xC0, 0xFF, 0xFF, 0xFF),
|
Gosu::Color.new(0xC0, 0xFF, 0xFF, 0xFF),
|
||||||
0)
|
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)
|
@x = (@width / 2) - (@toolbar_width / 2)
|
||||||
@y = @height - @toolbar_height
|
@y = @height - @toolbar_height
|
||||||
|
@mouse_down_last_update = false
|
||||||
end
|
end
|
||||||
|
|
||||||
def update(mouse_x, mouse_y)
|
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
|
end
|
||||||
|
|
||||||
def draw()
|
def draw()
|
||||||
|
|||||||
Reference in New Issue
Block a user