Пример #1
0
 private void Client_SelectedCommandChanged(object sender, UnitCommandIDEventArgs e)
 {
     // change the cursor based on the selected command
     // TODO fix this
     if (UnitCommand.GetTargetType(e.UnitCommandID) == UnitCommandTargetType.Tile)
     {
         unitCommandTargetCursor.Enable();
     }
     else
     {
         defaultCursor.Enable();
     }
 }
Пример #2
0
        // draws all the valid tiles the selected command can to used on
        private void DrawCommandTarget(SpriteBatch sb)
        {
            if (client.SelectedUnit == null)
            {
                return; // don't continue if there is no selected unit
            }
            if (UnitCommand.GetTargetType(client.SelectedCommand) != UnitCommandTargetType.Tile)
            {
                return; // don't continue if the selected command is not of target type tile
            }
            switch (client.SelectedCommand)
            {
            case UnitCommandID.UNITCMD_MOVE:     // Draw possible move locations
                lock (_lock_updateMoveTargets)
                {
                    if (moveTargets == null)
                    {
                        break;
                    }
                    foreach (Tile tileLoc in moveTargets)
                    {
                        tileHighlightSprite.Draw(sb, boardRenderer.GetTileRenderRect(tileLoc), null, Color.CornflowerBlue);
                    }
                    Tile tileUnderMouse = boardRenderer.GetTileAtPoint(InputManager.Instance.MouseWorldPos(camera));
                    if (tileUnderMouse != null && client.GetCachedTile(tileUnderMouse.Location) != null)
                    {
                        DrawPath(sb, client.SelectedUnit.Location, Board.FindPath(client.SelectedUnit.Location, tileUnderMouse.Location, client.Board), Color.Yellow);
                    }
                }
                break;

            case UnitCommandID.UNITCMD_SETTLE:     // Draw recommended city locations
                break;

            case UnitCommandID.UNITCMD_MELEE:     // Draw adjacent tiles
                foreach (Point nLoc in client.GetCachedTile(client.SelectedUnit.Location).GetNeighbourTileLocations())
                {
                    tileHighlightSprite.Draw(sb, boardRenderer.GetTileRenderRect(nLoc), null, Color.Red);
                }
                break;

            case UnitCommandID.UNITCMD_BOMBARD:     // Draw all tiles in range
                break;
            }
        }
Пример #3
0
        /// <summary>
        /// Shows the gui element
        /// </summary>
        public void Show()
        {
            lock (SceneGame._lock_guiDrawCall)
            {
                // hide other forms
                sceneGame.HideForms(true, false);

                // don't show try showing the form if no unit is selected
                if (client.SelectedUnit == null)
                {
                    Hide();
                    return;
                }

                // programatically build the form
                int height = 250;
                int width  = 400;
                canvas.RemoveChild(form);
                form                    = new Form(new Rectangle(0, canvas.Bounds.Height - height, width, height), canvas);
                form.Draggable          = false;
                form.CloseButtonEnabled = true;
                // format the form text
                form.Text = $"Unit - {client.DataManager.Empire.GetEmpire(client.Player.EmpireID).Adjective} {client.SelectedUnit.Name}".ToRichText();
                form.CloseButton.MouseClick += (s, a) =>
                {
                    // when the form is closed, deselect the selected unit
                    client.SelectedUnit = null;
                };

                // construct the command buttons based on the selected unit's abilities
                int xOffset    = 0;
                int yOffset    = 40;
                int btnWidth   = 50;
                int btnHeight  = 50;
                int maxPerLine = 5;
                int index      = 0;
                commandIds = client.SelectedUnit.Commands;
                if (commandIds == null) // if the unit has no commands, don't try build any buttons
                {
                    return;
                }
                for (int i = 0; i < commandIds.Count; i++)
                {
                    // move the buttons to the next line if appropriate
                    if (i != 0 && i % maxPerLine == 0)
                    {
                        index   = 0;
                        yOffset = 40 + btnHeight;
                    }
                    // build button
                    Button btnCmd = new Button(new Rectangle((xOffset + btnWidth) * index, yOffset, btnWidth, btnHeight), form);
                    btnCmd.Text    = UnitCommand.GetCommandIcon(commandIds[i]);
                    btnCmd.ToolTip = new ToolTip(UnitCommand.FormatName((commandIds[i]).ToString()).ToRichText(), 200);
                    int locali = i; // closure means we can't just use i
                    btnCmd.MouseClick += (s, a) =>
                    {
                        // execute the unit command
                        UnitCommandID cmdID = commandIds[locali];
                        ConsoleManager.Instance.WriteLine($"Select a new command, {cmdID}");
                        // if the command is instant, cast is instantly
                        if (UnitCommand.GetTargetType(cmdID) == UnitCommandTargetType.Instant)
                        {
                            // command the unit
                            if (client.SelectedUnit != null)
                            {
                                client.CommandUnit(new UnitCommand(cmdID, client.SelectedUnit, null));
                            }
                            if (cmdID == UnitCommandID.UNITCMD_DISBAND || cmdID == UnitCommandID.UNITCMD_SETTLE)
                            {
                                // disbanding and settling cause the unit to be removed, to close the form and deselect the unit
                                client.SelectedUnit = null;
                                Hide();
                            }
                        }
                        // otherwise select it
                        else
                        {
                            client.SelectedCommand = cmdID;
                        }
                    };
                    index++;
                }
            }
        }