Added vertical_/horizontal_margin/padding to Widgets, added HUD command to toggle HUD

This commit is contained in:
2021-06-02 12:55:08 +00:00
parent 5cb48233fb
commit 58b2f8b890
11 changed files with 126 additions and 55 deletions

View File

@@ -14,34 +14,39 @@ class IMICFPS
@text = Text.new("RADAR", size: 18, font: MONOSPACE_FONT, border: true, border_color: Gosu::Color::BLACK)
@image = Gosu::Image.new("#{CYBERARM_ENGINE_ROOT_PATH}/assets/textures/default.png", retro: true)
@scale = (@size - Widget.padding * 2.0) / @image.width
@scale = (@size - Widget.horizontal_padding * 2.0) / @image.width
end
def draw
Gosu.draw_rect(
Widget.margin, window.height - (@size + Widget.margin),
Widget.horizontal_margin, window.height - (@size + Widget.vertical_margin),
@size, @size,
@border_color
)
Gosu.draw_rect(
Widget.margin + Widget.padding, window.height - (@size + Widget.margin) + Widget.padding,
@size - Widget.padding * 2, @size - Widget.padding * 2,
Widget.horizontal_margin + Widget.horizontal_padding,
window.height - (@size + Widget.vertical_margin) + Widget.vertical_padding,
@size - Widget.horizontal_padding * 2, @size - Widget.horizontal_padding * 2,
@radar_color
)
@image.draw(Widget.margin + Widget.padding, window.height - (@size + Widget.margin) + Widget.padding, 46, @scale, @scale, 0x88ffffff)
@image.draw(
Widget.horizontal_margin + Widget.horizontal_padding,
window.height - (@size + Widget.vertical_margin) + Widget.vertical_padding,
46, @scale, @scale, 0x88ffffff
)
@text.draw
end
def update
@size = (window.width / @target_screen_width.to_f * @max_size).clamp(@min_size, @max_size)
@scale = (@size - Widget.padding * 2.0) / @image.width
@scale = (@size - Widget.horizontal_padding * 2.0) / @image.width
@text.text = "X: #{@player.position.x.round(1)} Y: #{@player.position.y.round(1)} Z: #{@player.position.z.round(1)}"
@text.x = Widget.margin + @size / 2 - @text.width / 2
@text.y = window.height - (Widget.margin + @size + @text.height)
@text.x = Widget.horizontal_margin + @size / 2 - @text.width / 2
@text.y = window.height - (Widget.vertical_margin + @size + @text.height)
end
end
end