Save and restore viewport position / selection / control groups.
This commit is contained in:
@@ -200,5 +200,42 @@ namespace OpenRA
|
|||||||
.Select(g => (int?)g.Key)
|
.Select(g => (int?)g.Key)
|
||||||
.FirstOrDefault();
|
.FirstOrDefault();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<MiniYamlNode> Serialize()
|
||||||
|
{
|
||||||
|
var groups = controlGroups
|
||||||
|
.Where(cg => cg.Value.Any())
|
||||||
|
.Select(cg => new MiniYamlNode(cg.Key.ToString(),
|
||||||
|
FieldSaver.FormatValue(cg.Value.Select(a => a.ActorID).ToArray())))
|
||||||
|
.ToList();
|
||||||
|
|
||||||
|
return new List<MiniYamlNode>()
|
||||||
|
{
|
||||||
|
new MiniYamlNode("Selection", FieldSaver.FormatValue(Actors.Select(a => a.ActorID).ToArray())),
|
||||||
|
new MiniYamlNode("Groups", new MiniYaml("", groups))
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Deserialize(World world, List<MiniYamlNode> data)
|
||||||
|
{
|
||||||
|
var selectionNode = data.FirstOrDefault(n => n.Key == "Selection");
|
||||||
|
if (selectionNode != null)
|
||||||
|
{
|
||||||
|
var selected = FieldLoader.GetValue<uint[]>("Selection", selectionNode.Value.Value)
|
||||||
|
.Select(a => world.GetActorById(a));
|
||||||
|
Combine(world, selected, false, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
var groupsNode = data.FirstOrDefault(n => n.Key == "Groups");
|
||||||
|
if (groupsNode != null)
|
||||||
|
{
|
||||||
|
foreach (var n in groupsNode.Value.Nodes)
|
||||||
|
{
|
||||||
|
var group = FieldLoader.GetValue<uint[]>(n.Key, n.Value.Value)
|
||||||
|
.Select(a => world.GetActorById(a));
|
||||||
|
controlGroups[int.Parse(n.Key)].AddRange(group);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -568,6 +568,7 @@
|
|||||||
<Compile Include="Traits\World\JumpjetLocomotor.cs" />
|
<Compile Include="Traits\World\JumpjetLocomotor.cs" />
|
||||||
<Compile Include="Traits\World\PaletteFromEmbeddedSpritePalette.cs" />
|
<Compile Include="Traits\World\PaletteFromEmbeddedSpritePalette.cs" />
|
||||||
<Compile Include="Traits\World\ResourceType.cs" />
|
<Compile Include="Traits\World\ResourceType.cs" />
|
||||||
|
<Compile Include="Traits\World\GameSaveViewportManager.cs" />
|
||||||
<Compile Include="Traits\World\SubterraneanLocomotor.cs" />
|
<Compile Include="Traits\World\SubterraneanLocomotor.cs" />
|
||||||
<Compile Include="Traits\World\LoadWidgetAtGameStart.cs" />
|
<Compile Include="Traits\World\LoadWidgetAtGameStart.cs" />
|
||||||
<Compile Include="Traits\World\MPStartLocations.cs" />
|
<Compile Include="Traits\World\MPStartLocations.cs" />
|
||||||
|
|||||||
53
OpenRA.Mods.Common/Traits/World/GameSaveViewportManager.cs
Normal file
53
OpenRA.Mods.Common/Traits/World/GameSaveViewportManager.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2019 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, either version 3 of
|
||||||
|
* the License, or (at your option) any later version. For more
|
||||||
|
* information, see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using OpenRA.Graphics;
|
||||||
|
using OpenRA.Traits;
|
||||||
|
|
||||||
|
namespace OpenRA.Mods.Common.Traits
|
||||||
|
{
|
||||||
|
public class GameSaveViewportManagerInfo : ITraitInfo
|
||||||
|
{
|
||||||
|
public object Create(ActorInitializer init) { return new GameSaveViewportManager(); }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class GameSaveViewportManager : IWorldLoaded, IGameSaveTraitData
|
||||||
|
{
|
||||||
|
WorldRenderer worldRenderer;
|
||||||
|
|
||||||
|
void IWorldLoaded.WorldLoaded(World w, WorldRenderer wr) { worldRenderer = wr; }
|
||||||
|
|
||||||
|
List<MiniYamlNode> IGameSaveTraitData.IssueTraitData(Actor self)
|
||||||
|
{
|
||||||
|
if (worldRenderer.World.LocalPlayer == null || self != worldRenderer.World.LocalPlayer.PlayerActor)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new List<MiniYamlNode>()
|
||||||
|
{
|
||||||
|
new MiniYamlNode("Viewport", FieldSaver.FormatValue(worldRenderer.Viewport.CenterPosition)),
|
||||||
|
new MiniYamlNode("Selection", "", self.World.Selection.Serialize())
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
void IGameSaveTraitData.ResolveTraitData(Actor self, List<MiniYamlNode> data)
|
||||||
|
{
|
||||||
|
var viewportNode = data.FirstOrDefault(n => n.Key == "Viewport");
|
||||||
|
if (viewportNode != null)
|
||||||
|
worldRenderer.Viewport.Center(FieldLoader.GetValue<WPos>("data", viewportNode.Value.Value));
|
||||||
|
|
||||||
|
var selectionNode = data.FirstOrDefault(n => n.Key == "Selection");
|
||||||
|
if (selectionNode != null)
|
||||||
|
self.World.Selection.Deserialize(self.World, selectionNode.Value.Nodes);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -59,3 +59,4 @@ Player:
|
|||||||
ResourceStorageWarning:
|
ResourceStorageWarning:
|
||||||
PlayerExperience:
|
PlayerExperience:
|
||||||
ConditionManager:
|
ConditionManager:
|
||||||
|
GameSaveViewportManager:
|
||||||
|
|||||||
@@ -145,3 +145,4 @@ Player:
|
|||||||
AdviceInterval: 26
|
AdviceInterval: 26
|
||||||
PlayerExperience:
|
PlayerExperience:
|
||||||
ConditionManager:
|
ConditionManager:
|
||||||
|
GameSaveViewportManager:
|
||||||
|
|||||||
@@ -144,3 +144,4 @@ Player:
|
|||||||
ResourceStorageWarning:
|
ResourceStorageWarning:
|
||||||
PlayerExperience:
|
PlayerExperience:
|
||||||
ConditionManager:
|
ConditionManager:
|
||||||
|
GameSaveViewportManager:
|
||||||
|
|||||||
@@ -120,3 +120,4 @@ Player:
|
|||||||
ResourceStorageWarning:
|
ResourceStorageWarning:
|
||||||
PlayerExperience:
|
PlayerExperience:
|
||||||
ConditionManager:
|
ConditionManager:
|
||||||
|
GameSaveViewportManager:
|
||||||
|
|||||||
Reference in New Issue
Block a user