Beispiel #1
0
        // End road construction mode for player interface.
        public void BuildRoadEnd()
        {
            mapCursorSprites[1].Sprite = 32;
            mapCursorSprites[2].Sprite = 32;
            mapCursorSprites[3].Sprite = 32;
            mapCursorSprites[4].Sprite = 32;
            mapCursorSprites[5].Sprite = 32;
            mapCursorSprites[6].Sprite = 32;

            ClearBuildingRoadSegments();
            buildingRoad.Invalidate();
            UpdateMapCursorPosition(mapCursorPosition);

            PanelBar?.Update();
        }
Beispiel #2
0
        protected override void Layout()
        {
            if (PanelBar != null)
            {
                int panelWidth  = 352;
                int panelHeight = 40;
                PanelBar.MoveTo((Width - panelWidth) / 2, Height - panelHeight);
                PanelBar.SetSize(panelWidth, panelHeight);
            }

            if (initBox != null)
            {
                int initBoxWidth  = 16 + 320 + 16;
                int initBoxHeight = 200;
                int initBoxX      = (Width - initBoxWidth) / 2;
                int initBoxY      = (Height - initBoxHeight) / 2;
                initBox.MoveTo(initBoxX, initBoxY);
                initBox.SetSize(initBoxWidth, initBoxHeight);
            }

            if (PopupBox != null && PopupBox.Parent != null)
            {
                int popupWidth  = 144;
                int popupHeight = 160;
                int popupX      = (PopupBox.Parent.Width - popupWidth) / 2;
                int popupY      = (PopupBox.Parent.Height - popupHeight) / 2;
                PopupBox.MoveTo(popupX, popupY);
                PopupBox.SetSize(popupWidth, popupHeight);
            }

            if (NotificationBox != null)
            {
                int notificationBoxWidth  = 144; // was 200
                int notificationBoxHeight = 160; // was 88
                int notificationBoxX      = (Width - notificationBoxWidth) / 2;
                int notificationBoxY      = (Height - notificationBoxHeight) / 2;
                NotificationBox.MoveTo(notificationBoxX, notificationBoxY);
                NotificationBox.SetSize(notificationBoxWidth, notificationBoxHeight);
            }

            if (Viewport != null)
            {
                Viewport.SetSize(Width, Height);
            }

            SetRedraw();
        }
Beispiel #3
0
        public Interface(IRenderView renderView, Audio.IAudioInterface audioInterface, Viewer viewer)
            : base(renderView, audioInterface)
        {
            RenderView     = renderView;
            AudioInterface = audioInterface;
            Viewer         = viewer;

            TextRenderer = new TextRenderer(renderView);

            displayed = true;
            config    = UserConfig.Game.Options;

            mapCursorSprites[0] = new SpriteLocation {
                Sprite = 31
            };
            mapCursorSprites[1] = new SpriteLocation {
                Sprite = 32
            };
            mapCursorSprites[2] = new SpriteLocation {
                Sprite = 32
            };
            mapCursorSprites[3] = new SpriteLocation {
                Sprite = 32
            };
            mapCursorSprites[4] = new SpriteLocation {
                Sprite = 32
            };
            mapCursorSprites[5] = new SpriteLocation {
                Sprite = 32
            };
            mapCursorSprites[6] = new SpriteLocation {
                Sprite = 32
            };

            cursorSprite         = renderView.SpriteFactory.Create(16, 16, 0, 0, false, false, 255);
            cursorSprite.Layer   = renderView.GetLayer(Freeserf.Layer.Cursor);
            cursorSprite.Visible = true;

            SetSize(640, 480); // original size

            Viewport = null;

            PanelBar = new PanelBar(this);
            AddChild(PanelBar, 0, 0, false);
            Layout();
        }
Beispiel #4
0
        // Open popup box
        public void OpenPopup(PopupBox.Type box)
        {
            if (PopupBox == null)
            {
                PopupBox = new PopupBox(this);
            }

            if (initBox != null)
            {
                initBox.AddChild(PopupBox, 0, 0);
            }
            else
            {
                AddChild(PopupBox, 0, 0);
            }

            Layout();
            PopupBox.Show(box);
            PanelBar?.Update();
        }
Beispiel #5
0
        // Close the current popup.
        public void ClosePopup()
        {
            if (PopupBox == null)
            {
                return;
            }

            PopupBox.Hide();

            if (initBox != null)
            {
                initBox.DeleteChild(PopupBox);
            }
            else
            {
                DeleteChild(PopupBox);
            }

            UpdateMapCursorPosition(mapCursorPosition);
            PanelBar?.Update();
        }
Beispiel #6
0
        // Start road construction mode for player interface.
        public void BuildRoadBegin()
        {
            DetermineMapCursorType();

            if (mapCursorType != CursorType.Flag &&
                mapCursorType != CursorType.RemovableFlag)
            {
                UpdateInterface();
                return;
            }

            if (buildingRoad == null)
            {
                buildingRoad = new Road();
            }

            buildingRoad.Invalidate();
            buildingRoad.Start(mapCursorPosition);
            UpdateMapCursorPosition(mapCursorPosition);

            PanelBar?.Update();
        }
Beispiel #7
0
        protected override bool HandleKeyPressed(char key, int modifier)
        {
            if (!Ingame)
            {
                return(false);
            }

            switch (key)
            {
            // Interface control
            case Event.SystemKeys.Tab:
            {
                if ((modifier & 2) != 0)
                {
                    ReturnFromMessage();
                }
                else
                {
                    OpenMessage();
                }
                break;
            }

            // Game speed
            case '+':
            {
                if (!IsRemote)
                {
                    Game.IncreaseSpeed();
                }
                break;
            }

            case '-':
            {
                if (!IsRemote)
                {
                    Game.DecreaseSpeed();
                }
                break;
            }

            case '0':
            {
                if (!IsRemote)
                {
                    Game.ResetSpeed();
                }
                break;
            }

            case 'P':
            {
                if (!IsRemote)
                {
                    Game.Pause();
                }
                break;
            }

            // Audio
            case 'S':
            {
                var soundPlayer = Audio?.GetSoundPlayer();

                if (soundPlayer != null)
                {
                    soundPlayer.Enabled = !soundPlayer.Enabled;
                }

                break;
            }

            case 'M':
            {
                var musicPlayer = Audio?.GetMusicPlayer();

                if (musicPlayer != null)
                {
                    musicPlayer.Enabled = !musicPlayer.Enabled;
                }

                break;
            }

            // Game control
            case 'B':
            {
                Viewport.ShowPossibleBuilds = !Viewport.ShowPossibleBuilds;
                break;
            }

            case 'J':
            {
                if (Viewer.AccessRights != Viewer.Access.Player)
                {
                    uint index = Game.GetNextPlayer(player).Index;
                    SetPlayer(index);
                    Log.Info.Write(ErrorSystemType.Game, "Switched to player #" + index);
                }

                break;
            }

            case 'Z':
                if ((modifier & 1) != 0)
                {
                    if (!IsRemote)
                    {
                        GameStore.Instance.QuickSave("quicksave", Game);
                    }
                }
                break;

            case 'N':
                if ((modifier & 1) != 0)
                {
                    if (!IsRemote)
                    {
                        OpenGameInit();
                    }
                }
                break;

            case 'C':
                if ((modifier & 1) != 0)
                {
                    OpenPopup(PopupBox.Type.QuitConfirm);
                }
                break;

            case Event.SystemKeys.Delete:
                if (PanelBar != null && PanelBar.Displayed && PanelBar.CanDemolish())
                {
                    PanelBar.Demolish();
                }
                break;

            default:
                return(false);
            }

            return(true);
        }
Beispiel #8
0
        // Set the appropriate sprites for the panel buttons and the map cursor.
        void UpdateInterface()
        {
            if (!IsBuildingRoad)
            {
                switch (mapCursorType)
                {
                case CursorType.None:
                    mapCursorSprites[0].Sprite = 31u;
                    mapCursorSprites[2].Sprite = 32u;
                    break;

                case CursorType.Flag:
                    mapCursorSprites[0].Sprite = 50u;
                    mapCursorSprites[2].Sprite = 32u;
                    break;

                case CursorType.RemovableFlag:
                    mapCursorSprites[0].Sprite = 50u;
                    mapCursorSprites[2].Sprite = 32u;
                    break;

                case CursorType.Building:
                    mapCursorSprites[0].Sprite = 31u;
                    mapCursorSprites[2].Sprite = 32u;
                    break;

                case CursorType.Path:
                    mapCursorSprites[0].Sprite = 51u;
                    mapCursorSprites[2].Sprite = 32u;
                    if (buildPossibility != BuildPossibility.None)
                    {
                        mapCursorSprites[0].Sprite = 46u;
                    }
                    break;

                case CursorType.ClearByFlag:
                    if (buildPossibility < BuildPossibility.Mine)
                    {
                        mapCursorSprites[0].Sprite = 31u;
                        mapCursorSprites[2].Sprite = 32u;
                    }
                    else
                    {
                        mapCursorSprites[0].Sprite = 45u + (uint)buildPossibility;
                        mapCursorSprites[2].Sprite = 32u;
                    }
                    break;

                case CursorType.ClearByPath:
                    if (buildPossibility != BuildPossibility.None)
                    {
                        mapCursorSprites[0].Sprite = 45u + (uint)buildPossibility;

                        if (buildPossibility == BuildPossibility.Flag)
                        {
                            mapCursorSprites[2].Sprite = 32u;
                        }
                        else
                        {
                            mapCursorSprites[2].Sprite = 46u;
                        }
                    }
                    else
                    {
                        mapCursorSprites[0].Sprite = 31u;
                        mapCursorSprites[2].Sprite = 32u;
                    }
                    break;

                case CursorType.Clear:
                    if (buildPossibility != BuildPossibility.None)
                    {
                        if (buildPossibility == BuildPossibility.Castle)
                        {
                            mapCursorSprites[0].Sprite = 49u;
                        }
                        else
                        {
                            mapCursorSprites[0].Sprite = 45u + (uint)buildPossibility;
                        }
                        if (buildPossibility == BuildPossibility.Flag)
                        {
                            mapCursorSprites[2].Sprite = 32u;
                        }
                        else
                        {
                            mapCursorSprites[2].Sprite = 46u;
                        }
                    }
                    else
                    {
                        mapCursorSprites[0].Sprite = 31u;
                        mapCursorSprites[2].Sprite = 32u;
                    }
                    break;

                default:
                    Debug.NotReached();
                    break;
                }
            }

            PanelBar?.Update();
        }