Fix ra queue visibility
This commit is contained in:
@@ -50,7 +50,6 @@ namespace OpenRA.Traits
|
||||
foreach (var a in Rules.TechTree.AllBuildables(Info.Type))
|
||||
{
|
||||
var bi = a.Traits.Get<BuildableInfo>();
|
||||
Console.WriteLine(a.Name);
|
||||
// Can our race build this by satisfying normal prereqs?
|
||||
var buildable = bi.Owner.Contains(self.Owner.Country.Race);
|
||||
Produceable.Add( a, new ProductionState(){ Visible = buildable && !bi.Hidden } );
|
||||
@@ -89,8 +88,12 @@ namespace OpenRA.Traits
|
||||
return Queue;
|
||||
}
|
||||
|
||||
ActorInfo[] None = new ActorInfo[]{};
|
||||
public IEnumerable<ActorInfo> AllItems()
|
||||
{
|
||||
if (!QueueActive)
|
||||
return None;
|
||||
|
||||
if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().AllTech)
|
||||
return Produceable.Select(a => a.Key);
|
||||
|
||||
@@ -99,6 +102,9 @@ namespace OpenRA.Traits
|
||||
|
||||
public IEnumerable<ActorInfo> BuildableItems()
|
||||
{
|
||||
if (!QueueActive)
|
||||
return None;
|
||||
|
||||
if (Game.LobbyInfo.GlobalSettings.AllowCheats && self.Owner.PlayerActor.Trait<DeveloperMode>().AllTech)
|
||||
return Produceable.Select(a => a.Key);
|
||||
|
||||
@@ -111,11 +117,17 @@ namespace OpenRA.Traits
|
||||
return Rules.TechTree.CanBuild(actor, self.Owner, buildings);
|
||||
}
|
||||
|
||||
[Sync] bool QueueActive = true;
|
||||
public void Tick( Actor self )
|
||||
{
|
||||
if (!initialized)
|
||||
Initialize();
|
||||
|
||||
if (self == self.Owner.PlayerActor)
|
||||
QueueActive = self.World.Queries.OwnedBy[self.Owner].WithTrait<Production>()
|
||||
.Where(x => x.Trait.Info.Produces.Contains(Info.Type))
|
||||
.Any();
|
||||
|
||||
while( Queue.Count > 0 && !BuildableItems().Any(b => b.Name == Queue[ 0 ].Item) )
|
||||
{
|
||||
self.Owner.PlayerActor.Trait<PlayerResources>().GiveCash(Queue[0].TotalCost - Queue[0].RemainingCost); // refund what's been paid so far.
|
||||
@@ -227,15 +239,9 @@ namespace OpenRA.Traits
|
||||
|
||||
void BuildUnit( string name )
|
||||
{
|
||||
// If the actor has a production trait, use it.
|
||||
var sp = self.TraitsImplementing<Production>().Where(p => p.Info.Produces.Contains(Info.Type)).FirstOrDefault();
|
||||
if (sp != null)
|
||||
if (self == self.Owner.PlayerActor)
|
||||
{
|
||||
if (!IsDisabledBuilding(self) && sp.Produce(self, Rules.Info[ name ]))
|
||||
FinishProduction();
|
||||
return;
|
||||
}
|
||||
|
||||
// original ra behavior; queue lives on PlayerActor, need to find a production structure
|
||||
var producers = self.World.Queries.OwnedBy[self.Owner]
|
||||
.WithTrait<Production>()
|
||||
.Where(x => x.Trait.Info.Produces.Contains(Info.Type))
|
||||
@@ -259,6 +265,14 @@ namespace OpenRA.Traits
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// queue lives on actor; is produced at same actor
|
||||
var sp = self.TraitsImplementing<Production>().Where(p => p.Info.Produces.Contains(Info.Type)).FirstOrDefault();
|
||||
if (sp != null && !IsDisabledBuilding(self) && sp.Produce(self, Rules.Info[ name ]))
|
||||
FinishProduction();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class ProductionState
|
||||
|
||||
@@ -26,7 +26,7 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
public int Rows = 5;
|
||||
|
||||
ProductionQueue CurrentQueue = null;
|
||||
List<ProductionQueue> visibleTabs = new List<ProductionQueue>();
|
||||
List<ProductionQueue> VisibleQueues = new List<ProductionQueue>();
|
||||
|
||||
bool paletteOpen = false;
|
||||
Dictionary<string, Sprite> iconSprites;
|
||||
@@ -75,20 +75,21 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
|
||||
public override void Tick(World world)
|
||||
{
|
||||
visibleTabs.Clear();
|
||||
VisibleQueues.Clear();
|
||||
|
||||
var queues = world.Queries.WithTraitMultiple<ProductionQueue>()
|
||||
.Where(p => p.Actor.Owner == world.LocalPlayer)
|
||||
.Select(p => p.Trait);
|
||||
|
||||
foreach (var queue in queues)
|
||||
if (queue.BuildableItems().Count() > 0)
|
||||
visibleTabs.Add(queue);
|
||||
{
|
||||
if (queue.AllItems().Count() > 0)
|
||||
VisibleQueues.Add(queue);
|
||||
else if (CurrentQueue == queue)
|
||||
CurrentQueue = null;
|
||||
|
||||
}
|
||||
if (CurrentQueue == null)
|
||||
CurrentQueue = queues.FirstOrDefault();
|
||||
CurrentQueue = VisibleQueues.FirstOrDefault();
|
||||
|
||||
TickPaletteAnimation(world);
|
||||
|
||||
@@ -386,11 +387,7 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
|
||||
tabs.Clear();
|
||||
|
||||
var queues = world.Queries.WithTraitMultiple<ProductionQueue>()
|
||||
.Where(p => p.Actor.Owner == world.LocalPlayer)
|
||||
.Select(p => p.Trait);
|
||||
|
||||
foreach (var queue in queues)
|
||||
foreach (var queue in VisibleQueues)
|
||||
{
|
||||
string[] tabKeys = { "normal", "ready", "selected" };
|
||||
var producing = queue.CurrentItem();
|
||||
@@ -500,23 +497,23 @@ namespace OpenRA.Mods.RA.Widgets
|
||||
|
||||
void TabChange(bool shift)
|
||||
{
|
||||
int size = visibleTabs.Count();
|
||||
int size = VisibleQueues.Count();
|
||||
if (size > 0)
|
||||
{
|
||||
int current = visibleTabs.IndexOf(CurrentQueue);
|
||||
int current = VisibleQueues.IndexOf(CurrentQueue);
|
||||
if (!shift)
|
||||
{
|
||||
if (current + 1 >= size)
|
||||
SetCurrentTab(visibleTabs.FirstOrDefault());
|
||||
SetCurrentTab(VisibleQueues.FirstOrDefault());
|
||||
else
|
||||
SetCurrentTab(visibleTabs[current + 1]);
|
||||
SetCurrentTab(VisibleQueues[current + 1]);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (current - 1 < 0)
|
||||
SetCurrentTab(visibleTabs.LastOrDefault());
|
||||
SetCurrentTab(VisibleQueues.LastOrDefault());
|
||||
else
|
||||
SetCurrentTab(visibleTabs[current - 1]);
|
||||
SetCurrentTab(VisibleQueues[current - 1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user