Ejemplo n.º 1
0
        public void SubmitMove(int indexX, int indexY, bool isHit, string username)
        {
            Point3D       position      = new Point3D(0, 0, 0);
            SelectionGrid selectionGrid = (UserLogin.Username != username) ? this.playerGrid : this.enemyGrid;

            position = selectionGrid.GetBattleshipGrid().GetWorldPosition(indexX, indexY);
            selectionGrid.GetBattleshipGrid().ExecuteMove(indexX, indexY);
            selectionGrid.UpdateMarkerMaterial();

            GameObject pin = new GameObject(this);

            pin.Position      = new Vector3D(position.X, position.Y, position.Z) + new Vector3D(0, 0.25, 0);
            pin.GeometryModel = ModelUtil.ConvertToGeometryModel3D(new OBJModelLoader().LoadModel(Asset.PinModel));
            pin.Material      = new DiffuseMaterial((isHit) ? Brushes.Red : Brushes.White);

            this.world.RemoveGameObject(selectionGrid.Marker);
            this.world.RemoveGameObject(selectionGrid);
            this.world.AddGameObject(pin);
            this.world.AddGameObject(selectionGrid.Marker);
            this.world.AddGameObject(selectionGrid);

            if (isHit && UserLogin.Username == username || !isHit && UserLogin.Username != username)
            {
                GameInput.KeyUp += OnKeyUp;
            }
        }
Ejemplo n.º 2
0
        private void UIElement_OnMouseDown(object sender, MouseButtonEventArgs e)
        {
            //Always send the event to the data context
            FocusGridModel dataContext = DataContext as FocusGridModel;

            if (dataContext == null)
            {
                return;
            }
            dataContext.LeftClickCommand.Execute(ListGrid);
            //Check if we are on the grid
            if (!(e.OriginalSource is GriddedGrid))
            {
                return;
            }
            //Make sure we aren't dragging already
            if (IsDragging)
            {
                return;
            }
            // Capture and track the mouse.
            IsSelecting  = true;
            mouseDownPos = e.GetPosition(SelectionGrid);
            SelectionGrid.CaptureMouse();
            // Initial placement of the drag selection box.
            Canvas.SetLeft(selectionBox, mouseDownPos.X);
            Canvas.SetTop(selectionBox, mouseDownPos.Y);
            selectionBox.Width  = 0;
            selectionBox.Height = 0;
            // Make the drag selection box visible.
            selectionBox.Visibility = Visibility.Visible;
            FocusGridModel model = DataContext as FocusGridModel;

            model?.ClearSelected();
        }
Ejemplo n.º 3
0
    public SelectionGrid SpawnSelectionGrid(bool cameraFollows = false)
    {
        SelectionGrid grid = SelectionGrid.GetInstance();

        grid.cameraFollows = cameraFollows;
        grid.gameObject.transform.SetParent(GetComponent <Map>().transform);
        return(grid);
    }
Ejemplo n.º 4
0
    // selects a square to be targeted by the acting unit, might be canceled
    public IEnumerator SelectTargetDirRoutine(Result <EightDir> result,
                                              BattleUnit actingUnit,
                                              List <EightDir> allowedDirs,
                                              bool canCancel = true)
    {
        actor = actingUnit.battler;

        gameObject.SetActive(true);
        actingUnit.battle.cursor.DisableReticules();

        SelectionGrid      grid    = actingUnit.battle.SpawnSelectionGrid();
        TacticsTerrainMesh terrain = actingUnit.battle.map.terrain;

        grid.ConfigureNewGrid(actingUnit.location, 1, terrain, (Vector2Int loc) => {
            return((loc.x + loc.y + actingUnit.location.x + actingUnit.location.y) % 2 < 2);
        }, (Vector2Int loc) => {
            return(allowedDirs.Contains(actingUnit.battler.GetComponent <MapEvent>().DirectionTo(loc)));
        });
        if (allowedDirs.Count > 0)
        {
            AttemptSetDirection(allowedDirs[0]);
        }
        else
        {
            GetComponent <MapEvent>().SetLocation(actor.location);
        }

        while (!result.finished)
        {
            Result <EightDir> dirResult = new Result <EightDir>();
            yield return(AwaitSelectionRoutine(actor, dirResult));

            if (dirResult.canceled)
            {
                if (canCancel)
                {
                    result.Cancel();
                    break;
                }
            }
            else
            {
                result.value = dirResult.value;
            }
        }

        Destroy(grid.gameObject);
        actingUnit.battle.cursor.EnableReticules();
        gameObject.SetActive(false);
    }
Ejemplo n.º 5
0
        private void SetupGrids()
        {
            this.playerGrid = new SelectionGrid(this, true, new Vector3D(-5.5, 0, 0));
            //this.playerGrid.Position = new Vector3D(-5.5, 0, 0);
            //this.playerGrid.Marker.Position = new Vector3D(this.playerGrid.Position.X - 4.5, this.playerGrid.Position.Y, this.playerGrid.Position.Z - 4.5);
            this.world.AddGameObject(playerGrid.Marker);
            this.world.AddGameObject(playerGrid);

            this.enemyGrid = new SelectionGrid(this, false, new Vector3D(5.5, 0, 0));
            //this.enemyGrid.Position = new Vector3D(5.5, 0, 0);
            //this.enemyGrid.Marker.Position = new Vector3D(this.enemyGrid.Position.X - 4.5, this.enemyGrid.Position.Y, this.enemyGrid.Position.Z - 4.5);
            this.world.AddGameObject(enemyGrid.Marker);
            this.world.AddGameObject(enemyGrid);
            this.enemyGrid.IsActive = false;
        }
Ejemplo n.º 6
0
    protected override IEnumerator InternalExecuteRoutine(Effector effect, Result <bool> result)
    {
        Func <Vector2Int, bool> rangeRule = (Vector2Int loc) => {
            return(Vector2Int.Distance(loc, actor.location) <= radius);
        };

        Vector2Int origin = new Vector2Int(
            (int)actorEvent.positionPx.x - Mathf.CeilToInt(radius),
            (int)actorEvent.positionPx.z - Mathf.CeilToInt(radius));

        SelectionGrid grid = battle.SpawnSelectionGrid();

        grid.ConfigureNewGrid(actor.location, Mathf.CeilToInt(radius), map.terrain, rangeRule, rangeRule);

        Result <Vector2Int> locResult = new Result <Vector2Int>();

        battle.SpawnCursor(actor.location);
        yield return(battle.cursor.AwaitSelectionRoutine(locResult, _ => true, null, loc => {
            return loc == actor.location;
        }));

        battle.DespawnCursor();
        Destroy(grid.gameObject);

        if (locResult.canceled)
        {
            result.Cancel();
        }
        else
        {
            List <Vector2Int> cells = new List <Vector2Int>();
            int r = Mathf.CeilToInt(radius);
            for (int y = locResult.value.y - r; y <= locResult.value.y + r; y += 1)
            {
                for (int x = locResult.value.x - r; x <= locResult.value.x + r; x += 1)
                {
                    Vector2Int cell = new Vector2Int(x, y);
                    if (DefaultSelectRule(effect)(cell))
                    {
                        cells.Add(cell);
                    }
                }
            }
            yield return(effect.ExecuteCellsRoutine(cells));

            result.value = true;
        }
    }
Ejemplo n.º 7
0
        void Start()
        {
            try
            {
                logger.ClearLog();
                logger.Log("Starting Debugger UI");
                debugger.Load();
                debugger.StartWatch();

                screenSelection          = new SelectionGrid(new string[] { "Log", "Mods", "Debugger" }, GUILayout.Height(25));
                screenSelection.Selected = 1;
                logWindow   = LogWindow();
                modWindow   = ModWindow();
                debugWindow = DebugWindow();
                RefreshMods();
                logger.Log("Debugger UI startup complete");
            }
            catch (Exception e)
            {
                logger.Log($"While starting UI threw {e.GetType().FullName}: {e.Message}{Environment.NewLine}{e.StackTrace}");
            }
        }
Ejemplo n.º 8
0
        private void UIElement_OnMouseUp(object sender, MouseButtonEventArgs e)
        {
            if (!IsSelecting)
            {
                return;
            }
            // Release the mouse capture and stop tracking it.
            IsSelecting = false;
            SelectionGrid.ReleaseMouseCapture();
            // Hide the drag selection box.
            selectionBox.Visibility = Visibility.Collapsed;
            Point mouseUpPos                 = e.GetPosition(SelectionGrid);
            Rect  selectedBoundaries         = new Rect(mouseDownPos, mouseUpPos);
            IEnumerable <Focus> selectedFoci = UiHelper.FindVisualChildren <Focus>(this)
                                               .Where(f =>
            {
                Image firstOrDefault = UiHelper.FindChildWithName(f, "FocusIcon") as Image;
                if (firstOrDefault == null)
                {
                    return(false);
                }
                Point pos = firstOrDefault.TranslatePoint(new Point(0, 0), this);
                return(selectedBoundaries
                       .Contains(new Point(pos.X + f.ActualWidth / 2,
                                           pos.Y + f.ActualHeight / 2)));
            });
            FocusGridModel model = DataContext as FocusGridModel;

            foreach (Focus focus in selectedFoci)
            {
                MouseEventArgs mouseLeaveEventArgs = new MouseEventArgs(Mouse.PrimaryDevice, 0)
                {
                    RoutedEvent = Mouse.MouseLeaveEvent
                };
                focus.RaiseEvent(mouseLeaveEventArgs);
                model?.SelectFocus(focus);
            }
        }
Ejemplo n.º 9
0
    protected override IEnumerator InternalExecuteRoutine(Effector effect, Result <bool> result)
    {
        Cursor        cursor = battle.SpawnCursor(actor.location);
        SelectionGrid grid   = battle.SpawnSelectionGrid();

        Func <Vector2Int, bool> selectRule = (Vector2Int v) => { return(IsSelected(effect, v)); };
        Func <Vector2Int, bool> rangeRule  = (Vector2Int v) => {
            Vector2Int otherLoc = battle.cursor.GetComponent <MapEvent>().location;
            return(map.PointsAlongPath(actor.location, otherLoc).Contains(v));
        };
        Func <Vector2Int, IEnumerator> scanner = (Vector2Int loc) => {
            grid.ConfigureNewGrid(actor.location, range, map.terrain, rangeRule, selectRule);
            return(null);
        };

        if (effect.TargetsHostiles())
        {
            float      minDist  = float.MaxValue;
            BattleUnit bestUnit = null;
            foreach (BattleUnit unit in battle.units)
            {
                float dist = Vector2Int.Distance(unit.location, actor.location);
                cursor.GetComponent <MapEvent>().SetLocation(unit.location);
                if (unit.align != actor.align && dist < minDist && selectRule(unit.location))
                {
                    bestUnit = unit;
                    minDist  = dist;
                }
            }
            if (bestUnit != null)
            {
                cursor.GetComponent <MapEvent>().SetLocation(bestUnit.location);
            }
        }

        Func <Vector2Int, bool> constrainer = loc => Vector2.Distance(loc, actor.location) <= range;

        grid.ConfigureNewGrid(actor.location, range, map.terrain, rangeRule, selectRule);

        Result <Vector2Int> locResult = new Result <Vector2Int>();

        yield return(battle.cursor.AwaitSelectionRoutine(locResult, selectRule, scanner, constrainer));

        battle.DespawnCursor();
        Destroy(grid.gameObject);

        if (locResult.canceled)
        {
            result.Cancel();
        }
        else
        {
            List <Vector2Int> cells = new List <Vector2Int>();
            if (penetrates)
            {
                foreach (Vector2Int v in map.PointsAlongPath(actor.location, locResult.value))
                {
                    if (map.terrain.HeightAt(v) == map.terrain.HeightAt(actor.location))
                    {
                        cells.Add(v);
                    }
                }
            }
            else
            {
                cells.Add(locResult.value);
            }

            yield return(effect.ExecuteCellsRoutine(cells));

            result.value = true;
        }
    }
Ejemplo n.º 10
0
    protected override IEnumerator InternalExecuteRoutine(Effector effect, Result <bool> result)
    {
        Cursor        cursor = battle.SpawnCursor(actor.location);
        SelectionGrid grid   = battle.SpawnSelectionGrid();

        Func <Vector2Int, bool>        selectRule;
        Func <Vector2Int, IEnumerator> scanner   = null;
        Func <Vector2Int, bool>        rangeRule = (Vector2Int loc) => {
            return(Vector2Int.Distance(loc, actor.location) <= range);
        };

        if (radius > 0)
        {
            selectRule = (Vector2Int loc) => {
                return(Vector2Int.Distance(cursor.GetComponent <MapEvent>().location, loc) <= radius);
            };
        }
        else
        {
            selectRule = DefaultSelectRule(effect);
        }
        scanner = (Vector2Int loc) => {
            grid.ConfigureNewGrid(actor.location, range + Mathf.CeilToInt(radius),
                                  map.terrain, rangeRule, selectRule);
            return(null);
        };

        if (effect.TargetsHostiles())
        {
            float      minDist  = float.MaxValue;
            BattleUnit bestUnit = null;
            foreach (BattleUnit unit in battle.units)
            {
                float dist = Vector2Int.Distance(unit.location, actor.location);
                if (unit.align != actor.align && dist < minDist && selectRule(unit.location))
                {
                    bestUnit = unit;
                    minDist  = dist;
                }
            }
            if (bestUnit != null)
            {
                cursor.GetComponent <MapEvent>().SetLocation(bestUnit.location);
            }
        }

        Vector2Int origin = new Vector2Int(
            (int)actorEvent.positionPx.x - (range + Mathf.CeilToInt(radius) - 1),
            (int)actorEvent.positionPx.z - (range + Mathf.CeilToInt(radius) - 1));

        Func <Vector2Int, bool> constrainer = loc => Vector2.Distance(loc, actor.location) <= range;

        grid.ConfigureNewGrid(actor.location, range, map.terrain, rangeRule, selectRule);

        Result <Vector2Int> locResult = new Result <Vector2Int>();

        yield return(battle.cursor.AwaitSelectionRoutine(locResult, _ => true, scanner, constrainer));

        battle.DespawnCursor();
        Destroy(grid.gameObject);

        if (locResult.canceled)
        {
            result.Cancel();
        }
        else
        {
            List <Vector2Int> cells = new List <Vector2Int>();
            int r = Mathf.CeilToInt(radius);
            for (int y = locResult.value.y - r; y <= locResult.value.y + r; y += 1)
            {
                for (int x = locResult.value.x - r; x <= locResult.value.x + r; x += 1)
                {
                    Vector2Int cell = new Vector2Int(x, y);
                    if (Vector2Int.Distance(cell, locResult.value) <= radius)
                    {
                        cells.Add(cell);
                    }
                }
            }
            yield return(effect.ExecuteCellsRoutine(cells));

            result.value = true;
        }
    }
Ejemplo n.º 11
0
    private void SetupUpGui()
    {
        // Initialize the loaders
        GuiModule.Initialize(this);
//        NetModule.Initialize(this);

        TweenSharkUnity3D.Initialize(this);

        _guiStage = GlobalGui.GetInstance();

        _guiStage.AddChild(
            new VGroup()
            .SetPos(10, 10)
            .SetPadding(5)
            .SetSpacing(5)
            .AddChild(
                new Box(new Rect(20, 50, 300, 300), "TweenShark")
                .SetAutoAdjustSize(true)
                .AddChild(
                    new VGroup()
                    .SetPos(0, 20)
                    .SetPadding(5)
                    .AddChild(
                        new Button(new Rect(5, 20, 100, 25), "SpinCube-X")
                        .AddClickHandler((e) => SpinCubeAroundX())
                        )
                    .AddChild(
                        new Button(new Rect(5, 20, 100, 25), "SpinCube-Y")
                        .AddClickHandler((e) => SpinCubeAroundY())
                        )
                    .AddChild(
                        new Button(new Rect(5, 20, 100, 25), "SpinCube-Z")
                        .AddClickHandler((e) => SpinCubeAroundZ())
                        )
                    )
                .AddChild(
                    // first column
                    new VGroup()
                    .SetPos(120, 20)
                    .SetPadding(5)
                    .AddChild(
                        new Button(new Rect(5, 20, 40, 25), "\\")
                        .AddClickHandler(e => BringCubeTo(_cube, 3, -3, 0, false))
                        )
                    .AddChild(
                        new Button(new Rect(5, 20, 40, 25), "-")
                        .AddClickHandler(e => BringCubeTo(_cube, 0, -3, 0, false))
                        )
                    .AddChild(
                        new Button(new Rect(5, 20, 40, 25), "/")
                        .AddClickHandler(e => BringCubeTo(_cube, -3, -3, 0, false))
                        )
                    )
                .AddChild(
                    // second column
                    new VGroup()
                    .SetPos(160, 20)
                    .SetPadding(5)
                    .AddChild(
                        new Button(new Rect(5, 20, 40, 25), "|")
                        .AddClickHandler((e) => BringCubeTo(_cube, 3, 0, 0, false))
                        )
                    .AddChild(
                        new Button(new Rect(5, 20, 40, 25), "+")
                        .AddClickHandler((e) => BringCubeTo(_cube, 0, 0, 0, false))
                        )
                    .AddChild(
                        new Button(new Rect(5, 20, 40, 25), "|")
                        .AddClickHandler((e) => BringCubeTo(_cube, -3, 0, 0, false))
                        )
                    )
                .AddChild(
                    // third column
                    new VGroup()
                    .SetPos(200, 20)
                    .SetPadding(5)
                    .AddChild(
                        new Button(new Rect(5, 20, 40, 25), "/")
                        .AddClickHandler((e) => BringCubeTo(_cube, 3, 3, 0, false))
                        )
                    .AddChild(
                        new Button(new Rect(5, 20, 40, 25), "-")
                        .AddClickHandler((e) => BringCubeTo(_cube, 0, 3, 0, false))
                        )
                    .AddChild(
                        new Button(new Rect(5, 20, 40, 25), "\\")
                        .AddClickHandler((e) => BringCubeTo(_cube, -3, 3, 0, false))
                        )
                    )
                .AddChild(
                    // 4th column
                    new VGroup()
                    .SetPos(250, 20)
                    .SetPadding(5)
                    .AddChild(
                        new Button(new Rect(5, 20, 40, 25), "/\\")
                        .AddClickHandler((e) => BringCubeVertical(0.5f))
                        )
                    .AddChild(
                        new Button(new Rect(5, 20, 40, 25), "-")
                        .AddClickHandler((e) => BringCubeVertical(0))
                        )
                    .AddChild(
                        new Button(new Rect(5, 20, 40, 25), "\\/")
                        .AddClickHandler((e) => BringCubeVertical(-0.5f))
                        )
                    )
                )
            .AddChild(
                _progressTextField = new TextField(new Rect(0, 0, 300, 20), "")
                )
            .AddChild(
                new Box(new Rect(20, 85, 300, 200), "Madness")
                .SetAutoAdjustSize(true)
                .SetPadding(5)
                .AddChild(
                    new Button(new Rect(0, 20, 290, 30), "Action!")
                    .AddClickHandler(e => StartTheMaddness())
                    )
                .AddChild(
                    _cubeCountTextField = new TextField(new Rect(0, 60, 290, 20), "")
                    )
                .AddChild(
                    _tweenerSelection = new SelectionGrid(new Rect(0, 90, 290, 25), new string[] { "TweenShark", "iTween" }, 2)
                    )
                )
            .AddChild(
                new Box(new Rect(20, 50, 350, 300), "Easing")
                .SetAutoAdjustSize(true)
                .SetPadding(5)
                .AddChild(
                    new Label(new Rect(0, 20, 140, 18), "Tween Duration in sec")
                    )
                .AddChild(
                    _tweenDuration = new TextField(new Rect(150, 20, 100, 20), "5")
                    )
                .AddChild(
                    _easingSelection = new SelectionGrid(new Rect(0, 50, 300, 200), _easingNames, 3).SetSelection(5)
                    )
                )
            .AddChild(
                new Box(new Rect(20, 50, 350, 300), "Material")
                .SetAutoAdjustSize(true)
                .SetPadding(5)
                .AddChild(
                    new Button(new Rect(0, 25, 100, 25), "Tween Mat")
                    .AddClickHandler(e => TweenMaterial())
                    )
                )

            );
    }