コード例 #1
0
        public override bool HandleMouseInput(MouseInput mi)
        {
            if (!EventBounds.Contains(mi.Location))
            {
                return(false);
            }

            if (mi.Button != MouseButton.Left)
            {
                return(true);
            }

            if (mi.Event == MouseInputEvent.Down)
            {
                ShowResearch = !ShowResearch;

                if (ShowResearch && !ResearchButtons.Any())
                {
                    CreateResearchMenu();
                }
                else if (!ShowResearch && ResearchButtons.Any())
                {
                    RemoveResearchMenu();
                }

                pressed = true;
            }
            else if (mi.Event == MouseInputEvent.Up)
            {
                pressed = false;
            }

            return(true);
        }
コード例 #2
0
        public override bool HandleMouseInput(MouseInput mi)
        {
            // TODO this whole block can be removed when arrows are widgets!
            if (EventBounds.Contains(mi.Location))
            {
                if (mi.Event == MouseInputEvent.Down)
                {
                    if (mi.Location.Y - EventBounds.Y >= visibleIcons * ButtonWidget.Size)
                    {
                        var arrow = (mi.Location.X - EventBounds.X) / (ButtonWidget.Size / 2);

                        if (arrow == 0 && scrollOffset + visibleIcons < buildableItems.Length)
                        {
                            Game.Sound.PlayNotification(sidebar.IngameUi.World.Map.Rules, null, "Sounds", "ClickSound", null);
                            scrollOffset++;
                        }
                        else if (arrow == 1 && scrollOffset > 0)
                        {
                            Game.Sound.PlayNotification(sidebar.IngameUi.World.Map.Rules, null, "Sounds", "ClickSound", null);
                            scrollOffset--;
                        }
                    }
                }
                else if (mi.Event == MouseInputEvent.Scroll)
                {
                    scrollOffset = Math.Max(0, Math.Min(scrollOffset += mi.ScrollDelta < 0 ? 1 : -1, buildableItems.Length - visibleIcons));
                }

                return(true);
            }

            return(false);
        }
コード例 #3
0
        public override bool HandleMouseInput(MouseInput mi)
        {
            if (!EventBounds.Contains(mi.Location))
            {
                tooltip.Visible = false;
                return(false);
            }

            tooltip.Visible = true;
            if (disabled)
            {
                return(false);
            }
            if (mi.Button != MouseButton.Left)
            {
                return(true);
            }
            var pr = actorActions.BamUi.World.LocalPlayer.PlayerActor.Trait <PlayerResources>();

            if (actorActions.Actor != null && mi.Event == MouseInputEvent.Down && pr.Cash + pr.Resources >= actorActions.BamUi.World.Map.Rules.Actors[actorString].TraitInfo <ValuedInfo>().Cost)
            {
                actorActions.Actor.World.IssueOrder(new Order("Convert-" + actorString, actorActions.Actor, false));
                pressed = true;
            }
            else if (mi.Event == MouseInputEvent.Up)
            {
                pressed = false;
            }

            return(true);
        }
コード例 #4
0
        public override bool HandleMouseInput(MouseInput mi)
        {
            if (!EventBounds.Contains(mi.Location) || SelectedValidActors.Count < 4)
            {
                return(false);
            }

            if (mi.Button != MouseButton.Left)
            {
                return(true);
            }

            if (mi.Event == MouseInputEvent.Down)
            {
                SelectedValidActors.First().World.IssueOrder(new Order("TransformTo", actorActions.Actor, false));
                foreach (var actor in SelectedValidActors)
                {
                    actor.World.IssueOrder(new Order("RemoveSelf", actor, false));
                }

                pressed = true;
            }

            if (mi.Event == MouseInputEvent.Up)
            {
                pressed = false;
            }

            return(true);
        }
コード例 #5
0
        public override bool HandleMouseInput(MouseInput mi)
        {
            if (!EventBounds.Contains(mi.Location))
            {
                return(false);
            }

            if (mi.Button != MouseButton.Left)
            {
                return(true);
            }

            if (mi.Event == MouseInputEvent.Down)
            {
                var actors = actorActions.ActorGroup.Where(a => a.Info.HasTraitInfo <ManaShooterInfo>()).ToArray();

                foreach (var actor in actors)
                {
                    actor.World.IssueOrder(new Order("ShootMana", actor, false));
                }

                pressed = true;
            }
            else if (mi.Event == MouseInputEvent.Up)
            {
                pressed = false;
            }

            return(true);
        }
コード例 #6
0
        public string GetCursorOuter(int2 pos)
        {
            // Is the cursor on top of us?
            if (!(IsVisible() && GetEventBounds().Contains(pos)))
            {
                return(null);
            }

            // Do any of our children specify a cursor?
            foreach (var child in Children.OfType <Widget>().Reverse())
            {
                var cc = child.GetCursorOuter(pos);
                if (cc != null)
                {
                    return(cc);
                }
            }

            return(EventBounds.Contains(pos) ? GetCursor(pos) : null);
        }
コード例 #7
0
        public override bool HandleMouseInput(MouseInput mi)
        {
            if (!EventBounds.Contains(mi.Location))
            {
                return(false);
            }

            if (mi.Button != MouseButton.Left)
            {
                return(true);
            }

            if (mi.Event == MouseInputEvent.Down)
            {
                actorActions.Actor.World.IssueOrder(new Order("SpawnAcolyte", actorActions.Actor, false));
                pressed = true;
            }
            else if (mi.Event == MouseInputEvent.Up)
            {
                pressed = false;
            }

            return(true);
        }
コード例 #8
0
        public override void Draw()
        {
            productionIcons.Clear();
            productionIconsBounds.Clear();

            var player = GetPlayer();

            if (player == null)
            {
                return;
            }

            var queues = world.ActorsWithTrait <ProductionQueue>()
                         .Where(a => a.Actor.Owner == player)
                         .Select((a, i) => new { a.Trait, i });

            foreach (var queue in queues)
            {
                if (!clocks.ContainsKey(queue.Trait))
                {
                    clocks.Add(queue.Trait, new Animation(world, ClockAnimation));
                }
            }

            var currentItemsByItem = queues
                                     .Select(a => a.Trait.CurrentItem())
                                     .Where(pi => pi != null)
                                     .GroupBy(pr => pr.Item)
                                     .OrderBy(g => g.First().Queue.Info.DisplayOrder)
                                     .ThenBy(g => g.First().BuildPaletteOrder)
                                     .ToList();

            Game.Renderer.EnableAntialiasingFilter();

            var queueCol = 0;

            foreach (var currentItems in currentItemsByItem)
            {
                var queued = currentItems
                             .OrderBy(pi => pi.Done ? 0 : (pi.Paused ? 2 : 1))
                             .ThenBy(q => q.RemainingTimeActual)
                             .ToList();

                var current = queued.First();
                var queue   = current.Queue;

                var faction = queue.Actor.Owner.Faction.InternalName;
                var actor   = queue.AllItems().FirstOrDefault(a => a.Name == current.Item);
                if (actor == null)
                {
                    continue;
                }

                var rsi  = actor.TraitInfo <RenderSpritesInfo>();
                var icon = new Animation(world, rsi.GetImage(actor, faction));
                var bi   = actor.TraitInfo <BuildableInfo>();

                icon.Play(bi.Icon);
                var topLeftOffset = new float2(queueCol * (IconWidth + IconSpacing), 0);

                var iconTopLeft    = RenderOrigin + topLeftOffset;
                var centerPosition = iconTopLeft + 0.5f * iconSize;

                var palette = bi.IconPaletteIsPlayerPalette ? bi.IconPalette + player.InternalName : bi.IconPalette;
                WidgetUtils.DrawSpriteCentered(icon.Image, worldRenderer.Palette(palette), centerPosition, 0.5f);

                var rect = new Rectangle((int)iconTopLeft.X, (int)iconTopLeft.Y, (int)iconSize.X, (int)iconSize.Y);
                productionIcons.Add(new ProductionIcon
                {
                    Actor           = actor,
                    Pos             = new float2(rect.Location),
                    Queued          = queued,
                    ProductionQueue = current.Queue
                });

                productionIconsBounds.Add(rect);

                var pio = queue.Actor.Owner.PlayerActor.TraitsImplementing <IProductionIconOverlay>()
                          .FirstOrDefault(p => p.IsOverlayActive(actor));

                if (pio != null)
                {
                    WidgetUtils.DrawSpriteCentered(pio.Sprite, worldRenderer.Palette(pio.Palette),
                                                   centerPosition + pio.Offset(iconSize), 0.5f);
                }

                var clock = clocks[queue];
                clock.PlayFetchIndex(ClockSequence, () => current.TotalTime == 0 ? 0 :
                                     (current.TotalTime - current.RemainingTime) * (clock.CurrentSequence.Length - 1) / current.TotalTime);

                clock.Tick();
                WidgetUtils.DrawSpriteCentered(clock.Image, worldRenderer.Palette(ClockPalette), centerPosition, 0.5f);

                queueCol++;
            }

            var newWidth = Math.Max(queueCol * (IconWidth + IconSpacing), MinWidth);

            if (newWidth != Bounds.Width)
            {
                var wasInBounds = EventBounds.Contains(Viewport.LastMousePos);
                Bounds.Width = newWidth;
                var isInBounds = EventBounds.Contains(Viewport.LastMousePos);

                // HACK: Ui.MouseOverWidget is normally only updated when the mouse moves
                // Call ResetTooltips to force a fake mouse movement so the checks in Tick will work properly
                if (wasInBounds != isInBounds)
                {
                    Game.RunAfterTick(Ui.ResetTooltips);
                }
            }

            Game.Renderer.DisableAntialiasingFilter();

            var tiny = Game.Renderer.Fonts["Tiny"];
            var bold = Game.Renderer.Fonts["Small"];

            foreach (var icon in productionIcons)
            {
                var current = icon.Queued.First();
                var text    = GetOverlayForItem(current, world.Timestep);
                tiny.DrawTextWithContrast(text,
                                          icon.Pos + new float2(16, 12) - new float2(tiny.Measure(text).X / 2, 0),
                                          Color.White, Color.Black, 1);

                if (icon.Queued.Count > 1)
                {
                    text = icon.Queued.Count.ToString();
                    bold.DrawTextWithContrast(text, icon.Pos + new float2(16, 0) - new float2(bold.Measure(text).X / 2, 0),
                                              Color.White, Color.Black, 1);
                }
            }

            var parentWidth = Bounds.X + Bounds.Width;

            Parent.Bounds.Width = parentWidth;

            var gradient = Parent.Get <GradientColorBlockWidget>("PLAYER_GRADIENT");

            var offset        = gradient.Bounds.X - Bounds.X;
            var gradientWidth = Math.Max(MinWidth - offset, currentItemsByItem.Count * (IconWidth + IconSpacing));

            gradient.Bounds.Width = gradientWidth;
            var widestChildWidth = Parent.Parent.Children.Max(x => x.Bounds.Width);

            Parent.Parent.Bounds.Width = Math.Max(25 + widestChildWidth, Bounds.Left + MinWidth);
        }
コード例 #9
0
        public override void Draw()
        {
            armyIcons.Clear();

            var player = GetPlayer();

            if (player == null)
            {
                return;
            }

            var playerStatistics = stats.Update(player);

            var items = playerStatistics.Units.Values
                        .Where(u => u.Count > 0 && u.Icon != null)
                        .OrderBy(u => u.ProductionQueueOrder)
                        .ThenBy(u => u.BuildPaletteOrder);

            Game.Renderer.EnableAntialiasingFilter();

            var queueCol = 0;

            foreach (var unit in items)
            {
                var icon          = unit.Icon;
                var topLeftOffset = new int2(queueCol * (IconWidth + IconSpacing), 0);

                var iconTopLeft    = RenderOrigin + topLeftOffset;
                var centerPosition = iconTopLeft;

                var palette = unit.IconPaletteIsPlayerPalette ? unit.IconPalette + player.InternalName : unit.IconPalette;
                WidgetUtils.DrawSpriteCentered(icon.Image, worldRenderer.Palette(palette), centerPosition + 0.5f * iconSize, 0.5f);

                armyIcons.Add(new ArmyIcon
                {
                    Bounds = new Rectangle(iconTopLeft.X, iconTopLeft.Y, (int)iconSize.X, (int)iconSize.Y),
                    Unit   = unit
                });

                queueCol++;
            }

            var newWidth = Math.Max(queueCol * (IconWidth + IconSpacing), MinWidth);

            if (newWidth != Bounds.Width)
            {
                var wasInBounds = EventBounds.Contains(Viewport.LastMousePos);
                Bounds.Width = newWidth;
                var isInBounds = EventBounds.Contains(Viewport.LastMousePos);

                // HACK: Ui.MouseOverWidget is normally only updated when the mouse moves
                // Call ResetTooltips to force a fake mouse movement so the checks in Tick will work properly
                if (wasInBounds != isInBounds)
                {
                    Game.RunAfterTick(Ui.ResetTooltips);
                }
            }

            Game.Renderer.DisableAntialiasingFilter();

            var bold = Game.Renderer.Fonts["TinyBold"];

            foreach (var armyIcon in armyIcons)
            {
                var text = armyIcon.Unit.Count.ToString();
                bold.DrawTextWithContrast(text, armyIcon.Bounds.Location + new float2(iconSize.X, 0) - new float2(bold.Measure(text).X, bold.TopOffset),
                                          Color.White, Color.Black, 1);
            }

            var parentWidth = Bounds.X + Bounds.Width;

            Parent.Bounds.Width = parentWidth;

            var gradient = Parent.Get <GradientColorBlockWidget>("PLAYER_GRADIENT");

            var offset        = gradient.Bounds.X - Bounds.X;
            var gradientWidth = Math.Max(MinWidth - offset, queueCol * (IconWidth + IconSpacing));

            gradient.Bounds.Width = gradientWidth;
            var widestChildWidth = Parent.Parent.Children.Max(x => x.Bounds.Width);

            Parent.Parent.Bounds.Width = Math.Max(25 + widestChildWidth, Bounds.Left + MinWidth);
        }
コード例 #10
0
 public override bool HandleMouseInput(MouseInput mi)
 {
     return(!ClickThrough && EventBounds.Contains(mi.Location));
 }
コード例 #11
0
 public override bool EventBoundsContains(int2 location)
 {
     return(EventBounds.Contains(location));
 }
コード例 #12
0
        public override bool HandleMouseInput(MouseInput mi)
        {
            if (!EventBounds.Contains(mi.Location))
            {
                tooltip.Visible = false;
                return(false);
            }

            tooltip.Visible = true;

            if (disabled)
            {
                return(false);
            }

            if (mi.Button != MouseButton.Left)
            {
                return(true);
            }

            if (mi.Event == MouseInputEvent.Down)
            {
                if (!showResearch.Researching && showResearch.ActorActions.BamUi.World.RenderPlayer.PlayerActor.Trait <DungeonsAndDragonsExperience>().Experience >= ResearchCost)
                {
                    showResearch.ActorActions.BamUi.World.IssueOrder(new Order("ExpRemove-" + researchItem, showResearch.ActorActions.BamUi.World.LocalPlayer.PlayerActor, false));
                    pressed = true;

                    showResearch.ResearchItem    = researchItem;
                    showResearch.MaxResearchTime = researchTime;
                    showResearch.Researching     = true;
                    showResearch.RemoveResearchMenu();
                    showResearch.ShowResearch = false;
                    pressed = true;
                }
                else if (showResearch.ActorActions.BamUi.World.RenderPlayer.PlayerActor.Trait <Research>().Researchable.Contains(researchItem) || showResearch.Researching)
                {
                    Game.Sound.PlayNotification(
                        showResearch.ActorActions.BamUi.World.Map.Rules,
                        showResearch.ActorActions.BamUi.World.LocalPlayer,
                        "Speech",
                        "AlreadyResearched",
                        showResearch.ActorActions.BamUi.World.LocalPlayer.Faction.InternalName
                        );
                }
                else if (showResearch.ActorActions.BamUi.World.RenderPlayer.PlayerActor.Trait <DungeonsAndDragonsExperience>().Experience < ResearchCost)
                {
                    Game.Sound.PlayNotification(
                        showResearch.ActorActions.BamUi.World.Map.Rules,
                        showResearch.ActorActions.BamUi.World.LocalPlayer,
                        "Speech",
                        "LowExp",
                        showResearch.ActorActions.BamUi.World.LocalPlayer.Faction.InternalName
                        );
                }
            }
            else if (mi.Event == MouseInputEvent.Up)
            {
                pressed = false;
            }


            return(true);
        }
コード例 #13
0
ファイル: Widget.cs プロジェクト: hadow/Commander
 public override bool HandleInput(GestureSample gs)
 {
     return(!ClickThrough && EventBounds.Contains(gs.Position.ToInt2()));
 }