forked from bionickatana/number_factory
Added selectable gui elements
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user