Add game speed dropdown to the lobby.
This commit is contained in:
40
OpenRA.Game/GameSpeed.cs
Normal file
40
OpenRA.Game/GameSpeed.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA
|
||||
{
|
||||
public class GameSpeed
|
||||
{
|
||||
[Translate]
|
||||
public readonly string Name = "Default";
|
||||
public readonly int Timestep = 40;
|
||||
public readonly int OrderLatency = 3;
|
||||
}
|
||||
|
||||
public class GameSpeeds : IGlobalModData
|
||||
{
|
||||
[FieldLoader.LoadUsing("LoadSpeeds")]
|
||||
public readonly Dictionary<string, GameSpeed> Speeds;
|
||||
|
||||
static object LoadSpeeds(MiniYaml y)
|
||||
{
|
||||
var ret = new Dictionary<string, GameSpeed>();
|
||||
foreach (var node in y.Nodes)
|
||||
ret.Add(node.Key, FieldLoader.Load<GameSpeed>(node.Value));
|
||||
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -188,6 +188,7 @@ namespace OpenRA.Network
|
||||
public int StartingCash = 5000;
|
||||
public string TechLevel = "none";
|
||||
public string StartingUnitsClass = "none";
|
||||
public string GameSpeedType = "default";
|
||||
public bool ShortGame = true;
|
||||
public bool AllowVersionMismatch;
|
||||
public string GameUid;
|
||||
|
||||
@@ -243,6 +243,7 @@
|
||||
<Compile Include="Map\MapCoordsRegion.cs" />
|
||||
<Compile Include="Renderer.cs" />
|
||||
<Compile Include="Platform.cs" />
|
||||
<Compile Include="GameSpeed.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="FileSystem\D2kSoundResources.cs" />
|
||||
|
||||
@@ -675,6 +675,34 @@ namespace OpenRA.Mods.Common.Server
|
||||
return true;
|
||||
}
|
||||
},
|
||||
{ "gamespeed",
|
||||
s =>
|
||||
{
|
||||
if (!client.IsAdmin)
|
||||
{
|
||||
server.SendOrderTo(conn, "Message", "Only the host can set that option.");
|
||||
return true;
|
||||
}
|
||||
|
||||
var gameSpeeds = Game.ModData.Manifest.Get<GameSpeeds>();
|
||||
|
||||
GameSpeed speed;
|
||||
if (!gameSpeeds.Speeds.TryGetValue(s, out speed))
|
||||
{
|
||||
server.SendOrderTo(conn, "Message", "Invalid game speed selected.");
|
||||
return true;
|
||||
}
|
||||
|
||||
server.LobbyInfo.GlobalSettings.GameSpeedType = s;
|
||||
server.LobbyInfo.GlobalSettings.Timestep = speed.Timestep;
|
||||
server.LobbyInfo.GlobalSettings.OrderLatency = speed.OrderLatency;
|
||||
|
||||
server.SyncLobbyInfo();
|
||||
server.SendMessage("{0} changed Game Speed to {1}.".F(client.Name, speed.Name));
|
||||
|
||||
return true;
|
||||
}
|
||||
},
|
||||
{ "kick",
|
||||
s =>
|
||||
{
|
||||
|
||||
@@ -23,7 +23,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
var status = widget.GetOrNull<LabelWidget>("GAME_TIMER_STATUS");
|
||||
var startTick = Ui.LastTickTime;
|
||||
|
||||
Func<bool> shouldShowStatus = () => (world.Paused || world.Timestep != Game.Timestep)
|
||||
Func<bool> shouldShowStatus = () => (world.Paused || world.Timestep != world.LobbyInfo.GlobalSettings.Timestep)
|
||||
&& (Ui.LastTickTime - startTick) / 1000 % 2 == 0;
|
||||
|
||||
Func<string> statusText = () =>
|
||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
if (world.Timestep == 1)
|
||||
return "Max Speed";
|
||||
|
||||
return "{0}% Speed".F(Game.Timestep * 100 / world.Timestep);
|
||||
return "{0}% Speed".F(world.LobbyInfo.GlobalSettings.Timestep * 100 / world.Timestep);
|
||||
};
|
||||
|
||||
if (timer != null)
|
||||
|
||||
@@ -490,6 +490,44 @@ namespace OpenRA.Mods.Common.Widgets.Logic
|
||||
};
|
||||
}
|
||||
|
||||
var gameSpeed = optionsBin.GetOrNull<DropDownButtonWidget>("GAMESPEED_DROPDOWNBUTTON");
|
||||
if (gameSpeed != null)
|
||||
{
|
||||
var speeds = Game.ModData.Manifest.Get<GameSpeeds>().Speeds;
|
||||
|
||||
gameSpeed.IsDisabled = () => Map.Status != MapStatus.Available || configurationDisabled();
|
||||
gameSpeed.GetText = () =>
|
||||
{
|
||||
if (Map.Status != MapStatus.Available)
|
||||
return "Not Available";
|
||||
|
||||
GameSpeed speed;
|
||||
if (!speeds.TryGetValue(orderManager.LobbyInfo.GlobalSettings.GameSpeedType, out speed))
|
||||
return "Unknown";
|
||||
|
||||
return speed.Name;
|
||||
};
|
||||
|
||||
gameSpeed.OnMouseDown = _ =>
|
||||
{
|
||||
var options = speeds.Select(s => new DropDownOption
|
||||
{
|
||||
Title = s.Value.Name,
|
||||
IsSelected = () => orderManager.LobbyInfo.GlobalSettings.GameSpeedType == s.Key,
|
||||
OnClick = () => orderManager.IssueOrder(Order.Command("gamespeed {0}".F(s.Key)))
|
||||
});
|
||||
|
||||
Func<DropDownOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
|
||||
{
|
||||
var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick);
|
||||
item.Get<LabelWidget>("LABEL").GetText = () => option.Title;
|
||||
return item;
|
||||
};
|
||||
|
||||
gameSpeed.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem);
|
||||
};
|
||||
}
|
||||
|
||||
var exploredMap = optionsBin.GetOrNull<CheckboxWidget>("EXPLORED_MAP_CHECKBOX");
|
||||
if (exploredMap != null)
|
||||
{
|
||||
|
||||
@@ -175,19 +175,6 @@ Background@LOBBY_OPTIONS_BIN:
|
||||
Width: 140
|
||||
Height: 25
|
||||
Font: Regular
|
||||
Label@DIFFICULTY_DESC:
|
||||
X: PARENT_RIGHT - WIDTH - 135
|
||||
Y: 107
|
||||
Width: 120
|
||||
Height: 25
|
||||
Text: Mission Difficulty:
|
||||
Align: Right
|
||||
DropDownButton@DIFFICULTY_DROPDOWNBUTTON:
|
||||
X: PARENT_RIGHT - WIDTH + 10
|
||||
Y: 107
|
||||
Width: 140
|
||||
Height: 25
|
||||
Font: Regular
|
||||
DropDownButton@TECHLEVEL_DROPDOWNBUTTON:
|
||||
X: 85
|
||||
Y: 112
|
||||
@@ -201,7 +188,32 @@ Background@LOBBY_OPTIONS_BIN:
|
||||
Height: 25
|
||||
Text: Tech Level:
|
||||
Align: Right
|
||||
|
||||
Label@GAMESPEED_DESC:
|
||||
X: PARENT_RIGHT - WIDTH - 135
|
||||
Y: 112
|
||||
Width: 120
|
||||
Height: 25
|
||||
Text: Game Speed:
|
||||
Align: Right
|
||||
DropDownButton@GAMESPEED_DROPDOWNBUTTON:
|
||||
X: PARENT_RIGHT - WIDTH + 10
|
||||
Y: 112
|
||||
Width: 140
|
||||
Height: 25
|
||||
Font: Regular
|
||||
Label@DIFFICULTY_DESC:
|
||||
X: PARENT_RIGHT - WIDTH - 135
|
||||
Y: 152
|
||||
Width: 120
|
||||
Height: 25
|
||||
Text: Mission Difficulty:
|
||||
Align: Right
|
||||
DropDownButton@DIFFICULTY_DROPDOWNBUTTON:
|
||||
X: PARENT_RIGHT - WIDTH + 10
|
||||
Y: 152
|
||||
Width: 140
|
||||
Height: 25
|
||||
Font: Regular
|
||||
Background@FORCE_START_DIALOG:
|
||||
X: 15
|
||||
Y: 30
|
||||
|
||||
@@ -214,3 +214,21 @@ SpriteSequenceFormat: TilesetSpecificSpriteSequence
|
||||
SNOW: .sno
|
||||
DESERT: .des
|
||||
JUNGLE: .jun
|
||||
|
||||
GameSpeeds:
|
||||
slower:
|
||||
Name: Slower
|
||||
Timestep: 50
|
||||
OrderLatency: 3
|
||||
default:
|
||||
Name: Default
|
||||
Timestep: 40
|
||||
OrderLatency: 3
|
||||
faster:
|
||||
Name: Faster
|
||||
Timestep: 30
|
||||
OrderLatency: 4
|
||||
fastest:
|
||||
Name: Fastest
|
||||
Timestep: 20
|
||||
OrderLatency: 6
|
||||
|
||||
@@ -151,6 +151,19 @@ Background@LOBBY_OPTIONS_BIN:
|
||||
Width: 140
|
||||
Height: 20
|
||||
Text: Debug Menu
|
||||
Label@DIFFICULTY_DESC:
|
||||
X: PARENT_RIGHT - WIDTH - 145
|
||||
Y: 70
|
||||
Width: 120
|
||||
Height: 25
|
||||
Text: Mission Difficulty:
|
||||
Align: Right
|
||||
DropDownButton@DIFFICULTY_DROPDOWNBUTTON:
|
||||
X: PARENT_RIGHT - WIDTH
|
||||
Y: 70
|
||||
Width: 140
|
||||
Height: 25
|
||||
Font: Regular
|
||||
Label@STARTINGCASH_DESC:
|
||||
Y: 110
|
||||
Width: 80
|
||||
@@ -177,19 +190,6 @@ Background@LOBBY_OPTIONS_BIN:
|
||||
Width: 140
|
||||
Height: 25
|
||||
Font: Regular
|
||||
Label@DIFFICULTY_DESC:
|
||||
X: PARENT_RIGHT - WIDTH - 145
|
||||
Y: 150
|
||||
Width: 120
|
||||
Height: 25
|
||||
Text: Mission Difficulty:
|
||||
Align: Right
|
||||
DropDownButton@DIFFICULTY_DROPDOWNBUTTON:
|
||||
X: PARENT_RIGHT - WIDTH
|
||||
Y: 150
|
||||
Width: 140
|
||||
Height: 25
|
||||
Font: Regular
|
||||
DropDownButton@TECHLEVEL_DROPDOWNBUTTON:
|
||||
X: 85
|
||||
Y: 150
|
||||
@@ -203,6 +203,19 @@ Background@LOBBY_OPTIONS_BIN:
|
||||
Height: 25
|
||||
Text: Tech Level:
|
||||
Align: Right
|
||||
Label@GAMESPEED_DESC:
|
||||
X: PARENT_RIGHT - WIDTH - 145
|
||||
Y: 150
|
||||
Width: 120
|
||||
Height: 25
|
||||
Text: Game Speed:
|
||||
Align: Right
|
||||
DropDownButton@GAMESPEED_DROPDOWNBUTTON:
|
||||
X: PARENT_RIGHT - WIDTH
|
||||
Y: 150
|
||||
Width: 140
|
||||
Height: 25
|
||||
Font: Regular
|
||||
|
||||
Background@FORCE_START_DIALOG:
|
||||
X: 20
|
||||
|
||||
@@ -193,3 +193,21 @@ SupportsMapsFrom: d2k
|
||||
SpriteFormats: R8, ShpTD, TmpRA
|
||||
|
||||
SpriteSequenceFormat: DefaultSpriteSequence
|
||||
|
||||
GameSpeeds:
|
||||
slower:
|
||||
Name: Slower
|
||||
Timestep: 50
|
||||
OrderLatency: 3
|
||||
default:
|
||||
Name: Default
|
||||
Timestep: 40
|
||||
OrderLatency: 3
|
||||
faster:
|
||||
Name: Faster
|
||||
Timestep: 30
|
||||
OrderLatency: 4
|
||||
fastest:
|
||||
Name: Fastest
|
||||
Timestep: 20
|
||||
OrderLatency: 6
|
||||
|
||||
@@ -145,6 +145,19 @@ Background@LOBBY_OPTIONS_BIN:
|
||||
Width: 140
|
||||
Height: 20
|
||||
Text: Debug Menu
|
||||
Label@DIFFICULTY_DESC:
|
||||
X: PARENT_RIGHT - WIDTH - 145
|
||||
Y: 70
|
||||
Width: 120
|
||||
Height: 25
|
||||
Text: Mission Difficulty:
|
||||
Align: Right
|
||||
DropDownButton@DIFFICULTY_DROPDOWNBUTTON:
|
||||
X: PARENT_RIGHT - WIDTH
|
||||
Y: 70
|
||||
Width: 140
|
||||
Height: 25
|
||||
Font: Regular
|
||||
Label@STARTINGCASH_DESC:
|
||||
Y: 110
|
||||
Width: 80
|
||||
@@ -171,19 +184,6 @@ Background@LOBBY_OPTIONS_BIN:
|
||||
Width: 140
|
||||
Height: 25
|
||||
Font: Regular
|
||||
Label@DIFFICULTY_DESC:
|
||||
X: PARENT_RIGHT - WIDTH - 145
|
||||
Y: 150
|
||||
Width: 120
|
||||
Height: 25
|
||||
Text: Mission Difficulty:
|
||||
Align: Right
|
||||
DropDownButton@DIFFICULTY_DROPDOWNBUTTON:
|
||||
X: PARENT_RIGHT - WIDTH
|
||||
Y: 150
|
||||
Width: 140
|
||||
Height: 25
|
||||
Font: Regular
|
||||
DropDownButton@TECHLEVEL_DROPDOWNBUTTON:
|
||||
X: 85
|
||||
Y: 150
|
||||
@@ -197,6 +197,19 @@ Background@LOBBY_OPTIONS_BIN:
|
||||
Height: 25
|
||||
Text: Tech Level:
|
||||
Align: Right
|
||||
Label@GAMESPEED_DESC:
|
||||
X: PARENT_RIGHT - WIDTH - 145
|
||||
Y: 150
|
||||
Width: 120
|
||||
Height: 25
|
||||
Text: Game Speed:
|
||||
Align: Right
|
||||
DropDownButton@GAMESPEED_DROPDOWNBUTTON:
|
||||
X: PARENT_RIGHT - WIDTH
|
||||
Y: 150
|
||||
Width: 140
|
||||
Height: 25
|
||||
Font: Regular
|
||||
|
||||
Background@FORCE_START_DIALOG:
|
||||
X: 20
|
||||
|
||||
@@ -213,3 +213,21 @@ SpriteSequenceFormat: TilesetSpecificSpriteSequence
|
||||
SNOW: .sno
|
||||
INTERIOR: .int
|
||||
DESERT: .des
|
||||
|
||||
GameSpeeds:
|
||||
slower:
|
||||
Name: Slower
|
||||
Timestep: 50
|
||||
OrderLatency: 3
|
||||
default:
|
||||
Name: Default
|
||||
Timestep: 40
|
||||
OrderLatency: 3
|
||||
faster:
|
||||
Name: Faster
|
||||
Timestep: 30
|
||||
OrderLatency: 4
|
||||
fastest:
|
||||
Name: Fastest
|
||||
Timestep: 20
|
||||
OrderLatency: 6
|
||||
|
||||
@@ -258,3 +258,21 @@ SpriteSequenceFormat: TilesetSpecificSpriteSequence
|
||||
TilesetCodes:
|
||||
TEMPERATE: t
|
||||
SNOW: a
|
||||
|
||||
GameSpeeds:
|
||||
slower:
|
||||
Name: Slower
|
||||
Timestep: 50
|
||||
OrderLatency: 3
|
||||
default:
|
||||
Name: Default
|
||||
Timestep: 40
|
||||
OrderLatency: 3
|
||||
faster:
|
||||
Name: Faster
|
||||
Timestep: 30
|
||||
OrderLatency: 4
|
||||
fastest:
|
||||
Name: Fastest
|
||||
Timestep: 20
|
||||
OrderLatency: 6
|
||||
|
||||
Reference in New Issue
Block a user