Implement observer shroud selector in C&C.
This commit is contained in:
@@ -422,6 +422,7 @@
|
|||||||
<Compile Include="DebugMuzzlePositions.cs" />
|
<Compile Include="DebugMuzzlePositions.cs" />
|
||||||
<Compile Include="Buildings\BaseProvider.cs" />
|
<Compile Include="Buildings\BaseProvider.cs" />
|
||||||
<Compile Include="Render\WithSpinner.cs" />
|
<Compile Include="Render\WithSpinner.cs" />
|
||||||
|
<Compile Include="Widgets\Logic\ObserverShroudSelectorLogic.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
<ProjectReference Include="..\OpenRA.FileFormats\OpenRA.FileFormats.csproj">
|
||||||
|
|||||||
@@ -62,44 +62,6 @@ namespace OpenRA.Mods.RA.Widgets.Logic
|
|||||||
var chatPanel = Game.LoadWidget(world, "CHAT_PANEL", Ui.Root, new WidgetArgs());
|
var chatPanel = Game.LoadWidget(world, "CHAT_PANEL", Ui.Root, new WidgetArgs());
|
||||||
gameRoot.AddChild(chatPanel);
|
gameRoot.AddChild(chatPanel);
|
||||||
}
|
}
|
||||||
|
|
||||||
var shroudSelector = Ui.Root.GetOrNull<DropDownButtonWidget>("SHROUD_SELECTOR");
|
|
||||||
if (shroudSelector != null)
|
|
||||||
{
|
|
||||||
if (world.RenderedShroud == world.LocalShroud)
|
|
||||||
shroudSelector.GetText = () => world.RenderedPlayer != null ? "{0}'s View".F(world.RenderedPlayer.PlayerName) : "Worldview";
|
|
||||||
|
|
||||||
shroudSelector.OnMouseDown = _ =>
|
|
||||||
{
|
|
||||||
|
|
||||||
var options = world.Players.Where(p => !p.NonCombatant).Select(p => new DropDownOption
|
|
||||||
{
|
|
||||||
Title = "{0}'s View".F(p.PlayerName),
|
|
||||||
IsSelected = () => world.RenderedPlayer == p,
|
|
||||||
OnClick = () => { world.RenderedPlayer = p; world.RenderedShroud.Jank(); }
|
|
||||||
}).ToList();
|
|
||||||
options.Add(new DropDownOption
|
|
||||||
{
|
|
||||||
Title = "Worldview",
|
|
||||||
IsSelected = () => world.RenderedPlayer == null,
|
|
||||||
OnClick = () => { world.RenderedPlayer = null; world.RenderedShroud.Jank(); }
|
|
||||||
});
|
|
||||||
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;
|
|
||||||
};
|
|
||||||
shroudSelector.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", options.Count() * 30, options, setupItem);
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class DropDownOption
|
|
||||||
{
|
|
||||||
public string Title;
|
|
||||||
public Func<bool> IsSelected;
|
|
||||||
public Action OnClick;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
65
OpenRA.Mods.RA/Widgets/Logic/ObserverShroudSelectorLogic.cs
Normal file
65
OpenRA.Mods.RA/Widgets/Logic/ObserverShroudSelectorLogic.cs
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2011 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.Drawing;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRA.Mods.RA.Buildings;
|
||||||
|
using OpenRA.Mods.RA.Orders;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.RA.Widgets.Logic
|
||||||
|
{
|
||||||
|
public class ObserverShroudSelectorLogic
|
||||||
|
{
|
||||||
|
class CameraOption
|
||||||
|
{
|
||||||
|
public string Label;
|
||||||
|
public Func<bool> IsSelected;
|
||||||
|
public Action OnClick;
|
||||||
|
|
||||||
|
public CameraOption(string label, Func<bool> isSelected, Action onClick)
|
||||||
|
{
|
||||||
|
Label = label;
|
||||||
|
IsSelected = isSelected;
|
||||||
|
OnClick = onClick;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[ObjectCreator.UseCtor]
|
||||||
|
public ObserverShroudSelectorLogic(Widget widget, World world)
|
||||||
|
{
|
||||||
|
var views = world.Players.Where(p => !p.NonCombatant).ToDictionary(p => p.PlayerName,
|
||||||
|
p => new CameraOption("{0}'s view".F(p.PlayerName),
|
||||||
|
() => world.RenderedPlayer == p,
|
||||||
|
() => { world.RenderedPlayer = p; world.RenderedShroud.Jank(); }
|
||||||
|
));
|
||||||
|
views.Add("", new CameraOption("World view",
|
||||||
|
() => world.RenderedPlayer == null,
|
||||||
|
() => { world.RenderedPlayer = null; world.RenderedShroud.Jank(); }
|
||||||
|
));
|
||||||
|
|
||||||
|
var shroudSelector = widget.Get<DropDownButtonWidget>("SHROUD_SELECTOR");
|
||||||
|
shroudSelector.GetText = () => views[world.RenderedPlayer == null ? "" : world.RenderedPlayer.PlayerName].Label;
|
||||||
|
shroudSelector.OnMouseDown = _ =>
|
||||||
|
{
|
||||||
|
Func<CameraOption, ScrollItemWidget, ScrollItemWidget> setupItem = (option, template) =>
|
||||||
|
{
|
||||||
|
var item = ScrollItemWidget.Setup(template, option.IsSelected, option.OnClick);
|
||||||
|
item.Get<LabelWidget>("LABEL").GetText = () => option.Label;
|
||||||
|
return item;
|
||||||
|
};
|
||||||
|
shroudSelector.ShowDropDown("LABEL_DROPDOWN_TEMPLATE", views.Count() * 30, views.Values, setupItem);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -71,6 +71,14 @@ Container@OBSERVER_WIDGETS:
|
|||||||
Y:1
|
Y:1
|
||||||
Width:PARENT_RIGHT-2
|
Width:PARENT_RIGHT-2
|
||||||
Height:PARENT_BOTTOM-2
|
Height:PARENT_BOTTOM-2
|
||||||
|
DropDownButton@SHROUD_SELECTOR:
|
||||||
|
Logic:ObserverShroudSelectorLogic
|
||||||
|
X:WINDOW_RIGHT-173
|
||||||
|
Y:172
|
||||||
|
Width:168
|
||||||
|
Height:25
|
||||||
|
Font:Bold
|
||||||
|
Visible:true
|
||||||
Container@PLAYER_WIDGETS:
|
Container@PLAYER_WIDGETS:
|
||||||
Children:
|
Children:
|
||||||
LogicTicker@WIN_LOSS_WATCHER:
|
LogicTicker@WIN_LOSS_WATCHER:
|
||||||
|
|||||||
@@ -305,6 +305,7 @@ Container@OBSERVER_ROOT:
|
|||||||
Height:PARENT_BOTTOM-19
|
Height:PARENT_BOTTOM-19
|
||||||
WorldInteractionController:INTERACTION_CONTROLLER
|
WorldInteractionController:INTERACTION_CONTROLLER
|
||||||
DropDownButton@SHROUD_SELECTOR:
|
DropDownButton@SHROUD_SELECTOR:
|
||||||
|
Logic:ObserverShroudSelectorLogic
|
||||||
X:WINDOW_RIGHT-250
|
X:WINDOW_RIGHT-250
|
||||||
Y:260
|
Y:260
|
||||||
Width:240
|
Width:240
|
||||||
|
|||||||
Reference in New Issue
Block a user