mirror of
https://github.com/cyberarm/i-mic-fps.git
synced 2025-12-15 23:52:35 +00:00
Added more menus; stub for settings, basic pause menu, fixes for multiple Game inits
This commit is contained in:
@@ -10,5 +10,6 @@ Requires a Ruby runtime that supports the gosu and opengl-bindings C-extensions
|
|||||||
### Options
|
### Options
|
||||||
* `--native` - Launch in fullscreen using primary displays resolution
|
* `--native` - Launch in fullscreen using primary displays resolution
|
||||||
* `--profile` - Run ruby-prof profiler
|
* `--profile` - Run ruby-prof profiler
|
||||||
|
* `--mesa-override` - (Linux) Force MESA to use OpenGL/GLSL version 3.30
|
||||||
* `--savedemo` - Record camera movement and key events to playback later *(alpha-quality feature)*
|
* `--savedemo` - Record camera movement and key events to playback later *(alpha-quality feature)*
|
||||||
* `--playdemo` - Plays the previously recorded demo *(alpha-quality feature)*
|
* `--playdemo` - Plays the previously recorded demo *(alpha-quality feature)*
|
||||||
@@ -52,6 +52,8 @@ Dir.glob("#{IMICFPS::GAME_ROOT_PATH}/lib/ui/commands/*.rb").each do |cmd|
|
|||||||
end
|
end
|
||||||
require_relative "lib/ui/console"
|
require_relative "lib/ui/console"
|
||||||
require_relative "lib/ui/menus/main_menu"
|
require_relative "lib/ui/menus/main_menu"
|
||||||
|
require_relative "lib/ui/menus/settings_menu"
|
||||||
|
require_relative "lib/ui/menus/game_pause_menu"
|
||||||
|
|
||||||
require_relative "lib/states/game_states/game"
|
require_relative "lib/states/game_states/game"
|
||||||
require_relative "lib/states/game_states/loading_state"
|
require_relative "lib/states/game_states/loading_state"
|
||||||
|
|||||||
@@ -7,12 +7,13 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.inherited(subclass)
|
def self.inherited(subclass)
|
||||||
pp subclass
|
|
||||||
COMPONENTS["__pending"] ||= []
|
COMPONENTS["__pending"] ||= []
|
||||||
COMPONENTS["__pending"] << subclass
|
COMPONENTS["__pending"] << subclass
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.initiate
|
def self.initiate
|
||||||
|
return unless COMPONENTS.dig("__pending") # Already setup
|
||||||
|
|
||||||
COMPONENTS["__pending"].each do |klass|
|
COMPONENTS["__pending"].each do |klass|
|
||||||
component = klass.new
|
component = klass.new
|
||||||
COMPONENTS[component.name] = component
|
COMPONENTS[component.name] = component
|
||||||
|
|||||||
@@ -9,14 +9,16 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.initiate
|
def self.initiate
|
||||||
|
preserve = @@handlers["__pending"]
|
||||||
|
@@handlers.clear
|
||||||
|
@@handlers["__pending"] = preserve
|
||||||
|
|
||||||
@@handlers["__pending"].each do |handler|
|
@@handlers["__pending"].each do |handler|
|
||||||
instance = handler.new
|
instance = handler.new
|
||||||
instance.handles.each do |event|
|
instance.handles.each do |event|
|
||||||
@@handlers[event] = instance
|
@@handlers[event] = instance
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@handlers.delete("__pending")
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.get(event)
|
def self.get(event)
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ class IMICFPS
|
|||||||
|
|
||||||
@demo.update if @demo
|
@demo.update if @demo
|
||||||
|
|
||||||
window.close if window.button_down?(Gosu::KbEscape)
|
|
||||||
window.number_of_vertices = 0
|
window.number_of_vertices = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -86,6 +85,11 @@ eos
|
|||||||
end
|
end
|
||||||
|
|
||||||
def button_down(id)
|
def button_down(id)
|
||||||
|
if id == Gosu::KB_ESCAPE
|
||||||
|
push_state(GamePauseMenu)
|
||||||
|
|
||||||
|
return
|
||||||
|
end
|
||||||
@demo.button_down(id) if @demo
|
@demo.button_down(id) if @demo
|
||||||
|
|
||||||
InputMapper.keydown(id)
|
InputMapper.keydown(id)
|
||||||
|
|||||||
@@ -12,14 +12,27 @@ class IMICFPS
|
|||||||
|
|
||||||
def title(text, color = @base_color)
|
def title(text, color = @base_color)
|
||||||
@elements << Text.new(text, color: color, size: 100, x: 0, y: 15, alignment: :center)
|
@elements << Text.new(text, color: color, size: 100, x: 0, y: 15, alignment: :center)
|
||||||
|
@_title = @elements.last
|
||||||
|
end
|
||||||
|
|
||||||
|
def subtitle(text, color = Gosu::Color::WHITE)
|
||||||
|
@elements << Text.new(text, color: color, size: 50, x: 0, y: 100, alignment: :center)
|
||||||
|
@_subtitle = @elements.last
|
||||||
end
|
end
|
||||||
|
|
||||||
def link(text, color = Gosu::Color.rgb(0,127,127), &block)
|
def link(text, color = Gosu::Color.rgb(0,127,127), &block)
|
||||||
text = Text.new(text, color: color, size: 50, x: 0, y: 100+(60*@elements.count), alignment: :center)
|
text = Text.new(text, color: color, size: 50, x: 0, y: 100 + (60 * @elements.count), alignment: :center)
|
||||||
@elements << Link.new(text, self, block)
|
@elements << Link.new(text, self, block)
|
||||||
end
|
end
|
||||||
|
|
||||||
def draw
|
def draw
|
||||||
|
draw_background
|
||||||
|
draw_menu_box
|
||||||
|
draw_menu
|
||||||
|
window.draw_cursor
|
||||||
|
end
|
||||||
|
|
||||||
|
def draw_background
|
||||||
@background ||= Gosu.record(Gosu.screen_width, Gosu.screen_height) do
|
@background ||= Gosu.record(Gosu.screen_width, Gosu.screen_height) do
|
||||||
((Gosu.screen_height+@slope)/@size).times do |i|
|
((Gosu.screen_height+@slope)/@size).times do |i|
|
||||||
fill_quad(
|
fill_quad(
|
||||||
@@ -41,30 +54,21 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
@background.draw(0, 0, 0)
|
@background.draw(0, 0, 0)
|
||||||
|
end
|
||||||
|
|
||||||
# Box
|
def draw_menu_box
|
||||||
draw_rect(
|
draw_rect(
|
||||||
window.width/4, 0,
|
window.width/4, 0,
|
||||||
window.width/2, window.height,
|
window.width/2, window.height,
|
||||||
Gosu::Color.rgba(0, 0, 0, 150)
|
Gosu::Color.rgba(0, 0, 0, 150)
|
||||||
# Gosu::Color.rgba(@base_color.red+@color_step, @base_color.green+@color_step, @base_color.blue+@color_step, 200)
|
# Gosu::Color.rgba(@base_color.red+@color_step, @base_color.green+@color_step, @base_color.blue+@color_step, 200)
|
||||||
)
|
)
|
||||||
|
end
|
||||||
|
|
||||||
# Texts
|
def draw_menu
|
||||||
@elements.each do |e|
|
@elements.each do |e|
|
||||||
e.draw
|
e.draw
|
||||||
end
|
end
|
||||||
|
|
||||||
# Cursor
|
|
||||||
if window.needs_cursor
|
|
||||||
fill_quad(
|
|
||||||
mouse_x, mouse_y,
|
|
||||||
mouse_x+16, mouse_y,
|
|
||||||
mouse_x, mouse_y+16,
|
|
||||||
mouse_x, mouse_y+16,
|
|
||||||
Gosu::Color::WHITE, Float::INFINITY
|
|
||||||
)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
@@ -84,7 +88,6 @@ class IMICFPS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def button_up(id)
|
def button_up(id)
|
||||||
window.close if id == Gosu::KbEscape
|
|
||||||
if id == Gosu::MsLeft
|
if id == Gosu::MsLeft
|
||||||
@elements.each do |e|
|
@elements.each do |e|
|
||||||
next unless e.is_a?(Link)
|
next unless e.is_a?(Link)
|
||||||
@@ -126,7 +129,7 @@ class IMICFPS
|
|||||||
def width; text.width; end
|
def width; text.width; end
|
||||||
def height; text.height; end
|
def height; text.height; end
|
||||||
def draw; text.draw; end
|
def draw; text.draw; end
|
||||||
def clicked; @block.call; end
|
def clicked; @block.call if @block; end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
23
lib/ui/menus/game_pause_menu.rb
Normal file
23
lib/ui/menus/game_pause_menu.rb
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
class IMICFPS
|
||||||
|
class GamePauseMenu < Menu
|
||||||
|
def setup
|
||||||
|
title "I-MIC FPS"
|
||||||
|
subtitle "Paused"
|
||||||
|
|
||||||
|
link "Resume" do
|
||||||
|
pop_state
|
||||||
|
end
|
||||||
|
|
||||||
|
link "Disconnect" do
|
||||||
|
push_state(MainMenu)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def draw
|
||||||
|
previous_state.draw
|
||||||
|
Gosu.flush
|
||||||
|
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -6,7 +6,7 @@ class IMICFPS
|
|||||||
push_state(LoadingState.new(forward: Game, map_file: GAME_ROOT_PATH + "/maps/test_map.json"))
|
push_state(LoadingState.new(forward: Game, map_file: GAME_ROOT_PATH + "/maps/test_map.json"))
|
||||||
end
|
end
|
||||||
link "Settings" do
|
link "Settings" do
|
||||||
# push_game_state(SettingsMenu)
|
push_state(SettingsMenu)
|
||||||
end
|
end
|
||||||
link "Exit" do
|
link "Exit" do
|
||||||
window.close
|
window.close
|
||||||
|
|||||||
14
lib/ui/menus/settings_menu.rb
Normal file
14
lib/ui/menus/settings_menu.rb
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
class IMICFPS
|
||||||
|
class SettingsMenu < Menu
|
||||||
|
def setup
|
||||||
|
title "I-MIC FPS"
|
||||||
|
subtitle "Settings"
|
||||||
|
|
||||||
|
link "\"There is no spoon.\""
|
||||||
|
|
||||||
|
link "Back" do
|
||||||
|
pop_state
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -36,6 +36,18 @@ class IMICFPS
|
|||||||
@console.draw if @show_console
|
@console.draw if @show_console
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def draw_cursor
|
||||||
|
if needs_cursor
|
||||||
|
draw_quad(
|
||||||
|
mouse_x, mouse_y, Gosu::Color::WHITE,
|
||||||
|
mouse_x+16, mouse_y, Gosu::Color::WHITE,
|
||||||
|
mouse_x, mouse_y+16, Gosu::Color::WHITE,
|
||||||
|
mouse_x, mouse_y+16, Gosu::Color::WHITE,
|
||||||
|
Float::INFINITY
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
super
|
super
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user