Пример #1
0
        public Entity(Map currentMap)
        {
            Performance.Push("Entity ctor");
            VisibleRange = 0;

            IconIndex = 0;

            currentTarget  = null;
            PreviousTarget = null;

            CurrentMap = currentMap;

            Performance.Push("Create base sprite");
            sprite = new Sprite(WarFile.GetSpriteResource(WarFile.KnowledgeBase.IndexByName("Human Peasant")));
            Performance.Pop();

            Performance.Push("new HateList");
            HateList = new HateList();
            Performance.Pop();

            Performance.Push("new StateMachine");
            StateMachine = new StateMachine(this);
            Performance.Pop();

            Performance.Push("StateMachine.ChangeState");
            StateMachine.ChangeState(new StateIdle(this));
            Performance.Pop();

            Performance.Pop();
        }
Пример #2
0
        private void ShowMultiUI()
        {
            // Fail-safe
            if (currentEntities.Length <= 1 || currentEntities.Length > 4)
            {
                return;
            }

            SpriteResource res = WarFile.GetSpriteResource(race == Race.Humans ? 360 : 359);
        }
Пример #3
0
        private void ShowSingleUI()
        {
            // Fail-safe
            if (currentEntities.Length != 1)
            {
                return;
            }

            SpriteResource res     = WarFile.GetSpriteResource(race == Race.Humans ? 360 : 359);
            SpriteResource resUnit = WarFile.GetSpriteResource(361);

            Entity ent = currentEntities[0];

            UISpriteImage unitFrame = new UISpriteImage(new Sprite(res));

            unitFrame.FixedSpriteFrame = ent.Mana > 0 ? 1 : 0;
            unitFrame.X = 0;
            unitFrame.Y = 0;
            AddComponent(unitFrame);

            UISpriteImage unitIcon = new UISpriteImage(new Sprite(resUnit));

            unitIcon.FixedSpriteFrame = ent.IconIndex;
            unitIcon.X = 4;
            unitIcon.Y = 4;
            unitFrame.AddComponent(unitIcon);

            UILabel nameLabel = new UILabel(currentEntities[0].Name);

            nameLabel.TextAlign = TextAlignHorizontal.Left;
            nameLabel.X         = 4;
            nameLabel.Y         = unitIcon.Y + unitIcon.Height + 2;
            unitFrame.AddComponent(nameLabel);

            UIImage img = new UIImage(null);

            img.X               = 35;
            img.Y               = 20;
            img.Height          = 3;
            img.BackgroundColor = new Color(0.0f, 1.0f, 0.0f, 1.0f);
            SetHealthbar(img, ent);
            unitFrame.AddComponent(img);

            healthBars.Add(ent, img);
        }
Пример #4
0
        private void ShowBuildSubMenu()
        {
            // Remove all old components
            ClearComponents();

            isInSubmenu = true;

            healthBars.Clear();

            // No entities? Then just exit
            if (currentEntities == null || currentEntities.Length == 0)
            {
                return;
            }

            if (currentEntities.Length == 1)
            {
                ShowSingleUI();
            }
            else
            {
                ShowMultiUI();
            }

            int buttonIndex = 0;

            if (ShowCancel)
            {
                UISpriteButton btn = new UISpriteButton(new Sprite(WarFile.GetSpriteResource(361)), "Cancel");
                btn.OnMouseUpInside += (position) => { RebuildUI(); };
                SetButtonPosition(btn, 5);
                AddComponent(btn);

                buttonIndex++;
            }
        }
Пример #5
0
 public HumanConjurer(Map currentMap)
     : base(currentMap)
 {
     sprite = new UnitSprite(WarFile.GetSpriteResource(WarFile.KnowledgeBase.IndexByName("Human Wizard")));
 }
Пример #6
0
 public OrcGrunt(Map currentMap)
     : base(currentMap)
 {
     sprite = new UnitSprite(WarFile.GetSpriteResource(WarFile.KnowledgeBase.IndexByName("Orc Grunt")));
 }
Пример #7
0
 public HumanBarracks(Map currentMap)
     : base(currentMap)
 {
     sprite = new Sprite(WarFile.GetSpriteResource(WarFile.KnowledgeBase.IndexByName("Human Barracks")));
 }
Пример #8
0
 public OrcTownhall(Map currentMap)
     : base(currentMap)
 {
     sprite = new Sprite(WarFile.GetSpriteResource(WarFile.KnowledgeBase.IndexByName("Orc Base")));
 }
Пример #9
0
 public HumanFootman(Map currentMap)
     : base(currentMap)
 {
     sprite = new UnitSprite(WarFile.GetSpriteResource(WarFile.KnowledgeBase.IndexByName("Human Warrior")));
 }
Пример #10
0
        internal static UISpriteImage FromSpriteResource(string name)
        {
            UISpriteImage res = new UISpriteImage(new UnitSprite(WarFile.GetSpriteResource(WarFile.KnowledgeBase.IndexByName(name))));

            return(res);
        }
Пример #11
0
        private void RebuildUI()
        {
            // Remove all old components
            ClearComponents();

            isInSubmenu = false;

            healthBars.Clear();

            // No entities? Then just exit
            if (currentEntities == null || currentEntities.Length == 0)
            {
                return;
            }

            if (currentEntities.Length == 1)
            {
                ShowSingleUI();
            }
            else
            {
                ShowMultiUI();
            }

            int buttonIndex = 0;

            if (ShowMove)
            {
                UISpriteButton moveBtn = new UISpriteButton(new Sprite(WarFile.GetSpriteResource(361)), "Move" + race);
                moveBtn.OnMouseUpInside += (position) => { SetMapUnitOrder(MapUnitOrder.Move); };
                SetButtonPosition(moveBtn, buttonIndex);
                AddComponent(moveBtn);

                buttonIndex++;
            }
            if (ShowStop)
            {
                UISpriteButton btn = new UISpriteButton(new Sprite(WarFile.GetSpriteResource(361)), "Shield1" + (race == Race.Humans ? "" : "Orcs"));
                btn.OnMouseUpInside += (position) => { Stop(); };
                SetButtonPosition(btn, buttonIndex);
                AddComponent(btn);

                buttonIndex++;
            }
            if (ShowAttack)
            {
                UISpriteButton btn = new UISpriteButton(new Sprite(WarFile.GetSpriteResource(361)), "Sword1");
                btn.OnMouseUpInside += (position) => { SetMapUnitOrder(MapUnitOrder.Attack); };
                SetButtonPosition(btn, buttonIndex);
                AddComponent(btn);

                buttonIndex++;
            }
            if (ShowRepair)
            {
                UISpriteButton btn = new UISpriteButton(new Sprite(WarFile.GetSpriteResource(361)), "Repair");
                btn.OnMouseUpInside += (position) => { SetMapUnitOrder(MapUnitOrder.Repair); };
                SetButtonPosition(btn, buttonIndex);
                AddComponent(btn);

                buttonIndex++;
            }
            if (ShowHarvest)
            {
                UISpriteButton btn = new UISpriteButton(new Sprite(WarFile.GetSpriteResource(361)), "Harvest");
                btn.OnMouseUpInside += (position) => { SetMapUnitOrder(MapUnitOrder.Harvest); };
                SetButtonPosition(btn, buttonIndex);
                AddComponent(btn);

                buttonIndex++;
            }
            if (ShowBuild)
            {
                UISpriteButton btn = new UISpriteButton(new Sprite(WarFile.GetSpriteResource(361)), "Build");
                btn.OnMouseUpInside += (position) => { ShowBuildSubMenu(); };
                SetButtonPosition(btn, buttonIndex);
                AddComponent(btn);

                buttonIndex++;
            }
            if (ShowCancel)
            {
                UISpriteButton btn = new UISpriteButton(new Sprite(WarFile.GetSpriteResource(361)), "Cancel");
                btn.OnMouseUpInside += (position) => { RebuildUI(); };
                SetButtonPosition(btn, 6);
                AddComponent(btn);

                buttonIndex++;
            }

            if (currentEntities.Length == 1)
            {
                currentEntities[0].AddCustomUI(this);
            }
        }
Пример #12
0
 public OrcSpearman(Map currentMap)
     : base(currentMap)
 {
     sprite = new UnitSprite(WarFile.GetSpriteResource(WarFile.KnowledgeBase.IndexByName("Orc Axethrower")));
 }
Пример #13
0
 public Corpse(Map currentMap)
     : base(currentMap)
 {
     sprite = new Sprite(WarFile.GetSpriteResource(WarFile.KnowledgeBase.IndexByName("Corpse")));
 }
Пример #14
0
 public HumanArcher(Map currentMap)
     : base(currentMap)
 {
     sprite = new UnitSprite(WarFile.GetSpriteResource(WarFile.KnowledgeBase.IndexByName("Human Bowman")));
 }
Пример #15
0
 public HumanStormwind(Map currentMap)
     : base(currentMap)
 {
     sprite = new Sprite(WarFile.GetSpriteResource(WarFile.KnowledgeBase.IndexByName("Stormwind")));
 }
Пример #16
0
 public HumanCatapult(Map currentMap)
     : base(currentMap)
 {
     sprite = new UnitSprite(WarFile.GetSpriteResource(WarFile.KnowledgeBase.IndexByName("Human Catapult")));
 }