Exemple #1
0
        //Game Rendering
        public static void Render()
        {
            var takingScreenshot = false;

            if (Renderer?.ScreenshotRequests.Count > 0)
            {
                takingScreenshot = Renderer.BeginScreenshot();
            }

            if (!(Renderer?.Begin() ?? false))
            {
                return;
            }

            if (Renderer.GetScreenWidth() != sOldWidth ||
                Renderer.GetScreenHeight() != sOldHeight ||
                Renderer.DisplayModeChanged())
            {
                sDarknessTexture = null;
                Interface.Interface.DestroyGwen();
                Interface.Interface.InitGwen();
                sOldWidth  = Renderer.GetScreenWidth();
                sOldHeight = Renderer.GetScreenHeight();
            }

            Renderer.Clear(Color.Black);
            DrawCalls     = 0;
            MapsDrawn     = 0;
            EntitiesDrawn = 0;
            LightsDrawn   = 0;

            UpdateView();

            switch (Globals.GameState)
            {
            case GameStates.Intro:
                DrawIntro();

                break;

            case GameStates.Menu:
                DrawMenu();

                break;

            case GameStates.Loading:
                break;

            case GameStates.InGame:
                DrawInGame();

                break;

            case GameStates.Error:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            Interface.Interface.DrawGui();

            DrawGameTexture(
                Renderer.GetWhiteTexture(), new FloatRect(0, 0, 1, 1), CurrentView,
                new Color((int)Fade.GetFade(), 0, 0, 0), null, GameBlendModes.None
                );

            // Draw our mousecursor at the very end, but not when taking screenshots.
            if (!takingScreenshot && !string.IsNullOrWhiteSpace(ClientConfiguration.Instance.MouseCursor))
            {
                var renderLoc = ConvertToWorldPoint(Globals.InputManager.GetMousePosition());
                DrawGameTexture(
                    Globals.ContentManager.GetTexture(GameContentManager.TextureType.Misc, ClientConfiguration.Instance.MouseCursor), renderLoc.X, renderLoc.Y
                    );
            }

            Renderer.End();

            if (takingScreenshot)
            {
                Renderer.EndScreenshot();
            }
        }
Exemple #2
0
        public static void OnKeyPressed(Keys key)
        {
            if (key == Keys.None)
            {
                return;
            }

            var  consumeKey   = false;
            bool canFocusChat = true;

            KeyDown?.Invoke(key);
            switch (key)
            {
            case Keys.Escape:
                if (Globals.GameState != GameStates.Intro)
                {
                    break;
                }

                Fade.FadeIn();
                Globals.GameState = GameStates.Menu;

                return;

            case Keys.Enter:

                for (int i = Interface.Interface.InputBlockingElements.Count - 1; i >= 0; i--)
                {
                    try
                    {
                        var iBox = (InputBox)Interface.Interface.InputBlockingElements[i];
                        if (iBox != null && !iBox.IsHidden)
                        {
                            iBox.okayBtn_Clicked(null, null);
                            canFocusChat = false;

                            break;
                        }
                    }
                    catch { }

                    try
                    {
                        var eventWindow = (EventWindow)Interface.Interface.InputBlockingElements[i];
                        if (eventWindow != null && !eventWindow.IsHidden && Globals.EventDialogs.Count > 0)
                        {
                            eventWindow.EventResponse1_Clicked(null, null);
                            canFocusChat = false;

                            break;
                        }
                    }
                    catch { }
                }

                break;
            }

            if (Controls.Controls.ControlHasKey(Control.OpenMenu, key))
            {
                if (Globals.GameState != GameStates.InGame)
                {
                    return;
                }

                // First try and unfocus chat then close all UI elements, then untarget our target.. and THEN open the escape menu.
                // Most games do this, why not this?
                if (Interface.Interface.GameUi != null && Interface.Interface.GameUi.ChatFocussed)
                {
                    Interface.Interface.GameUi.UnfocusChat = true;
                }
                else if (Interface.Interface.GameUi != null && Interface.Interface.GameUi.CloseAllWindows())
                {
                    // We've closed our windows, don't do anything else. :)
                }
                else if (Globals.Me != null && Globals.Me.TargetIndex != Guid.Empty)
                {
                    Globals.Me.ClearTarget();
                }
                else
                {
                    Interface.Interface.GameUi?.EscapeMenu?.ToggleHidden();
                }
            }

            if (Interface.Interface.HasInputFocus())
            {
                return;
            }

            Controls.Controls.GetControlsFor(key)
            ?.ForEach(
                control =>
            {
                if (consumeKey)
                {
                    return;
                }

                switch (control)
                {
                case Control.Screenshot:
                    Graphics.Renderer?.RequestScreenshot();

                    break;

                case Control.ToggleGui:
                    if (Globals.GameState == GameStates.InGame)
                    {
                        Interface.Interface.HideUi = !Interface.Interface.HideUi;
                    }

                    break;
                }

                switch (Globals.GameState)
                {
                case GameStates.Intro:
                    break;

                case GameStates.Menu:
                    break;

                case GameStates.InGame:
                    switch (control)
                    {
                    case Control.MoveUp:
                        break;

                    case Control.MoveLeft:
                        break;

                    case Control.MoveDown:
                        break;

                    case Control.MoveRight:
                        break;

                    case Control.AttackInteract:
                        break;

                    case Control.Block:
                        Globals.Me?.TryBlock();

                        break;

                    case Control.AutoTarget:
                        Globals.Me?.AutoTarget();

                        break;

                    case Control.PickUp:
                        Globals.Me?.TryPickupItem(Globals.Me.MapInstance.Id, Globals.Me.Y * Options.MapWidth + Globals.Me.X);

                        break;

                    case Control.Enter:
                        if (canFocusChat)
                        {
                            Interface.Interface.GameUi.FocusChat = true;
                            consumeKey = true;
                        }

                        return;

                    case Control.Hotkey1:
                    case Control.Hotkey2:
                    case Control.Hotkey3:
                    case Control.Hotkey4:
                    case Control.Hotkey5:
                    case Control.Hotkey6:
                    case Control.Hotkey7:
                    case Control.Hotkey8:
                    case Control.Hotkey9:
                    case Control.Hotkey0:
                        break;

                    case Control.OpenInventory:
                        Interface.Interface.GameUi?.GameMenu?.ToggleInventoryWindow();

                        break;

                    case Control.OpenQuests:
                        Interface.Interface.GameUi?.GameMenu?.ToggleQuestsWindow();

                        break;

                    case Control.OpenCharacterInfo:
                        Interface.Interface.GameUi?.GameMenu?.ToggleCharacterWindow();

                        break;

                    case Control.OpenParties:
                        Interface.Interface.GameUi?.GameMenu?.TogglePartyWindow();

                        break;

                    case Control.OpenSpells:
                        Interface.Interface.GameUi?.GameMenu?.ToggleSpellsWindow();

                        break;

                    case Control.OpenFriends:
                        Interface.Interface.GameUi?.GameMenu?.ToggleFriendsWindow();

                        break;

                    case Control.OpenSettings:
                        Interface.Interface.GameUi?.EscapeMenu?.OpenSettings();

                        break;

                    case Control.OpenDebugger:
                        Interface.Interface.GameUi?.ShowHideDebug();

                        break;

                    case Control.OpenAdminPanel:
                        PacketSender.SendOpenAdminWindow();

                        break;

                    case Control.OpenGuild:
                        Interface.Interface.GameUi?.GameMenu.ToggleGuildWindow();

                        break;
                    }

                    break;

                case GameStates.Loading:
                    break;

                case GameStates.Error:
                    break;

                default:
                    throw new ArgumentOutOfRangeException(
                        nameof(Globals.GameState), Globals.GameState, null
                        );
                }
            }
                );
        }
Exemple #3
0
        public static void OnKeyPressed(Keys key)
        {
            if (key == Keys.None)
            {
                return;
            }

            var consumeKey = false;

            KeyDown?.Invoke(key);
            switch (key)
            {
            case Keys.Escape:
                if (Globals.GameState != GameStates.Intro)
                {
                    break;
                }

                Fade.FadeIn();
                Globals.GameState = GameStates.Menu;

                return;
            }

            if (Controls.Controls.ControlHasKey(Control.OpenMenu, key))
            {
                if (Globals.GameState != GameStates.InGame)
                {
                    return;
                }

                Interface.Interface.GameUi?.EscapeMenu?.ToggleHidden();
            }

            if (Interface.Interface.HasInputFocus())
            {
                return;
            }

            Controls.Controls.GetControlsFor(key)
            ?.ForEach(
                control =>
            {
                if (consumeKey)
                {
                    return;
                }

                switch (control)
                {
                case Control.Screenshot:
                    Graphics.Renderer?.RequestScreenshot();

                    break;

                case Control.ToggleGui:
                    if (Globals.GameState == GameStates.InGame)
                    {
                        Interface.Interface.HideUi = !Interface.Interface.HideUi;
                    }

                    break;
                }

                switch (Globals.GameState)
                {
                case GameStates.Intro:
                    break;

                case GameStates.Menu:
                    break;

                case GameStates.InGame:
                    switch (control)
                    {
                    case Control.MoveUp:
                        break;

                    case Control.MoveLeft:
                        break;

                    case Control.MoveDown:
                        break;

                    case Control.MoveRight:
                        break;

                    case Control.AttackInteract:
                        break;

                    case Control.Block:
                        Globals.Me?.TryBlock();

                        break;

                    case Control.AutoTarget:
                        Globals.Me?.AutoTarget();

                        break;

                    case Control.PickUp:
                        Globals.Me?.TryPickupItem();

                        break;

                    case Control.Enter:
                        Interface.Interface.GameUi.FocusChat = true;
                        consumeKey = true;

                        return;

                    case Control.Hotkey1:
                    case Control.Hotkey2:
                    case Control.Hotkey3:
                    case Control.Hotkey4:
                    case Control.Hotkey5:
                    case Control.Hotkey6:
                    case Control.Hotkey7:
                    case Control.Hotkey8:
                    case Control.Hotkey9:
                    case Control.Hotkey0:
                        var index = control - Control.Hotkey1;
                        if (0 <= index && index < Interface.Interface.GameUi?.Hotbar?.Items?.Count)
                        {
                            Interface.Interface.GameUi?.Hotbar?.Items?[index]?.Activate();
                        }
                        else
                        {
                            Log.Warn(
                                Interface.Interface.GameUi?.Hotbar?.Items == null
                                                    ? $"Tried to press Hotkey{(index + 1) % 10} but the hotbar items are null."
                                                    : $"Tried to press Hotkey{(index + 1) % 10} which was out of bounds ({control})."
                                );
                        }

                        break;

                    case Control.OpenInventory:
                        Interface.Interface.GameUi?.GameMenu?.ToggleInventoryWindow();

                        break;

                    case Control.OpenQuests:
                        Interface.Interface.GameUi?.GameMenu?.ToggleQuestsWindow();

                        break;

                    case Control.OpenCharacterInfo:
                        Interface.Interface.GameUi?.GameMenu?.ToggleCharacterWindow();

                        break;

                    case Control.OpenParties:
                        Interface.Interface.GameUi?.GameMenu?.TogglePartyWindow();

                        break;

                    case Control.OpenSpells:
                        Interface.Interface.GameUi?.GameMenu?.ToggleSpellsWindow();

                        break;

                    case Control.OpenFriends:
                        Interface.Interface.GameUi?.GameMenu?.ToggleFriendsWindow();

                        break;

                    case Control.OpenSettings:
                        Interface.Interface.GameUi?.EscapeMenu?.OpenSettings();

                        break;

                    case Control.OpenDebugger:
                        Interface.Interface.GameUi?.ShowHideDebug();

                        break;

                    case Control.OpenAdminPanel:
                        PacketSender.SendOpenAdminWindow();

                        break;
                    }

                    break;

                case GameStates.Loading:
                    break;

                case GameStates.Error:
                    break;

                default:
                    throw new ArgumentOutOfRangeException(
                        nameof(Globals.GameState), Globals.GameState, null
                        );
                }
            }
                );
        }
        //Game Rendering
        public static void Render()
        {
            var takingScreenshot = false;

            if (Renderer?.ScreenshotRequests.Count > 0)
            {
                takingScreenshot = Renderer.BeginScreenshot();
            }

            if (!(Renderer?.Begin() ?? false))
            {
                return;
            }

            if (Renderer.GetScreenWidth() != sOldWidth ||
                Renderer.GetScreenHeight() != sOldHeight ||
                Renderer.DisplayModeChanged())
            {
                sDarknessTexture = null;
                Interface.Interface.DestroyGwen();
                Interface.Interface.InitGwen();
                sOldWidth  = Renderer.GetScreenWidth();
                sOldHeight = Renderer.GetScreenHeight();
            }

            Renderer.Clear(Color.Black);
            DrawCalls     = 0;
            MapsDrawn     = 0;
            EntitiesDrawn = 0;
            LightsDrawn   = 0;

            UpdateView();

            switch (Globals.GameState)
            {
            case GameStates.Intro:
                DrawIntro();

                break;

            case GameStates.Menu:
                DrawMenu();

                break;

            case GameStates.Loading:
                break;

            case GameStates.InGame:
                DrawInGame();

                break;

            case GameStates.Error:
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            Interface.Interface.DrawGui();

            DrawGameTexture(
                Renderer.GetWhiteTexture(), new FloatRect(0, 0, 1, 1), CurrentView,
                new Color((int)Fade.GetFade(), 0, 0, 0), null, GameBlendModes.None
                );

            Renderer.End();

            if (takingScreenshot)
            {
                Renderer.EndScreenshot();
            }
        }