Add game speed dropdown to the lobby.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user