コード例 #1
0
ファイル: InputHandler.cs プロジェクト: p-svacha/TheWorldGame
        public void OnNewTroopMovementDialogReturn(int numTroops)
        {
            Destroy(ActiveTroopDialog.gameObject);
            ActiveTroopDialog = null;

            if (numTroops == 0)
            {
                Destroy(DragArrow);
            }
            else
            {
                Vector2 midPos = Vector2.Lerp(DragArrowStart, DragArrowEnd, 0.5f);

                GameObject rectangle = MeshGenerator.DrawRectangle(midPos, PolygonMapGenerator.LAYER_OVERLAY2, 0.13f, 0.13f, Color.gray);
                rectangle.AddComponent <MeshCollider>();
                rectangle.transform.SetParent(DragArrow.transform);

                TextMesh movementLabel = MeshGenerator.DrawTextMesh(midPos, PolygonMapGenerator.LAYER_OVERLAY3, numTroops.ToString(), 60);
                movementLabel.transform.SetParent(DragArrow.transform);

                Army newMovement = Game.AddArmy(DragSourceTerritory, DragTargetTerritory, numTroops);

                ArmyArrow movementArrow = DragArrow.AddComponent <ArmyArrow>();
                movementArrow.Init(newMovement, movementLabel, midPos);
                Game.ArmyArrows.Add(movementArrow);
            }

            State = InputState.Idle;
        }
コード例 #2
0
ファイル: InputHandler.cs プロジェクト: p-svacha/TheWorldGame
        public void OnEditTroopMovementDialogReturn(int numTroopsNew)
        {
            if (numTroopsNew == 0)
            {
                Game.RemoveArmy(EditedMovement.TroopMovement);
                Game.ArmyArrows.Remove(EditedMovement);
                Destroy(EditedMovement.gameObject);
            }
            if (numTroopsNew != 0)
            {
                Game.EditArmy(EditedMovement.TroopMovement, numTroopsNew);
                EditedMovement.Label.text = numTroopsNew.ToString();
            }

            Destroy(ActiveTroopDialog.gameObject);
            EditedMovement    = null;
            ActiveTroopDialog = null;
            State             = InputState.Idle;
        }
コード例 #3
0
ファイル: InputHandler.cs プロジェクト: p-svacha/TheWorldGame
 protected override void OnLeftMouseDragEnd()
 {
     base.OnLeftMouseDragEnd();
     if (State == InputState.Dragging)
     {
         Region hoveredRegion = GetHoveredRegion();
         if (CanCreateNewTroopMovement())
         {
             DragTargetTerritory = Game.Territories[hoveredRegion];
             ActiveTroopDialog   = Instantiate(Game.UI.TroopMovementDialog);
             ActiveTroopDialog.Init(DragSourceTerritory.UnplannedTroops, DragSourceTerritory.UnplannedTroops, OnNewTroopMovementDialogReturn);
             ActiveTroopDialog.transform.SetParent(Game.UI.OverlayContainer.transform);
             Vector3 targetPos = Vector3.Lerp(Camera.WorldToScreenPoint(new Vector3(DragArrowStart.x, 0f, DragArrowStart.y)), Camera.WorldToScreenPoint(new Vector3(DragArrowEnd.x, 0f, DragArrowEnd.y)), 0.5f);
             ActiveTroopDialog.transform.position = targetPos;
             State = InputState.AmountDialog;
         }
         else
         {
             Destroy(DragArrow);
             State = InputState.Idle;
         }
     }
 }
コード例 #4
0
ファイル: InputHandler.cs プロジェクト: p-svacha/TheWorldGame
        private void UpdatePlanningPhase()
        {
            switch (State)
            {
            case InputState.Idle:
                // Click on existing movement
                if (Input.GetKeyDown(KeyCode.Mouse0))
                {
                    ArmyArrow hoveredMovement = GetHoveredTroopMovement();
                    if (hoveredMovement != null)
                    {
                        EditedMovement    = hoveredMovement;
                        ActiveTroopDialog = Instantiate(Game.UI.TroopMovementDialog);
                        ActiveTroopDialog.Init(hoveredMovement.TroopMovement.SourceTerritory.UnplannedTroops + hoveredMovement.TroopMovement.NumTroops, hoveredMovement.TroopMovement.NumTroops, OnEditTroopMovementDialogReturn);
                        ActiveTroopDialog.transform.SetParent(Game.UI.OverlayContainer.transform);
                        Vector3 targetPos = Camera.WorldToScreenPoint(new Vector3(hoveredMovement.MidPoint.x, 0f, hoveredMovement.MidPoint.y));
                        ActiveTroopDialog.transform.position = targetPos;
                        State = InputState.AmountDialog;
                    }
                }

                // Space ends planning phase
                else if (Input.GetKeyDown(KeyCode.Space))
                {
                    Game.EndPlanningPhase();
                }
                break;

            // Dragging current arrow
            case InputState.Dragging:
                Destroy(DragArrow);
                bool validDrag = CanCreateNewTroopMovement();
                DragArrowEnd = GetMousePositionOnMap();
                DragArrow    = MeshGenerator.DrawArrow(DragArrowStart, DragArrowEnd, validDrag ? Color.red : Color.black, width: 0.02f, arrowHeadWidth: 0.06f, arrowHeadLength: 0.15f, yPos: PolygonMapGenerator.LAYER_OVERLAY1);
                break;
            }
        }