public void InitializeDefault(GameInfo game)
        {
            if (playerData == null)
            {
                playerData = new List<PlayerInfo>();
            }

            if (screens == null)
            {
                screens = new List<UserScreen>();
            }

            if (options == null)
            {
                options = new Dictionary<string, object>();

                foreach (var opt in game.Options)
                {
                    options.Add(opt.Key, opt.Value.Value);
                }
            }
        }
        private void list_Games_SelectedChanged(object arg1, Control arg2)
        {
            currentControl = (GameControl)arg1;
            currentGameInfo = currentControl.Game;
            if (currentGameInfo == null)
            {
                return;
            }

            if (!setSize)
            {
                this.Size = defaultSize;
                setSize = true;
            }

            panelGameName.Visible = true;
            label_StepTitle.Visible = true;
            StepPanel.Visible = true;
            btnBack.Visible = true;
            btnNext.Visible = true;

            currentGame = currentGameInfo.Game;

            btn_Play.Enabled = false;

            if (currentGame.Steps == null ||
                currentStepIndex == currentGame.Steps.Length)
            {
                // can play
                btn_Play.Enabled = true;

                // remove the current step if there's one
                KillCurrentStep();

                btnBack.Visible = false;
                btnNext.Visible = false;
            }

            currentProfile = new GameProfile();
            currentProfile.InitializeDefault(currentGame);

            this.label_GameTitle.Text = currentGame.GameName;
            this.pic_Game.Image = currentGameInfo.Icon;

            Type[] steps = currentGame.Steps;
            if (steps != null && steps.Length > 0)
            {
                GoToStep(0);
            }
        }
 private void gameBox_SelectedIndexChanged(object sender, EventArgs e)
 {
     SelectedGame = (GameInfo)combo_Games.SelectedItem;
     groupBox2.Enabled = SelectedGame != null;
 }
        public UserGameInfo AddGame(GameInfo game, string exePath)
        {
            UserGameInfo gInfo = new UserGameInfo();
            gInfo.InitializeDefault(game, exePath);
            user.Games.Add(gInfo);

            SaveUserProfile();

            return gInfo;
        }
        public void ExecuteBackup(GameInfo game)
        {
            string appData = GetAppDataPath();
            string gamePath = Path.Combine(appData, game.GUID);

            for (int i = 0; i < backupFiles.Count; i++)
            {
                BackupFile bkp = backupFiles[i];
                if (File.Exists(bkp.BackupPath))
                {
                    File.Delete(bkp.Source);
                    File.Move(bkp.BackupPath, bkp.Source);
                }
            }
        }
        public BackupFile BackupFile(GameInfo game, string path)
        {
            string appData = GetAppDataPath();
            string gamePath = Path.Combine(appData, game.GUID);
            string destination = Path.Combine(gamePath, Path.GetFileName(path));

            if (!File.Exists(path) && File.Exists(destination))
            {
                // we f****d up and the backup exists
                File.Copy(destination, path);
            }
            else
            {
                if (File.Exists(destination))
                {
                    File.Delete(destination);
                }
                File.Copy(path, destination);
            }

            BackupFile bkp = new BackupFile(path, destination);
            backupFiles.Add(bkp);

            return bkp;
        }
 public string GetBackupFolder(GameInfo game)
 {
     string appData = GetAppDataPath();
     return Path.Combine(appData, game.GUID);
 }
 public IGameHandler MakeHandler(GameInfo game)
 {
     return (IGameHandler)Activator.CreateInstance(game.HandlerType);
 }
        public void StartBackup(GameInfo game)
        {
            string appData = GetAppDataPath();
            string gamePath = Path.Combine(appData, game.GUID);
            Directory.CreateDirectory(gamePath);

            backupFiles = new List<BackupFile>();
        }
        public void UpdatePlayerCount(int player, GameInfo info, UserGameInfo userGame)
        {
            this.info = info;
            this.userGameInfo = userGame;
            if (info == null)
            {
                return;
            }

            if (player != playerCount || reset)
            {
                // Clean players!
                playerCount = player;
                players.Clear();
                for (int i = 0; i < loaded_screens.Count; i++)
                {
                    var mscreen = loaded_screens[i];
                    for (int j = 0; j < mscreen.Controls.Count; j++)
                    {
                        Control con = mscreen.Controls[j];

                        if (con is PlayerControl)
                        {
                            mscreen.Controls.Remove(con);
                            j--;
                        }
                    }
                }

                // remake monitors
                MakeContextStrip();
                MakeMonitors();
            }

            for (int i = 0; i < screenStrip.Items.Count; i++)
            {
                var item = screenStrip.Items[i];
                item.Enabled = i < player;
            }

            if (reset)
            {
                if (info.NeedPositioning)
                {
                    if (posLabel != null && panel1.Controls.Contains(posLabel))
                    {
                        panel1.Controls.Remove(posLabel);
                    }
                }
                else
                {
                    panel1.Controls.Clear();

                    posLabel = new Label();
                    posLabel.Text = "The selected game does not support positioning";
                    posLabel.Width = 500;
                    posLabel.Font = this.Font;

                    panel1.Controls.Add(posLabel);
                }
            }
            reset = false;
        }
 public void UpdateSelectedGame(int players, GameInfo info, UserGameInfo uInfo)
 {
 }
Beispiel #12
0
        public void UpdateItems(GameInfo prof)
        {
            this.Controls.Clear();

            var options = prof.Options;
            foreach (var opt in options.Values)
            {
                CoolListControl cool = new CoolListControl();
                cool.Text = opt.Name;
                cool.Description = opt.Description;
                cool.Width = this.Width;

                this.Controls.Add(cool);

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

                    box.Checked = (bool)opt.Value;
                    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.AddControl(box, false);

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

                    num.Value = (int)opt.Value;

                    num.Width = 150;
                    num.Height = 40;
                    num.Left = cool.Width - num.Width - border;
                    num.Top = (cool.Height / 2) - (num.Height / 2);
                    num.Anchor = AnchorStyles.Right;
                    cool.AddControl(num, false);

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

                    Array values = Enum.GetValues(opt.Value.GetType());
                    for (int i = 0; i < values.Length; i++)
                    {
                        box.Items.Add(((IList)values)[i]);
                    }
                    box.SelectedIndex = values.Length - 1;

                    box.Width = 150;
                    box.Height = 40;
                    box.Left = cool.Width - box.Width - border;
                    box.Top = (cool.Height / 2) - (box.Height / 2);
                    box.Anchor = AnchorStyles.Right;
                    cool.AddControl(box, false);

                    box.Tag = opt;
                    box.SelectedValueChanged += box_SelectedValueChanged;
                }
            }
        }
 public void InitializeDefault(GameInfo game, string exePath)
 {
     this.game = game;
     this.exePath = exePath;
     this.profiles = new List<GameProfile>();
 }
        /// <summary>
        /// Handles updating the game's image and info when the user selects a different game
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void list_Games_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!(list_Games.SelectedItem is UserGameInfo))
            {
                return;
            }

            ResetSteps();
            step = 0;
            UpdateStep();

            info = (UserGameInfo)list_Games.SelectedItem;
            gameInfo = gameManager.Games[info.GameGuid];

            // Remove game from library if not found
            if (!File.Exists(info.ExecutablePath))
            {
                MessageBox.Show("Game Executable not Found. Deleting game from your library. TO-DO: User might have game on a disconnected hard-drive. Handle that.");

                gameManager.User.Games.Remove(info);
                gameManager.UpdateUserProfile();

                info = null;
                gameInfo = null;

                list_Games.DataSource = null;
                list_Games.SelectedIndex = -1;
                list_Games.DataSource = gameManager.User.Games;

                if (list_Games.Items.Count > 0)
                {
                    list_Games.SelectedIndex = 0;
                }
                return;
            }

            label_GameName.Text = info.GameName;
            playerCount1.MaxPlayers = gameInfo.MaxPlayers;
            label_maxPlayas.Text = gameInfo.MaxPlayers.ToString();
            if (gameInfo.SupportsKeyboard)
            {
                pic_Keyboard.Image = Resources.keyboard;
            }
            else
            {
                pic_Keyboard.Image = Resources.no_keyboard;
            }


            monitorControl1.UpdatePlayerCount(playerCount1.Players, gameInfo, info);
            playerOptions1.UpdateItems(gameInfo);

            addSteps.Clear();
            if (gameInfo.Steps != null)
            {
                // Add custom steps the game might need
                int count = steps.Count;
                for (int i = 0; i < gameInfo.Steps.Length; i++)
                {
                    Control s = (Control)Activator.CreateInstance(gameInfo.Steps[i]);
                    s.Location = this.monitorControl1.Location;
                    s.Size = this.monitorControl1.Size;
                    s.Anchor = this.monitorControl1.Anchor;
                    borderPanel1.Controls.Add(s);
                    steps.Add(count + i, s);

                    addSteps.Add(s);
                }
            }
            else
            {
                // Delete any old files
                if (steps.Count > DefaultSteps)
                {
                    int count = steps.Count;
                    for (int i = DefaultSteps; i < count; i++)
                    {
                        borderPanel1.Controls.Remove(steps[i]);
                        steps.Remove(i);
                    }
                }
            }

            // Extract icon from game executable
            if (this.game_Box.Image != null)
            {
                this.game_Box.Image.Dispose();
            }
            using (Icon sysicon = Icon.ExtractAssociatedIcon(info.ExecutablePath))
            {
                using (MemoryStream str = new MemoryStream())
                {
                    sysicon.Save(str);
                    str.Position = 0;
                    game_Box.Image = Image.FromStream(str);
                }
            }
        }