示例#1
0
        /// <summary>
        /// On the touches ended event.
        /// </summary>
        /// <param name="touches">Touches, where the user touched.</param>
        /// <param name="touchEvent">Touch event.</param>
        /// <returns>Return true after processing the touch events and drawing.</returns>
        public bool OnTouchesEnded(List<CCTouch> touches, CCEvent touchEvent)
        {
            m_timer.Stop();
            var startPosI = Helper.PositionHelper.WorldspaceToPositionI(m_startLocation, m_worldLayer);
            switch (Gesture)
            {
                case TouchGesture.Zoom:
                    // Set Current Scale
                    m_worldLayer.ZoomWorld(m_newZoom);
                    Gesture = TouchGesture.None;
                    break;

                case TouchGesture.Move:
                    Gesture = TouchGesture.None;
                    break;

                case TouchGesture.Start:
                    var region = Core.Controllers.Controller.Instance.RegionManagerController.GetRegion(startPosI.RegionPosition);
                    var entity = region.GetEntity(startPosI.CellPosition);
                    int range = 0;
                    Area area = Area.Movement;
                    m_indicator = new IndicatorView(m_worldLayer);

                    if (entity != null && entity.Definition.Category == Category.Unit)
                    {
                        Gesture = TouchGesture.MoveUnit;
                        range = Core.Controllers.Controller.Instance.RegionManagerController.GetRegion(startPosI.RegionPosition).GetEntity(startPosI.CellPosition).Move;
                        m_indicator.ShowUnitIndicator(startPosI, range, area);
                    }
                    else if (entity != null && (entity.Definition.SubType == EntityType.Headquarter || entity.Definition.SubType == EntityType.GuardTower))
                    {
                        Gesture = TouchGesture.Area;
                        var owner = Core.Controllers.Controller.Instance.RegionManagerController.GetRegion(startPosI.RegionPosition).GetEntity(startPosI.CellPosition).Owner;
                        area = Area.OwnTerritory;
                        if (owner != GameAppDelegate.Account)
                        {
                            area = Area.EnemyTerritory;
                        }
                        m_indicator.ShowBuildingIndicator(startPosI, area);
                    }
                    else if (entity != null && entity.DefinitionID == (long)EntityType.Barracks && entity.Owner == GameAppDelegate.Account)
                    {
                        m_menuView = new MenuView(m_worldLayer, startPosI, MenuView.MenuType.Unity);
                        m_menuView.DrawMenu(MenuView.MenuType.Unity);
                        Gesture = TouchGesture.Menu;
                    }
                    else if (entity == null)
                    {
                        var defM = Core.Models.World.Instance.DefinitionManager;
                        var action = ActionHelper.CreateEntity(startPosI, defM.GetDefinition(EntityType.Headquarter), GameAppDelegate.Account);
                        var actionC = (Core.Controllers.Actions.CreateTerritoryBuilding)action.Control;
                        if (actionC.Possible())
                        {
                            m_menuView = new MenuView(m_worldLayer, startPosI, MenuView.MenuType.Headquarter);
                            m_menuView.DrawMenu(MenuView.MenuType.Headquarter);
                        }
                        else if (region.GetClaimedTerritory(startPosI) == action.Account)
                        {
                            m_menuView = new MenuView(m_worldLayer, startPosI, MenuView.MenuType.Major);
                            m_menuView.DrawMenu(MenuView.MenuType.Major);
                        }
                        else
                        {
                            // create an empty menu but didnt show it and set the m_menuView for the next touche
                            m_menuView = new MenuView(m_worldLayer, startPosI, MenuView.MenuType.Empty);
                            Gesture = TouchGesture.None;
                            return true;
                        }
                        Gesture = TouchGesture.Menu;
                    }
                    break;
            }
            m_worldLayer.UglyDraw();
            return true;
        }
示例#2
0
        /// <summary>
        /// On the touches began event.
        /// </summary>
        /// <param name="touches">Touches, where the user touched.</param>
        /// <param name="touchEvent">Touch event.</param>
        /// <returns> Returns true after processing the touches.</returns>
        public bool OnTouchesBegan(List<CCTouch> touches, CCEvent touchEvent)
        {
            var oldWorldPosition = m_startLocation;
            var oldGamePositionI = Helper.PositionHelper.WorldspaceToPositionI(oldWorldPosition, m_worldLayer);

            m_startLocation = m_worldLayer.ConvertToWorldspace(touches[0].Location);
            var gamePositionI = Helper.PositionHelper.WorldspaceToPositionI(m_startLocation, m_worldLayer);

            switch (Gesture)
            {
                case TouchGesture.Area:
                    m_indicator.RemoveIndicator();
                    Gesture = TouchGesture.None;
                    break;
                case TouchGesture.MoveUnit:
                    var action = ActionHelper.MoveUnit(oldGamePositionI, gamePositionI);

                    var actionC = (Core.Controllers.Actions.Action)action.Control;
                    var possible = actionC.Possible();
                    if (possible)
                    {
                        m_worldLayer.DoAction(action);
                    }
                    m_indicator.RemoveIndicator();
                    Gesture = TouchGesture.None;
                    break;

                case TouchGesture.Menu:
                    var def = m_menuView.GetSelectedDefinition(gamePositionI);
                    if (def != null)
                    {
                        var action2 = ActionHelper.CreateEntity(m_menuView.GetCenterPosition(), def, GameAppDelegate.Account);
                        var actionC2 = (Core.Controllers.Actions.Action)action2.Control;
                        if (actionC2.Possible())
                        {
                            m_worldLayer.DoAction(action2);
                        }
                    }

                    if (m_menuView.IsExtended())
                    {
                        // var regionView = m_worldLayer.GetRegionViewHex(gamePositionI.RegionPosition);
                        var gid = m_menuView.GetSelectedKategory(gamePositionI);
                        switch (gid.Gid)
                        {
                            case Client.Common.Constants.BuildingMenuGid.MILITARY:
                            case Client.Common.Constants.BuildingMenuGid.CIVIL:
                            case Client.Common.Constants.BuildingMenuGid.UPGRADE:
                            case Client.Common.Constants.BuildingMenuGid.RESOURCES:
                            case Client.Common.Constants.BuildingMenuGid.STORAGE:
                                m_menuView.ExtendMenu((short)gid.Gid, gamePositionI);
                                break;
                            default:
                                m_menuView.CloseMenu();
                                m_menuView = null;
                                Gesture = TouchGesture.None;
                                break;
                        }
                    }
                    else
                    {
                        m_menuView.CloseMenu();
                        Gesture = TouchGesture.None;
                    }

                    m_worldLayer.UglyDraw();
                    return true;

                case TouchGesture.None:
                    Gesture = TouchGesture.Start;
                    break;
            }

            m_timer.Reset();
            m_timer.Start();

            m_zoom = m_worldLayer.GetZoom();
            m_worldLayer.UglyDraw();
            return true;
        }