Added quick build feature
This commit is contained in:
@@ -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;
|
||||||
|
|||||||
@@ -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;
|
||||||
|
|||||||
@@ -182,59 +182,90 @@ 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void PickUpCompletedBuilding()
|
||||||
|
{
|
||||||
|
foreach (var icon in icons.Values)
|
||||||
|
{
|
||||||
|
var item = icon.Queued.FirstOrDefault();
|
||||||
|
if (PickUpCompletedBuildingIcon(icon, item))
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool HandleLeftClick(ProductionItem item, ProductionIcon icon, bool handleMultiple)
|
||||||
|
{
|
||||||
|
if (PickUpCompletedBuildingIcon(icon, item))
|
||||||
{
|
{
|
||||||
Sound.Play(TabClick);
|
Sound.Play(TabClick);
|
||||||
World.OrderGenerator = new PlaceBuildingOrderGenerator(CurrentQueue, icon.Name);
|
return true;
|
||||||
}
|
}
|
||||||
else if (first != null && first.Paused)
|
|
||||||
|
if (item != null && item.Paused)
|
||||||
{
|
{
|
||||||
// Resume a paused item
|
// Resume a paused item
|
||||||
Sound.Play(TabClick);
|
Sound.Play(TabClick);
|
||||||
World.IssueOrder(Order.PauseProduction(CurrentQueue.Actor, icon.Name, false));
|
World.IssueOrder(Order.PauseProduction(CurrentQueue.Actor, icon.Name, false));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else if (CurrentQueue.BuildableItems().Any(a => a.Name == icon.Name))
|
|
||||||
|
if (CurrentQueue.BuildableItems().Any(a => a.Name == icon.Name))
|
||||||
{
|
{
|
||||||
// Queue a new item
|
// Queue a new item
|
||||||
Sound.Play(TabClick);
|
Sound.Play(TabClick);
|
||||||
Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.QueuedAudio, World.LocalPlayer.Country.Race);
|
Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.QueuedAudio, World.LocalPlayer.Country.Race);
|
||||||
World.IssueOrder(Order.StartProduction(CurrentQueue.Actor, icon.Name,
|
World.IssueOrder(Order.StartProduction(CurrentQueue.Actor, icon.Name,
|
||||||
handleMultiple ? 5 : 1));
|
handleMultiple ? 5 : 1));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
Sound.Play(DisabledTabClick);
|
return false;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
bool HandleRightClick(ProductionItem item, ProductionIcon icon, bool handleMultiple)
|
||||||
// Hold/Cancel an existing item
|
|
||||||
if (first != null)
|
|
||||||
{
|
{
|
||||||
|
if (item == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
Sound.Play(TabClick);
|
Sound.Play(TabClick);
|
||||||
|
|
||||||
// instant cancel of things we havent started yet and things that are finished
|
if (item.Paused || item.Done || item.TotalCost == item.RemainingCost)
|
||||||
if (first.Paused || first.Done || first.TotalCost == first.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);
|
Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.CancelledAudio, World.LocalPlayer.Country.Race);
|
||||||
World.IssueOrder(Order.CancelProduction(CurrentQueue.Actor, icon.Name,
|
World.IssueOrder(Order.CancelProduction(CurrentQueue.Actor, icon.Name,
|
||||||
handleMultiple ? 5 : 1));
|
handleMultiple ? 5 : 1));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// Pause an existing item
|
||||||
Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.OnHoldAudio, World.LocalPlayer.Country.Race);
|
Sound.PlayNotification(World.Map.Rules, World.LocalPlayer, "Speech", CurrentQueue.Info.OnHoldAudio, World.LocalPlayer.Country.Race);
|
||||||
World.IssueOrder(Order.PauseProduction(CurrentQueue.Actor, icon.Name, true));
|
World.IssueOrder(Order.PauseProduction(CurrentQueue.Actor, icon.Name, true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
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);
|
Sound.Play(DisabledTabClick);
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user