mirror of
https://github.com/cyberarm/i-mic-rts.git
synced 2025-12-15 15:52:34 +00:00
Added pause menu, refreshed solo lobby menu, added settings for storing player's color and team, misc.
This commit is contained in:
@@ -15,6 +15,7 @@ GEM
|
|||||||
mini_portile2 (~> 2.4.0)
|
mini_portile2 (~> 2.4.0)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
|
ruby
|
||||||
x86_64-linux
|
x86_64-linux
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ require_relative "lib/states/closing"
|
|||||||
require_relative "lib/states/menus/main_menu"
|
require_relative "lib/states/menus/main_menu"
|
||||||
require_relative "lib/states/menus/credits_menu"
|
require_relative "lib/states/menus/credits_menu"
|
||||||
require_relative "lib/states/menus/settings_menu"
|
require_relative "lib/states/menus/settings_menu"
|
||||||
|
require_relative "lib/states/menus/pause_menu"
|
||||||
require_relative "lib/states/menus/solo_play_menu"
|
require_relative "lib/states/menus/solo_play_menu"
|
||||||
require_relative "lib/states/menus/multiplayer_menu"
|
require_relative "lib/states/menus/multiplayer_menu"
|
||||||
require_relative "lib/states/menus/solo_lobby_menu"
|
require_relative "lib/states/menus/solo_lobby_menu"
|
||||||
|
|||||||
@@ -5,15 +5,12 @@ class IMICRTS
|
|||||||
|
|
||||||
return unless item
|
return unless item
|
||||||
|
|
||||||
item.progress += 1
|
item.progress += 1 if @parent.component(:building).construction_complete?
|
||||||
|
|
||||||
if item.progress >= item.entity.build_steps
|
return unless item.progress >= item.entity.build_steps && !item.completed
|
||||||
unless item.completed
|
|
||||||
item.completed = true
|
|
||||||
|
|
||||||
@parent.director.schedule_order(IMICRTS::Order::BUILD_UNIT_COMPLETE, @parent.player.id, @parent.id)
|
item.completed = true
|
||||||
end
|
@parent.director.schedule_order(IMICRTS::Order::BUILD_UNIT_COMPLETE, @parent.player.id, @parent.id)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -2,19 +2,24 @@ class IMICRTS
|
|||||||
class Director
|
class Director
|
||||||
attr_reader :current_tick, :map, :game, :players
|
attr_reader :current_tick, :map, :game, :players
|
||||||
|
|
||||||
def initialize(game:, map:, players: [], networking_mode:, tick_rate: 10)
|
def initialize(game:, map:, players: [], networking_mode:, tick_rate: 10, local_game: true)
|
||||||
@game = game
|
@game = game
|
||||||
@map = map
|
@map = map
|
||||||
@players = players
|
@players = players
|
||||||
@connection = IMICRTS::Connection.new(director: self, mode: networking_mode)
|
@connection = IMICRTS::Connection.new(director: self, mode: networking_mode)
|
||||||
@networking_mode = networking_mode
|
@networking_mode = networking_mode
|
||||||
@tick_rate = tick_rate
|
@tick_rate = tick_rate
|
||||||
|
@local_game = local_game
|
||||||
|
|
||||||
@last_tick_at = Gosu.milliseconds
|
@last_tick_at = Gosu.milliseconds
|
||||||
@tick_time = 1000.0 / @tick_rate
|
@tick_time = 1000.0 / @tick_rate
|
||||||
@current_tick = 0
|
@current_tick = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def local_game?
|
||||||
|
@local_game
|
||||||
|
end
|
||||||
|
|
||||||
def add_player(player)
|
def add_player(player)
|
||||||
@players << player
|
@players << player
|
||||||
end
|
end
|
||||||
@@ -145,7 +150,8 @@ class IMICRTS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def finalize
|
def finalize
|
||||||
@connection.finalize
|
@server&.stop
|
||||||
|
@connection&.finalize
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ class IMICRTS
|
|||||||
def self.save_defaults
|
def self.save_defaults
|
||||||
hash = {
|
hash = {
|
||||||
player_name: "Rookie",
|
player_name: "Rookie",
|
||||||
|
player_color: :orange,
|
||||||
|
player_team: 1,
|
||||||
player_default_map_spawn: 0,
|
player_default_map_spawn: 0,
|
||||||
default_map: "test_map",
|
default_map: "test_map",
|
||||||
|
|
||||||
@@ -43,7 +45,7 @@ class IMICRTS
|
|||||||
end
|
end
|
||||||
|
|
||||||
def self.save!
|
def self.save!
|
||||||
File.open(Setting.file_path, "w") {|f| f.write(JSON.dump(@store))}
|
File.open(Setting.file_path, "w") { |f| f.write(JSON.dump(@store)) }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -2,17 +2,31 @@ class IMICRTS
|
|||||||
class Game < CyberarmEngine::GuiState
|
class Game < CyberarmEngine::GuiState
|
||||||
Overlay = Struct.new(:image, :position, :angle, :alpha)
|
Overlay = Struct.new(:image, :position, :angle, :alpha)
|
||||||
|
|
||||||
attr_reader :sidebar, :sidebar_actions, :overlays
|
attr_reader :sidebar, :sidebar_actions, :overlays, :director
|
||||||
attr_accessor :selected_entities
|
attr_accessor :selected_entities
|
||||||
|
|
||||||
def setup
|
def setup
|
||||||
window.show_cursor = true
|
window.show_cursor = true
|
||||||
@options[:networking_mode] ||= :host
|
@options[:networking_mode] ||= :virtual
|
||||||
|
@options[:map] ||= Map.new(map_file: "maps/test_map.tmx")
|
||||||
|
@options[:local_player_id] ||= 0
|
||||||
|
|
||||||
@director = Director.new(game: self, map: Map.new(map_file: "maps/test_map.tmx"), networking_mode: @options[:networking_mode])
|
@director = Director.new(game: self, map: @options[:map], networking_mode: @options[:networking_mode])
|
||||||
@player = Player.new(id: 0, spawnpoint: @director.map.spawnpoints.last)
|
@options[:players] ||= [
|
||||||
@player2 = Player.new(id: 1, spawnpoint: @director.map.spawnpoints.first)
|
{ id: 0, team: 1, spawnpoint: @director.map.spawnpoints.last, color: :orange },
|
||||||
@director.add_player(@player)
|
{ id: 1, team: 2, spawnpoint: @director.map.spawnpoints.first, color: :lightblue }
|
||||||
@director.add_player(@player2)
|
]
|
||||||
|
|
||||||
|
@options[:players].each do |pl|
|
||||||
|
player = Player.new(id: pl[:id], spawnpoint: pl[:spawnpoint], team: pl[:team], color: TeamColors[pl[:color]])
|
||||||
|
@player = player if player.id == @options[:local_player_id]
|
||||||
|
@director.add_player(player)
|
||||||
|
end
|
||||||
|
|
||||||
|
# @player = Player.new(id: 0, spawnpoint: @director.map.spawnpoints.last)
|
||||||
|
# @player2 = Player.new(id: 1, spawnpoint: @director.map.spawnpoints.first)
|
||||||
|
# @director.add_player(@player)
|
||||||
|
# @director.add_player(@player2)
|
||||||
|
|
||||||
@selected_entities = []
|
@selected_entities = []
|
||||||
@tool = set_tool(:entity_controller)
|
@tool = set_tool(:entity_controller)
|
||||||
@@ -20,7 +34,7 @@ class IMICRTS
|
|||||||
|
|
||||||
@debug_info = CyberarmEngine::Text.new("", y: 10, z: Float::INFINITY, shadow_color: Gosu::Color.rgba(0, 0, 0, 200))
|
@debug_info = CyberarmEngine::Text.new("", y: 10, z: Float::INFINITY, shadow_color: Gosu::Color.rgba(0, 0, 0, 200))
|
||||||
|
|
||||||
@sidebar = stack(height: 1.0) do
|
@sidebar = stack(width: 350, height: 1.0) do
|
||||||
background [0x55555555, 0x55666666]
|
background [0x55555555, 0x55666666]
|
||||||
|
|
||||||
label "SIDEBAR", text_size: 78, margin_bottom: 20
|
label "SIDEBAR", text_size: 78, margin_bottom: 20
|
||||||
@@ -115,6 +129,8 @@ class IMICRTS
|
|||||||
|
|
||||||
@tool.button_down(id) if @tool
|
@tool.button_down(id) if @tool
|
||||||
@player.camera.button_down(id) unless @sidebar.hit?(window.mouse_x, window.mouse_y)
|
@player.camera.button_down(id) unless @sidebar.hit?(window.mouse_x, window.mouse_y)
|
||||||
|
|
||||||
|
push_state(PauseMenu) if id == Gosu::KB_ESCAPE
|
||||||
end
|
end
|
||||||
|
|
||||||
def button_up(id)
|
def button_up(id)
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ class IMICRTS
|
|||||||
def setup
|
def setup
|
||||||
background [0xff7b6ead, 0xff7a0d71, 0xff7a0d71, 0xff7b6ead]
|
background [0xff7b6ead, 0xff7a0d71, 0xff7a0d71, 0xff7b6ead]
|
||||||
|
|
||||||
stack(height: 1.0) do
|
stack(width: 600, height: 1.0) do
|
||||||
background [0xff555555, Gosu::Color::GRAY]
|
background [0xff555555, Gosu::Color::GRAY]
|
||||||
|
|
||||||
label "About I-MIC-RTS", text_size: 78, margin: 20
|
label "About I-MIC-RTS", text_size: 78, margin: 20
|
||||||
label "Words go here.\nMore words also go here. Thank you and have a nice day."
|
label "Words go here. More words also go here. Thank you and have a nice day.", text_wrap: :word_wrap
|
||||||
|
|
||||||
button("Back", width: 1.0, margin_top: 20) do
|
button("Back", width: 1.0, margin_top: 20) do
|
||||||
push_state(MainMenu)
|
push_state(MainMenu)
|
||||||
|
|||||||
@@ -5,10 +5,13 @@ class IMICRTS
|
|||||||
|
|
||||||
background [0xff7b6ead, 0xff7a0d71, 0xff7a0d71, 0xff7b6ead]
|
background [0xff7b6ead, 0xff7a0d71, 0xff7a0d71, 0xff7b6ead]
|
||||||
|
|
||||||
stack(height: 1.0) do
|
stack(width: 350, height: 1.0) do
|
||||||
background [0xff555555, Gosu::Color::GRAY]
|
background [0xff555555, Gosu::Color::GRAY]
|
||||||
label "I-MIC-RTS", text_size: 78, margin: 20
|
label "I-MIC-RTS", text_size: 78, margin: 20
|
||||||
button("Solo Play", width: 1.0) do
|
button("Campaign", width: 1.0) do
|
||||||
|
end
|
||||||
|
|
||||||
|
button("Skirmish", width: 1.0) do
|
||||||
# push_state(SoloPlayMenu)
|
# push_state(SoloPlayMenu)
|
||||||
push_state(SoloLobbyMenu)
|
push_state(SoloLobbyMenu)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -14,8 +14,12 @@ class IMICRTS
|
|||||||
button("Refresh") do
|
button("Refresh") do
|
||||||
refresh_games
|
refresh_games
|
||||||
end
|
end
|
||||||
button("Host Game")
|
button("Host Game") do
|
||||||
button("Join Game")
|
push_state(HostMultiplayerGameMenu)
|
||||||
|
end
|
||||||
|
button("Join Game") do
|
||||||
|
push_state(MultiplayerLobbyMenu)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
button("Back", width: 1.0, margin_top: 20) do
|
button("Back", width: 1.0, margin_top: 20) do
|
||||||
|
|||||||
39
lib/states/menus/pause_menu.rb
Normal file
39
lib/states/menus/pause_menu.rb
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
class IMICRTS
|
||||||
|
class PauseMenu < CyberarmEngine::GuiState
|
||||||
|
def setup
|
||||||
|
stack(width: 350) do
|
||||||
|
button "Resume", width: 1.0 do
|
||||||
|
pop_state
|
||||||
|
end
|
||||||
|
button "Settings", width: 1.0 do
|
||||||
|
push_state(SettingsMenu)
|
||||||
|
end
|
||||||
|
button "Quit", width: 1.0 do
|
||||||
|
# TODO: Confirm
|
||||||
|
|
||||||
|
previous_state.director.finalize
|
||||||
|
|
||||||
|
if previous_state&.director.local_game?
|
||||||
|
push_state(SoloLobbyMenu)
|
||||||
|
else
|
||||||
|
push_state(MultiplayerLobbyMenu)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def draw
|
||||||
|
previous_state&.draw
|
||||||
|
|
||||||
|
# Gosu.flush
|
||||||
|
|
||||||
|
super
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
super
|
||||||
|
|
||||||
|
previous_state&.director.update unless previous_state&.director.local_game?
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -3,7 +3,7 @@ class IMICRTS
|
|||||||
def setup
|
def setup
|
||||||
background [0xff7b6ead, 0xff7a0d71, 0xff7a0d71, 0xff7b6ead]
|
background [0xff7b6ead, 0xff7a0d71, 0xff7a0d71, 0xff7b6ead]
|
||||||
|
|
||||||
stack(height: 1.0) do
|
stack(width: 350, height: 1.0) do
|
||||||
background [0xff555555, Gosu::Color::GRAY]
|
background [0xff555555, Gosu::Color::GRAY]
|
||||||
|
|
||||||
label "Settings", text_size: 78, margin: 20
|
label "Settings", text_size: 78, margin: 20
|
||||||
@@ -24,12 +24,12 @@ class IMICRTS
|
|||||||
if valid_options?
|
if valid_options?
|
||||||
save_settings
|
save_settings
|
||||||
|
|
||||||
push_state(MainMenu)
|
pop_state
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
button("Back", width: 1.0, margin_top: 20) do
|
button("Back", width: 1.0, margin_top: 20) do
|
||||||
push_state(MainMenu)
|
pop_state
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,40 +3,67 @@ class IMICRTS
|
|||||||
def setup
|
def setup
|
||||||
background [0xff7b6ead, 0xff7a0d71, 0xff7a0d71, 0xff7b6ead]
|
background [0xff7b6ead, 0xff7a0d71, 0xff7a0d71, 0xff7b6ead]
|
||||||
|
|
||||||
stack(height: 1.0) do
|
stack(width: 0.5, min_width: 720, height: 1.0) do
|
||||||
background [0xff555555, Gosu::Color::GRAY]
|
background [0xff555555, Gosu::Color::GRAY]
|
||||||
|
|
||||||
label "Lobby", text_size: 78, margin: 20
|
label "Lobby", text_size: 78, margin: 20
|
||||||
stack do
|
flow(width: 1.0, height: 0.8) do
|
||||||
flow do
|
flow(width: 0.70, height: 1.0) do
|
||||||
|
stack(width: 0.40) do
|
||||||
|
label "Name"
|
||||||
|
@player_name = edit_line Setting.get(:player_name), width: 1.0
|
||||||
|
|
||||||
elements = [:edit_line, :button, :button, :toggle_button]
|
7.times do |i|
|
||||||
["Players", "Color", "Team", "Map Preview"].each_with_index do |item, index|
|
list_box items: [:open, :closed, :easy, :hard, :brutal], width: 1.0
|
||||||
stack do
|
end
|
||||||
label item, background: 0xff7a0d71
|
end
|
||||||
|
|
||||||
stack do
|
stack(width: 0.29) do
|
||||||
case elements[index]
|
label "Color"
|
||||||
when :edit_line
|
@player_color = list_box items: TeamColors.keys, choose: Setting.get(:player_color).to_sym, width: 1.0
|
||||||
@player_name = edit_line Setting.get(:player_name)
|
@player_color.style.background = (TeamColors[@player_color.value.to_sym])
|
||||||
when :button
|
@player_color.subscribe(:changed) do |sender, value|
|
||||||
button item
|
@player_color.style.background = TeamColors[value.to_sym]
|
||||||
when :toggle_button
|
:handled
|
||||||
toggle_button
|
end
|
||||||
end
|
|
||||||
|
7.times do |i|
|
||||||
|
box = list_box items: TeamColors.keys, choose: TeamColors.keys[i + 1], width: 1.0
|
||||||
|
box.style.background = (TeamColors[box.value.to_sym])
|
||||||
|
box.subscribe(:changed) do |sender, value|
|
||||||
|
box.style.background = TeamColors[value.to_sym]
|
||||||
|
:handled
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
stack(width: 0.29) do
|
||||||
|
label "Team"
|
||||||
|
@player_team = list_box items: Array(1..8), choose: Setting.get(:player_team), width: 1.0
|
||||||
|
|
||||||
|
7.times do |i|
|
||||||
|
list_box items: Array(1..8), choose: i + 2, width: 1.0
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
stack(height: 100) do
|
stack(width: 0.30, height: 1.0) do
|
||||||
|
# TODO: Show preview image
|
||||||
|
label "Map"
|
||||||
|
@map_name = list_box items: [:test_map], choose: :test_map, width: 1.0
|
||||||
|
image "#{GAME_ROOT_PATH}/assets/logo.png", width: 1.0
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
flow(width: 1.0) do
|
flow(width: 1.0, height: 0.2) do
|
||||||
button("Accept", width: 0.5) do
|
button("Accept") do
|
||||||
save_playerdata
|
save_playerdata
|
||||||
push_state(Game, networking_mode: :virtual)
|
map = Map.new(map_file: "maps/#{@map_name.value}.tmx")
|
||||||
|
players = [
|
||||||
|
{ id: 0, team: @player_team.value.to_i, spawnpoint: map.spawnpoints.last, color: @player_color.value.to_sym },
|
||||||
|
{ id: 1, team: 2, spawnpoint: map.spawnpoints.first, color: :lightblue }
|
||||||
|
]
|
||||||
|
push_state(Game, networking_mode: :virtual, map: map, players: players)
|
||||||
end
|
end
|
||||||
|
|
||||||
button("Back", align: :right) do
|
button("Back", align: :right) do
|
||||||
@@ -49,6 +76,8 @@ class IMICRTS
|
|||||||
|
|
||||||
def save_playerdata
|
def save_playerdata
|
||||||
Setting.set(:player_name, @player_name.value)
|
Setting.set(:player_name, @player_name.value)
|
||||||
|
Setting.set(:player_color, @player_color.value.to_sym)
|
||||||
|
Setting.set(:player_team, @player_team.value.to_i)
|
||||||
|
|
||||||
Setting.save!
|
Setting.save!
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -51,12 +51,5 @@ class IMICRTS
|
|||||||
def dt
|
def dt
|
||||||
delta_time / 1000.0
|
delta_time / 1000.0
|
||||||
end
|
end
|
||||||
|
|
||||||
# Override CyberarmEngine::Window#push_state to only ever have 1 state
|
|
||||||
def push_state(*args)
|
|
||||||
@states.clear
|
|
||||||
|
|
||||||
super(*args)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user