Disable queue buttons when there are no tabs
This commit is contained in:
@@ -66,11 +66,32 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
|
|||||||
var buildPalette = playerWidgets.GetWidget<ProductionPaletteWidget>("PRODUCTION_PALETTE");
|
var buildPalette = playerWidgets.GetWidget<ProductionPaletteWidget>("PRODUCTION_PALETTE");
|
||||||
var queueTabs = playerWidgets.GetWidget<ProductionTabsWidget>("PRODUCTION_TABS");
|
var queueTabs = playerWidgets.GetWidget<ProductionTabsWidget>("PRODUCTION_TABS");
|
||||||
var queueTypes = sidebarRoot.GetWidget("PRODUCTION_TYPES");
|
var queueTypes = sidebarRoot.GetWidget("PRODUCTION_TYPES");
|
||||||
queueTypes.GetWidget<ButtonWidget>("BUILDING").OnClick = () => queueTabs.QueueType = "Building";
|
|
||||||
queueTypes.GetWidget<ButtonWidget>("DEFENSE").OnClick = () => queueTabs.QueueType = "Defense";
|
var buildingTab = queueTypes.GetWidget<ButtonWidget>("BUILDING");
|
||||||
queueTypes.GetWidget<ButtonWidget>("INFANTRY").OnClick = () => queueTabs.QueueType = "Infantry";
|
buildingTab.OnClick = () => queueTabs.QueueType = "Building";
|
||||||
queueTypes.GetWidget<ButtonWidget>("VEHICLE").OnClick = () => queueTabs.QueueType = "Vehicle";
|
buildingTab.IsDisabled = () => !queueTabs.QueueCounts.ContainsKey("Building")
|
||||||
queueTypes.GetWidget<ButtonWidget>("AIRCRAFT").OnClick = () => queueTabs.QueueType = "Aircraft";
|
|| queueTabs.QueueCounts["Building"] == 0;
|
||||||
|
|
||||||
|
var defenseTab = queueTypes.GetWidget<ButtonWidget>("DEFENSE");
|
||||||
|
defenseTab.OnClick = () => queueTabs.QueueType = "Defense";
|
||||||
|
defenseTab.IsDisabled = () => !queueTabs.QueueCounts.ContainsKey("Defense")
|
||||||
|
|| queueTabs.QueueCounts["Defense"] == 0;
|
||||||
|
|
||||||
|
var infantryTab = queueTypes.GetWidget<ButtonWidget>("INFANTRY");
|
||||||
|
infantryTab.OnClick = () => queueTabs.QueueType = "Infantry";
|
||||||
|
infantryTab.IsDisabled = () => !queueTabs.QueueCounts.ContainsKey("Infantry")
|
||||||
|
|| queueTabs.QueueCounts["Infantry"] == 0;
|
||||||
|
|
||||||
|
var vehicleTab = queueTypes.GetWidget<ButtonWidget>("VEHICLE");
|
||||||
|
vehicleTab.OnClick = () => queueTabs.QueueType = "Vehicle";
|
||||||
|
vehicleTab.IsDisabled = () => !queueTabs.QueueCounts.ContainsKey("Vehicle")
|
||||||
|
|| queueTabs.QueueCounts["Vehicle"] == 0;
|
||||||
|
|
||||||
|
var aircraftTab = queueTypes.GetWidget<ButtonWidget>("AIRCRAFT");
|
||||||
|
aircraftTab.OnClick = () => queueTabs.QueueType = "Aircraft";
|
||||||
|
aircraftTab.IsDisabled = () => !queueTabs.QueueCounts.ContainsKey("Aircraft")
|
||||||
|
|| queueTabs.QueueCounts["Aircraft"] == 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
ingameRoot.GetWidget<ButtonWidget>("OPTIONS_BUTTON").OnClick = () =>
|
ingameRoot.GetWidget<ButtonWidget>("OPTIONS_BUTTON").OnClick = () =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
ListOffset = 0;
|
ListOffset = 0;
|
||||||
ResetButtons();
|
ResetButtons();
|
||||||
Widget.RootWidget.GetWidget<ProductionPaletteWidget>(PaletteWidget)
|
Widget.RootWidget.GetWidget<ProductionPaletteWidget>(PaletteWidget)
|
||||||
.CurrentQueue = VisibleQueues.Keys.FirstOrDefault();
|
.CurrentQueue = tabs.Keys.FirstOrDefault();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +42,10 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
public float ScrollVelocity = 4f;
|
public float ScrollVelocity = 4f;
|
||||||
public int TabWidth = 30;
|
public int TabWidth = 30;
|
||||||
public int ArrowWidth = 20;
|
public int ArrowWidth = 20;
|
||||||
Dictionary<ProductionQueue, Rectangle> VisibleQueues = new Dictionary<ProductionQueue, Rectangle>();
|
|
||||||
|
public ProductionQueue[] AllQueues;
|
||||||
|
public Dictionary<string, int> QueueCounts = new Dictionary<string, int>();
|
||||||
|
Dictionary<ProductionQueue, Rectangle> tabs = new Dictionary<ProductionQueue, Rectangle>();
|
||||||
|
|
||||||
int ContentWidth = 0;
|
int ContentWidth = 0;
|
||||||
float ListOffset = 0;
|
float ListOffset = 0;
|
||||||
@@ -85,14 +88,14 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
var palette = Widget.RootWidget.GetWidget<ProductionPaletteWidget>(PaletteWidget);
|
var palette = Widget.RootWidget.GetWidget<ProductionPaletteWidget>(PaletteWidget);
|
||||||
// TODO: Draw children buttons
|
// TODO: Draw children buttons
|
||||||
var i = 1;
|
var i = 1;
|
||||||
foreach (var queue in VisibleQueues)
|
foreach (var tab in tabs)
|
||||||
{
|
{
|
||||||
ButtonWidget.DrawBackground("button", queue.Value, false, queue.Key == palette.CurrentQueue, queue.Value.Contains(Viewport.LastMousePos));
|
ButtonWidget.DrawBackground("button", tab.Value, false, tab.Key == palette.CurrentQueue, tab.Value.Contains(Viewport.LastMousePos));
|
||||||
|
|
||||||
SpriteFont font = Game.Renderer.Fonts["TinyBold"];
|
SpriteFont font = Game.Renderer.Fonts["TinyBold"];
|
||||||
var text = i.ToString();
|
var text = i.ToString();
|
||||||
int2 textSize = font.Measure(text);
|
int2 textSize = font.Measure(text);
|
||||||
int2 position = new int2(queue.Value.X + (queue.Value.Width - textSize.X)/2, queue.Value.Y + (queue.Value.Height - textSize.Y)/2);
|
int2 position = new int2(tab.Value.X + (tab.Value.Width - textSize.X)/2, tab.Value.Y + (tab.Value.Height - textSize.Y)/2);
|
||||||
font.DrawTextWithContrast(text, position, Color.White, Color.Black, 1);
|
font.DrawTextWithContrast(text, position, Color.White, Color.Black, 1);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
@@ -108,19 +111,15 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
|
|
||||||
public void ResetButtons()
|
public void ResetButtons()
|
||||||
{
|
{
|
||||||
VisibleQueues.Clear();
|
tabs.Clear();
|
||||||
ContentWidth = 0;
|
ContentWidth = 0;
|
||||||
var rb = RenderBounds;
|
var rb = RenderBounds;
|
||||||
var origin = new int2(leftButtonRect.Right - 1 + (int)ListOffset, leftButtonRect.Y);
|
var origin = new int2(leftButtonRect.Right - 1 + (int)ListOffset, leftButtonRect.Y);
|
||||||
|
|
||||||
var queues = world.ActorsWithTrait<ProductionQueue>()
|
foreach (var queue in AllQueues.Where(q => q.Info.Type == QueueType))
|
||||||
.Where(p => p.Actor.Owner == world.LocalPlayer && p.Trait.Info.Type == QueueType)
|
|
||||||
.Select(p => p.Trait).ToList();
|
|
||||||
|
|
||||||
foreach (var queue in queues)
|
|
||||||
{
|
{
|
||||||
var rect = new Rectangle(origin.X + ContentWidth, origin.Y, TabWidth, rb.Height);
|
var rect = new Rectangle(origin.X + ContentWidth, origin.Y, TabWidth, rb.Height);
|
||||||
VisibleQueues.Add(queue, rect);
|
tabs.Add(queue, rect);
|
||||||
ContentWidth += TabWidth - 1;
|
ContentWidth += TabWidth - 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -130,6 +129,13 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
if (leftPressed) Scroll(1);
|
if (leftPressed) Scroll(1);
|
||||||
if (rightPressed) Scroll(-1);
|
if (rightPressed) Scroll(-1);
|
||||||
|
|
||||||
|
AllQueues = world.ActorsWithTrait<ProductionQueue>()
|
||||||
|
.Where(p => p.Actor.Owner == world.LocalPlayer)
|
||||||
|
.Select(p => p.Trait).ToArray();
|
||||||
|
|
||||||
|
QueueCounts = AllQueues.Select(q => q.Info.Type).Distinct()
|
||||||
|
.ToDictionary(t => t, t => AllQueues.Count(q => q.Info.Type == t));
|
||||||
|
|
||||||
ResetButtons();
|
ResetButtons();
|
||||||
base.Tick();
|
base.Tick();
|
||||||
}
|
}
|
||||||
@@ -169,7 +175,7 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
leftPressed = leftButtonRect.Contains(mi.Location.X, mi.Location.Y);
|
leftPressed = leftButtonRect.Contains(mi.Location.X, mi.Location.Y);
|
||||||
rightPressed = rightButtonRect.Contains(mi.Location.X, mi.Location.Y);
|
rightPressed = rightButtonRect.Contains(mi.Location.X, mi.Location.Y);
|
||||||
|
|
||||||
var queue = VisibleQueues.Where(a => a.Value.Contains(mi.Location))
|
var queue = tabs.Where(a => a.Value.Contains(mi.Location))
|
||||||
.Select(a => a.Key).FirstOrDefault();
|
.Select(a => a.Key).FirstOrDefault();
|
||||||
|
|
||||||
if (queue != null)
|
if (queue != null)
|
||||||
|
|||||||
Reference in New Issue
Block a user