public bool Initialize(UserGameInfo game, GameProfile profile)
        {
            this.userGame = game;
            this.profile  = profile;

            // see if we have any save game to backup
            gen = game.Game as GenericGameInfo;
            if (gen == null)
            {
                // you f****d up
                return(false);
            }

            if (gen.LockMouse)
            {
                _cursorModule = new CursorModule();
            }

            jsData = new Dictionary <string, string>();
            jsData.Add(Folder.Documents.ToString(), Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
            jsData.Add(Folder.MainGameFolder.ToString(), Path.GetDirectoryName(game.ExePath));
            jsData.Add(Folder.InstancedGameFolder.ToString(), Path.GetDirectoryName(game.ExePath));

            timerInterval = gen.HandlerInterval;

            Log.RegisterForLogCallback(this);

            return(true);
        }
Example #2
0
        public static GameProfile CleanClone(GameProfile profile)
        {
            GameProfile nprof = new GameProfile();

            nprof.playerData = new List <PlayerInfo>();
            nprof.screens    = profile.screens.ToList();

            List <PlayerInfo> source = profile.playerData;

            for (int i = 0; i < source.Count; i++)
            {
                PlayerInfo player = source[i];
                if (player.ScreenIndex != -1)
                {
                    // only add valid players to the clean version
                    nprof.playerData.Add(player);
                }
            }

            Dictionary <string, object> noptions = new Dictionary <string, object>();

            foreach (var opt in profile.Options)
            {
                noptions.Add(opt.Key, opt.Value);
            }
            nprof.options = noptions;

            return(nprof);
        }
        public void Initialize(UserGameInfo game, GameProfile profile)
        {
            string documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string configFolder = Path.Combine(documents, @"My Games\Borderlands 2\WillowGame\SaveData");
            DirectoryInfo[] userDirs = new DirectoryInfo(configFolder).GetDirectories();

            for (int i = 0; i < userDirs.Length; i++)
            {
                DirectoryInfo user = userDirs[i];

                FileInfo[] saves = user.GetFiles("*.sav");
                for (int j = 0; j < saves.Length; j++)
                {
                    FileInfo save = saves[j];

                    BorderlandsSaveControl con = new BorderlandsSaveControl();
                    using (Stream s = save.OpenRead())
                    {
                        con.SaveFile = SaveFile.Deserialize(s, SaveFile.DeserializeSettings.None);
                    }

                    con.UserName = user.Name;
                    //con.SaveName = con.SaveFile.SaveGame.AppliedCustomizations;
                    this.flowLayoutPanel1.Controls.Add(con);
                }
            }
        }
        public bool Initialize(UserGameInfo game, GameProfile profile)
        {
            this.userGame = game;
            this.profile = profile;

            // see if we have any save game to backup
            gen = game.Game as GenericGameInfo;
            if (gen == null)
            {
                // you f****d up
                return false;
            }

            engine = new Engine();
            engine.SetValue("Options", profile.Options);

            data = new Dictionary<string, string>();
            data.Add(NucleusFolderEnum.GameFolder.ToString(), Path.GetDirectoryName(game.ExePath));

            if (gen.SaveType == GenericGameSaveType.None)
            {
                return true;
            }

            string saveFile = ProcessPath(gen.SavePath);
            GameManager.Instance.BeginBackup(game.Game);
            GameManager.Instance.BackupFile(game.Game, saveFile);

            return true;
        }
        public bool Initialize(UserGameInfo game, GameProfile profile)
        {
            this.userGame = game;
            this.profile  = profile;

            // see if we have any save game to backup
            gen = game.Game as GenericGameInfo;
            if (gen == null)
            {
                // you f****d up
                return(false);
            }

            engine = new Engine();
            engine.SetValue("Options", profile.Options);

            data = new Dictionary <string, string>();
            data.Add(NucleusFolderEnum.GameFolder.ToString(), Path.GetDirectoryName(game.ExePath));

            if (gen.SaveType == GenericGameSaveType.None)
            {
                return(true);
            }

            string saveFile = ProcessPath(gen.SavePath);

            GameManager.Instance.BeginBackup(game.Game);
            GameManager.Instance.BackupFile(game.Game, saveFile);

            return(true);
        }
Example #6
0
        /// <summary>
        /// Clones this Game Info into a new Generic Context
        /// </summary>
        /// <returns></returns>
        public GenericContext CreateContext(GameProfile profile, PlayerInfo info, GenericGameHandler handler)
        {
            GenericContext context = new GenericContext(profile, info, handler);

            Type t = GetType();

            PropertyInfo[] props = t.GetProperties();

            Type c = context.GetType();

            PropertyInfo[] cprops = c.GetProperties();

            for (int i = 0; i < props.Length; i++)
            {
                PropertyInfo p = props[i];
                PropertyInfo d = cprops.FirstOrDefault(k => k.Name == p.Name);
                if (d == null)
                {
                    continue;
                }

                if (p.PropertyType != d.PropertyType ||
                    !d.CanWrite)
                {
                    continue;
                }

                object value = p.GetValue(this, null);
                d.SetValue(context, value, null);
            }

            return(context);
        }
Example #7
0
        public GenericContext(GameProfile prof, PlayerInfo info, GenericGameHandler handler, bool hasKeyboard)
        {
            profile = prof;
            pInfo   = info;
            parent  = handler;

            bHasKeyboardPlayer = hasKeyboard;
        }
        /// <summary>
        /// Clones this Game Info into a new Generic Context
        /// </summary>
        /// <returns></returns>
        public GenericContext CreateContext(GameProfile profile, PlayerInfo info, GenericGameHandler handler, bool hasKeyboardPlayer)
        {
            GenericContext context = new GenericContext(profile, info, handler, hasKeyboardPlayer);

            Type t = GetType();

            PropertyInfo[] props  = t.GetProperties();
            FieldInfo[]    fields = t.GetFields();

            Type c = context.GetType();

            PropertyInfo[] cprops  = c.GetProperties();
            FieldInfo[]    cfields = c.GetFields();

            for (int i = 0; i < props.Length; i++)
            {
                PropertyInfo p = props[i];
                PropertyInfo d = cprops.FirstOrDefault(k => k.Name == p.Name);
                if (d == null)
                {
                    continue;
                }

                if (p.PropertyType != d.PropertyType ||
                    !d.CanWrite)
                {
                    continue;
                }

                object value = p.GetValue(this, null);
                d.SetValue(context, value, null);
            }

            for (int i = 0; i < fields.Length; i++)
            {
                FieldInfo source = fields[i];
                FieldInfo dest   = cfields.FirstOrDefault(k => k.Name == source.Name);
                if (dest == null)
                {
                    continue;
                }

                if (source.FieldType != dest.FieldType)
                {
                    continue;
                }

                object value = source.GetValue(this);
                dest.SetValue(context, value);
            }

            return(context);
        }
        public bool Initialize(UserGameInfo game, GameProfile profile)
        {
            this.executablePlace = game.ExePath;
            this.profile = profile;
            this.userGame = game;

            // Let's search for the save file
            string documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string configFolder;

            if (game.Game.GUID == "E1CCA90A-7B48-4F3A-8F19-FD61B32A0F83")
            {
                // borderlands pre-sequel
                configFolder = Path.Combine(documents, @"My Games\Borderlands The Pre-Sequel\WillowGame\Config");
            }
            else
            {
                // borderlands 2
                configFolder = Path.Combine(documents, @"My Games\Borderlands 2\WillowGame\Config");
            }
            string willowEngine = Path.Combine(configFolder, "WillowEngine.ini");

            if (File.Exists(willowEngine))
            {
                saveFile = willowEngine;
            }
            else
            {
                MessageBox.Show("Could not find WillowEngine.ini file!");

                using (OpenFileDialog open = new OpenFileDialog())
                {
                    open.Filter = "WillowEngine.ini file|WillowEngine.ini";
                    if (open.ShowDialog() == DialogResult.OK)
                    {
                        saveFile = open.FileName;
                    }
                    else
                    {
                        return false;
                    }
                }
            }

            // backup the WillowEngine ini
            GameManager.Instance.StartBackup(game.Game);
            GameManager.Instance.BackupFile(game.Game, willowEngine);

            return true;
        }
        public override void Initialize(UserGameInfo game, GameProfile profile)
        {
            base.Initialize(game, profile);

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

            int maxPlayers = game.Game.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);
            }
        }
Example #11
0
        static void Main(string[] args)
        {
            GameManager manager = new GameManager();

            GameInfo borderlands2 = manager.Games["720CE71B-FCBF-46C8-AC9D-C4B2BF3169E3"];
            UserGameInfo borderInfo = manager.AddGame(borderlands2, @"C:\Program Files (x86)\Steam\steamapps\common\Borderlands 2\Binaries\Win32\Borderlands2.exe");

            GameProfile profile = new GameProfile();
            profile.InitializeDefault(borderlands2);

            PlayerInfo p1 = new PlayerInfo();
            p1.monitorBounds = new Rectangle(0, 0, 960, 540);
            p1.screenIndex = 0;
            profile.PlayerData.Add(p1);

            PlayerInfo p2 = new PlayerInfo();
            p2.monitorBounds = new Rectangle(0, 540, 960, 540);
            p2.screenIndex = 0;
            profile.PlayerData.Add(p2);

            borderInfo.Profiles.Add(profile);

            manager.WaitSave();

            // try to play game with custom profile
            handler = manager.MakeHandler(borderlands2);

            handler.Initialize(borderInfo, profile);

            ThreadPool.QueueUserWorkItem(Play);
            //handler.Play();

            for (; ; )
            {
                Thread.Sleep(16);
                handler.Update(16);

                if (handler.HasEnded)
                {
                    break;
                }
            }
        }
        public bool Initialize(UserGameInfo game, GameProfile profile)
        {
            this.userGame = game;
            this.profile  = profile;

            // see if we have any save game to backup
            gen = game.Game as GenericGameInfo;
            if (gen == null)
            {
                // you f****d up
                return(false);
            }

            data = new Dictionary <string, string>();
            data.Add(Folder.Documents.ToString(), Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
            data.Add(Folder.GameFolder.ToString(), Path.GetDirectoryName(game.ExePath));

            return(true);
        }
        public bool Initialize(UserGameInfo game, GameProfile profile)
        {
            this.executablePlace = game.ExePath;
            this.profile = profile;
            this.userGame = game;

            delayTime = (int)((double)profile.Options["delay"] * 1000);

            // Let's search for the save file
            string documents = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
            string myGames = Path.Combine(documents, @"My Games\Borderlands The Pre-Sequel\WillowGame\Config");
            string willowEngine = Path.Combine(myGames, "WillowEngine.ini");

            if (File.Exists(willowEngine))
            {
                saveFile = willowEngine;
            }
            else
            {
                MessageBox.Show("Could not find WillowEngine.ini file!");

                using (OpenFileDialog open = new OpenFileDialog())
                {
                    open.Filter = "WillowEngine.ini file|WillowEngine.ini";
                    if (open.ShowDialog() == DialogResult.OK)
                    {
                        saveFile = open.FileName;
                    }
                    else
                    {
                        return false;
                    }
                }
            }

            // backup the WillowEngine ini
            GameManager.Instance.StartBackup(game.Game);
            GameManager.Instance.BackupFile(game.Game, willowEngine);

            return true;
        }
Example #14
0
        public void Initialize(UserGameInfo game, GameProfile profile)
        {
            this.profile = profile;

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

            int maxPlayers = game.Game.MaxPlayers;
            int half       = (int)Math.Round(maxPlayers / 2.0);
            int width      = Size.Width / half;
            int height     = Size.Height / 2;
            int player     = 2;

            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);
                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);
                this.Controls.Add(btn);
            }
        }
        public void Initialize(UserGameInfo game, GameProfile profile)
        {
            this.profile = profile;

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

            int maxPlayers = game.Game.MaxPlayers;
            int half = (int)Math.Round(maxPlayers / 2.0);
            int width = Size.Width / half;
            int height = Size.Height / 2;
            int player = 2;

            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);
                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);
                this.Controls.Add(btn);
            }
        }
Example #16
0
        public bool Initialize(HandlerData handlerData, UserGameInfo game, GameProfile profile)
        {
            this.userGame = game;
            this.profile  = profile;

            // see if we have any save game to backup
            this.handlerData = handlerData;

            if (this.handlerData.LockMouse)
            {
                _cursorModule = new CursorModule();
            }

            jsData = new Dictionary <string, string>();
            jsData.Add(Folder.Documents.ToString(), Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments));
            jsData.Add(Folder.MainGameFolder.ToString(), Path.GetDirectoryName(game.ExePath));
            jsData.Add(Folder.InstancedGameFolder.ToString(), "");

            timerInterval = this.handlerData.HandlerInterval;

            Log.RegisterForLogCallback(this);

            return(true);
        }
        public void Initialize(UserGameInfo game, GameProfile profile)
        {
            this.profile = profile;
            profile.PlayerData.Clear();// reset profile

            playerFont = new Font("Segoe UI", 40);
            playerTextFont = new Font("Segoe UI", 18);

            RemoveFlicker();

            float playersWidth = this.Width * 0.5f;

            int playerCount = profile.PlayerCount;
            float playerWidth = (playersWidth * 0.9f) / (float)playerCount;
            float playerHeight = playerWidth * 0.5625f;
            float offset = (playersWidth * 0.1f) / (float)playerCount;
            playersArea = new RectangleF(50, 100, playersWidth, playerHeight);

            for (int i = 0; i < playerCount; i++)
            {
                Rectangle r = new Rectangle((int)(50 + ((playerWidth + offset) * i)), 100, (int)playerWidth, (int)playerHeight);
                PlayerInfo playa = new PlayerInfo();
                playa.editBounds = r;
                profile.PlayerData.Add(playa);
            }

            screens = ScreensUtil.AllScreens();
            Rectangle totalBounds = RectangleUtil.Union(ScreensUtil.AllScreensRec());

            // see if most screens are either vertical or horizontal
            int vertical = 0;
            int horizontal = 0;
            for (int i = 0; i < screens.Length; i++)
            {
                UserScreen s = screens[i];
                if (s.bounds.Width > s.bounds.Height)
                {
                    horizontal++;
                }
                else
                {
                    vertical++;
                }
            }


            if (horizontal > vertical)
            {
                // horizontal setup
                scale = (this.Width * 0.9f) / (float)totalBounds.Width;
            }
            else
            {
                // vertical setup
                scale = (this.Height * 0.6f) / (float)totalBounds.Height;
                //scale = (this.Width * 0.9f) / (float)totalBounds.Width;
            }

            totalBounds = new Rectangle(
                (int)(totalBounds.X * scale),
                (int)(totalBounds.Y * scale),
                (int)(totalBounds.Width * scale),
                (int)(totalBounds.Height * scale));
            int offsetViewsX = totalBounds.X;
            int offsetViewsY = totalBounds.Y;
            totalBounds = RectangleUtil.Center(totalBounds, new Rectangle(0, (int)(this.Height * 0.25f), this.Width, (int)(this.Height * 0.7f)));

            for (int i = 0; i < screens.Length; i++)
            {
                UserScreen screen = screens[i];

                Rectangle s = screen.bounds;
                int width = (int)(s.Width * scale);
                int height = (int)(s.Height * scale);
                int x = (int)(s.X * scale);
                int y = (int)(s.Y * scale);
                screen.bounds = new Rectangle(x + totalBounds.X - offsetViewsX, y + totalBounds.Y - offsetViewsY, width, height);
                screen.swapTypeRect = new Rectangle(screen.bounds.X, screen.bounds.Y, (int)(screen.bounds.Width * 0.1f), (int)(screen.bounds.Width * 0.1f));
            }
        }
        public void Initialize(UserGameInfo game, GameProfile profile)
        {
            this.profile = profile;
            this.Controls.Clear();

            var options = game.Game.Options;
            var vals = profile.Options;
            foreach (var opt in options)
            {
                CoolListControl cool = new CoolListControl();
                cool.Text = opt.Value.Name;
                cool.Description = opt.Value.Description;
                cool.Width = this.Width;

                this.Controls.Add(cool);

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

                    box.Checked = (bool)vals[opt.Key];
                    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.Value is int)
                {
                    NumericUpDown num = new NumericUpDown();
                    int border = 10;

                    num.Value = (int)vals[opt.Key];

                    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.Value is Enum)
                {
                    ComboBox box = new ComboBox();
                    int border = 10;

                    Enum value = (Enum)vals[opt.Key];
                    Array values = Enum.GetValues(value.GetType());
                    for (int i = 0; i < values.Length; i++)
                    {
                        box.Items.Add(((IList)values)[i]);
                    }
                    box.SelectedIndex = box.Items.IndexOf(value);

                    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;
                }
            }

            UpdateSizes();
        }
Example #19
0
        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);
            }
        }
Example #20
0
 public GenericContext(GameProfile prof, PlayerInfo info, GenericGameHandler handler)
 {
     this.profile = prof;
     this.pInfo   = info;
     this.parent  = handler;
 }
 public virtual void Initialize(UserGameInfo game, GameProfile profile)
 {
     this.profile = profile;
     this.game    = game;
 }
Example #22
0
 public void UpdateCurrentGameProfile(GameProfile newProfile)
 {
     currentProfile = newProfile;
     RawInputProcessor.CurrentProfile = newProfile;
 }
Example #23
0
        public void Initialize(UserGameInfo game, GameProfile profile)
        {
            this.profile = profile;
            this.Controls.Clear();

            var options = game.Game.Options;
            var vals    = profile.Options;

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

                this.Controls.Add(cool);

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

                    box.Checked = (bool)vals[opt.Key];
                    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.Value is int)
                {
                    NumericUpDown num    = new NumericUpDown();
                    int           border = 10;

                    num.Value = (int)vals[opt.Key];

                    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.Value is Enum)
                {
                    ComboBox box    = new ComboBox();
                    int      border = 10;

                    Enum  value  = (Enum)vals[opt.Key];
                    Array values = Enum.GetValues(value.GetType());
                    for (int i = 0; i < values.Length; i++)
                    {
                        box.Items.Add(((IList)values)[i]);
                    }
                    box.SelectedIndex = box.Items.IndexOf(value);

                    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;
                }
            }

            UpdateSizes();
        }
        public override void Initialize(UserGameInfo game, GameProfile profile)
        {
            base.Initialize(game, profile);

            this.Controls.Clear();

            int wid = 200;

            list = new ControlListBox();
            GameOption[] options             = game.Game.Options;
            Dictionary <string, object> vals = profile.Options;

            for (int j = 0; j < options.Length; j++)
            {
                GameOption opt = options[j];

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

                CoolListControl cool = new CoolListControl();
                cool.Text        = opt.Name;
                cool.Description = opt.Description;
                cool.Width       = this.Width;

                list.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)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.AddControl(box, false);

                    box.Tag             = opt;
                    box.CheckedChanged += box_CheckedChanged;
                }
                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.AddControl(num, false);

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

                    Enum  value  = (Enum)val;
                    Array values = Enum.GetValues(value.GetType());
                    for (int i = 0; i < values.Length; i++)
                    {
                        box.Items.Add(((IList)values)[i]);
                    }
                    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;
                    cool.AddControl(box, false);

                    box.Tag = opt;
                    box.SelectedValueChanged += box_SelectedValueChanged;
                }
                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;
                    cool.AddControl(box, false);

                    box.Tag = opt;
                    box.SelectedValueChanged += box_SelectedValueChanged;
                }
            }

            list.Size = this.Size;
            this.Controls.Add(list);

            list.UpdateSizes();
            OnCanPlayTrue(false);
        }
Example #25
0
        public override void Initialize(HandlerData handlerData, UserGameInfo game, GameProfile profile)
        {
            base.Initialize(handlerData, game, profile);

            Controls.Clear();

            // grab the CustomStep and extract what we have to show from it
            GameOption option = CustomStep.Option;

            if (option.IsCollection())
            {
                ControlListBox list = new ControlListBox();
                list.Size       = this.Size;
                list.AutoScroll = true;

                Controls.Add(list);

                collection = option.GetCollection();
                for (int i = 0; i < collection.Count; i++)
                {
                    object val = collection[i];

                    // TODO: make image options
                    if (!(val is IDictionary <string, JToken>))
                    {
                        continue;
                    }

                    CoolListControl control = new CoolListControl(true);
                    control.Anchor      = AnchorStyles.Left | AnchorStyles.Top | AnchorStyles.Right;
                    control.BackColor   = Color.FromArgb(30, 30, 30);
                    control.Size        = new Size(list.Width, 120);
                    control.Data        = val;
                    control.OnSelected += Control_OnSelected;

                    IDictionary <string, JToken> value = (IDictionary <string, JToken>)val;
                    string name = value["Name"].ToString();

                    control.Title       = name;
                    control.TitleFont   = nameFont;
                    control.DetailsFont = detailsFont;

                    string details = "";
                    JToken detailsObj;
                    if (value.TryGetValue("Details", out detailsObj))
                    {
                        details = detailsObj.ToString();

                        control.Details = details;
                    }

                    JToken imageUrlObj;
                    value.TryGetValue("ImageUrl", out imageUrlObj);
                    if (imageUrlObj != null)
                    {
                        string imageUrl = imageUrlObj.ToString();
                        if (!string.IsNullOrEmpty(imageUrl))
                        {
                            Image img = DataManager.Content.LoadImage(imageUrl);

                            PictureBox box = new PictureBox();
                            box.Anchor   = AnchorStyles.Top | AnchorStyles.Right;
                            box.Size     = new Size(140, 80);
                            box.Location = new Point(list.Width - box.Width - 10, 20);
                            box.SizeMode = PictureBoxSizeMode.Zoom;
                            box.Image    = img;
                            control.Controls.Add(box);
                        }
                    }

                    list.Controls.Add(control);
                }
            }
            else
            {
            }
        }