diff --git a/i-mic-fps.rb b/i-mic-fps.rb index 28fb07f..f72e400 100644 --- a/i-mic-fps.rb +++ b/i-mic-fps.rb @@ -79,17 +79,6 @@ end if prevent_launch?[0] puts prevent_launch?[1] -elsif ARGV.join.include?("--profile") - begin - require "ruby-prof" - RubyProf.start - IMICFPS::Window.new.show - result = RubyProf.stop - printer = RubyProf::MultiPrinter.new(result) - printer.print(path: ".", profile: "profile", min_percent: 2) - rescue LoadError - puts "ruby-prof not installed!" - end else native = ARGV.join.include?("--native") fps_target = ARGV.first.to_i != 0 ? ARGV.first.to_i : 60 @@ -97,11 +86,29 @@ else window_height = native ? Gosu.screen_height : 720 window_fullscreen = native ? true : false - IMICFPS::Window.new( + window = IMICFPS::Window.new( width: window_width, height: window_height, fullscreen: window_fullscreen, resizable: !window_fullscreen, update_interval: 1000.0 / fps_target - ).show + ) + + if ARGV.join.include?("--profile") + begin + require "ruby-prof" + RubyProf.start + + window.show + + result = RubyProf.stop + printer = RubyProf::MultiPrinter.new(result) + printer.print(path: ".", profile: "profile", min_percent: 2) + rescue LoadError + puts "ruby-prof not installed!" + raise + end + else + window.show + end end diff --git a/lib/hud/widget.rb b/lib/hud/widget.rb index efa9322..61862ed 100644 --- a/lib/hud/widget.rb +++ b/lib/hud/widget.rb @@ -7,21 +7,37 @@ class IMICFPS # Widget margin from screen edge # or how much widget is pushed in - def self.margin - @@margin ||= 10 + def self.vertical_margin + @@vertical_margin ||= 36 end - def self.padding=(n) - @@padding = n + def self.vertical_margin=(n) + @@vertical_margin = n + end + + def self.horizontal_margin + @@horizontal_margin ||= 10 + end + + def self.horizontal_margin=(n) + @@horizontal_margin = n end # Widget element padding - def self.padding - @@margin ||= 10 + def self.vertical_padding + @@vertical_padding ||= 10 end - def self.padding=(n) - @@padding = n + def self.vertical_padding=(n) + @@vertical_padding = n + end + + def self.horizontal_padding + @@horizontal_padding ||= 10 + end + + def self.horizontal_padding=(n) + @@horizontal_padding = n end attr_reader :options diff --git a/lib/hud/widgets/ammo.rb b/lib/hud/widgets/ammo.rb index 19a5d07..86ba594 100644 --- a/lib/hud/widgets/ammo.rb +++ b/lib/hud/widgets/ammo.rb @@ -9,11 +9,11 @@ class IMICFPS end def draw - # Gosu.draw_rect( - # @text.x - Widget.padding, @text.y - Widget.padding, - # @text.width + Widget.padding * 2, @text.height + Widget.padding * 2, - # @background - # ) + Gosu.draw_rect( + @text.x - Widget.horizontal_padding, @text.y - Widget.vertical_padding, + @text.width + Widget.horizontal_padding * 2, @text.height + Widget.vertical_padding * 2, + @background + ) @text.draw end @@ -23,8 +23,8 @@ class IMICFPS @text.text = "#{random}/999" end - @text.x = window.width - (Widget.margin + @text.width + Widget.padding) - @text.y = window.height - (Widget.margin + @text.height + Widget.padding) + @text.x = window.width - (Widget.horizontal_margin + @text.width + Widget.horizontal_padding) + @text.y = window.height - (Widget.vertical_margin + @text.height + Widget.vertical_padding) end end end diff --git a/lib/hud/widgets/chat.rb b/lib/hud/widgets/chat.rb index af28a51..e381143 100644 --- a/lib/hud/widgets/chat.rb +++ b/lib/hud/widgets/chat.rb @@ -12,8 +12,8 @@ class IMICFPS return unless window.text_input Gosu.draw_rect( - @text.x - Widget.padding, @text.y - Widget.padding, - @text.width + Widget.padding * 2, @text.height + Widget.padding * 2, + @text.x - Widget.horizontal_padding, @text.y - Widget.horizontal_padding, + @text.width + Widget.vertical_padding * 2, @text.height + Widget.vertical_padding * 2, @background ) @@ -37,8 +37,8 @@ class IMICFPS end @text.text = text.to_s - @text.x = window.width / 2 - (Widget.margin + @text.width / 2 + Widget.padding) - @text.y = window.height - (Widget.margin + @text.height + Widget.padding) + @text.x = window.width / 2 - (Widget.horizontal_margin + @text.width / 2 + Widget.horizontal_padding) + @text.y = window.height - (Widget.vertical_margin + @text.height + Widget.vertical_padding) end end end diff --git a/lib/hud/widgets/chat_history.rb b/lib/hud/widgets/chat_history.rb index 32b5c03..3941cf0 100644 --- a/lib/hud/widgets/chat_history.rb +++ b/lib/hud/widgets/chat_history.rb @@ -9,7 +9,7 @@ class IMICFPS @text = CyberarmEngine::Text.new( "", size: 16, - x: Widget.margin, y: Widget.margin, z: 45, + x: Widget.horizontal_margin, y: Widget.vertical_margin, z: 45, border_color: Gosu::Color::BLACK, font: BOLD_SANS_FONT ) diff --git a/lib/hud/widgets/health.rb b/lib/hud/widgets/health.rb index b506fdf..1f9f045 100644 --- a/lib/hud/widgets/health.rb +++ b/lib/hud/widgets/health.rb @@ -19,10 +19,10 @@ class IMICFPS def draw @text.draw fill_quad( - window.width / 2 - @width / 2, @spacer + Widget.margin, # TOP LEFT - window.width / 2 + @width / 2, @spacer + Widget.margin, # TOP RIGHT - window.width / 2 + @width / 2 - @slant, @spacer + Widget.margin + @height, # BOTTOM RIGHT - window.width / 2 - @width / 2 + @slant, @spacer + Widget.margin + @height, # BOTTOM LEFT + window.width / 2 - @width / 2, @spacer + Widget.vertical_margin, # TOP LEFT + window.width / 2 + @width / 2, @spacer + Widget.vertical_margin, # TOP RIGHT + window.width / 2 + @width / 2 - @slant, @spacer + Widget.vertical_margin + @height, # BOTTOM RIGHT + window.width / 2 - @width / 2 + @slant, @spacer + Widget.vertical_margin + @height, # BOTTOM LEFT @color ) @@ -31,10 +31,10 @@ class IMICFPS # Current Health fill_quad( - window.width / 2 - @width / 2, @spacer + Widget.margin, # TOP LEFT - (window.width / 2 - @width / 2) + @width * @health, @spacer + Widget.margin, # TOP RIGHT - bottom_right, @spacer + Widget.margin + @height, # BOTTOM RIGHT - window.width / 2 - @width / 2 + @slant, @spacer + Widget.margin + @height, # BOTTOM LEFT + window.width / 2 - @width / 2, @spacer + Widget.vertical_margin, # TOP LEFT + (window.width / 2 - @width / 2) + @width * @health, @spacer + Widget.vertical_margin, # TOP RIGHT + bottom_right, @spacer + Widget.vertical_margin + @height, # BOTTOM RIGHT + window.width / 2 - @width / 2 + @slant, @spacer + Widget.vertical_margin + @height, # BOTTOM LEFT @shield ) end @@ -43,7 +43,7 @@ class IMICFPS percentage = (@health * 100).round.to_s.rjust(3, "0") @text.text = "[Health #{percentage}%]" @text.x = window.width / 2 - @text.width / 2 - @text.y = @spacer + Widget.margin + @height / 2 - @text.height / 2 + @text.y = @spacer + Widget.vertical_margin + @height / 2 - @text.height / 2 @health += 0.1 * window.dt @health = 0 if @health > 1.0 diff --git a/lib/hud/widgets/radar.rb b/lib/hud/widgets/radar.rb index b762af1..42553a4 100644 --- a/lib/hud/widgets/radar.rb +++ b/lib/hud/widgets/radar.rb @@ -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 diff --git a/lib/hud/widgets/score_board.rb b/lib/hud/widgets/score_board.rb index e9ba7e9..919cd53 100644 --- a/lib/hud/widgets/score_board.rb +++ b/lib/hud/widgets/score_board.rb @@ -9,7 +9,7 @@ class IMICFPS @text = CyberarmEngine::Text.new( "", size: 16, - x: Widget.margin, y: Widget.margin, z: 45, + x: Widget.horizontal_margin, y: Widget.vertical_margin, z: 45, border: true, border_color: Gosu::Color::BLACK, font: BOLD_SANS_FONT @@ -23,7 +23,7 @@ class IMICFPS end def update - @text.x = window.width - (@text.markup_width + Widget.margin) + @text.x = window.width - (@text.markup_width + Widget.horizontal_margin) end def generate_random_data diff --git a/lib/hud/widgets/squad.rb b/lib/hud/widgets/squad.rb index bf78f14..767e0d2 100644 --- a/lib/hud/widgets/squad.rb +++ b/lib/hud/widgets/squad.rb @@ -28,8 +28,8 @@ class IMICFPS def update @size = (window.width / @target_screen_width.to_f * @max_size).clamp(@min_size, @max_size) - @text.x = Widget.margin + @size + Widget.padding - @text.y = window.height - (Widget.margin + @text.height) + @text.x = Widget.horizontal_margin + @size + Widget.horizontal_padding + @text.y = window.height - (Widget.vertical_margin + @text.height) end end end diff --git a/lib/states/game_states/game.rb b/lib/states/game_states/game.rb index d893b8e..e70a36f 100644 --- a/lib/states/game_states/game.rb +++ b/lib/states/game_states/game.rb @@ -27,7 +27,7 @@ class IMICFPS def draw window.director.map.render(@camera) - @hud.draw + @hud.draw if window.config.get(:options, :hud) end def update diff --git a/lib/ui/commands/hud_command.rb b/lib/ui/commands/hud_command.rb new file mode 100644 index 0000000..e1a8412 --- /dev/null +++ b/lib/ui/commands/hud_command.rb @@ -0,0 +1,43 @@ +# frozen_string_literal: true + +class IMICFPS + class Commands + class HUDCommand < Command + def group + :global + end + + def command + :hud + end + + def setup + $window.config[:options, :hud] = true if $window.config.get(:options, :hud).nil? + end + + def handle(arguments, console) + if arguments.size > 1 + console.stdin("to many arguments for #{Style.highlight(command.to_s)}, got #{Style.error(arguments.size)} expected #{Style.notice(1)}.") + return + end + + case arguments.last + when "", nil + console.stdin("#{Style.highlight(command.to_s)}: #{$window.config.get(:options, command)}") + when "on" + var = $window.config[:options, command] = true + console.stdin("fps => #{Style.highlight(var)}") + when "off" + var = $window.config[:options, command] = false + console.stdin("fps => #{Style.highlight(var)}") + else + console.stdin("Invalid argument for #{Style.highlight(command.to_s)}, got #{Style.error(arguments.last)} expected #{Style.notice('on')}, or #{Style.notice('off')}.") + end + end + + def usage + "#{Style.highlight('hud')} #{Style.notice('[on|off]')}" + end + end + end +end