Example #1
0
        bool HandleEvent(ProductionIcon icon, bool isLeftClick, bool handleMultiple)
        {
            var actor = World.Map.Rules.Actors[icon.Name];
            var first = icon.Queued.FirstOrDefault();

            if (isLeftClick)
            {
                // Pick up a completed building
                if (first != null && first.Done && actor.Traits.Contains <BuildingInfo>())
                {
                    Sound.Play(TabClick);
                    World.OrderGenerator = new PlaceBuildingOrderGenerator(CurrentQueue, icon.Name);
                }
                else if (first != null && first.Paused)
                {
                    // Resume a paused item
                    Sound.Play(TabClick);
                    World.IssueOrder(Order.PauseProduction(CurrentQueue.Actor, icon.Name, false));
                }
                else 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));
                }
                else
                {
                    Sound.Play(DisabledTabClick);
                }
            }
            else
            {
                // Hold/Cancel an existing item
                if (first != null)
                {
                    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);
        }
Example #2
0
        public void RefreshIcons()
        {
            icons = new Dictionary <Rectangle, ProductionIcon>();
            if (CurrentQueue == null)
            {
                if (IconCount != 0)
                {
                    OnIconCountChanged(IconCount, 0);
                    IconCount = 0;
                }

                return;
            }

            var allBuildables = CurrentQueue.AllItems().OrderBy(a => a.Traits.Get <BuildableInfo>().BuildPaletteOrder);

            var oldIconCount = IconCount;

            IconCount = 0;

            var ks = Game.Settings.Keys;
            var rb = RenderBounds;

            foreach (var item in allBuildables)
            {
                var x    = IconCount % Columns;
                var y    = IconCount / Columns;
                var rect = new Rectangle(rb.X + x * (IconSize.X + IconMargin.X), rb.Y + y * (IconSize.Y + IconMargin.Y), IconSize.X, IconSize.Y);
                var icon = new Animation(World, RenderSimple.GetImage(item));
                icon.Play(item.Traits.Get <TooltipInfo>().Icon);

                var pi = new ProductionIcon()
                {
                    Actor  = item,
                    Name   = item.Name,
                    Hotkey = ks.GetProductionHotkey(IconCount),
                    Sprite = icon.Image,
                    Pos    = new float2(rect.Location),
                    Queued = CurrentQueue.AllQueued().Where(a => a.Item == item.Name).ToList(),
                };

                icons.Add(rect, pi);
                IconCount++;
            }

            eventBounds = icons.Any() ? icons.Keys.Aggregate(Rectangle.Union) : Rectangle.Empty;

            if (oldIconCount != IconCount)
            {
                OnIconCountChanged(oldIconCount, IconCount);
            }
        }
		public void RefreshIcons()
		{
			icons = new Dictionary<Rectangle, ProductionIcon>();
			if (CurrentQueue == null)
			{
				if (IconCount != 0)
				{
					OnIconCountChanged(IconCount, 0);
					IconCount = 0;
				}

				return;
			}

			var allBuildables = CurrentQueue.AllItems().OrderBy(a => a.Traits.Get<BuildableInfo>().BuildPaletteOrder);

			var oldIconCount = IconCount;
			IconCount = 0;

			var ks = Game.Settings.Keys;
			var rb = RenderBounds;
			foreach (var item in allBuildables)
			{
				var x = IconCount % Columns;
				var y = IconCount / Columns;
				var rect = new Rectangle(rb.X + x * (IconSize.X + IconMargin.X), rb.Y + y * (IconSize.Y + IconMargin.Y), IconSize.X, IconSize.Y);
				var icon = new Animation(World, RenderSimple.GetImage(item));
				icon.Play(item.Traits.Get<TooltipInfo>().Icon);

				var pi = new ProductionIcon()
				{
					Actor = item,
					Name = item.Name,
					Hotkey = ks.GetProductionHotkey(IconCount),
					Sprite = icon.Image,
					Pos = new float2(rect.Location),
					Queued = CurrentQueue.AllQueued().Where(a => a.Item == item.Name).ToList(),
				};

				icons.Add(rect, pi);
				IconCount++;
			}

			eventBounds = icons.Any() ? icons.Keys.Aggregate(Rectangle.Union) : Rectangle.Empty;

			if (oldIconCount != IconCount)
				OnIconCountChanged(oldIconCount, IconCount);
		}
		bool HandleEvent(ProductionIcon icon, bool isLeftClick, bool handleMultiple)
		{
			var actor = World.Map.Rules.Actors[icon.Name];
			var first = icon.Queued.FirstOrDefault();

			if (isLeftClick)
			{
				// Pick up a completed building
				if (first != null && first.Done && actor.Traits.Contains<BuildingInfo>())
				{
					Sound.Play(TabClick);
					World.OrderGenerator = new PlaceBuildingOrderGenerator(CurrentQueue, icon.Name);
				}
				else if (first != null && first.Paused)
				{
					// Resume a paused item
					Sound.Play(TabClick);
					World.IssueOrder(Order.PauseProduction(CurrentQueue.Actor, icon.Name, false));
				}
				else 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));
				}
				else
					Sound.Play(DisabledTabClick);
			}
			else
			{
				// Hold/Cancel an existing item
				if (first != null)
				{
					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;
		}