Exemple #1
0
        public void RefreshViewport(IGameSettings settings, IGameWindow gameWindow)
        { 
            if (settings.PreserveAspectRatio) //http://www.david-amador.com/2013/04/opengl-2d-independent-resolution-rendering/
            {
                float targetAspectRatio = (float)settings.VirtualResolution.Width / settings.VirtualResolution.Height;
                Size screen = new Size(gameWindow.Width, gameWindow.Height);
                int width = screen.Width;
                int height = (int)(width / targetAspectRatio + 0.5f);
                if (height > screen.Height)
                {
                    //It doesn't fit our height, we must switch to pillarbox then
                    height = screen.Height;
                    width = (int)(height * targetAspectRatio + 0.5f);
                }

                // set up the new viewport centered in the backbuffer
                int viewX = (screen.Width / 2) - (width / 2);
                int viewY = (screen.Height / 2) - (height / 2);

                _graphics.Viewport(viewX, viewY, width, height);
            }
            else
            {
                _graphics.Viewport(0, 0, gameWindow.Width, gameWindow.Height);
            }
        }
Exemple #2
0
		public IconButton(IGameWindow window, Camera<OrthographicProjection> camera, Vector2 position, IRenderable renderable, Key? hotkey = null)
			: base(window, camera, position)
		{
			Renderable = renderable;
			IsSelected = false;
			Hotkey = hotkey;
		}
		public GameStateManager(IGameWindow gameWindow, ContentManager content)
		{
			GameWindow = gameWindow;

			_content = content;
			_states = new List<GameState>();
		}
		public GamePresenter(IGameWindow window)
		{
			this.window = window;
			window.CheckWord += window_CheckWord;
			window.AcceptWord += window_AcceptWord;

			StartGame();
		}
Exemple #5
0
		public Label(IGameWindow window, Camera<OrthographicProjection> camera, Vector2 position, string text)
			: base(window, camera, position)
		{
			Text = text;
			TextColor = COLOR_TEXT;
			Shadowed = SHADOWED;
			ShadowColor = COLOR_SHADOW;
		}
Exemple #6
0
		public Border(IGameWindow window, Camera<OrthographicProjection> camera, Vector2 position, int tileWidth, int tileHeight)
			: base(window, camera, position)
		{
			_tileWidth = tileWidth;
			_tileHeight = tileHeight;

			BackgroundColor = COLOR_BACKGROUND;
			BorderColor = COLOR_BORDER;
		}
		public InputReceiver(IGameWindow window)
		{
			Window = window;

			InputManager.Instance.Keyboard.KeyDown += Keyboard_KeyDown;
			InputManager.Instance.Keyboard.KeyUp += Keyboard_KeyUp;
			InputManager.Instance.Mouse.ButtonDown += Mouse_ButtonDown;
			InputManager.Instance.Mouse.ButtonUp += Mouse_ButtonUp;
			InputManager.Instance.Mouse.Move += Mouse_Move;
			InputManager.Instance.Mouse.WheelChanged += Mouse_WheelChanged;
		}
		public virtual void Dispose()
		{
			Window = null;

			InputManager.Instance.Keyboard.KeyDown -= Keyboard_KeyDown;
			InputManager.Instance.Keyboard.KeyUp -= Keyboard_KeyUp;
			InputManager.Instance.Mouse.ButtonDown -= Mouse_ButtonDown;
			InputManager.Instance.Mouse.ButtonUp -= Mouse_ButtonUp;
			InputManager.Instance.Mouse.Move -= Mouse_Move;
			InputManager.Instance.Mouse.WheelChanged -= Mouse_WheelChanged;
		}
        public ModelRenderer(IGameWindow control, File3di file)
        {
            _viewport = control;
            _file = file;

            _viewport.MakeCurrent();
            OnLoad(EventArgs.Empty);

            _viewport.UpdateFrame += OnUpdateFrame;
            _viewport.RenderFrame += OnRenderFrame;
        }
Exemple #10
0
		public UIElement(IGameWindow window, Camera<OrthographicProjection> camera, Vector2 position)
			: base(window)
		{
			ClickStarted = false;

			Camera = camera;
			HasMouseHover = false;
			CanHaveMouseHover = true;

			Bounds = new RectangleF(position.X, position.Y, 0, 0);
		}
 public AGSRuntimeSettings(IGameSettings settings, IGameWindow gameWindow, IMessagePump messagePump, IGLUtils glUtils)
 {
     _glUtils = glUtils;
     _gameWindow = gameWindow;
     _messagePump = messagePump;
     Title = settings.Title;
     VirtualResolution = settings.VirtualResolution;
     Vsync = settings.Vsync;
     PreserveAspectRatio = settings.PreserveAspectRatio;
     WindowState = settings.WindowState;
     WindowBorder = settings.WindowBorder;
 }
Exemple #12
0
 internal XogoWindow(IGameWindow gameWindow, IGlAdapter adapter)
 {
     if (gameWindow == null)
     {
         throw new ArgumentNullException(nameof(gameWindow));
     }
     if (adapter == null)
     {
         throw new ArgumentNullException(nameof(adapter));
     }
     this.gameWindow = gameWindow;
     this.adapter = adapter;
     textureLoader = new TextureLoader(adapter, new FileSystem());
     AddEventHandles();
 }
Exemple #13
0
        public GameFrame(Game pmGame)
        {
            game=	pmGame;
            frame=	new PCGameWindow();
            viewport=	new PCViewport();
            resizeComponents=	defaultResizeComponents;

            ((PCGameWindow)frame).setDoubleBuffered(true);
            viewport.clearColor=	new Color("#f0ffff");
            frame.title=	"Game";
            frame.size=	new Size2(800, 640);
            frame.onResize+=	frameResize;

            frame.addControl(viewport);
            resizeComponents();
        }
Exemple #14
0
		public UIManager(IGameWindow window, Viewport viewport, WorldManager worldManager)
		{
			_window = window;

			_worldManager = worldManager;

			_children = new List<UIElement>();

			_hudCamera = Camera.CreateOrthographicCamera(viewport);
			_hudCamera.Projection.OrthographicSize = viewport.Height / 2;

			//_tessellator = new ImmediateModeTessellator();
			_tessellator = new VertexBufferTessellator() { Mode = VertexTessellatorMode.Render };

			ToolbarItems = new List<ItemStackButton>();
		}
Exemple #15
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public GameConsole(IGameWindow window, IGraphicsDevice graphicsDevice)
            : base()
        {
            if (window == null)
                throw new ArgumentNullException("window");

            if (graphicsDevice == null)
                throw new ArgumentNullException("graphicsDevice");

            this.Window = window;
            this.Window.KeyPress += this.Window_KeyPress;

            this.GraphicsDevice = graphicsDevice;

            this.inputReceivedEventArgs = new GameConsoleInputEventArgs();
            this.outputReceivedEventArgs = new GameConsoleOutputEventArgs();

            this.DefaultTextColor = Color.Black;
            this.BackgroundColor = Color.White;
            this.Height = (int)(this.Window.DisplayHeight * 0.75);
            this.Animate = true;
            this.AnimationTime = TimeSpan.FromMilliseconds(500);
            this.animationElapsedTime = TimeSpan.Zero;

            this.Padding = 4;

            this.maxLines = 25;
            this.lines = new GameConsoleLine[this.maxLines];
            for (int i = 0; i < this.lines.Length; i++)
                this.lines[i] = new GameConsoleLine();

            this.lineCount = 0;
            this.firstLine = 0;

            this.InputEnabled = false;
            this.InputPrompt = "> ";
            this.InputColor = Color.Black;
            this.input = new StringBuilder(128);
            this.cursorPosition = 0;

            this.ToggleKeyCode = 192;
        }
 public AndroidGameWindowSize(IGameWindow gameWindow)
 {
     _gameWindow = gameWindow;
 }
Exemple #17
0
 public BaseButton(IGameWindow window, Camera <OrthographicProjection> camera, Vector2 position)
     : base(window, camera, position)
 {
 }
Exemple #18
0
 public InventorySlotButton(IGameWindow window, Camera <OrthographicProjection> camera, Vector2 position, Func <InventoryContainer> inventory, int slotIndex, Key?hotkey = null)
     : base(window, camera, position, null, hotkey)
 {
     _inventory = inventory;
     _slotIndex = slotIndex;
 }
Exemple #19
0
 public TestWindow(IGameWindow window, IGlAdapter adapter)
     : base(window, adapter) { }
 public AGSRendererLoop(Resolver resolver, IGame game,
                        IAGSRoomTransitions roomTransitions, IGLUtils glUtils, IGameWindow gameWindow,
                        IAGSRenderPipeline pipeline, IDisplayList displayList,
                        IInput input, IMatrixUpdater matrixUpdater)
 {
     _pipeline                   = pipeline;
     _input                      = input;
     _displayList                = displayList;
     _glUtils                    = glUtils;
     _gameWindow                 = gameWindow;
     _resolver                   = resolver;
     _game                       = game;
     _gameState                  = game.State;
     _noAspectRatioSettings      = new AGSGameSettings(game.Settings.Title, game.Settings.VirtualResolution, preserveAspectRatio: false);
     _roomTransitions            = roomTransitions;
     _matrixUpdater              = matrixUpdater;
     _roomTransitions.Transition = new RoomTransitionInstant();
 }
Exemple #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SampleGame"/> class.
 /// </summary>
 /// <param name="window">The game window.</param>
 public SampleGame(IGameWindow window)
     : base(window)
 {
     this.Content = new ContentManager(this);
     this.Chunks  = new ChunkManager(this.Content);
 }
 public InsertCoinWarningView(IGameWindow parent)
 {
     _parent = parent;
 }
Exemple #23
0
 public TextButton(IGameWindow window, Camera <OrthographicProjection> camera, Vector2 position, string text)
     : base(window, camera, position)
 {
     Text = text;
 }
Exemple #24
0
 public Photon(IGameWindow parent)
 {
     _parent = parent;
 }
#pragma warning restore CS0067

        public AGSRuntimeSettings(IGameSettings settings, IGameWindow gameWindow, IRenderMessagePump messagePump)
        {
            _gameWindow  = gameWindow;
            _messagePump = messagePump;
            LoadFrom(settings);
        }
 public AndroidGameWindowSize(IGameWindow gameWindow)
 {
     _gameWindow = gameWindow;
     _density    = Resources.System.DisplayMetrics.Density;
 }
		public InventorySlotButton(IGameWindow window, Camera<OrthographicProjection> camera, Vector2 position, Func<InventoryContainer> inventory, int slotIndex, Key? hotkey = null)
			: base(window, camera, position, null, hotkey)
		{
			_inventory = inventory;
			_slotIndex = slotIndex;
		}
Exemple #28
0
 public GameWindowPresenter(IGameWindow gameWindow, IApplicationModel applicationModel)
 {
     _applicationModel   = applicationModel;
     _gameWindow         = gameWindow;
     _windowSubPresenter = new WindowSubPresenter(applicationModel, ResourceId.GameWindow, _gameWindow);
 }
Exemple #29
0
        public Engine(EngineSettings settings, Control container)
        {
            if (container != null && container.IsDisposed)
            {
                throw new ArgumentException("Container is disposed.", "container");
            }

            Log.Info("");
            Log.Info("===========");
            Log.Info("DotGame {0}", Version);
            Log.Info("===========");
            Log.Info("Engine starting...");

            if (!SystemCapabilities.IsSupported(settings.GraphicsAPI))
            {
                throw new PlatformNotSupportedException(string.Format("Graphics api \"{0}\" not supported.", settings.GraphicsAPI));
            }

            if (!SystemCapabilities.IsSupported(settings.AudioAPI))
            {
                throw new PlatformNotSupportedException(string.Format("Audio api \"{0}\" not supported.", settings.AudioAPI));
            }

            this.Settings = settings;

            switch (Settings.GraphicsAPI)
            {
            case GraphicsAPI.OpenGL4:
                if (container == null)
                {
                    window = new DotGame.OpenGL4.Windows.GameWindow(Settings.Width, Settings.Height);
                }
                else
                {
                    window = new DotGame.OpenGL4.Windows.GameControl(container);
                }
                break;

            case GraphicsAPI.Direct3D11:
                if (container == null)
                {
                    window = new DotGame.DirectX11.Windows.GameWindow(Settings.Width, Settings.Height);
                }
                else
                {
                    window = new DotGame.DirectX11.Windows.GameControl(container);
                }
                break;

            default:
                throw new NotImplementedException("GraphicsAPI not implemented.");
            }

            // Engine initialisieren
            Init();

            thread = new Thread(new ThreadStart(Run));
            thread.Start();

            // auf Start warten
            onStart.WaitOne();

            Log.Info("Engine init done!");
            Log.Info("===========");
            Log.FlushBuffer();
        }
Exemple #30
0
 public WindowSpy(IGameWindow gameWindow, GlClear glClear, Renderer renderer) : base(gameWindow, glClear, renderer)
 {
 }
		public ItemStackButton(IGameWindow window, Camera<OrthographicProjection> camera, Vector2 position, ItemStack itemStack, Key? hotkey = null)
			: base(window, camera, position, null, hotkey)
		{
			ItemStack = itemStack;
		}
Exemple #32
0
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();

            string cityPickerTitle = ClientResources.GetString("sabotage_cityPickerTitle");

            SelectCity(cityPickerTitle);
            if (this.City == null)
            {
                OnCanceled();
                return;
            }
            BuildableItem   improvement = this.City.NextImprovement;
            EspionageResult result      = this.DiplomaticTie.Sabotage(this.City);
            string          text        = string.Empty;

            switch (result)
            {
            case EspionageResult.Failure:
                break;

            case EspionageResult.ImmuneToEspionage:
                text = ClientResources.GetString("sabotage_immune");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.Civilization.Adjective);
                break;

            case EspionageResult.SpyCaught:
                text = ClientResources.GetString("sabotage_spycaught");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;

            case EspionageResult.Success:
                text = ClientResources.GetString("sabotage_success");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name,
                    improvement.Name);
                break;

            case EspionageResult.SuccessWithCapturedSpy:
                text = ClientResources.GetString("sabotage_success_spycaught");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name,
                    improvement.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;
            }
            IGameWindow gw = ClientApplication.Instance.GameWindow;

            gw.ShowMessageBox(text, ClientResources.GetString(StringKey.GameTitle));
            OnInvoked();
        }
Exemple #33
0
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            OnInvoking();
            ClientApplication ca        = ClientApplication.Instance;
            bool hasValidTies           = false;
            IDiplomaticTiePicker picker = (IDiplomaticTiePicker)ca.GetControl(typeof(IDiplomaticTiePicker));

            picker.PickerTitle = ClientResources.GetString("plantSpy_tiePickerTitle");
            Collection <DiplomaticTie> ties = new Collection <DiplomaticTie>();

            foreach (DiplomaticTie t in ca.Player.DiplomaticTies)
            {
                //TODO:  account for needed improvements
                if (t.HasEmbassy)
                {
                    hasValidTies = true;
                    if (!t.HasSpy)
                    {
                        ties.Add(t);
                    }
                }
            }
            if (ties.Count == 0 && hasValidTies)
            {
                //all the valid civs already have spys.
                string msg = ClientResources.GetString("plantSpy_spysExists");
                ca.GameWindow.ShowMessageBox(msg, ClientResources.GetString(StringKey.GameTitle));
                OnCanceled();
                return;
            }
            picker.InitializePicker(ties);
            picker.ShowSimilizationControl();
            this.tie = picker.DiplomaticTie;
            EspionageResult result = this.DiplomaticTie.PlantSpy();
            string          text   = string.Empty;

            switch (result)
            {
            case EspionageResult.Success:
                text = ClientResources.GetString("plantspy_success");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.CapitalCity.Name);
                break;

            case EspionageResult.Failure:
                text = ClientResources.GetString("plantspy_failure");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.CapitalCity.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;
            }
            IGameWindow gw = ClientApplication.Instance.GameWindow;

            gw.ShowMessageBox(text, ClientResources.GetString(StringKey.GameTitle));
            OnInvoked();
        }
Exemple #34
0
 public EnemyShip(IGameWindow parent)
 {
     _parent   = parent;
     _location = new Vector2(-40, -40);
 }
Exemple #35
0
 protected GamePlatform(Game game, string title)
 {
     // ReSharper disable once VirtualMemberCallInConstructor
     _mainWindow             = CreateGameWindow(game, title);
     _mainWindow.FormClosed += game.Shutdown;
 }
Exemple #36
0
		public TextButton(IGameWindow window, Camera<OrthographicProjection> camera, Vector2 position, string text)
			: base(window, camera, position)
		{
			Text = text;
		}
Exemple #37
0
        /// <summary>
        /// Creates a first person camera controller.
        /// </summary>
        /// <param name="window">The window.</param>
        /// <param name="speed">The movement speed.</param>
        /// <param name="position">The starting position.</param>
        /// <param name="fieldOfViewY">The field of view y.</param>
        /// <param name="nearClip">The near clip plane.</param>
        /// <param name="farClip">The far clip plane.</param>
        /// <returns>a Camera</returns>
        public static Camera <FirstPerson, Perspective> CreateFirstPersonCameraController(this IGameWindow window, float speed, System.Numerics.Vector3 position, float fieldOfViewY = 90f, float nearClip = 0.1f, float farClip = 1f)
        {
            var perspective = new Perspective(fieldOfViewY, nearClip, farClip);
            var camera      = new Camera <FirstPerson, Perspective>(new FirstPerson(position), perspective);

            window.AddWindowAspectHandling(perspective);
            var movementState = window.AddFirstPersonCameraEvents(camera.View);

            window.UpdateFrame += (s, a) => camera.View.ApplyRotatedMovement(movementState.movement * speed * (float)a.Time);

            return(camera);
        }
Exemple #38
0
 public AGSUpdateThread(IGameWindow window)
 {
     _window = window;
 }
        protected IEnumerator StartTimer(IGameWindow gameWindow, Action OnComplete = null)
        {
            _audioService.StartGameMusic();
            float seconds = 4;


            previousSecondCounter = seconds;

            Rigidbody _prb = null;

            if (_playerCar != null)
            {
                _prb = _playerCar.GetComponent <Rigidbody>();
            }

            Rigidbody _erb = null;

            if (_ghostCar != null)
            {
                _erb = _ghostCar.GetComponent <Rigidbody>();
            }


            gameWindow.Get_TimerText().GetComponent <CanvasGroup>().alpha = 1;

            while (seconds > 1)
            {
                gameWindow.Get_TimerText().text = (seconds - (seconds % 1)).ToString();

                if (previousSecondCounter != (seconds - (seconds % 1)) && seconds != 4)
                {
                    previousSecondCounter = (seconds - (seconds % 1));
                    _audioService.RM_PlayOneShot(audioCounterPath);
                }

                yield return(new WaitForEndOfFrame());

                seconds -= Time.deltaTime;

                if (_prb != null)
                {
                    _prb.velocity = new Vector3(0, _prb.velocity.y, _prb.velocity.z);
                }

                if (_erb != null)
                {
                    _erb.velocity = new Vector3(0, _erb.velocity.y, _erb.velocity.z);
                }

                _playerCar.transform.position = new Vector3(_playerCar.transform.position.x, _playerCar.transform.position.y, 2);
            }

            gameWindow.Get_TimerText().GetComponent <CanvasGroup>().alpha = 0;

            _playerCar.EnablePlayerControll(true);
            if (_gameData.ghostData.Count > 0)
            {
                _ghostCar.EnableEnemyControll(true);
            }



            gameWindow.Get_PauseButton().interactable = true;



            // invoke callback
            if (OnComplete != null)
            {
                OnComplete();
            }
        }
        /// <summary>
        /// Invokes the command.
        /// </summary>
        public override void Invoke()
        {
            ClientApplication    ca     = ClientApplication.Instance;
            IDiplomaticTiePicker picker = (IDiplomaticTiePicker)ca.GetControl(typeof(IDiplomaticTiePicker));

            picker.PickerTitle = ClientResources.GetString("exposespy_tiePickerTitle");
            Collection <DiplomaticTie> ties = new Collection <DiplomaticTie>();

            foreach (DiplomaticTie t in ca.Player.DiplomaticTies)
            {
                //TODO:  account for needed improvements
                if (t.HasEmbassy)
                {
                    ties.Add(t);
                }
            }
            picker.InitializePicker(ties);
            picker.ShowSimilizationControl();
            this.DiplomaticTie = picker.DiplomaticTie;
            IGameWindow gw = ClientApplication.Instance.GameWindow;

            this.City = this.DiplomaticTie.ForeignCountry.CapitalCity;
            EspionageResult result = this.DiplomaticTie.ExposeSpy();
            string          text   = string.Empty;

            switch (result)
            {
            case EspionageResult.ImmuneToEspionage:
                text = ClientResources.GetString("exposespy_immune");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName,
                    ClientApplication.Instance.Player.CapitalCity.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;

            case EspionageResult.SpyCaught:
                text = ClientResources.GetString("exposespy_spycaught");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    this.City.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;

            case EspionageResult.Success:
                text = ClientResources.GetString("exposespy_success");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text, this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName,
                    ClientApplication.Instance.Player.CapitalCity.Name);
                break;

            case EspionageResult.SuccessWithCapturedSpy:
                text = ClientResources.GetString("exposespy_success_spycaught");
                text = string.Format(
                    CultureInfo.CurrentCulture,
                    text,
                    ClientApplication.Instance.Player.CapitalCity.Name,
                    this.DiplomaticTie.ForeignCountry.Government.LeaderTitle,
                    this.DiplomaticTie.ForeignCountry.LeaderName);
                break;
            }

            gw.ShowMessageBox(text, ClientResources.GetString(StringKey.GameTitle));
            OnInvoked();
        }
Exemple #41
0
 public AGSRendererLoop(Resolver resolver, IGame game, IImageRenderer renderer,
                        IAGSRoomTransitions roomTransitions, IGLUtils glUtils, IGameWindow gameWindow,
                        IBlockingEvent <DisplayListEventArgs> onBeforeRenderingDisplayList, IDisplayList displayList,
                        IInput input, IMatrixUpdater matrixUpdater)
 {
     _input                       = input;
     _displayList                 = displayList;
     _glUtils                     = glUtils;
     _gameWindow                  = gameWindow;
     _resolver                    = resolver;
     _game                        = game;
     _gameState                   = game.State;
     _renderer                    = renderer;
     _roomTransitions             = roomTransitions;
     _displayListEventArgs        = new DisplayListEventArgs(null);
     _matrixUpdater               = matrixUpdater;
     OnBeforeRenderingDisplayList = onBeforeRenderingDisplayList;
     _roomTransitions.Transition  = new RoomTransitionInstant();
 }
Exemple #42
0
        public IOSInput(IOSGestures gestures, IGameState state, IShouldBlockInput shouldBlockInput, IGameWindow gameWindow)
        {
            MousePosition     = new MousePosition(0f, 0f, state.Viewport);
            _shouldBlockInput = shouldBlockInput;
            _gameWindow       = gameWindow;
            _state            = state;
            updateWindowSizeFunctions();

            MouseDown = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseUp   = new AGSEvent <AGS.API.MouseButtonEventArgs>();
            MouseMove = new AGSEvent <MousePositionEventArgs>();
            KeyDown   = new AGSEvent <KeyboardEventArgs>();
            KeyUp     = new AGSEvent <KeyboardEventArgs>();

            IOSGameWindow.Instance.View.OnInsertText     += onInsertText;
            IOSGameWindow.Instance.View.OnDeleteBackward += onDeleteBackwards;

            gestures.OnUserDrag += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                DateTime now = DateTime.Now;
                _lastDrag   = now;
                IsTouchDrag = true;
                setMousePosition(e);
                await MouseMove.InvokeAsync(new MousePositionEventArgs(MousePosition));

                await Task.Delay(300);

                if (_lastDrag <= now)
                {
                    IsTouchDrag = false;
                }
            };
            gestures.OnUserSingleTap += async(sender, e) =>
            {
                if (isInputBlocked())
                {
                    return;
                }
                setMousePosition(e);
                LeftMouseButtonDown = true;
                await MouseDown.InvokeAsync(new MouseButtonEventArgs(null, MouseButton.Left, MousePosition));

                await Task.Delay(250);

                await MouseUp.InvokeAsync(new MouseButtonEventArgs(null, MouseButton.Left, MousePosition));

                LeftMouseButtonDown = false;
            };
        }
Exemple #43
0
		public BaseButton(IGameWindow window, Camera<OrthographicProjection> camera, Vector2 position)
			: base(window, camera, position)
		{
		}
 protected void ShowRaceTime(IGameWindow gameWindow)
 {
     _textRaceTime.text = gameWindow.Get_TextRaceTimer().text;
 }
        /// <summary>
        /// Creates a <see cref="GameWindow"/> with a given <see cref="IGameWindow"/> implementation.
        /// </summary>
        protected GameWindow([NotNull] IGameWindow implementation)
        {
            Implementation          = implementation;
            Implementation.KeyDown += OnKeyDown;

            Closing += (sender, e) => e.Cancel = ExitRequested?.Invoke() ?? false;
            Closed  += (sender, e) => Exited?.Invoke();

            MouseEnter += (sender, args) => CursorInWindow = true;
            MouseLeave += (sender, args) => CursorInWindow = false;

            FocusedChanged += (o, e) => isActive.Value = Focused;

            supportedWindowModes.AddRange(DefaultSupportedWindowModes);

            bool firstUpdate = true;

            UpdateFrame += (o, e) =>
            {
                if (firstUpdate)
                {
                    isActive.Value = Focused;
                    firstUpdate    = false;
                }
            };

            WindowStateChanged += (o, e) => isActive.Value = WindowState != WindowState.Minimized;

            MakeCurrent();

            string version = GL.GetString(StringName.Version);
            string versionNumberSubstring = getVersionNumberSubstring(version);

            GLVersion = new Version(versionNumberSubstring);

            // As defined by https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glGetString.xml
            IsEmbedded = version.Contains("OpenGL ES");

            version = GL.GetString(StringName.ShadingLanguageVersion);

            if (!string.IsNullOrEmpty(version))
            {
                try
                {
                    GLSLVersion = new Version(versionNumberSubstring);
                }
                catch (Exception e)
                {
                    Logger.Error(e, $@"couldn't set GLSL version using string '{version}'");
                }
            }

            if (GLSLVersion == null)
            {
                GLSLVersion = new Version();
            }

            Logger.Log($@"GL Initialized
                        GL Version:                 {GL.GetString(StringName.Version)}
                        GL Renderer:                {GL.GetString(StringName.Renderer)}
                        GL Shader Language version: {GL.GetString(StringName.ShadingLanguageVersion)}
                        GL Vendor:                  {GL.GetString(StringName.Vendor)}
                        GL Extensions:              {GL.GetString(StringName.Extensions)}");

            Context.MakeCurrent(null);
        }
Exemple #46
0
        protected override void LoadContent()
        {
            GraphicsDevice.DeviceLost += (sender, e) =>
            {
                _coreGame?.DeviceLost();
            };
            GraphicsDevice.DeviceReset += (sender, e) =>
            {
                _coreGame?.DeviceReset();
            };
            GraphicsDevice.DeviceResetting += (sender, e) =>
            {
                _coreGame?.DeviceResetting();
            };
            GraphicsDevice.ResourceCreated += (sender, e) =>
            {
                _coreGame?.ResourceCreated(e.Resource);
            };
            GraphicsDevice.ResourceDestroyed += (sender, e) =>
            {
                _coreGame?.ResourceDestroyed(e.Name, e.Tag);
            };

            // Construct a platform-independent game window.
            ProtogameWindow = ConstructGameWindow();

#if PLATFORM_ANDROID
            // On Android, disable viewport / backbuffer scaling because we expect games
            // to make use of the full display area.
            this.GraphicsDeviceManager.IsFullScreen = true;
            this.GraphicsDeviceManager.PreferredBackBufferHeight = this.Window.ClientBounds.Height;
            this.GraphicsDeviceManager.PreferredBackBufferWidth  = this.Window.ClientBounds.Width;
#endif

#if PLATFORM_WINDOWS
            // Register for the window resize event so we can scale
            // the window correctly.
            Window.ClientSizeChanged += OnClientSizeChanged;

            // Register for the window close event so we can dispatch
            // it correctly.
            var form = System.Windows.Forms.Control.FromHandle(Window.Handle) as System.Windows.Forms.Form;
            if (form != null)
            {
                form.FormClosing += (sender, args) =>
                {
                    bool cancel = false;
                    _coreGame?.CloseRequested(out cancel);

                    if (cancel)
                    {
                        args.Cancel = true;
                    }
                };
            }
#endif

            if (_coreGame != null)
            {
                _coreGame.LoadContent();
                return;
            }

            _shouldLoadContentOnDelayedGame = true;

            _splashSpriteBatch = new SpriteBatch(GraphicsDevice);

#if PLATFORM_ANDROID
            try
            {
                var layout       = _gameActivity.Window.DecorView.FindViewById(Android.Resource.Id.Content);
                var backgroundId = _gameActivity.Resources.GetIdentifier("background", "drawable", Android.App.Application.Context.PackageName);
                _splash = Texture2D.FromStream(GraphicsDevice, Android.Graphics.BitmapFactory.DecodeResource(_gameActivity.Resources, backgroundId));
            }
            catch
            {
                // Setting background is optional.
            }
#endif
        }
Exemple #47
0
 public GameScoreKeeper(IGameWindow parent)
 {
     _insertCoinWarningView = new InsertCoinWarningView(parent);
 }
        /// <summary>
        /// Creates a <see cref="OsuTKWindow"/> with a given <see cref="IGameWindow"/> implementation.
        /// </summary>
        protected OsuTKWindow([NotNull] IGameWindow osuTKGameWindow)
        {
            OsuTKGameWindow          = osuTKGameWindow;
            OsuTKGameWindow.KeyDown += OnKeyDown;

            CurrentDisplayBindable.Value = PrimaryDisplay;

            // Moving or resizing the window needs to check to see if we've moved to a different display.
            // This will update the CurrentDisplay bindable.
            Move   += (sender, e) => checkCurrentDisplay();
            Resize += (sender, e) =>
            {
                checkCurrentDisplay();
                Resized?.Invoke();
            };

            Closing += (sender, e) => e.Cancel = ExitRequested?.Invoke() ?? false;
            Closed  += (sender, e) => Exited?.Invoke();

            MouseEnter += (sender, args) => cursorInWindow.Value = true;
            MouseLeave += (sender, args) => cursorInWindow.Value = false;

            supportedWindowModes.AddRange(DefaultSupportedWindowModes);

            UpdateFrame += (o, e) => UpdateFrameScheduler.Update();

            MakeCurrent();

            string version = GL.GetString(StringName.Version);
            string versionNumberSubstring = getVersionNumberSubstring(version);

            GLVersion = new Version(versionNumberSubstring);

            // As defined by https://www.khronos.org/registry/OpenGL-Refpages/es2.0/xhtml/glGetString.xml
            IsEmbedded = version.Contains("OpenGL ES");

            version = GL.GetString(StringName.ShadingLanguageVersion);

            if (!string.IsNullOrEmpty(version))
            {
                try
                {
                    GLSLVersion = new Version(versionNumberSubstring);
                }
                catch (Exception e)
                {
                    Logger.Error(e, $@"couldn't set GLSL version using string '{version}'");
                }
            }

            if (GLSLVersion == null)
            {
                GLSLVersion = new Version();
            }

            Logger.Log($@"GL Initialized
                        GL Version:                 {GL.GetString(StringName.Version)}
                        GL Renderer:                {GL.GetString(StringName.Renderer)}
                        GL Shader Language version: {GL.GetString(StringName.ShadingLanguageVersion)}
                        GL Vendor:                  {GL.GetString(StringName.Vendor)}
                        GL Extensions:              {GL.GetString(StringName.Extensions)}");
        }
 public ItemStackButton(IGameWindow window, Camera <OrthographicProjection> camera, Vector2 position, ItemStack itemStack, Key?hotkey = null)
     : base(window, camera, position, null, hotkey)
 {
     ItemStack = itemStack;
 }