Exemplo n.º 1
0
        public void RefreshIcons()
        {
            icons = new Dictionary <Rectangle, ProductionIcon>();
            if (CurrentQueue == null)
            {
                return;
            }

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

            foreach (var item in allBuildables)
            {
                var x    = i % Columns;
                var y    = i / Columns;
                var rect = new Rectangle(rb.X + x * 64 + 1, rb.Y + y * 48 + 1, 64, 48);
                var icon = new Animation(RenderSimple.GetImage(item));
                icon.Play(item.Traits.Get <TooltipInfo>().Icon);
                var pi = new ProductionIcon()
                {
                    Name   = item.Name,
                    Sprite = icon.Image,
                    Pos    = new float2(rect.Location),
                    Queued = CurrentQueue.AllQueued().Where(a => a.Item == item.Name).ToList(),
                };
                icons.Add(rect, pi);
                i++;
            }

            eventBounds = icons.Keys.Aggregate(Rectangle.Union);
        }
Exemplo n.º 2
0
        public static ActorTemplate RenderActor(ActorInfo info, TileSet tileset, Palette p)
        {
            var image = RenderSimple.GetImage(info);

            using (var s = FileSystem.OpenWithExts(image, tileset.Extensions))
            {
                var shp    = new ShpReader(s);
                var bitmap = RenderShp(shp, p);

                try
                {
                    using (var s2 = FileSystem.OpenWithExts(image + "2", tileset.Extensions))
                    {
                        var shp2       = new ShpReader(s2);
                        var roofBitmap = RenderShp(shp2, p);

                        using (var g = System.Drawing.Graphics.FromImage(bitmap))
                            g.DrawImage(roofBitmap, 0, 0);
                    }
                }
                catch { }

                return(new ActorTemplate
                {
                    Bitmap = bitmap,
                    Info = info,
                    Appearance = info.Traits.GetOrDefault <EditorAppearanceInfo>()
                });
            }
        }
Exemplo n.º 3
0
        public override void Draw()
        {
            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, "clock"));
                }
            }

            var iconSize = new float2(IconWidth, IconHeight);

            foreach (var queue in queues)
            {
                var current = queue.Trait.CurrentItem();
                if (current == null)
                {
                    continue;
                }

                var actor = queue.Trait.AllItems().FirstOrDefault(a => a.Name == current.Item);
                if (actor == null)
                {
                    continue;
                }

                var icon = new Animation(world, RenderSimple.GetImage(actor));
                icon.Play(actor.Traits.Get <TooltipInfo>().Icon);
                var location = new float2(RenderBounds.Location) + new float2(queue.i * (IconWidth + IconSpacing), 0);
                WidgetUtils.DrawSHPCentered(icon.Image, location + 0.5f * iconSize, worldRenderer, 0.5f);

                var clock = clocks[queue.Trait];
                clock.PlayFetchIndex("idle",
                                     () => current.TotalTime == 0 ? 0 : ((current.TotalTime - current.RemainingTime)
                                                                         * (clock.CurrentSequence.Length - 1) / current.TotalTime));
                clock.Tick();
                WidgetUtils.DrawSHPCentered(clock.Image, location + 0.5f * iconSize, worldRenderer, 0.5f);

                var tiny = Game.Renderer.Fonts["Tiny"];
                var text = GetOverlayForItem(current);
                tiny.DrawTextWithContrast(text,
                                          location + new float2(16, 16) - new float2(tiny.Measure(text).X / 2, 0),
                                          Color.White, Color.Black, 1);
            }
        }
Exemplo n.º 4
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);
            }
        }
Exemplo n.º 5
0
        public GpsDot(ActorInitializer init, string s)
        {
            anim = new Animation("gpsdot");
            anim.PlayRepeating(s);

            self = init.self;
            rs   = self.Trait <RenderSimple>();
            self.World.AddFrameEndTask(w => w.Add(this));
            if (self.World.LocalPlayer != null)
            {
                watcher = self.World.LocalPlayer.PlayerActor.Trait <GpsWatcher>();
            }
        }
Exemplo n.º 6
0
        int DrawPalette(ProductionQueue queue)
        {
            buttons.Clear();

            var paletteCollection = "palette-" + world.LocalPlayer.Country.Race;
            var origin            = new float2(paletteOrigin.X + 9, paletteOrigin.Y + 9);
            var iconOffset        = 0.5f * new float2(IconWidth, IconHeight);
            var x = 0;
            var y = 0;

            if (queue != null)
            {
                var buildableItems = queue.BuildableItems().ToArray();
                var allBuildables  = queue.AllItems().OrderBy(a => a.Traits.Get <BuildableInfo>().BuildPaletteOrder).ToArray();

                var overlayBits = new List <Pair <Sprite, float2> >();
                var textBits    = new List <Pair <float2, string> >();
                numActualRows = Math.Max((allBuildables.Count() + Columns - 1) / Columns, Rows);

                // Palette Background
                WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "top"), new float2(origin.X - 9, origin.Y - 9));
                for (var w = 0; w < numActualRows; w++)
                {
                    WidgetUtils.DrawRGBA(
                        ChromeProvider.GetImage(paletteCollection, "bg-" + (w % 4)),
                        new float2(origin.X - 9, origin.Y + IconHeight * w));
                }
                WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "bottom"),
                                     new float2(origin.X - 9, origin.Y - 1 + IconHeight * numActualRows));


                // Icons
                string tooltipItem   = null;
                var    tooltipHotkey = Hotkey.Invalid;
                var    i             = 0;
                foreach (var item in allBuildables)
                {
                    var rect    = new RectangleF(origin.X + x * IconWidth, origin.Y + IconHeight * y, IconWidth, IconHeight);
                    var drawPos = new float2(rect.Location);
                    var icon    = new Animation(world, RenderSimple.GetImage(item));
                    icon.Play(item.Traits.Get <TooltipInfo>().Icon);
                    WidgetUtils.DrawSHPCentered(icon.Image, drawPos + iconOffset, worldRenderer);

                    var firstOfThis = queue.AllQueued().FirstOrDefault(a => a.Item == item.Name);

                    if (rect.Contains(Viewport.LastMousePos))
                    {
                        tooltipItem   = item.Name;
                        tooltipHotkey = Game.Settings.Keys.GetProductionHotkey(i);
                    }

                    var overlayPos = drawPos + new float2(32, 16);

                    if (firstOfThis != null)
                    {
                        clock.PlayFetchIndex("idle",
                                             () => (firstOfThis.TotalTime - firstOfThis.RemainingTime)
                                             * (clock.CurrentSequence.Length - 1) / firstOfThis.TotalTime);
                        clock.Tick();
                        WidgetUtils.DrawSHPCentered(clock.Image, drawPos + iconOffset, worldRenderer);

                        if (queue.CurrentItem() == firstOfThis)
                        {
                            textBits.Add(Pair.New(overlayPos, GetOverlayForItem(firstOfThis)));
                        }

                        var repeats = queue.AllQueued().Count(a => a.Item == item.Name);
                        if (repeats > 1 || queue.CurrentItem() != firstOfThis)
                        {
                            textBits.Add(Pair.New(overlayPos + new float2(-24, -14), repeats.ToString()));
                        }
                    }
                    else
                    if (buildableItems.All(a => a.Name != item.Name))
                    {
                        overlayBits.Add(Pair.New(cantBuild.Image, drawPos));
                    }

                    var closureName = buildableItems.Any(a => a.Name == item.Name) ? item.Name : null;
                    buttons.Add(Pair.New(new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height), HandleClick(closureName, world)));

                    if (++x == Columns)
                    {
                        x = 0; y++;
                    }
                    i++;
                }
                if (x != 0)
                {
                    y++;
                }

                foreach (var ob in overlayBits)
                {
                    WidgetUtils.DrawSHPCentered(ob.First, ob.Second + iconOffset, worldRenderer);
                }

                var font = Game.Renderer.Fonts["TinyBold"];
                foreach (var tb in textBits)
                {
                    var size = font.Measure(tb.Second);
                    if (ReadyTextStyle == ReadyTextStyleOptions.Solid || orderManager.LocalFrameNumber / 9 % 2 == 0 || tb.Second != ReadyText)
                    {
                        font.DrawTextWithContrast(tb.Second, tb.First - new float2(size.X / 2, 0),
                                                  Color.White, Color.Black, 1);
                    }
                    else if (ReadyTextStyle == ReadyTextStyleOptions.AlternatingColor)
                    {
                        font.DrawTextWithContrast(tb.Second, tb.First - new float2(size.X / 2, 0),
                                                  ReadyTextAltColor, Color.Black, 1);
                    }
                }

                // Tooltip
                if (tooltipItem != null && !paletteAnimating && paletteOpen)
                {
                    DrawProductionTooltip(world, tooltipItem, tooltipHotkey,
                                          new float2(Game.Renderer.Resolution.Width, origin.Y + numActualRows * IconHeight + 9).ToInt2());
                }
            }

            // Palette Dock
            WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-top"),
                                 new float2(Game.Renderer.Resolution.Width - 14, origin.Y - 23));

            for (var i = 0; i < numActualRows; i++)
            {
                WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-" + (i % 4)),
                                     new float2(Game.Renderer.Resolution.Width - 14, origin.Y + IconHeight * i));
            }

            WidgetUtils.DrawRGBA(ChromeProvider.GetImage(paletteCollection, "dock-bottom"),
                                 new float2(Game.Renderer.Resolution.Width - 14, origin.Y - 1 + IconHeight * numActualRows));

            return(IconHeight * y + 9);
        }
Exemplo n.º 7
0
 void Awake()
 {
     rs = GetComponent <RenderSimple>();
     FaceunityWorker.OnInitOK += InitApplication;
 }
Exemplo n.º 8
0
 public DeadBuildingState(Actor self, DeadBuildingStateInfo info)
 {
     this.info = info;
     rs        = self.Trait <RenderSimple>();
     self.Trait <Health>().RemoveOnDeath = !rs.DefaultAnimation.HasSequence("dead");
 }
Exemplo n.º 9
0
    public GameObject image_face_detect;                                          //Active时表示没有检测到人脸

    /// <summary>
    /// Awake时注册SDK初始化完成事件
    /// </summary>
    void Awake()
    {
        _render_simple = GetComponent <RenderSimple>();
        FaceunityWorker.Instance.OnInitOK += _InitApplication;
    }
Exemplo n.º 10
0
 void Awake()
 {
     rs = GetComponent <RenderSimple>();
 }