Added quick build feature

This commit is contained in:
sinf
2015-04-25 14:58:13 +03:00
parent f6051b1e2b
commit 5991a9b439
4 changed files with 87 additions and 45 deletions

View File

@@ -30,6 +30,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
tabs.SelectNextTab(reverse); tabs.SelectNextTab(reverse);
else else
tabs.QueueGroup = button.ProductionGroup; tabs.QueueGroup = button.ProductionGroup;
tabs.PickUpCompletedBuilding();
}; };
Func<ButtonWidget, Hotkey> getKey = _ => Hotkey.Invalid; Func<ButtonWidget, Hotkey> getKey = _ => Hotkey.Invalid;

View File

@@ -38,6 +38,9 @@ namespace OpenRA.Mods.Common.Widgets.Logic
// When a tab is selected, scroll to the top because the current row position may be invalid for the new tab // When a tab is selected, scroll to the top because the current row position may be invalid for the new tab
palette.ScrollToTop(); palette.ScrollToTop();
// Attempt to pick up a completed building (if there is one) so it can be placed
palette.PickUpCompletedBuilding();
}; };
Func<ButtonWidget, Hotkey> getKey = _ => Hotkey.Invalid; Func<ButtonWidget, Hotkey> getKey = _ => Hotkey.Invalid;

View File

@@ -182,63 +182,94 @@ namespace OpenRA.Mods.Common.Widgets
return HandleEvent(icon, mi.Button == MouseButton.Left, mi.Modifiers.HasModifier(Modifiers.Shift)); return HandleEvent(icon, mi.Button == MouseButton.Left, mi.Modifiers.HasModifier(Modifiers.Shift));
} }
bool HandleEvent(ProductionIcon icon, bool isLeftClick, bool handleMultiple) protected bool PickUpCompletedBuildingIcon(ProductionIcon icon, ProductionItem item)
{ {
var actor = World.Map.Rules.Actors[icon.Name]; var actor = World.Map.Rules.Actors[icon.Name];
var first = icon.Queued.FirstOrDefault();
if (isLeftClick) if (item != null && item.Done && actor.Traits.Contains<BuildingInfo>())
{ {
// Pick up a completed building World.OrderGenerator = new PlaceBuildingOrderGenerator(CurrentQueue, icon.Name);
if (first != null && first.Done && actor.Traits.Contains<BuildingInfo>()) return true;
{ }
Sound.Play(TabClick);
World.OrderGenerator = new PlaceBuildingOrderGenerator(CurrentQueue, icon.Name); return false;
} }
else if (first != null && first.Paused)
{ public void PickUpCompletedBuilding()
// Resume a paused item {
Sound.Play(TabClick); foreach (var icon in icons.Values)
World.IssueOrder(Order.PauseProduction(CurrentQueue.Actor, icon.Name, false)); {
} var item = icon.Queued.FirstOrDefault();
else if (CurrentQueue.BuildableItems().Any(a => a.Name == icon.Name)) if (PickUpCompletedBuildingIcon(icon, item))
{ break;
// Queue a new item }
Sound.Play(TabClick); }
Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.QueuedAudio, World.LocalPlayer.Country.Race);
World.IssueOrder(Order.StartProduction(CurrentQueue.Actor, icon.Name, bool HandleLeftClick(ProductionItem item, ProductionIcon icon, bool handleMultiple)
handleMultiple ? 5 : 1)); {
} if (PickUpCompletedBuildingIcon(icon, item))
else {
Sound.Play(DisabledTabClick); Sound.Play(TabClick);
return true;
}
if (item != null && item.Paused)
{
// Resume a paused item
Sound.Play(TabClick);
World.IssueOrder(Order.PauseProduction(CurrentQueue.Actor, icon.Name, false));
return true;
}
if (CurrentQueue.BuildableItems().Any(a => a.Name == icon.Name))
{
// Queue a new item
Sound.Play(TabClick);
Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.QueuedAudio, World.LocalPlayer.Country.Race);
World.IssueOrder(Order.StartProduction(CurrentQueue.Actor, icon.Name,
handleMultiple ? 5 : 1));
return true;
}
return false;
}
bool HandleRightClick(ProductionItem item, ProductionIcon icon, bool handleMultiple)
{
if (item == null)
return false;
Sound.Play(TabClick);
if (item.Paused || item.Done || item.TotalCost == item.RemainingCost)
{
// Instant cancel of things we have not started yet and things that are finished
Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.CancelledAudio, World.LocalPlayer.Country.Race);
World.IssueOrder(Order.CancelProduction(CurrentQueue.Actor, icon.Name,
handleMultiple ? 5 : 1));
} }
else else
{ {
// Hold/Cancel an existing item // Pause an existing item
if (first != null) Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.OnHoldAudio, World.LocalPlayer.Country.Race);
{ World.IssueOrder(Order.PauseProduction(CurrentQueue.Actor, icon.Name, true));
Sound.Play(TabClick);
// instant cancel of things we havent started yet and things that are finished
if (first.Paused || first.Done || first.TotalCost == first.RemainingCost)
{
Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.CancelledAudio, World.LocalPlayer.Country.Race);
World.IssueOrder(Order.CancelProduction(CurrentQueue.Actor, icon.Name,
handleMultiple ? 5 : 1));
}
else
{
Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.OnHoldAudio, World.LocalPlayer.Country.Race);
World.IssueOrder(Order.PauseProduction(CurrentQueue.Actor, icon.Name, true));
}
}
else
Sound.Play(DisabledTabClick);
} }
return true; return true;
} }
bool HandleEvent(ProductionIcon icon, bool isLeftClick, bool handleMultiple)
{
var item = icon.Queued.FirstOrDefault();
var handled = isLeftClick ? HandleLeftClick(item, icon, handleMultiple)
: HandleRightClick(item, icon, handleMultiple);
if (!handled)
Sound.Play(DisabledTabClick);
return true;
}
public override bool HandleKeyPress(KeyInput e) public override bool HandleKeyPress(KeyInput e)
{ {
if (e.Event == KeyInputEvent.Up || CurrentQueue == null) if (e.Event == KeyInputEvent.Up || CurrentQueue == null)

View File

@@ -110,6 +110,12 @@ namespace OpenRA.Mods.Common.Widgets
return true; return true;
} }
public void PickUpCompletedBuilding()
{
// This is called from ProductionTabsLogic
paletteWidget.Value.PickUpCompletedBuilding();
}
public string QueueGroup public string QueueGroup
{ {
get get