Example #1
0
        internal override DisplayModeCollection GetDisplayModes()
        {
            if (supportedDisplayModes == null)
            {
                List <DisplayMode>  modes  = new List <DisplayMode>(new DisplayMode[] { GetCurrentDisplayMode(), });
                SDL.SDL_DisplayMode filler = new SDL.SDL_DisplayMode();
                int numModes = SDL.SDL_GetNumDisplayModes(0);
                for (int i = 0; i < numModes; i += 1)
                {
                    SDL.SDL_GetDisplayMode(0, i, out filler);

                    // Check for dupes caused by varying refresh rates.
                    bool dupe = false;
                    foreach (DisplayMode mode in modes)
                    {
                        if (filler.w == mode.Width && filler.h == mode.Height)
                        {
                            dupe = true;
                        }
                    }
                    if (!dupe)
                    {
                        modes.Add(
                            new DisplayMode(
                                filler.w,
                                filler.h,
                                SurfaceFormat.Color                                 // FIXME: Assumption!
                                )
                            );
                    }
                }
                supportedDisplayModes = new DisplayModeCollection(modes);
            }
            return(supportedDisplayModes);
        }
Example #2
0
        private void INTERNAL_GenerateDisplayModes()
        {
            List <DisplayMode> modes = new List <DisplayMode>();

            SDL.SDL_DisplayMode filler = new SDL.SDL_DisplayMode();
            int numModes = SDL.SDL_GetNumDisplayModes(displayIndex);

            for (int i = 0; i < numModes; i += 1)
            {
                SDL.SDL_GetDisplayMode(displayIndex, i, out filler);

                // Check for dupes caused by varying refresh rates.
                bool dupe = false;
                foreach (DisplayMode mode in modes)
                {
                    if (filler.w == mode.Width && filler.h == mode.Height)
                    {
                        dupe = true;
                    }
                }
                if (!dupe)
                {
                    modes.Add(
                        new DisplayMode(
                            filler.w,
                            filler.h,
                            SurfaceFormat.Color                             // FIXME: Assumption!
                            )
                        );
                }
            }
            supportedDisplayModes = new DisplayModeCollection(modes);
        }
 public void getDisplayMode(out SDL.SDL_DisplayMode DM)
 {
     if (SDL.SDL_GetCurrentDisplayMode(0, out DM) != 0)
     {
         Console.WriteLine("SDL_GetCurrentDisplayMode failed" + SDL.SDL_GetError());
         return;
     }
     SDL.SDL_GetCurrentDisplayMode(0, out DM);
 }
Example #4
0
 public void setWindowSizeDynamically(Config configObj, IntPtr window, SDL.SDL_DisplayMode DM)
 {
     if (configObj.DisplayState == (int)DisplayState.Windowed && configObj.DisplayResolution == (int)DisplayResolution.Available)
     {
         SDL.SDL_SetWindowSize(window, DM.w, DM.h - 70);
     }
     else if (configObj.DisplayState == (int)DisplayState.Fullscreen && configObj.DisplayResolution == (int)DisplayResolution.Available)
     {
         SDL.SDL_SetWindowSize(window, DM.w, DM.h);
     }
     else if (configObj.DisplayResolution != (int)DisplayResolution.Available)
     {
         SDL.SDL_SetWindowSize(window, configObj.DisplayWidth, configObj.DisplayHeight);
     }
 }
 public static DisplayMode ToDisplayMode(this SDL.SDL_DisplayMode mode, int displayIndex)
 {
     SDL.SDL_PixelFormatEnumToMasks(mode.format, out int bpp, out _, out _, out _, out _);
     return(new DisplayMode(SDL.SDL_GetPixelFormatName(mode.format), new Size(mode.w, mode.h), bpp, mode.refresh_rate, displayIndex));
 }
Example #6
0
        static void Main(string[] args)
        {
            using (var gl = new GameLogic())
            {
                new Player {
                    Name = "Alex", Color = System.Drawing.Color.Blue
                };
                new Player {
                    Name = "Randy", Color = System.Drawing.Color.Red
                };

                Player Alex = Instances.FirstOrDefault(x => x.Name == nameof(Alex));
                Alex.Board.Printer.SetBid(Alex.Tokens.OfType <Gold>().Take(2));
                Alex.Board.Apothecary.SetBid(Alex.Tokens.OfType <Blackmail>().Take(1));

                Player Randy = Instances.FirstOrDefault(x => x.Name == nameof(Randy));
                Randy.Board.Printer.SetBid(Randy.Tokens.OfType <Gold>().Take(3));
                Randy.Board.General.SetBid(Randy.Tokens.OfType <Force>().Take(1));


                var actionsWithBids = Instances.Select(x => x.Board).SelectMany(x => x.Actions.Where(y => y.Bid.Any()));

                var winners = actionsWithBids
                              .Select(x => x.GetType().Name)
                              .Distinct()
                              .ToList()
                              .Select(x =>
                {
                    var z = actionsWithBids.Where(y => y.GetType().Name == x).OrderByDescending(y => y.Bid.ToInt()).FirstOrDefault();
                    return(new
                    {
                        ActionName = x,
                        z.Bid,
                        z.PlayerBoard.Player
                    });
                })
                              .ToList();

                winners.ForEach(x =>
                {
                    var pi = typeof(PlayerBoard).GetProperty(x.ActionName);
                    var pa = pi?.GetValue(x.Player.Board) as GameLogic.Action;
                    pa?.Resolve();
                });
            }
            var rv = SDL.Init(SDL2.SDL.INIT_EVERYTHING);
            var sdlIntitialized = !Convert.ToBoolean(rv);

            if (sdlIntitialized)
            {
                var mode         = new SDL.SDL_DisplayMode();
                var displayRect  = new SDL.Rect();
                var displayCount = SDL.GetNumVideoDisplays();
                SDL.GetDisplayBounds(0, out displayRect);
                SDL.GetCurrentDisplayMode(0, out mode);
                int width = 1280, height = 720;//720p

                var left = (int)((mode.w - width) * .5);
                var top  = (int)((mode.h - height) * .5);


                using (var window = new Window(nameof(Revolution), left, top, width, height, SDL.SDL_WindowFlags.SDL_WINDOW_SHOWN, true))
                {
                    if (window.IsValid())
                    {
                        window.Show();
                        window.Raise();
                    }
                    SetupTimerCallback(60, null);
                    var  @event = new SDL.SDL_Event();
                    bool run    = true;

                    //RecipeCardDeck recipeDeck = new RecipeCardDeck();
                    //var recipeTextures = gameLogic.Recipes.ToList().ToDictionary(x => x.GetHashCode(), x => window.Renderer.LoadTexture(x.Source));

                    var tokenTextures = new Dictionary <char, Texture>
                    {
                        { 'b', window.Renderer.LoadTexture("images/blackmail.png") },
                        { 'g', window.Renderer.LoadTexture("images/money.png") },
                        { 'p', window.Renderer.LoadTexture("images/force.png") }
                    };

                    window.Scene = new List <Sprite>();

                    var boardTexture = window.Renderer.LoadTexture("images/board.png");


                    var boardSprite = boardTexture.CreateSprite();
                    boardSprite.X     = 0;
                    boardSprite.Y     = 0;
                    boardSprite.Z     = 0;
                    boardSprite.Scale = 1f;
                    window.Scene.Add(boardSprite);

                    //Debug.WriteLine(gameLogic.FishMarket);

                    int xc = boardSprite.Width;
                    tokenTextures.ToList().ForEach(x =>
                    {
                        var s = new Sprite(x.Value)
                        {
                            Y = 500, X = xc += x.Value.Width, Z = 0, Scale = 1.0f
                        };
                        window.Scene.Add(s);
                        xc += s.Width;
                    });


                    //var s2 = test.CreateSprite();
                    //s2.X = 100;
                    //s2.Y = 100;
                    //s2.Z = 1;
                    //s2.Scale = 1f;
                    //window.Scene.Add(s2);

                    //var s3 = new Sprite(test)
                    //{
                    //    X = 150,
                    //    Y = 150,
                    //    Z = 2,
                    //    Scale = 1f,
                    //};
                    //window.Scene.Add(generalMarketSprite);
                    SDL.SetHint(SDL.SDL_HINT_RENDER_SCALE_QUALITY, "1");
                    window.Clear();
                    window.Present();

                    while (run)
                    {
                        SDL.SDL_PollEvent(out @event);
                        //while ( != 0)
                        //{
                        switch (@event.type)
                        {
                        case SDL.SDL_EventType.SDL_MOUSEBUTTONDOWN:
                            var button = @event.button;
                            var point  = new SDL.Point()
                            {
                                x = button.x, y = button.y
                            };
                            var timestamp = new DateTime(button.timestamp);
                            var matches   = window.Scene.Where(sprite => sprite.Contains(point)).ToList();
                            var brown     = window.Scene.First();
                            matches.ForEach(sprite => sprite.MouseDown(@event));
                            //button.button  1   byte
                            //button.clicks  1   byte
                            //button.padding1    0   byte
                            //button.state   1   byte
                            //button.timestamp   140630  uint
                            //button.@type   SDL_MOUSEBUTTONDOWN SDL2.SDL.SDL_EventType
                            //button.which   0   uint
                            //button.windowID    1   uint
                            //button.x   182 int
                            //button.y   169 int

                            break;

                        case SDL.SDL_EventType.SDL_QUIT:
                            run = false;
                            break;

                        case SDL.SDL_EventType.SDL_FIRSTEVENT:
                            Debug.WriteLine("First Event");
                            break;

                        case SDL.SDL_EventType.SDL_LASTEVENT:
                            Debug.WriteLine("Last Event");
                            break;
                        }
                        //}
                    }
                    //SDL.SDL_WaitEvent(out @event);
                    //var quit = @event.quit;
                }
            }
        }