Move widget delegates into Mods.
This commit is contained in:
@@ -312,6 +312,18 @@
|
||||
<Compile Include="ServerTraits\LobbyCommands.cs" />
|
||||
<Compile Include="Scripting\RASpecialPowers.cs" />
|
||||
<Compile Include="PaletteFromCurrentTileset.cs" />
|
||||
<Compile Include="Widgets\Delegates\ConnectionDialogsDelegate.cs" />
|
||||
<Compile Include="Widgets\Delegates\CreateServerMenuDelegate.cs" />
|
||||
<Compile Include="Widgets\Delegates\DeveloperModeDelegate.cs" />
|
||||
<Compile Include="Widgets\Delegates\DiplomacyDelegate.cs" />
|
||||
<Compile Include="Widgets\Delegates\LobbyDelegate.cs" />
|
||||
<Compile Include="Widgets\Delegates\MainMenuButtonsDelegate.cs" />
|
||||
<Compile Include="Widgets\Delegates\MapChooserDelegate.cs" />
|
||||
<Compile Include="Widgets\Delegates\MusicPlayerDelegate.cs" />
|
||||
<Compile Include="Widgets\Delegates\PerfDebugDelegate.cs" />
|
||||
<Compile Include="Widgets\Delegates\ServerBrowserDelegate.cs" />
|
||||
<Compile Include="Widgets\Delegates\SettingsMenuDelegate.cs" />
|
||||
<Compile Include="Widgets\Delegates\VideoPlayerDelegate.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
{
|
||||
public class ConnectionDialogsDelegate : IWidgetDelegate
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public ConnectionDialogsDelegate(
|
||||
[ObjectCreator.Param] Widget widget,
|
||||
[ObjectCreator.Param] string host,
|
||||
[ObjectCreator.Param] int port )
|
||||
{
|
||||
widget.GetWidget("CONNECTION_BUTTON_ABORT").OnMouseUp = mi => {
|
||||
widget.GetWidget("CONNECTION_BUTTON_ABORT").Parent.Visible = false;
|
||||
Game.Disconnect();
|
||||
return true;
|
||||
};
|
||||
|
||||
widget.GetWidget<LabelWidget>("CONNECTING_DESC").GetText = () =>
|
||||
"Connecting to {0}:{1}...".F(host, port);
|
||||
}
|
||||
}
|
||||
|
||||
public class ConnectionFailedDelegate : IWidgetDelegate
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public ConnectionFailedDelegate(
|
||||
[ObjectCreator.Param] Widget widget,
|
||||
[ObjectCreator.Param] string host,
|
||||
[ObjectCreator.Param] int port )
|
||||
{
|
||||
widget.GetWidget("CONNECTION_BUTTON_CANCEL").OnMouseUp = mi => {
|
||||
widget.GetWidget("CONNECTION_BUTTON_CANCEL").Parent.Visible = false;
|
||||
Game.Disconnect();
|
||||
return true;
|
||||
};
|
||||
widget.GetWidget("CONNECTION_BUTTON_RETRY").OnMouseUp = mi => {
|
||||
Game.JoinServer(host, port);
|
||||
return true;
|
||||
};
|
||||
|
||||
widget.GetWidget<LabelWidget>("CONNECTION_FAILED_DESC").GetText = () =>
|
||||
"Could not connect to {0}:{1}".F(host, port);
|
||||
}
|
||||
}
|
||||
}
|
||||
58
OpenRA.Mods.RA/Widgets/Delegates/CreateServerMenuDelegate.cs
Normal file
58
OpenRA.Mods.RA/Widgets/Delegates/CreateServerMenuDelegate.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
{
|
||||
public class CreateServerMenuDelegate : IWidgetDelegate
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public CreateServerMenuDelegate( [ObjectCreator.Param( "widget" )] Widget cs )
|
||||
{
|
||||
var settings = Game.Settings;
|
||||
|
||||
cs.GetWidget("BUTTON_CANCEL").OnMouseUp = mi => {
|
||||
Widget.CloseWindow();
|
||||
return true;
|
||||
};
|
||||
|
||||
cs.GetWidget("BUTTON_START").OnMouseUp = mi => {
|
||||
var map = Game.modData.AvailableMaps.FirstOrDefault(m => m.Value.Selectable).Key;
|
||||
|
||||
settings.Server.Name = cs.GetWidget<TextFieldWidget>("GAME_TITLE").Text;
|
||||
settings.Server.ListenPort = int.Parse(cs.GetWidget<TextFieldWidget>("LISTEN_PORT").Text);
|
||||
settings.Server.ExternalPort = int.Parse(cs.GetWidget<TextFieldWidget>("EXTERNAL_PORT").Text);
|
||||
settings.Save();
|
||||
|
||||
Game.CreateAndJoinServer(settings, map);
|
||||
return true;
|
||||
};
|
||||
|
||||
cs.GetWidget<TextFieldWidget>("GAME_TITLE").Text = settings.Server.Name;
|
||||
cs.GetWidget<TextFieldWidget>("LISTEN_PORT").Text = settings.Server.ListenPort.ToString();
|
||||
cs.GetWidget<TextFieldWidget>("EXTERNAL_PORT").Text = settings.Server.ExternalPort.ToString();
|
||||
cs.GetWidget<CheckboxWidget>("CHECKBOX_ONLINE").Checked = () => settings.Server.AdvertiseOnline;
|
||||
cs.GetWidget("CHECKBOX_ONLINE").OnMouseDown = mi => {
|
||||
settings.Server.AdvertiseOnline ^= true;
|
||||
settings.Save();
|
||||
return true;
|
||||
};
|
||||
cs.GetWidget<CheckboxWidget>("CHECKBOX_CHEATS").Checked = () => settings.Server.AllowCheats;
|
||||
cs.GetWidget<CheckboxWidget>("CHECKBOX_CHEATS").OnMouseDown = mi => {
|
||||
settings.Server.AllowCheats ^=true;
|
||||
settings.Save();
|
||||
return true;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
113
OpenRA.Mods.RA/Widgets/Delegates/DeveloperModeDelegate.cs
Normal file
113
OpenRA.Mods.RA/Widgets/Delegates/DeveloperModeDelegate.cs
Normal file
@@ -0,0 +1,113 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007,2009,2010 Chris Forbes, Robert Pepperell, Matthew Bowra-Dean, Paul Chote, Alli Witheford.
|
||||
* This file is part of OpenRA.
|
||||
*
|
||||
* OpenRA is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* OpenRA is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with OpenRA. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
{
|
||||
public class DeveloperModeDelegate : IWidgetDelegate
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public DeveloperModeDelegate( [ObjectCreator.Param] World world )
|
||||
{
|
||||
var devmodeBG = Widget.RootWidget.GetWidget("INGAME_ROOT").GetWidget("DEVELOPERMODE_BG");
|
||||
var devModeButton = Widget.RootWidget.GetWidget<ButtonWidget>("INGAME_DEVELOPERMODE_BUTTON");
|
||||
|
||||
devModeButton.OnMouseUp = mi =>
|
||||
{
|
||||
devmodeBG.Visible ^= true;
|
||||
return true;
|
||||
};
|
||||
|
||||
devmodeBG.GetWidget<CheckboxWidget>("CHECKBOX_SHROUD").Checked =
|
||||
() => world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().DisableShroud;
|
||||
devmodeBG.GetWidget<CheckboxWidget>("CHECKBOX_SHROUD").OnMouseDown = mi =>
|
||||
{
|
||||
world.IssueOrder(new Order("DevShroud", world.LocalPlayer.PlayerActor, false));
|
||||
return true;
|
||||
};
|
||||
|
||||
devmodeBG.GetWidget<CheckboxWidget>("CHECKBOX_UNITDEBUG").Checked =
|
||||
() => world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().UnitInfluenceDebug;
|
||||
devmodeBG.GetWidget("CHECKBOX_UNITDEBUG").OnMouseDown = mi =>
|
||||
{
|
||||
world.IssueOrder(new Order("DevUnitDebug", world.LocalPlayer.PlayerActor, false));
|
||||
return true;
|
||||
};
|
||||
|
||||
devmodeBG.GetWidget<CheckboxWidget>("CHECKBOX_PATHDEBUG").Checked =
|
||||
() => world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().PathDebug;
|
||||
devmodeBG.GetWidget("CHECKBOX_PATHDEBUG").OnMouseDown = mi =>
|
||||
{
|
||||
world.IssueOrder(new Order("DevPathDebug", world.LocalPlayer.PlayerActor, false));
|
||||
return true;
|
||||
};
|
||||
|
||||
devmodeBG.GetWidget<ButtonWidget>("GIVE_CASH").OnMouseUp = mi =>
|
||||
{
|
||||
world.IssueOrder(new Order("DevGiveCash", world.LocalPlayer.PlayerActor, false));
|
||||
return true;
|
||||
};
|
||||
|
||||
devmodeBG.GetWidget<CheckboxWidget>("INSTANT_BUILD").Checked =
|
||||
() => world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().FastBuild;
|
||||
devmodeBG.GetWidget<CheckboxWidget>("INSTANT_BUILD").OnMouseDown = mi =>
|
||||
{
|
||||
world.IssueOrder(new Order("DevFastBuild", world.LocalPlayer.PlayerActor, false));
|
||||
return true;
|
||||
};
|
||||
|
||||
devmodeBG.GetWidget<CheckboxWidget>("INSTANT_CHARGE").Checked =
|
||||
() => world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().FastCharge;
|
||||
devmodeBG.GetWidget<CheckboxWidget>("INSTANT_CHARGE").OnMouseDown = mi =>
|
||||
{
|
||||
world.IssueOrder(new Order("DevFastCharge", world.LocalPlayer.PlayerActor, false));
|
||||
return true;
|
||||
};
|
||||
|
||||
devmodeBG.GetWidget<CheckboxWidget>("ENABLE_TECH").Checked =
|
||||
() => world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().AllTech;
|
||||
devmodeBG.GetWidget<CheckboxWidget>("ENABLE_TECH").OnMouseDown = mi =>
|
||||
{
|
||||
world.IssueOrder(new Order("DevEnableTech", world.LocalPlayer.PlayerActor, false));
|
||||
return true;
|
||||
};
|
||||
|
||||
devmodeBG.GetWidget<CheckboxWidget>("UNLIMITED_POWER").Checked =
|
||||
() => world.LocalPlayer.PlayerActor.Trait<DeveloperMode>().UnlimitedPower;
|
||||
devmodeBG.GetWidget<CheckboxWidget>("UNLIMITED_POWER").OnMouseDown = mi =>
|
||||
{
|
||||
world.IssueOrder(new Order("DevUnlimitedPower", world.LocalPlayer.PlayerActor, false));
|
||||
return true;
|
||||
};
|
||||
|
||||
devmodeBG.GetWidget<ButtonWidget>("GIVE_EXPLORATION").OnMouseUp = mi =>
|
||||
{
|
||||
world.IssueOrder(new Order("DevGiveExploration", world.LocalPlayer.PlayerActor, false));
|
||||
return true;
|
||||
};
|
||||
|
||||
devModeButton.IsVisible = () => { return world.LobbyInfo.GlobalSettings.AllowCheats; };
|
||||
}
|
||||
}
|
||||
}
|
||||
145
OpenRA.Mods.RA/Widgets/Delegates/DiplomacyDelegate.cs
Normal file
145
OpenRA.Mods.RA/Widgets/Delegates/DiplomacyDelegate.cs
Normal file
@@ -0,0 +1,145 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.Traits;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
{
|
||||
public class DiplomacyDelegate : IWidgetDelegate
|
||||
{
|
||||
static List<Widget> controls = new List<Widget>();
|
||||
|
||||
int validPlayers = 0;
|
||||
readonly World world;
|
||||
[ObjectCreator.UseCtor]
|
||||
public DiplomacyDelegate( [ObjectCreator.Param] World world )
|
||||
{
|
||||
this.world = world;
|
||||
var root = Widget.RootWidget.GetWidget("INGAME_ROOT");
|
||||
var diplomacyBG = root.GetWidget("DIPLOMACY_BG");
|
||||
var diplomacy = root.GetWidget("INGAME_DIPLOMACY_BUTTON");
|
||||
diplomacy.OnMouseUp = mi =>
|
||||
{
|
||||
diplomacyBG.Visible = !diplomacyBG.Visible;
|
||||
if (diplomacyBG.IsVisible())
|
||||
LayoutDialog(diplomacyBG);
|
||||
return true;
|
||||
};
|
||||
|
||||
Game.AfterGameStart += _ => validPlayers = world.players.Values.Where(a => a != world.LocalPlayer && !a.NonCombatant).Count();
|
||||
diplomacy.IsVisible = () => (validPlayers > 0);
|
||||
}
|
||||
|
||||
void LayoutDialog(Widget bg)
|
||||
{
|
||||
bg.Children.RemoveAll(w => controls.Contains(w));
|
||||
controls.Clear();
|
||||
|
||||
var y = 50;
|
||||
var margin = 20;
|
||||
var labelWidth = (bg.Bounds.Width - 3 * margin) / 3;
|
||||
|
||||
var ts = new LabelWidget
|
||||
{
|
||||
Bold = true,
|
||||
Bounds = new Rectangle(margin + labelWidth + 10, y, labelWidth, 25),
|
||||
Text = "Their Stance",
|
||||
Align = LabelWidget.TextAlign.Left,
|
||||
};
|
||||
|
||||
bg.AddChild(ts);
|
||||
controls.Add(ts);
|
||||
|
||||
var ms = new LabelWidget
|
||||
{
|
||||
Bold = true,
|
||||
Bounds = new Rectangle(margin + 2 * labelWidth + 20, y, labelWidth, 25),
|
||||
Text = "My Stance",
|
||||
Align = LabelWidget.TextAlign.Left,
|
||||
};
|
||||
|
||||
bg.AddChild(ms);
|
||||
controls.Add(ms);
|
||||
|
||||
y += 35;
|
||||
|
||||
foreach (var p in world.players.Values.Where(a => a != world.LocalPlayer && !a.NonCombatant))
|
||||
{
|
||||
var pp = p;
|
||||
var label = new LabelWidget
|
||||
{
|
||||
Bounds = new Rectangle(margin, y, labelWidth, 25),
|
||||
Id = "DIPLOMACY_PLAYER_LABEL_{0}".F(p.Index),
|
||||
Text = p.PlayerName,
|
||||
Align = LabelWidget.TextAlign.Left,
|
||||
Bold = true,
|
||||
};
|
||||
|
||||
bg.AddChild(label);
|
||||
controls.Add(label);
|
||||
|
||||
var theirStance = new LabelWidget
|
||||
{
|
||||
Bounds = new Rectangle( margin + labelWidth + 10, y, labelWidth, 25),
|
||||
Id = "DIPLOMACY_PLAYER_LABEL_THEIR_{0}".F(p.Index),
|
||||
Text = p.PlayerName,
|
||||
Align = LabelWidget.TextAlign.Left,
|
||||
Bold = false,
|
||||
|
||||
GetText = () => pp.Stances[ world.LocalPlayer ].ToString(),
|
||||
};
|
||||
|
||||
bg.AddChild(theirStance);
|
||||
controls.Add(theirStance);
|
||||
|
||||
var myStance = new DropDownButtonWidget
|
||||
{
|
||||
Bounds = new Rectangle( margin + 2 * labelWidth + 20, y, labelWidth, 25),
|
||||
Id = "DIPLOMACY_PLAYER_LABEL_MY_{0}".F(p.Index),
|
||||
Text = world.LocalPlayer.Stances[ pp ].ToString(),
|
||||
};
|
||||
|
||||
myStance.OnMouseDown = mi => { ShowDropDown(pp, myStance); return true; };
|
||||
|
||||
bg.AddChild(myStance);
|
||||
controls.Add(myStance);
|
||||
|
||||
y += 35;
|
||||
}
|
||||
}
|
||||
|
||||
void ShowDropDown(Player p, Widget w)
|
||||
{
|
||||
DropDownButtonWidget.ShowDropDown(w, Enum.GetValues(typeof(Stance)).OfType<Stance>(),
|
||||
(s, width) => new LabelWidget
|
||||
{
|
||||
Bounds = new Rectangle(0, 0, width, 24),
|
||||
Text = " {0}".F(s),
|
||||
OnMouseUp = mi => { SetStance((ButtonWidget)w, p, s); return true; },
|
||||
});
|
||||
}
|
||||
|
||||
void SetStance(ButtonWidget bw, Player p, Stance ss)
|
||||
{
|
||||
if (p.World.LobbyInfo.GlobalSettings.LockTeams)
|
||||
return; // team changes are banned
|
||||
|
||||
world.IssueOrder(new Order("SetStance", world.LocalPlayer.PlayerActor,
|
||||
false) { TargetLocation = new int2(p.Index, (int)ss) });
|
||||
|
||||
bw.Text = ss.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
457
OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs
Executable file
457
OpenRA.Mods.RA/Widgets/Delegates/LobbyDelegate.cs
Executable file
@@ -0,0 +1,457 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Graphics;
|
||||
|
||||
namespace OpenRA.Widgets.Delegates
|
||||
{
|
||||
public class LobbyDelegate : IWidgetDelegate
|
||||
{
|
||||
Widget Players, LocalPlayerTemplate, RemotePlayerTemplate, EmptySlotTemplate, EmptySlotTemplateHost;
|
||||
|
||||
Dictionary<string, string> CountryNames;
|
||||
string MapUid;
|
||||
Map Map;
|
||||
|
||||
public static Color CurrentColorPreview1;
|
||||
public static Color CurrentColorPreview2;
|
||||
|
||||
readonly OrderManager orderManager;
|
||||
[ObjectCreator.UseCtor]
|
||||
internal LobbyDelegate( [ObjectCreator.Param( "widget" )] Widget lobby, [ObjectCreator.Param] OrderManager orderManager )
|
||||
{
|
||||
this.orderManager = orderManager;
|
||||
Game.LobbyInfoChanged += UpdateCurrentMap;
|
||||
UpdateCurrentMap();
|
||||
|
||||
CurrentColorPreview1 = Game.Settings.Player.Color1;
|
||||
CurrentColorPreview2 = Game.Settings.Player.Color2;
|
||||
|
||||
Players = lobby.GetWidget("PLAYERS");
|
||||
LocalPlayerTemplate = Players.GetWidget("TEMPLATE_LOCAL");
|
||||
RemotePlayerTemplate = Players.GetWidget("TEMPLATE_REMOTE");
|
||||
EmptySlotTemplate = Players.GetWidget("TEMPLATE_EMPTY");
|
||||
EmptySlotTemplateHost = Players.GetWidget("TEMPLATE_EMPTY_HOST");
|
||||
|
||||
var mapPreview = lobby.GetWidget<MapPreviewWidget>("LOBBY_MAP_PREVIEW");
|
||||
mapPreview.Map = () => Map;
|
||||
mapPreview.OnSpawnClick = sp =>
|
||||
{
|
||||
if (orderManager.LocalClient.State == Session.ClientState.Ready) return;
|
||||
var owned = orderManager.LobbyInfo.Clients.Any(c => c.SpawnPoint == sp);
|
||||
if (sp == 0 || !owned)
|
||||
orderManager.IssueOrder(Order.Command("spawn {0}".F(sp)));
|
||||
};
|
||||
|
||||
mapPreview.SpawnColors = () =>
|
||||
{
|
||||
var spawns = Map.SpawnPoints;
|
||||
var sc = new Dictionary<int2, Color>();
|
||||
|
||||
for (int i = 1; i <= spawns.Count(); i++)
|
||||
{
|
||||
var client = orderManager.LobbyInfo.Clients.FirstOrDefault(c => c.SpawnPoint == i);
|
||||
if (client == null)
|
||||
continue;
|
||||
sc.Add(spawns.ElementAt(i - 1), client.Color1);
|
||||
}
|
||||
return sc;
|
||||
};
|
||||
|
||||
CountryNames = Rules.Info["world"].Traits.WithInterface<OpenRA.Traits.CountryInfo>().ToDictionary(a => a.Race, a => a.Name);
|
||||
|
||||
CountryNames.Add("random", "Random");
|
||||
|
||||
var mapButton = lobby.GetWidget("CHANGEMAP_BUTTON");
|
||||
mapButton.OnMouseUp = mi =>
|
||||
{
|
||||
Widget.OpenWindow( "MAP_CHOOSER", new Dictionary<string, object> { { "orderManager", orderManager }, { "mapName", MapUid } } );
|
||||
return true;
|
||||
};
|
||||
|
||||
mapButton.IsVisible = () => mapButton.Visible && Game.IsHost;
|
||||
|
||||
var disconnectButton = lobby.GetWidget("DISCONNECT_BUTTON");
|
||||
disconnectButton.OnMouseUp = mi =>
|
||||
{
|
||||
Game.Disconnect();
|
||||
return true;
|
||||
};
|
||||
|
||||
var lockTeamsCheckbox = lobby.GetWidget<CheckboxWidget>("LOCKTEAMS_CHECKBOX");
|
||||
lockTeamsCheckbox.IsVisible = () => lockTeamsCheckbox.Visible && true;
|
||||
lockTeamsCheckbox.Checked = () => orderManager.LobbyInfo.GlobalSettings.LockTeams;
|
||||
lockTeamsCheckbox.OnMouseDown = mi =>
|
||||
{
|
||||
if (Game.IsHost)
|
||||
orderManager.IssueOrder(Order.Command(
|
||||
"lockteams {0}".F(!orderManager.LobbyInfo.GlobalSettings.LockTeams)));
|
||||
return true;
|
||||
};
|
||||
|
||||
var startGameButton = lobby.GetWidget("START_GAME_BUTTON");
|
||||
startGameButton.OnMouseUp = mi =>
|
||||
{
|
||||
mapButton.Visible = false;
|
||||
disconnectButton.Visible = false;
|
||||
lockTeamsCheckbox.Visible = false;
|
||||
orderManager.IssueOrder(Order.Command("startgame"));
|
||||
return true;
|
||||
};
|
||||
|
||||
// Todo: Only show if the map requirements are met for player slots
|
||||
startGameButton.IsVisible = () => Game.IsHost;
|
||||
|
||||
Game.LobbyInfoChanged += JoinedServer;
|
||||
Game.ConnectionStateChanged += ResetConnectionState;
|
||||
Game.LobbyInfoChanged += UpdatePlayerList;
|
||||
|
||||
Game.AddChatLine += lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").AddLine;
|
||||
|
||||
bool teamChat = false;
|
||||
var chatLabel = lobby.GetWidget<LabelWidget>("LABEL_CHATTYPE");
|
||||
var chatTextField = lobby.GetWidget<TextFieldWidget>("CHAT_TEXTFIELD");
|
||||
chatTextField.OnEnterKey = () =>
|
||||
{
|
||||
if (chatTextField.Text.Length == 0)
|
||||
return true;
|
||||
|
||||
var order = (teamChat) ? Order.TeamChat(chatTextField.Text) : Order.Chat(chatTextField.Text);
|
||||
orderManager.IssueOrder(order);
|
||||
chatTextField.Text = "";
|
||||
return true;
|
||||
};
|
||||
|
||||
chatTextField.OnTabKey = () =>
|
||||
{
|
||||
teamChat ^= true;
|
||||
chatLabel.Text = (teamChat) ? "Team:" : "Chat:";
|
||||
return true;
|
||||
};
|
||||
|
||||
var colorChooser = lobby.GetWidget("COLOR_CHOOSER");
|
||||
var hueSlider = colorChooser.GetWidget<SliderWidget>("HUE_SLIDER");
|
||||
var satSlider = colorChooser.GetWidget<SliderWidget>("SAT_SLIDER");
|
||||
var lumSlider = colorChooser.GetWidget<SliderWidget>("LUM_SLIDER");
|
||||
var rangeSlider = colorChooser.GetWidget<SliderWidget>("RANGE_SLIDER");
|
||||
|
||||
hueSlider.OnChange += _ => UpdateColorPreview(hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset(), rangeSlider.GetOffset());
|
||||
satSlider.OnChange += _ => UpdateColorPreview(hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset(), rangeSlider.GetOffset());
|
||||
lumSlider.OnChange += _ => UpdateColorPreview(hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset(), rangeSlider.GetOffset());
|
||||
rangeSlider.OnChange += _ => UpdateColorPreview(hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset(), rangeSlider.GetOffset());
|
||||
|
||||
colorChooser.GetWidget<ButtonWidget>("BUTTON_OK").OnMouseUp = mi =>
|
||||
{
|
||||
colorChooser.IsVisible = () => false;
|
||||
UpdateColorPreview(hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset(), rangeSlider.GetOffset());
|
||||
UpdatePlayerColor(hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset(), rangeSlider.GetOffset());
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
void UpdatePlayerColor(float hf, float sf, float lf, float r)
|
||||
{
|
||||
var c1 = PlayerColorRemap.ColorFromHSL(hf, sf, lf);
|
||||
var c2 = PlayerColorRemap.ColorFromHSL(hf, sf, r * lf);
|
||||
|
||||
Game.Settings.Player.Color1 = c1;
|
||||
Game.Settings.Player.Color2 = c2;
|
||||
Game.Settings.Save();
|
||||
orderManager.IssueOrder(Order.Command("color {0},{1},{2},{3},{4},{5}".F(c1.R,c1.G,c1.B,c2.R,c2.G,c2.B)));
|
||||
}
|
||||
|
||||
void UpdateColorPreview(float hf, float sf, float lf, float r)
|
||||
{
|
||||
CurrentColorPreview1 = PlayerColorRemap.ColorFromHSL(hf, sf, lf);
|
||||
CurrentColorPreview2 = PlayerColorRemap.ColorFromHSL(hf, sf, r * lf);
|
||||
}
|
||||
|
||||
void UpdateCurrentMap()
|
||||
{
|
||||
if (MapUid == orderManager.LobbyInfo.GlobalSettings.Map) return;
|
||||
MapUid = orderManager.LobbyInfo.GlobalSettings.Map;
|
||||
Map = new Map(Game.modData.AvailableMaps[MapUid]);
|
||||
|
||||
var title = Widget.RootWidget.GetWidget<LabelWidget>("LOBBY_TITLE");
|
||||
title.Text = "OpenRA Multiplayer Lobby - " + orderManager.LobbyInfo.GlobalSettings.ServerName;
|
||||
}
|
||||
|
||||
bool hasJoined = false;
|
||||
void JoinedServer()
|
||||
{
|
||||
if (hasJoined)
|
||||
return;
|
||||
hasJoined = true;
|
||||
|
||||
if (orderManager.LocalClient.Name != Game.Settings.Player.Name)
|
||||
orderManager.IssueOrder(Order.Command("name " + Game.Settings.Player.Name));
|
||||
|
||||
var c1 = Game.Settings.Player.Color1;
|
||||
var c2 = Game.Settings.Player.Color2;
|
||||
|
||||
if (orderManager.LocalClient.Color1 != c1 || orderManager.LocalClient.Color2 != c2)
|
||||
orderManager.IssueOrder(Order.Command("color {0},{1},{2},{3},{4},{5}".F(c1.R,c1.G,c1.B,c2.R,c2.G,c2.B)));
|
||||
}
|
||||
|
||||
void ResetConnectionState( OrderManager orderManager )
|
||||
{
|
||||
if( orderManager.Connection.ConnectionState == ConnectionState.PreConnecting )
|
||||
hasJoined = false;
|
||||
}
|
||||
|
||||
Session.Client GetClientInSlot(Session.Slot slot)
|
||||
{
|
||||
return orderManager.LobbyInfo.ClientInSlot( slot );
|
||||
}
|
||||
|
||||
void ShowDropDown(Session.Slot slot, ButtonWidget name, bool showBotOptions)
|
||||
{
|
||||
var dropDownOptions = new List<Pair<string, Action>>
|
||||
{
|
||||
new Pair<string, Action>( "Open",
|
||||
() => orderManager.IssueOrder( Order.Command( "slot_open " + slot.Index ) )),
|
||||
new Pair<string, Action>( "Closed",
|
||||
() => orderManager.IssueOrder( Order.Command( "slot_close " + slot.Index ) )),
|
||||
};
|
||||
|
||||
if (showBotOptions)
|
||||
{
|
||||
var bots = new string[] { "HackyAI" };
|
||||
bots.Do(bot =>
|
||||
dropDownOptions.Add(new Pair<string, Action>("Bot: {0}".F(bot),
|
||||
() => orderManager.IssueOrder(Order.Command("slot_bot {0} {1}".F(slot.Index, bot))))));
|
||||
}
|
||||
|
||||
DropDownButtonWidget.ShowDropDown( name,
|
||||
dropDownOptions,
|
||||
(ac, w) => new LabelWidget
|
||||
{
|
||||
Bounds = new Rectangle(0, 0, w, 24),
|
||||
Text = " {0}".F(ac.First),
|
||||
OnMouseUp = mi => { ac.Second(); return true; },
|
||||
});
|
||||
}
|
||||
|
||||
void UpdatePlayerList()
|
||||
{
|
||||
// This causes problems for people who are in the process of editing their names (the widgets vanish from beneath them)
|
||||
// Todo: handle this nicer
|
||||
Players.Children.Clear();
|
||||
|
||||
int offset = 0;
|
||||
foreach (var slot in orderManager.LobbyInfo.Slots)
|
||||
{
|
||||
var s = slot;
|
||||
var c = GetClientInSlot(s);
|
||||
Widget template;
|
||||
|
||||
if (c == null)
|
||||
{
|
||||
if (Game.IsHost)
|
||||
{
|
||||
if (slot.Spectator)
|
||||
{
|
||||
template = EmptySlotTemplateHost.Clone();
|
||||
var name = template.GetWidget<ButtonWidget>("NAME");
|
||||
var btn = template.GetWidget<ButtonWidget>("JOIN");
|
||||
btn.GetText = () => "Spectate in this slot";
|
||||
name.GetText = () => s.Closed ? "Closed" : "Open";
|
||||
name.OnMouseDown = _ => { ShowDropDown(s, name, false); return true; };
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
template = EmptySlotTemplateHost.Clone();
|
||||
var name = template.GetWidget<ButtonWidget>("NAME");
|
||||
name.GetText = () => s.Closed ? "Closed" : (s.Bot == null) ? "Open" : "Bot: " + s.Bot;
|
||||
name.OnMouseDown = _ => { ShowDropDown(s, name, Map.Players[ s.MapPlayer ].AllowBots); return true; };
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
template = EmptySlotTemplate.Clone();
|
||||
var name = template.GetWidget<LabelWidget>("NAME");
|
||||
name.GetText = () => s.Closed ? "Closed" : (s.Bot == null) ? "Open" : "Bot: " + s.Bot;
|
||||
|
||||
if (slot.Spectator)
|
||||
{
|
||||
var btn = template.GetWidget<ButtonWidget>("JOIN");
|
||||
btn.GetText = () => "Spectate in this slot";
|
||||
}
|
||||
}
|
||||
|
||||
var join = template.GetWidget<ButtonWidget>("JOIN");
|
||||
if (join != null)
|
||||
{
|
||||
join.OnMouseUp = _ => { orderManager.IssueOrder(Order.Command("slot " + s.Index)); return true; };
|
||||
join.IsVisible = () => !s.Closed && s.Bot == null;
|
||||
}
|
||||
}
|
||||
else if (c.Index == orderManager.LocalClient.Index && c.State != Session.ClientState.Ready)
|
||||
{
|
||||
template = LocalPlayerTemplate.Clone();
|
||||
var name = template.GetWidget<TextFieldWidget>("NAME");
|
||||
name.Text = c.Name;
|
||||
name.OnEnterKey = () =>
|
||||
{
|
||||
name.Text = name.Text.Trim();
|
||||
if (name.Text.Length == 0)
|
||||
name.Text = c.Name;
|
||||
|
||||
name.LoseFocus();
|
||||
if (name.Text == c.Name)
|
||||
return true;
|
||||
|
||||
orderManager.IssueOrder(Order.Command("name " + name.Text));
|
||||
Game.Settings.Player.Name = name.Text;
|
||||
Game.Settings.Save();
|
||||
return true;
|
||||
};
|
||||
name.OnLoseFocus = () => name.OnEnterKey();
|
||||
|
||||
var color = template.GetWidget<ButtonWidget>("COLOR");
|
||||
color.OnMouseUp = mi =>
|
||||
{
|
||||
if (Map.Players[s.MapPlayer].LockColor)
|
||||
return false;
|
||||
|
||||
var colorChooser = Widget.RootWidget.GetWidget("SERVER_LOBBY").GetWidget("COLOR_CHOOSER");
|
||||
var hueSlider = colorChooser.GetWidget<SliderWidget>("HUE_SLIDER");
|
||||
hueSlider.SetOffset(orderManager.LocalClient.Color1.GetHue()/360f);
|
||||
|
||||
var satSlider = colorChooser.GetWidget<SliderWidget>("SAT_SLIDER");
|
||||
satSlider.SetOffset(orderManager.LocalClient.Color1.GetSaturation());
|
||||
|
||||
var lumSlider = colorChooser.GetWidget<SliderWidget>("LUM_SLIDER");
|
||||
lumSlider.SetOffset(orderManager.LocalClient.Color1.GetBrightness());
|
||||
|
||||
var rangeSlider = colorChooser.GetWidget<SliderWidget>("RANGE_SLIDER");
|
||||
rangeSlider.SetOffset(orderManager.LocalClient.Color1.GetBrightness() == 0 ? 0 : orderManager.LocalClient.Color2.GetBrightness()/orderManager.LocalClient.Color1.GetBrightness());
|
||||
|
||||
UpdateColorPreview(hueSlider.GetOffset(), satSlider.GetOffset(), lumSlider.GetOffset(), rangeSlider.GetOffset());
|
||||
colorChooser.IsVisible = () => true;
|
||||
return true;
|
||||
};
|
||||
|
||||
var colorBlock = color.GetWidget<ColorBlockWidget>("COLORBLOCK");
|
||||
colorBlock.GetColor = () => c.Color1;
|
||||
|
||||
var faction = template.GetWidget<ButtonWidget>("FACTION");
|
||||
faction.OnMouseUp = mi => CycleRace(mi, s);
|
||||
var factionname = faction.GetWidget<LabelWidget>("FACTIONNAME");
|
||||
factionname.GetText = () => CountryNames[c.Country];
|
||||
var factionflag = faction.GetWidget<ImageWidget>("FACTIONFLAG");
|
||||
factionflag.GetImageName = () => c.Country;
|
||||
factionflag.GetImageCollection = () => "flags";
|
||||
|
||||
var team = template.GetWidget<ButtonWidget>("TEAM");
|
||||
team.OnMouseUp = CycleTeam;
|
||||
team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
|
||||
|
||||
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
||||
status.Checked = () => c.State == Session.ClientState.Ready;
|
||||
status.OnMouseDown = CycleReady;
|
||||
|
||||
Session.Slot slot1 = slot;
|
||||
color.IsVisible = () => !slot1.Spectator;
|
||||
colorBlock.IsVisible = () => !slot1.Spectator;
|
||||
faction.IsVisible = () => !slot1.Spectator;
|
||||
factionname.IsVisible = () => !slot1.Spectator;
|
||||
factionflag.IsVisible = () => !slot1.Spectator;
|
||||
team.IsVisible = () => !slot1.Spectator;
|
||||
}
|
||||
else
|
||||
{
|
||||
template = RemotePlayerTemplate.Clone();
|
||||
template.GetWidget<LabelWidget>("NAME").GetText = () => c.Name;
|
||||
var color = template.GetWidget<ColorBlockWidget>("COLOR");
|
||||
color.GetColor = () => c.Color1;
|
||||
|
||||
var faction = template.GetWidget<LabelWidget>("FACTION");
|
||||
var factionname = faction.GetWidget<LabelWidget>("FACTIONNAME");
|
||||
factionname.GetText = () => CountryNames[c.Country];
|
||||
var factionflag = faction.GetWidget<ImageWidget>("FACTIONFLAG");
|
||||
factionflag.GetImageName = () => c.Country;
|
||||
factionflag.GetImageCollection = () => "flags";
|
||||
|
||||
var team = template.GetWidget<LabelWidget>("TEAM");
|
||||
team.GetText = () => (c.Team == 0) ? "-" : c.Team.ToString();
|
||||
|
||||
var status = template.GetWidget<CheckboxWidget>("STATUS");
|
||||
status.Checked = () => c.State == Session.ClientState.Ready;
|
||||
if (c.Index == orderManager.LocalClient.Index) status.OnMouseDown = CycleReady;
|
||||
|
||||
|
||||
Session.Slot slot1 = slot;
|
||||
color.IsVisible = () => !slot1.Spectator;
|
||||
//colorBlock.IsVisible = () => !slot1.Spectator;
|
||||
faction.IsVisible = () => !slot1.Spectator;
|
||||
factionname.IsVisible = () => !slot1.Spectator;
|
||||
factionflag.IsVisible = () => !slot1.Spectator;
|
||||
team.IsVisible = () => !slot1.Spectator;
|
||||
}
|
||||
|
||||
template.Id = "SLOT_{0}".F(s.Index);
|
||||
template.Parent = Players;
|
||||
|
||||
template.Bounds = new Rectangle(0, offset, template.Bounds.Width, template.Bounds.Height);
|
||||
template.IsVisible = () => true;
|
||||
Players.AddChild(template);
|
||||
|
||||
offset += template.Bounds.Height;
|
||||
}
|
||||
}
|
||||
|
||||
bool SpawnPointAvailable(int index) { return (index == 0) || orderManager.LobbyInfo.Clients.All(c => c.SpawnPoint != index); }
|
||||
bool CycleRace(MouseInput mi, Session.Slot s)
|
||||
{
|
||||
if (Map.Players[s.MapPlayer].LockColor)
|
||||
return false;
|
||||
|
||||
var countries = CountryNames.Select(a => a.Key);
|
||||
|
||||
if (mi.Button == MouseButton.Right)
|
||||
countries = countries.Reverse();
|
||||
|
||||
var nextCountry = countries
|
||||
.SkipWhile(c => c != orderManager.LocalClient.Country)
|
||||
.Skip(1)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (nextCountry == null)
|
||||
nextCountry = countries.First();
|
||||
|
||||
orderManager.IssueOrder(Order.Command("race " + nextCountry));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CycleReady(MouseInput mi)
|
||||
{
|
||||
orderManager.IssueOrder(Order.Command("ready"));
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CycleTeam(MouseInput mi)
|
||||
{
|
||||
var d = (mi.Button == MouseButton.Left) ? +1 : Map.PlayerCount;
|
||||
var newIndex = (orderManager.LocalClient.Team + d) % (Map.PlayerCount + 1);
|
||||
|
||||
orderManager.IssueOrder(
|
||||
Order.Command("team " + newIndex));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
89
OpenRA.Mods.RA/Widgets/Delegates/MainMenuButtonsDelegate.cs
Executable file
89
OpenRA.Mods.RA/Widgets/Delegates/MainMenuButtonsDelegate.cs
Executable file
@@ -0,0 +1,89 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Server;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
{
|
||||
public class MainMenuButtonsDelegate : IWidgetDelegate
|
||||
{
|
||||
static bool FirstInit = true;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public MainMenuButtonsDelegate( [ObjectCreator.Param] Widget widget )
|
||||
{
|
||||
// Main menu is the default window
|
||||
widget.GetWidget( "MAINMENU_BUTTON_JOIN" ).OnMouseUp = mi => { Widget.OpenWindow( "JOINSERVER_BG" ); return true; };
|
||||
widget.GetWidget( "MAINMENU_BUTTON_CREATE" ).OnMouseUp = mi => { Widget.OpenWindow( "CREATESERVER_BG" ); return true; };
|
||||
widget.GetWidget( "MAINMENU_BUTTON_SETTINGS" ).OnMouseUp = mi => { Widget.OpenWindow( "SETTINGS_MENU" ); return true; };
|
||||
widget.GetWidget( "MAINMENU_BUTTON_MUSIC" ).OnMouseUp = mi => { Widget.OpenWindow( "MUSIC_MENU" ); return true; };
|
||||
widget.GetWidget( "MAINMENU_BUTTON_QUIT" ).OnMouseUp = mi => { Game.Exit(); return true; };
|
||||
|
||||
var version = widget.GetWidget<LabelWidget>("VERSION_STRING");
|
||||
|
||||
if (FileSystem.Exists("VERSION"))
|
||||
{
|
||||
var s = FileSystem.Open("VERSION");
|
||||
var versionFileContent = s.ReadAllText();
|
||||
version.Text = versionFileContent;
|
||||
s.Close();
|
||||
|
||||
MasterServerQuery.OnVersion += v =>
|
||||
{
|
||||
if (!string.IsNullOrEmpty(v))
|
||||
version.Text = versionFileContent + "\nLatest: " + v;
|
||||
};
|
||||
MasterServerQuery.GetCurrentVersion(Game.Settings.Server.MasterServer);
|
||||
}
|
||||
else
|
||||
{
|
||||
version.Text = "Dev Build";
|
||||
}
|
||||
MasterServerQuery.ClientVersion = version.Text;
|
||||
|
||||
MasterServerQuery.GetMOTD(Game.Settings.Server.MasterServer);
|
||||
|
||||
if (FirstInit)
|
||||
{
|
||||
FirstInit = false;
|
||||
Game.ConnectionStateChanged += orderManager =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
switch( orderManager.Connection.ConnectionState )
|
||||
{
|
||||
case ConnectionState.PreConnecting:
|
||||
Widget.OpenWindow("MAINMENU_BG");
|
||||
break;
|
||||
case ConnectionState.Connecting:
|
||||
Widget.OpenWindow( "CONNECTING_BG",
|
||||
new Dictionary<string, object> { { "host", orderManager.Host }, { "port", orderManager.Port } } );
|
||||
break;
|
||||
case ConnectionState.NotConnected:
|
||||
Widget.OpenWindow( "CONNECTION_FAILED_BG",
|
||||
new Dictionary<string, object> { { "host", orderManager.Host }, { "port", orderManager.Port } } );
|
||||
break;
|
||||
case ConnectionState.Connected:
|
||||
var lobby = Widget.OpenWindow( "SERVER_LOBBY", new Dictionary<string, object> { { "orderManager", orderManager } } );
|
||||
lobby.GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").ClearChat();
|
||||
lobby.GetWidget("CHANGEMAP_BUTTON").Visible = true;
|
||||
lobby.GetWidget("LOCKTEAMS_CHECKBOX").Visible = true;
|
||||
lobby.GetWidget("DISCONNECT_BUTTON").Visible = true;
|
||||
//r.GetWidget("INGAME_ROOT").GetWidget<ChatDisplayWidget>("CHAT_DISPLAY").ClearChat();
|
||||
break;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
78
OpenRA.Mods.RA/Widgets/Delegates/MapChooserDelegate.cs
Normal file
78
OpenRA.Mods.RA/Widgets/Delegates/MapChooserDelegate.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Network;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
{
|
||||
public class MapChooserDelegate : IWidgetDelegate
|
||||
{
|
||||
MapStub Map = null;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
internal MapChooserDelegate(
|
||||
[ObjectCreator.Param( "widget" )] Widget bg,
|
||||
[ObjectCreator.Param] OrderManager orderManager,
|
||||
[ObjectCreator.Param] string mapName )
|
||||
{
|
||||
if (mapName != null)
|
||||
Map = Game.modData.AvailableMaps[mapName];
|
||||
else
|
||||
Map = Game.modData.AvailableMaps.FirstOrDefault(m => m.Value.Selectable).Value;
|
||||
|
||||
var ml = bg.GetWidget<ListBoxWidget>("MAP_LIST");
|
||||
bg.GetWidget<MapPreviewWidget>("MAPCHOOSER_MAP_PREVIEW").Map = () => Map;
|
||||
bg.GetWidget<LabelWidget>("CURMAP_TITLE").GetText = () => Map.Title;
|
||||
bg.GetWidget<LabelWidget>("CURMAP_SIZE").GetText = () => "{0}x{1}".F(Map.Bounds.Width, Map.Bounds.Height);
|
||||
bg.GetWidget<LabelWidget>("CURMAP_THEATER").GetText = () => Rules.TileSets[Map.Tileset].Name;
|
||||
bg.GetWidget<LabelWidget>("CURMAP_PLAYERS").GetText = () => Map.PlayerCount.ToString();
|
||||
|
||||
bg.GetWidget("BUTTON_OK").OnMouseUp = mi =>
|
||||
{
|
||||
orderManager.IssueOrder(Order.Command("map " + Map.Uid));
|
||||
Widget.CloseWindow();
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget("BUTTON_CANCEL").OnMouseUp = mi =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
return true;
|
||||
};
|
||||
|
||||
var itemTemplate = ml.GetWidget<LabelWidget>("MAP_TEMPLATE");
|
||||
int offset = itemTemplate.Bounds.Y;
|
||||
foreach (var kv in Game.modData.AvailableMaps)
|
||||
{
|
||||
var map = kv.Value;
|
||||
if (!map.Selectable)
|
||||
continue;
|
||||
|
||||
var template = itemTemplate.Clone() as LabelWidget;
|
||||
template.Id = "MAP_{0}".F(map.Uid);
|
||||
template.GetText = () => " " + map.Title;
|
||||
template.GetBackground = () => ((Map == map) ? "dialog2" : null);
|
||||
template.OnMouseDown = mi => { Map = map; return true; };
|
||||
template.Parent = ml;
|
||||
|
||||
template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
|
||||
template.IsVisible = () => true;
|
||||
ml.AddChild(template);
|
||||
|
||||
offset += template.Bounds.Height;
|
||||
ml.ContentHeight += template.Bounds.Height;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
171
OpenRA.Mods.RA/Widgets/Delegates/MusicPlayerDelegate.cs
Normal file
171
OpenRA.Mods.RA/Widgets/Delegates/MusicPlayerDelegate.cs
Normal file
@@ -0,0 +1,171 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
{
|
||||
public class MusicPlayerDelegate : IWidgetDelegate
|
||||
{
|
||||
string CurrentSong = null;
|
||||
public MusicPlayerDelegate()
|
||||
{
|
||||
var bg = Widget.RootWidget.GetWidget("MUSIC_MENU");
|
||||
CurrentSong = GetNextSong();
|
||||
|
||||
bg.GetWidget("BUTTON_CLOSE").OnMouseUp = mi => {
|
||||
Game.Settings.Save();
|
||||
Widget.CloseWindow();
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget("BUTTON_PLAY").OnMouseUp = mi =>
|
||||
{
|
||||
if (CurrentSong == null)
|
||||
return true;
|
||||
|
||||
Sound.PlayMusicThen(Rules.Music[CurrentSong].Filename,
|
||||
() => bg.GetWidget(Game.Settings.Sound.Repeat ? "BUTTON_PLAY" : "BUTTON_NEXT").OnMouseUp(new MouseInput()));
|
||||
bg.GetWidget("BUTTON_PLAY").Visible = false;
|
||||
bg.GetWidget("BUTTON_PAUSE").Visible = true;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget("BUTTON_PAUSE").OnMouseUp = mi =>
|
||||
{
|
||||
Sound.PauseMusic();
|
||||
bg.GetWidget("BUTTON_PAUSE").Visible = false;
|
||||
bg.GetWidget("BUTTON_PLAY").Visible = true;
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget("BUTTON_STOP").OnMouseUp = mi =>
|
||||
{
|
||||
Sound.StopMusic();
|
||||
bg.GetWidget("BUTTON_PAUSE").Visible = false;
|
||||
bg.GetWidget("BUTTON_PLAY").Visible = true;
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget("BUTTON_NEXT").OnMouseUp = mi =>
|
||||
{
|
||||
CurrentSong = GetNextSong();
|
||||
return bg.GetWidget("BUTTON_PLAY").OnMouseUp(mi);
|
||||
};
|
||||
|
||||
bg.GetWidget("BUTTON_PREV").OnMouseUp = mi =>
|
||||
{
|
||||
CurrentSong = GetPrevSong();
|
||||
return bg.GetWidget("BUTTON_PLAY").OnMouseUp(mi);
|
||||
};
|
||||
|
||||
var shuffle = bg.GetWidget<CheckboxWidget>("SHUFFLE");
|
||||
shuffle.OnMouseDown = mi =>
|
||||
{
|
||||
Game.Settings.Sound.Shuffle ^= true;
|
||||
return true;
|
||||
};
|
||||
shuffle.Checked = () => Game.Settings.Sound.Shuffle;
|
||||
|
||||
var repeat = bg.GetWidget<CheckboxWidget>("REPEAT");
|
||||
repeat.OnMouseDown = mi =>
|
||||
{
|
||||
Game.Settings.Sound.Repeat ^= true;
|
||||
return true;
|
||||
};
|
||||
repeat.Checked = () => Game.Settings.Sound.Repeat;
|
||||
|
||||
bg.GetWidget<LabelWidget>("TIME").GetText = () =>
|
||||
{
|
||||
if (CurrentSong == null)
|
||||
return "";
|
||||
return "{0:D2}:{1:D2} / {2:D2}:{3:D2}".F((int)Sound.MusicSeekPosition / 60, (int)Sound.MusicSeekPosition % 60,
|
||||
Rules.Music[CurrentSong].Length / 60, Rules.Music[CurrentSong].Length % 60);
|
||||
};
|
||||
|
||||
var ml = bg.GetWidget<ListBoxWidget>("MUSIC_LIST");
|
||||
var itemTemplate = ml.GetWidget<LabelWidget>("MUSIC_TEMPLATE");
|
||||
int offset = itemTemplate.Bounds.Y;
|
||||
|
||||
if (!Rules.Music.Where(m => m.Value.Exists).Any())
|
||||
{
|
||||
itemTemplate.IsVisible = () => true;
|
||||
itemTemplate.GetWidget<LabelWidget>("TITLE").GetText = () => "No Music Installed";
|
||||
itemTemplate.GetWidget<LabelWidget>("TITLE").Align = LabelWidget.TextAlign.Center;
|
||||
}
|
||||
|
||||
foreach (var kv in Rules.Music.Where(m => m.Value.Exists))
|
||||
{
|
||||
var song = kv.Key;
|
||||
if (CurrentSong == null)
|
||||
CurrentSong = song;
|
||||
|
||||
var template = itemTemplate.Clone() as LabelWidget;
|
||||
template.Id = "SONG_{0}".F(song);
|
||||
template.GetBackground = () => ((song == CurrentSong) ? "dialog2" : null);
|
||||
template.OnMouseDown = mi =>
|
||||
{
|
||||
CurrentSong = song;
|
||||
bg.GetWidget("BUTTON_PLAY").OnMouseUp(mi);
|
||||
return true;
|
||||
};
|
||||
template.Parent = ml;
|
||||
|
||||
template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
|
||||
template.IsVisible = () => true;
|
||||
|
||||
template.GetWidget<LabelWidget>("TITLE").GetText = () => " " + Rules.Music[song].Title;
|
||||
template.GetWidget<LabelWidget>("LENGTH").GetText = () => "{0:D1}:{1:D2}".F(Rules.Music[song].Length / 60, Rules.Music[song].Length % 60);
|
||||
|
||||
ml.AddChild(template);
|
||||
|
||||
offset += template.Bounds.Height;
|
||||
ml.ContentHeight += template.Bounds.Height;
|
||||
}
|
||||
}
|
||||
|
||||
string GetNextSong()
|
||||
{
|
||||
var songs = Rules.Music.Where(a => a.Value.Exists)
|
||||
.Select(a => a.Key);
|
||||
|
||||
if (!songs.Any())
|
||||
return null;
|
||||
|
||||
if (Game.Settings.Sound.Shuffle)
|
||||
return songs.Random(Game.CosmeticRandom);
|
||||
|
||||
return songs.SkipWhile(m => m != CurrentSong)
|
||||
.Skip(1).FirstOrDefault() ?? songs.FirstOrDefault();
|
||||
|
||||
}
|
||||
|
||||
string GetPrevSong()
|
||||
{
|
||||
var songs = Rules.Music.Where(a => a.Value.Exists)
|
||||
.Select(a => a.Key).Reverse();
|
||||
|
||||
if (!songs.Any())
|
||||
return null;
|
||||
|
||||
if (Game.Settings.Sound.Shuffle)
|
||||
return songs.Random(Game.CosmeticRandom);
|
||||
|
||||
return songs.SkipWhile(m => m != CurrentSong)
|
||||
.Skip(1).FirstOrDefault() ?? songs.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
35
OpenRA.Mods.RA/Widgets/Delegates/PerfDebugDelegate.cs
Normal file
35
OpenRA.Mods.RA/Widgets/Delegates/PerfDebugDelegate.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using OpenRA.Support;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
{
|
||||
public class PerfDebugDelegate : IWidgetDelegate
|
||||
{
|
||||
public PerfDebugDelegate()
|
||||
{
|
||||
var r = Widget.RootWidget;
|
||||
var perfRoot = r.GetWidget("PERF_BG");
|
||||
perfRoot.IsVisible = () => perfRoot.Visible && Game.Settings.Debug.PerfGraph;
|
||||
|
||||
// Perf text
|
||||
var perfText = perfRoot.GetWidget<LabelWidget>("TEXT");
|
||||
perfText.GetText = () => "Render {0} ({5}={2:F1} ms)\nTick {4} ({3:F1} ms)".F(
|
||||
Game.RenderFrame,
|
||||
Game.NetFrameNumber,
|
||||
PerfHistory.items["render"].LastValue,
|
||||
PerfHistory.items["tick_time"].LastValue,
|
||||
Game.LocalTick,
|
||||
PerfHistory.items["batches"].LastValue);
|
||||
}
|
||||
}
|
||||
}
|
||||
220
OpenRA.Mods.RA/Widgets/Delegates/ServerBrowserDelegate.cs
Normal file
220
OpenRA.Mods.RA/Widgets/Delegates/ServerBrowserDelegate.cs
Normal file
@@ -0,0 +1,220 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Server;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
{
|
||||
public class ServerBrowserDelegate : IWidgetDelegate
|
||||
{
|
||||
static List<Widget> GameButtons = new List<Widget>();
|
||||
|
||||
GameServer currentServer = null;
|
||||
Widget ServerTemplate;
|
||||
|
||||
[ObjectCreator.UseCtor]
|
||||
public ServerBrowserDelegate( [ObjectCreator.Param] Widget widget )
|
||||
{
|
||||
var bg = widget.GetWidget("JOINSERVER_BG");
|
||||
|
||||
MasterServerQuery.OnComplete += games => RefreshServerList(games);
|
||||
|
||||
bg.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = true;
|
||||
bg.GetWidget<LabelWidget>("JOINSERVER_PROGRESS_TITLE").Text = "Fetching game list...";
|
||||
|
||||
bg.Children.RemoveAll(a => GameButtons.Contains(a));
|
||||
GameButtons.Clear();
|
||||
|
||||
MasterServerQuery.Refresh(Game.Settings.Server.MasterServer);
|
||||
|
||||
bg.GetWidget("SERVER_INFO").IsVisible = () => currentServer != null;
|
||||
var preview = bg.GetWidget<MapPreviewWidget>("MAP_PREVIEW");
|
||||
preview.Map = () => CurrentMap();
|
||||
preview.IsVisible = () => CurrentMap() != null;
|
||||
|
||||
bg.GetWidget<LabelWidget>("SERVER_IP").GetText = () => currentServer.Address;
|
||||
bg.GetWidget<LabelWidget>("SERVER_MODS").GetText = () => GenerateModsLabel();
|
||||
bg.GetWidget<LabelWidget>("MAP_TITLE").GetText = () => (CurrentMap() != null) ? CurrentMap().Title : "Unknown";
|
||||
bg.GetWidget<LabelWidget>("MAP_PLAYERS").GetText = () =>
|
||||
{
|
||||
if (currentServer == null)
|
||||
return "";
|
||||
string ret = currentServer.Players.ToString();
|
||||
if (CurrentMap() != null)
|
||||
ret += "/" + CurrentMap().PlayerCount.ToString();
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
var sl = bg.GetWidget<ListBoxWidget>("SERVER_LIST");
|
||||
ServerTemplate = sl.GetWidget<LabelWidget>("SERVER_TEMPLATE");
|
||||
|
||||
bg.GetWidget("REFRESH_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
bg.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = true;
|
||||
bg.GetWidget<LabelWidget>("JOINSERVER_PROGRESS_TITLE").Text = "Fetching game list...";
|
||||
|
||||
bg.Children.RemoveAll(a => GameButtons.Contains(a));
|
||||
GameButtons.Clear();
|
||||
|
||||
MasterServerQuery.Refresh(Game.Settings.Server.MasterServer);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget("CANCEL_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget("DIRECTCONNECT_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
Widget.OpenWindow("DIRECTCONNECT_BG");
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget("JOIN_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
if (currentServer == null)
|
||||
return false;
|
||||
|
||||
// Todo: Add an error dialog explaining why we aren't letting them join
|
||||
// Or even better, reject them server side and display the error in the connection failed dialog.
|
||||
|
||||
// Don't bother joining a server with different mods... its only going to crash
|
||||
if (currentServer.Mods.SymmetricDifference(Game.modData.Manifest.Mods).Any())
|
||||
{
|
||||
System.Console.WriteLine("Player has different mods to server; not connecting to avoid crash");
|
||||
System.Console.WriteLine("FIX THIS BUG YOU NOOB!");
|
||||
return false;
|
||||
}
|
||||
|
||||
// Prevent user joining a full server
|
||||
if (CurrentMap() != null && currentServer.Players >= CurrentMap().PlayerCount)
|
||||
{
|
||||
System.Console.WriteLine("Server is full; not connecting");
|
||||
return false;
|
||||
}
|
||||
|
||||
Widget.CloseWindow();
|
||||
Game.JoinServer(currentServer.Address.Split(':')[0], int.Parse(currentServer.Address.Split(':')[1]));
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
MapStub CurrentMap()
|
||||
{
|
||||
return (currentServer == null || !Game.modData.AvailableMaps.ContainsKey(currentServer.Map))
|
||||
? null : Game.modData.AvailableMaps[currentServer.Map];
|
||||
}
|
||||
|
||||
string GenerateModsLabel()
|
||||
{
|
||||
return string.Join("\n", currentServer.Mods.Select(m =>
|
||||
Mod.AllMods.ContainsKey(m) ? string.Format("{0} ({1})", Mod.AllMods[m].Title, Mod.AllMods[m].Version)
|
||||
: string.Format("Unknown Mod: {0}",m)).ToArray());
|
||||
}
|
||||
|
||||
void RefreshServerList(IEnumerable<GameServer> games)
|
||||
{
|
||||
var r = Widget.RootWidget;
|
||||
var bg = r.GetWidget("JOINSERVER_BG");
|
||||
|
||||
if (bg == null) // We got a MasterServer reply AFTER the browser is gone, just return to prevent crash - Gecko
|
||||
return;
|
||||
|
||||
var sl = bg.GetWidget<ListBoxWidget>("SERVER_LIST");
|
||||
|
||||
sl.Children.Clear();
|
||||
currentServer = null;
|
||||
|
||||
if (games == null)
|
||||
{
|
||||
r.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = true;
|
||||
r.GetWidget<LabelWidget>("JOINSERVER_PROGRESS_TITLE").Text = "Failed to contact master server.";
|
||||
return;
|
||||
}
|
||||
|
||||
if (games.Count() == 0)
|
||||
{
|
||||
r.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = true;
|
||||
r.GetWidget<LabelWidget>("JOINSERVER_PROGRESS_TITLE").Text = "No games found.";
|
||||
return;
|
||||
}
|
||||
|
||||
r.GetWidget("JOINSERVER_PROGRESS_TITLE").Visible = false;
|
||||
|
||||
int offset = ServerTemplate.Bounds.Y;
|
||||
int i = 0;
|
||||
foreach (var loop in games.Where(g => g.State == 1)) /* only "waiting for players" */
|
||||
{
|
||||
var game = loop;
|
||||
var template = ServerTemplate.Clone() as LabelWidget;
|
||||
template.Id = "JOIN_GAME_{0}".F(i);
|
||||
template.GetText = () => " {0} ({1})".F( /* /8 = hack */
|
||||
game.Name,
|
||||
game.Address);
|
||||
template.GetBackground = () => (currentServer == game) ? "dialog2" : null;
|
||||
template.OnMouseDown = mi => { currentServer = game; return true; };
|
||||
template.Parent = sl;
|
||||
|
||||
template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
|
||||
template.IsVisible = () => true;
|
||||
sl.AddChild(template);
|
||||
|
||||
if (i == 0) currentServer = game;
|
||||
|
||||
offset += template.Bounds.Height;
|
||||
sl.ContentHeight += template.Bounds.Height;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class DirectConnectDelegate : IWidgetDelegate
|
||||
{
|
||||
[ObjectCreator.UseCtor]
|
||||
public DirectConnectDelegate( [ObjectCreator.Param] Widget widget )
|
||||
{
|
||||
var dc = widget.GetWidget("DIRECTCONNECT_BG");
|
||||
|
||||
dc.GetWidget<TextFieldWidget>("SERVER_ADDRESS").Text = Game.Settings.Player.LastServer;
|
||||
|
||||
dc.GetWidget("JOIN_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
var address = dc.GetWidget<TextFieldWidget>("SERVER_ADDRESS").Text;
|
||||
var cpts = address.Split(':').ToArray();
|
||||
if (cpts.Length != 2)
|
||||
return true;
|
||||
|
||||
Game.Settings.Player.LastServer = address;
|
||||
Game.Settings.Save();
|
||||
|
||||
Widget.CloseWindow();
|
||||
Game.JoinServer(cpts[0], int.Parse(cpts[1]));
|
||||
return true;
|
||||
};
|
||||
|
||||
dc.GetWidget("CANCEL_BUTTON").OnMouseUp = mi =>
|
||||
{
|
||||
Widget.CloseWindow();
|
||||
Widget.OpenWindow("MAINMENU_BG");
|
||||
return true;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
186
OpenRA.Mods.RA/Widgets/Delegates/SettingsMenuDelegate.cs
Executable file
186
OpenRA.Mods.RA/Widgets/Delegates/SettingsMenuDelegate.cs
Executable file
@@ -0,0 +1,186 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using OpenRA.FileFormats.Graphics;
|
||||
using OpenRA.GameRules;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
{
|
||||
public class SettingsMenuDelegate : IWidgetDelegate
|
||||
{
|
||||
Widget bg;
|
||||
public SettingsMenuDelegate()
|
||||
{
|
||||
bg = Widget.RootWidget.GetWidget<BackgroundWidget>("SETTINGS_MENU");
|
||||
var tabs = bg.GetWidget<ContainerWidget>("TAB_CONTAINER");
|
||||
|
||||
//Tabs
|
||||
tabs.GetWidget<ButtonWidget>("GENERAL").OnMouseUp = mi => FlipToTab("GENERAL_PANE");
|
||||
tabs.GetWidget<ButtonWidget>("AUDIO").OnMouseUp = mi => FlipToTab("AUDIO_PANE");
|
||||
tabs.GetWidget<ButtonWidget>("DISPLAY").OnMouseUp = mi => FlipToTab("DISPLAY_PANE");
|
||||
tabs.GetWidget<ButtonWidget>("DEBUG").OnMouseUp = mi => FlipToTab("DEBUG_PANE");
|
||||
FlipToTab("GENERAL_PANE");
|
||||
|
||||
//General
|
||||
var general = bg.GetWidget("GENERAL_PANE");
|
||||
|
||||
var name = general.GetWidget<TextFieldWidget>("NAME");
|
||||
name.Text = Game.Settings.Player.Name;
|
||||
name.OnLoseFocus = () =>
|
||||
{
|
||||
name.Text = name.Text.Trim();
|
||||
|
||||
if (name.Text.Length == 0)
|
||||
name.Text = Game.Settings.Player.Name;
|
||||
else
|
||||
Game.Settings.Player.Name = name.Text;
|
||||
};
|
||||
name.OnEnterKey = () => { name.LoseFocus(); return true; };
|
||||
|
||||
var edgeScroll = general.GetWidget<CheckboxWidget>("EDGE_SCROLL");
|
||||
edgeScroll.Checked = () => Game.Settings.Game.ViewportEdgeScroll;
|
||||
edgeScroll.OnMouseDown = mi =>
|
||||
{
|
||||
Game.Settings.Game.ViewportEdgeScroll ^= true;
|
||||
return true;
|
||||
};
|
||||
|
||||
// Added scroll sensitivity - Gecko
|
||||
var edgeScrollSlider = general.GetWidget<SliderWidget>("EDGE_SCROLL_AMOUNT");
|
||||
if (edgeScrollSlider != null) // Backwards compatible - Gecko
|
||||
{
|
||||
edgeScrollSlider.SetOffset(Game.Settings.Game.ViewportEdgeScrollStep);
|
||||
edgeScrollSlider.OnChange += _ => { Game.Settings.Game.ViewportEdgeScrollStep = edgeScrollSlider.GetOffset(); };
|
||||
Game.Settings.Game.ViewportEdgeScrollStep = edgeScrollSlider.GetOffset();
|
||||
}
|
||||
|
||||
var inverseScroll = general.GetWidget<CheckboxWidget>("INVERSE_SCROLL");
|
||||
inverseScroll.Checked = () => Game.Settings.Game.InverseDragScroll;
|
||||
inverseScroll.OnMouseDown = mi =>
|
||||
{
|
||||
Game.Settings.Game.InverseDragScroll ^= true;
|
||||
return true;
|
||||
};
|
||||
|
||||
var teamChatToggle = general.GetWidget<CheckboxWidget>("TEAMCHAT_TOGGLE");
|
||||
teamChatToggle.Checked = () => Game.Settings.Game.TeamChatToggle;
|
||||
teamChatToggle.OnMouseDown = mi =>
|
||||
{
|
||||
Game.Settings.Game.TeamChatToggle ^= true;
|
||||
return true;
|
||||
};
|
||||
|
||||
// Audio
|
||||
var audio = bg.GetWidget("AUDIO_PANE");
|
||||
|
||||
var soundslider = audio.GetWidget<SliderWidget>("SOUND_VOLUME");
|
||||
soundslider.OnChange += x => { Sound.SoundVolume = x; };
|
||||
soundslider.GetOffset = () => { return Sound.SoundVolume; };
|
||||
soundslider.SetOffset(Sound.SoundVolume);
|
||||
|
||||
var musicslider = audio.GetWidget<SliderWidget>("MUSIC_VOLUME");
|
||||
musicslider.OnChange += x => { Sound.MusicVolume = x; };
|
||||
musicslider.GetOffset = () => { return Sound.MusicVolume; };
|
||||
musicslider.SetOffset(Sound.MusicVolume);
|
||||
|
||||
|
||||
// Display
|
||||
var display = bg.GetWidget("DISPLAY_PANE");
|
||||
var fullscreen = display.GetWidget<CheckboxWidget>("FULLSCREEN_CHECKBOX");
|
||||
fullscreen.Checked = () => {return Game.Settings.Graphics.Mode != WindowMode.Windowed;};
|
||||
fullscreen.OnMouseDown = mi =>
|
||||
{
|
||||
Game.Settings.Graphics.Mode = (Game.Settings.Graphics.Mode == WindowMode.Windowed) ? WindowMode.PseudoFullscreen : WindowMode.Windowed;
|
||||
return true;
|
||||
};
|
||||
|
||||
var width = display.GetWidget<TextFieldWidget>("SCREEN_WIDTH");
|
||||
Game.Settings.Graphics.WindowedSize.X = (Game.Settings.Graphics.WindowedSize.X < Game.Settings.Graphics.MinResolution.X)?
|
||||
Game.Settings.Graphics.MinResolution.X : Game.Settings.Graphics.WindowedSize.X;
|
||||
width.Text = Game.Settings.Graphics.WindowedSize.X.ToString();
|
||||
width.OnLoseFocus = () =>
|
||||
{
|
||||
try {
|
||||
var w = int.Parse(width.Text);
|
||||
if (w > Game.Settings.Graphics.MinResolution.X)
|
||||
Game.Settings.Graphics.WindowedSize = new int2(w, Game.Settings.Graphics.WindowedSize.Y);
|
||||
}
|
||||
catch (FormatException) {
|
||||
width.Text = Game.Settings.Graphics.WindowedSize.X.ToString();
|
||||
}
|
||||
};
|
||||
width.OnEnterKey = () => { width.LoseFocus(); return true; };
|
||||
|
||||
var height = display.GetWidget<TextFieldWidget>("SCREEN_HEIGHT");
|
||||
Game.Settings.Graphics.WindowedSize.Y = (Game.Settings.Graphics.WindowedSize.Y < Game.Settings.Graphics.MinResolution.Y)?
|
||||
Game.Settings.Graphics.MinResolution.Y : Game.Settings.Graphics.WindowedSize.Y;
|
||||
height.Text = Game.Settings.Graphics.WindowedSize.Y.ToString();
|
||||
height.OnLoseFocus = () =>
|
||||
{
|
||||
try {
|
||||
var h = int.Parse(height.Text);
|
||||
if (h > Game.Settings.Graphics.MinResolution.Y)
|
||||
Game.Settings.Graphics.WindowedSize = new int2(Game.Settings.Graphics.WindowedSize.X, h);
|
||||
else
|
||||
height.Text = Game.Settings.Graphics.WindowedSize.Y.ToString();
|
||||
}
|
||||
catch (FormatException) {
|
||||
height.Text = Game.Settings.Graphics.WindowedSize.Y.ToString();
|
||||
}
|
||||
};
|
||||
height.OnEnterKey = () => { height.LoseFocus(); return true; };
|
||||
|
||||
// Debug
|
||||
var debug = bg.GetWidget("DEBUG_PANE");
|
||||
var perfdebug = debug.GetWidget<CheckboxWidget>("PERFDEBUG_CHECKBOX");
|
||||
perfdebug.Checked = () => {return Game.Settings.Debug.PerfGraph;};
|
||||
perfdebug.OnMouseDown = mi =>
|
||||
{
|
||||
Game.Settings.Debug.PerfGraph ^= true;
|
||||
return true;
|
||||
};
|
||||
|
||||
var syncreports = debug.GetWidget<CheckboxWidget>("SYNCREPORTS_CHECKBOX");
|
||||
syncreports.Checked = () => { return Game.Settings.Debug.RecordSyncReports; };
|
||||
syncreports.OnMouseDown = mi =>
|
||||
{
|
||||
Game.Settings.Debug.RecordSyncReports ^= true;
|
||||
return true;
|
||||
};
|
||||
|
||||
var timedebug = debug.GetWidget<CheckboxWidget>("GAMETIME_CHECKBOX");
|
||||
timedebug.Checked = () => {return Game.Settings.Game.MatchTimer;};
|
||||
timedebug.OnMouseDown = mi =>
|
||||
{
|
||||
Game.Settings.Game.MatchTimer ^= true;
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget("BUTTON_CLOSE").OnMouseUp = mi => {
|
||||
Game.Settings.Save();
|
||||
Widget.CloseWindow();
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
string open = null;
|
||||
bool FlipToTab(string id)
|
||||
{
|
||||
if (open != null)
|
||||
bg.GetWidget(open).Visible = false;
|
||||
|
||||
open = id;
|
||||
bg.GetWidget(open).Visible = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
93
OpenRA.Mods.RA/Widgets/Delegates/VideoPlayerDelegate.cs
Normal file
93
OpenRA.Mods.RA/Widgets/Delegates/VideoPlayerDelegate.cs
Normal file
@@ -0,0 +1,93 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2010 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 LICENSE.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System.Drawing;
|
||||
using OpenRA.FileFormats;
|
||||
using OpenRA.Widgets;
|
||||
|
||||
namespace OpenRA.Mods.RA.Widgets.Delegates
|
||||
{
|
||||
public class VideoPlayerDelegate : IWidgetDelegate
|
||||
{
|
||||
string Selected;
|
||||
|
||||
public VideoPlayerDelegate()
|
||||
{
|
||||
var bg = Widget.RootWidget.GetWidget("VIDEOPLAYER_MENU");
|
||||
var player = bg.GetWidget<VqaPlayerWidget>("VIDEOPLAYER");
|
||||
|
||||
var pp = bg.GetWidget("BUTTON_PLAYPAUSE");
|
||||
pp.OnMouseUp = mi =>
|
||||
{
|
||||
if (player.Paused)
|
||||
player.Play();
|
||||
else
|
||||
player.Pause();
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
pp.GetWidget("PLAY").IsVisible = () => player.Paused;
|
||||
pp.GetWidget("PAUSE").IsVisible = () => !player.Paused;
|
||||
|
||||
bg.GetWidget("BUTTON_STOP").OnMouseUp = mi =>
|
||||
{
|
||||
player.Stop();
|
||||
return true;
|
||||
};
|
||||
|
||||
bg.GetWidget("BUTTON_CLOSE").OnMouseUp = mi => {
|
||||
player.Stop();
|
||||
Widget.CloseWindow();
|
||||
return true;
|
||||
};
|
||||
|
||||
// Menu Buttons
|
||||
Widget.RootWidget.GetWidget("MAINMENU_BUTTON_VIDEOPLAYER").OnMouseUp = mi => {
|
||||
Widget.OpenWindow("VIDEOPLAYER_MENU");
|
||||
return true;
|
||||
};
|
||||
|
||||
var vl = bg.GetWidget<ListBoxWidget>("VIDEO_LIST");
|
||||
var itemTemplate = vl.GetWidget<LabelWidget>("VIDEO_TEMPLATE");
|
||||
int offset = itemTemplate.Bounds.Y;
|
||||
|
||||
foreach (var kv in Rules.Movies)
|
||||
{
|
||||
var video = kv.Key;
|
||||
var title = kv.Value;
|
||||
if (!FileSystem.Exists(video))
|
||||
continue;
|
||||
|
||||
if (Selected == null)
|
||||
player.Load(Selected = video);
|
||||
|
||||
var template = itemTemplate.Clone() as LabelWidget;
|
||||
template.Id = "VIDEO_{0}".F(video);
|
||||
template.GetText = () => " " + title;
|
||||
template.GetBackground = () => ((video == Selected) ? "dialog2" : null);
|
||||
template.OnMouseDown = mi =>
|
||||
{
|
||||
Selected = video;
|
||||
player.Load(video);
|
||||
return true;
|
||||
};
|
||||
template.Parent = vl;
|
||||
|
||||
template.Bounds = new Rectangle(template.Bounds.X, offset, template.Bounds.Width, template.Bounds.Height);
|
||||
template.IsVisible = () => true;
|
||||
vl.AddChild(template);
|
||||
|
||||
offset += template.Bounds.Height;
|
||||
vl.ContentHeight += template.Bounds.Height;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user