Exemple #1
0
        public override void Initialize(UserGameInfo game, GameProfile profile)
        {
            base.Initialize(game, profile);

            gamepadTimer.Enabled = true;
            UpdatePlayers();
        }
Exemple #2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public IOrderedEnumerable <KeyValuePair <string, List <UserGameInfo> > > GetInstalledGamesOrdered()
        {
            List <UserGameInfo> games = user.Games;
            Dictionary <string, List <UserGameInfo> > allGames = new Dictionary <string, List <UserGameInfo> >();

            for (int i = 0; i < games.Count; i++)
            {
                UserGameInfo game = games[i];
                if (!game.IsGamePresent())
                {
                    continue;
                }

                List <UserGameInfo> allSame;
                if (!allGames.TryGetValue(game.GameID, out allSame))
                {
                    allSame = new List <UserGameInfo>();
                    allGames.Add(game.GameID, allSame);
                }

                allSame.Add(game);
            }

            // <3 linq
            return(allGames.OrderBy(c => GameManager.Instance.MetadataManager.GetGameName(c.Key)));
        }
Exemple #3
0
        public GameControl(GenericGameInfo game, UserGameInfo userGame)
        {
            GameInfo     = game;
            UserGameInfo = userGame;

            picture          = new PictureBox();
            picture.SizeMode = PictureBoxSizeMode.StretchImage;

            title = new Label();
            if (game == null)
            {
                title.Text = "No games";
            }
            else
            {
                title.Text = GameInfo.GameName;
            }
            TitleText = title.Text;

            BackColor = Color.FromArgb(30, 30, 30);
            Size      = new Size(200, 52);

            Controls.Add(picture);
            Controls.Add(title);

            DPIManager.Register(this);
        }
Exemple #4
0
 public int Compare(UserGameInfo x, UserGameInfo y)
 {
     if (x.Game == null || y.Game == null)
     {
         return(0);
     }
     return(x.Game.GameName.CompareTo(y.Game.GameName));
 }
Exemple #5
0
        /// <summary>
        /// Tries adding a game to the collection with the provided executable path
        /// </summary>
        /// <param name="exePath"></param>
        /// <returns></returns>
        public UserGameInfo TryAddGame(string exePath)
        {
            string lower    = exePath.ToLower();
            string fileName = Path.GetFileName(exePath).ToLower();
            string dir      = Path.GetDirectoryName(exePath);

            var possibilities = Games.Values.Where(c => c.ExecutableName == fileName);

            foreach (GenericGameInfo game in possibilities)
            {
                // check if the Context matches
                string[] context = game.ExecutableContext;
                bool     notAdd  = false;
                if (context != null)
                {
                    for (int j = 0; j < context.Length; j++)
                    {
                        string con = Path.Combine(dir, context[j]);
                        if (!File.Exists(con) &&
                            !Directory.Exists(con))
                        {
                            notAdd = true;
                            break;
                        }
                    }
                }

                if (notAdd)
                {
                    continue;
                }

                // search for the same exe on the user profile
                if (GameManager.Instance.User.Games.Any(c => c.ExePath.ToLower() == lower))
                {
                    continue;
                }

#if RELEASE
                if (game.Debug)
                {
                    continue;
                }
#endif

                Log.WriteLine($"Found game: {game.GameName}, full path: {exePath}");
                UserGameInfo uinfo = new UserGameInfo();
                uinfo.InitializeDefault(game, exePath);
                GameManager.Instance.User.Games.Add(uinfo);
                GameManager.Instance.SaveUserProfile();

                return(uinfo);
            }

            return(null);
        }
Exemple #6
0
        public UserGameInfo AddGame(GenericGameInfo game, string exePath)
        {
            UserGameInfo gInfo = new UserGameInfo();

            gInfo.InitializeDefault(game, exePath);
            user.Games.Add(gInfo);

            SaveUserProfile();

            return(gInfo);
        }
Exemple #7
0
 public void SetUserGame(UserGameInfo userGame)
 {
     UserGameInfo = userGame;
     if (userGame == null)
     {
         title.Text = "No games";
     }
     else
     {
         title.Text = GameManager.Instance.MetadataManager.GetGameName(userGame.GameID);
     }
     TitleText = title.Text;
 }
Exemple #8
0
        private void LoadUser()
        {
            string userProfile = GetUserProfilePath();

            if (File.Exists(userProfile))
            {
                try
                {
                    using (FileStream stream = new FileStream(userProfile, FileMode.Open))
                    {
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            string json = reader.ReadToEnd();
                            user = JsonConvert.DeserializeObject <UserProfile>(json);

                            if (user.Games == null)
                            {
                                // json doesn't save empty lists, and user didn't add any game
                                user.InitializeDefault();
                            }
                            else
                            {
                                // delete invalid games
                                for (int i = 0; i < user.Games.Count; i++)
                                {
                                    UserGameInfo gameInfo = user.Games[i];
                                    if (gameInfo.Game == null)
                                    {
                                        user.Games.RemoveAt(i);
                                        i--;
                                    }
                                }
                            }
                        }
                    }
                }
                catch
                {
                    makeDefaultUserFile();
                }
            }
            else
            {
                makeDefaultUserFile();
            }
        }
Exemple #9
0
        //public override void Initialize(HandlerData handlerData, UserGameInfo game, GameProfile profile) {
        public override void Initialize(UserGameInfo game, GameProfile profile)
        {
            base.Initialize(game, profile);

            this.Controls.Clear();
            canProceed = false;

#if false
            int maxPlayers = handlerData.MaxPlayers;
            int half       = (int)Math.Round(maxPlayers / 2.0);
            int width      = Size.Width / half;
            int height     = Size.Height / 2;
            int player     = 2;

            top = new List <Button>();
            bot = new List <Button>();

            int left = Math.Max(half - 1, 1);
            width = Size.Width / left;
            for (int i = 0; i < left; i++)
            {
                Button btn = MkButton();
                btn.Text = player.ToString();
                player++;

                btn.SetBounds(i * width, 0, width, height);

                top.Add(btn);
                this.Controls.Add(btn);
            }

            half  = maxPlayers - half;
            width = Size.Width / half;
            for (int i = 0; i < half; i++)
            {
                Button btn = MkButton();
                btn.Text = player.ToString();
                player++;

                btn.SetBounds(i * width, height, width, height);

                bot.Add(btn);
                this.Controls.Add(btn);
            }
#endif
        }
Exemple #10
0
        /// <summary>
        /// Tries adding a game to the collection with the provided IGameInfo
        /// </summary>
        /// <param name="exePath"></param>
        /// <returns></returns>
        public UserGameInfo TryAddGame(string exePath, GameHandlerMetadata metadata)
        {
            string lower = exePath.ToLower();
            string dir   = Path.GetDirectoryName(exePath);

            if (user.Games.Any(c => c.ExePath.ToLower() == lower))
            {
                return(null);
            }

            Log.WriteLine($"Added game: {metadata.Title}, on path: {exePath}");
            UserGameInfo uinfo = new UserGameInfo();

            uinfo.InitializeDefault(metadata, exePath);
            user.Games.Add(uinfo);
            user.Save();

            return(uinfo);
        }
Exemple #11
0
        /// <summary>
        /// Tries adding a game to the collection with the provided executable path
        /// </summary>
        /// <param name="exePath"></param>
        /// <returns></returns>
        public UserGameInfo TryAddGame(string exePath)
        {
            string lower = exePath.ToLower();
            string dir   = Path.GetDirectoryName(exePath);

            var possibilities = GetAllHandlers(exePath);

            foreach (GameHandlerMetadata metadata in possibilities)
            {
                // check if the Context matches
                string[] context = metadata.ExeContext;
                bool     notAdd  = false;
                if (context != null)
                {
                    for (int j = 0; j < context.Length; j++)
                    {
                        string con = Path.Combine(dir, context[j]);
                        if (!File.Exists(con) &&
                            !Directory.Exists(con))
                        {
                            notAdd = true;
                            break;
                        }
                    }
                }

                if (notAdd ||
                    user.Games.Any(c => c.ExePath.ToLower() == lower))
                {
                    continue;
                }

                Log.WriteLine($"Found game: {metadata.Title}, on path: {exePath}");
                UserGameInfo uinfo = new UserGameInfo();
                uinfo.InitializeDefault(metadata, exePath);
                user.Games.Add(uinfo);
                user.Save();

                return(uinfo);
            }

            return(null);
        }
Exemple #12
0
        /// <summary>
        /// Tries adding a game to the collection with the provided IGameInfo
        /// </summary>
        /// <param name="exePath"></param>
        /// <returns></returns>
        public UserGameInfo TryAddGame(string exePath, GenericGameInfo game)
        {
            string lower = exePath.ToLower();

            // search for the same exe on the user profile
            if (GameManager.Instance.User.Games.Any(c => c.ExePath.ToLower() == lower))
            {
                return(null);
            }

            Log.WriteLine($"Found game: {game.GameName}, full path: {exePath}");
            UserGameInfo uinfo = new UserGameInfo();

            uinfo.InitializeDefault(game, exePath);
            GameManager.Instance.User.Games.Add(uinfo);
            GameManager.Instance.SaveUserProfile();

            return(uinfo);
        }
Exemple #13
0
        private void ThreadGetIcon(object state)
        {
            UserGameInfo game = (UserGameInfo)state;
            Icon         icon = Shell32Interop.GetIcon(game.ExePath, false);

            Bitmap bmp = icon.ToBitmap();

            icon.Dispose();
            game.Icon = bmp;

            lock (callbacks) {
                List <Action <Bitmap> > calls;
                if (callbacks.TryGetValue(game.GameID, out calls))
                {
                    for (int i = 0; i < calls.Count; i++)
                    {
                        calls[i](bmp);
                    }
                    callbacks.Remove(game.GameID);
                }

                GameIcons.Add(game.GameID, bmp);
            }
        }
Exemple #14
0
        public void GetIcon(UserGameInfo game, Action <Bitmap> callback)
        {
            Bitmap icon;

            if (GameIcons.TryGetValue(game.GameID, out icon))
            {
                callback(icon);
            }
            else
            {
                // extract icon from exe file
                lock (callbacks) {
                    List <Action <Bitmap> > calls;
                    if (!callbacks.TryGetValue(game.GameID, out calls))
                    {
                        calls = new List <Action <Bitmap> >();
                        callbacks.Add(game.GameID, calls);

                        ThreadPool.QueueUserWorkItem(ThreadGetIcon, game);
                    }
                    calls.Add(callback);
                }
            }
        }
Exemple #15
0
 public abstract bool Initialize(GameHandler handler, HandlerData handlerData, UserGameInfo game, GameProfile profile);
Exemple #16
0
 public void SetUserGameExe(UserGameInfo userGame)
 {
     UserGameInfo = userGame;
     title.Text   = userGame.ExePath;
     TitleText    = title.Text;
 }
 public virtual void Initialize(UserGameInfo game, GameProfile profile)
 {
     this.profile = profile;
     this.game    = game;
 }
        public override void Initialize(HandlerData handlerData, UserGameInfo game, GameProfile profile)
        {
            base.Initialize(handlerData, game, profile);

            this.Controls.Clear();

            int wid = 200;

            list      = new ControlListBox();
            list.Size = this.Size;

            List <GameOption>           options = handlerData.Options;
            Dictionary <string, object> vals    = profile.Options;

            for (int j = 0; j < options.Count; j++)
            {
                GameOption opt = options[j];
                if (opt.Hidden)
                {
                    continue;
                }

                object val;
                if (!vals.TryGetValue(opt.Key, out val))
                {
                    continue;
                }

                CoolListControl cool = new CoolListControl(false);
                cool.Title       = opt.Name;
                cool.Details     = opt.Description;
                cool.Width       = list.Width;
                cool.TitleFont   = nameFont;
                cool.DetailsFont = detailsFont;

                list.Controls.Add(cool);

                // Check the value type and add a control for it
                if (opt.Value is Enum || opt.IsCollection())
                {
                    ComboBox box    = new ComboBox();
                    int      border = 10;

                    object value;
                    object defaultValue;
                    IList  values;
                    if (opt.Value is Enum)
                    {
                        value        = (Enum)val;
                        values       = Enum.GetValues(value.GetType());
                        defaultValue = opt.DefaultValue;
                    }
                    else
                    {
                        values       = opt.GetCollection();
                        value        = values[0];
                        defaultValue = opt.DefaultValue;
                    }

                    for (int i = 0; i < values.Count; i++)
                    {
                        box.Items.Add(values[i]);
                    }

                    if (defaultValue != null)
                    {
                        box.SelectedIndex = box.Items.IndexOf(defaultValue);
                        if (box.SelectedIndex == -1)
                        {
                            box.SelectedIndex = box.Items.IndexOf(value);
                        }
                    }
                    else
                    {
                        box.SelectedIndex = box.Items.IndexOf(value);
                    }

                    box.Width         = wid;
                    box.Height        = 40;
                    box.Left          = cool.Width - box.Width - border;
                    box.Top           = (cool.Height / 2) - (box.Height / 2);
                    box.Anchor        = AnchorStyles.Right;
                    box.DropDownStyle = ComboBoxStyle.DropDownList;
                    cool.Controls.Add(box);

                    box.Tag = opt;
                    box.SelectedValueChanged += box_SelectedValueChanged;
                    ChangeOption(box.Tag, box.SelectedItem);
                }
                else if (opt.Value is bool)
                {
                    SizeableCheckbox box = new SizeableCheckbox();
                    int border           = 10;

                    box.Checked = (bool)val;
                    box.Width   = 40;
                    box.Height  = 40;
                    box.Left    = cool.Width - box.Width - border;
                    box.Top     = (cool.Height / 2) - (box.Height / 2);
                    box.Anchor  = AnchorStyles.Right;
                    cool.Controls.Add(box);

                    box.Tag             = opt;
                    box.CheckedChanged += box_CheckedChanged;
                    ChangeOption(box.Tag, box.Checked);
                }
                else if (opt.Value is int || opt.Value is double)
                {
                    NumericUpDown num    = new NumericUpDown();
                    int           border = 10;

                    int value = (int)(double)val;
                    if (value < num.Minimum)
                    {
                        num.Minimum = value;
                    }

                    num.Value = value;

                    num.Width  = wid;
                    num.Height = 40;
                    num.Left   = cool.Width - num.Width - border;
                    num.Top    = (cool.Height / 2) - (num.Height / 2);
                    num.Anchor = AnchorStyles.Right;
                    cool.Controls.Add(num);

                    num.Tag           = opt;
                    num.ValueChanged += num_ValueChanged;
                    ChangeOption(num.Tag, num.Value);
                }
                else if (opt.Value is GameOptionValue)
                {
                    ComboBox box    = new ComboBox();
                    int      border = 10;

                    GameOptionValue value = (GameOptionValue)val;
                    PropertyInfo[]  props = value.GetType().GetProperties(BindingFlags.Public | BindingFlags.Static);

                    for (int i = 0; i < props.Length; i++)
                    {
                        PropertyInfo prop = props[i];
                        box.Items.Add(prop.GetValue(null, null));
                    }
                    box.SelectedIndex = box.Items.IndexOf(value);

                    box.Width  = wid;
                    box.Height = 40;
                    box.Left   = cool.Width - box.Width - border;
                    box.Top    = (cool.Height / 2) - (box.Height / 2);
                    box.Anchor = AnchorStyles.Right;
                    //box.DropDownStyle = ComboBoxStyle.DropDownList;
                    cool.Controls.Add(box);

                    box.Tag = opt;
                    box.SelectedValueChanged += box_SelectedValueChanged;
                    ChangeOption(box.Tag, box.SelectedItem);
                }
            }

            this.Controls.Add(list);
            list.UpdateSizes();
            CanPlayUpdated(true, false);
        }
Exemple #19
0
 public virtual void Initialize(UserGameInfo game, GameProfile profile)
 {
     //this.handlerData = handlerData;
     this.profile = profile;
     this.game    = game;
 }