public void SetProperty(SettingPropertyAttribute attr, PropertyInfo pInfo, TournamentXPSettings settings)
        {
            _pInfo    = pInfo;
            _settings = settings;


            string text = attr.DisplayName;

            if (text.Trim().StartsWith("{"))
            {
                var id = LocalizedTextManager.GetStringId(text);
                text = LocalizedTextManager.GetTranslatedText(languageId, id);
            }
            lblName.Text = text;
            if (!string.IsNullOrWhiteSpace(attr.HintText))
            {
                string text2 = attr.HintText;
                if (text2.Trim().StartsWith("{"))
                {
                    var id = LocalizedTextManager.GetStringId(text2);
                    text2 = LocalizedTextManager.GetTranslatedText(languageId, id);
                }
                ToolTip tt = new ToolTip();
                tt.IsBalloon = true;
                tt.SetToolTip(lblName, text2);
            }

            checkBox1.Visible  = false;
            textBox1.Visible   = false;
            textBox1.TextAlign = HorizontalAlignment.Right;
            trackBar1.Visible  = false;
            trackBar2.Visible  = false;

            switch (pInfo.PropertyType.Name)
            {
            case "Boolean":
                checkBox1.Visible = true;
                checkBox1.Checked = (bool)pInfo.GetValue(settings);
                break;

            case "Int32":
            case "Int64":
            case "Integer":
                textBox1.Visible  = true;
                textBox1.Text     = ((int)pInfo.GetValue(settings)).ToString();
                trackBar1.Visible = true;
                trackBar1.Minimum = (int)attr.MinValue;
                trackBar1.Maximum = (int)attr.MaxValue;
                trackBar1.Value   = ((int)pInfo.GetValue(settings));
                break;

            case "Single":
                textBox1.Visible  = true;
                textBox1.Text     = ((float)pInfo.GetValue(settings)).ToString();
                trackBar2.Visible = true;
                trackBar2.Minimum = attr.MinValue;
                trackBar2.Maximum = attr.MaxValue;
                trackBar2.Value   = ((float)pInfo.GetValue(settings));
                break;

            default:
                break;
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Form1 frm = new Form1();
            frm.TopLevel = true;
            frm.BringToFront();
            frm.Focus();
            string path = "";
            if (args.Length > 0)
            {
                path = args[0];
            }
            else
            {
                path = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "Mount and Blade II Bannerlord", "Configs", "TournamentsXPanded", "tournamentxpsettings.json");
            }

            DirectoryInfo di = new DirectoryInfo(Assembly.GetEntryAssembly().Location);
            LocalizedTextManager.LoadLocalizationXmls(di.Parent.Parent.Parent.Parent.Parent.FullName);
            frm.SetupLanguageDropdown();
            frm.LoadConfig(path);


#if DEBUG
            string pathxml = "E:\\Users\\Brandon\\OneDrive - Mathis Consulting, LLC\\Development\\BannerLord\\BrandonMods\\TournamentXPanded.Configurator\\Languages\\settings-en.xml";
            string pathcs = "E:\\Users\\Brandon\\OneDrive - Mathis Consulting, LLC\\Development\\BannerLord\\BrandonMods\\TournamentsXPanded.Settings\\TournamentXPSettings.cs";
            string pathoutput = "e:\\settings.cs";

            var xmlstrings = File.ReadAllLines(pathxml);
            var csfile = File.ReadAllLines(pathcs);

            using (var sw = new StreamWriter(pathoutput, false))
            {
                foreach (var line in csfile)
                {
                    if (line.Trim().StartsWith("[SettingProperty"))
                    {
                        var parts = line.Split('"');
                        var newparts = "";
                        foreach(var p in parts)
                        {
                            var pt = LocalizedTextManager.FindStringId("English", p);
                            if (pt.StartsWith("{"))
                            {
                                //pt = pt + LocalizedTextManager.GetTranslatedText("English", LocalizedTextManager.GetStringId(pt));
                                pt = LocalizedTextManager.GetTranslatedText("English", LocalizedTextManager.GetStringId(pt));
                            }
                            newparts += pt + "\"";
                        }
                        newparts = newparts.Substring(0,newparts.Length - 1);
                        sw.WriteLine(newparts);
                    }
                    else
                    {
                        sw.WriteLine(line);
                    }
                }
            }
#endif


            Application.Run(frm);
        }
Exemple #3
0
        public void LoadConfig(TournamentXPSettings settings)
        {
            _settings = settings;
            pnlSettings.Controls.Clear();
            settingprops = new List <XPSettingControlBase>();
            //var groups = new List<SettingPropertyGroup>();
            propList = (from p in typeof(TournamentXPSettings).GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance)
                        let propAttr = p.GetCustomAttribute <SettingPropertyAttribute>(true)
                                       let groupAttr = p.GetCustomAttribute <SettingPropertyGroupAttribute>(true)
                                                       where propAttr != null
                                                       let groupAttrToAdd = groupAttr ?? null
                                                                            select new ConfigInfo {
                attribute = propAttr, propertyInfo = p, pgroup = groupAttrToAdd
            }).ToList();


            List <string> descriptions = new List <string>();
            List <string> hints        = new List <string>();
            List <string> groups       = new List <string>();


            List <FlowLayoutPanel> groupPanels = new List <FlowLayoutPanel>();

            groupPanels.Add(new FlowLayoutPanel()
            {
                Name = "Default"
            });

            var groupcount = 0;

            foreach (var pr in propList)
            {
                FlowLayoutPanel pnl = groupPanels.Where(x => x.Name == "Default").First();
                if (pr.pgroup != null)
                {
                    pnl = groupPanels.Where(x => x.Name == pr.pgroup.GroupName).FirstOrDefault();
                    if (pnl == null)
                    {
                        pnl = new FlowLayoutPanel()
                        {
                            Name = pr.pgroup.GroupName
                        };
                        pnl.AutoScroll   = false;
                        pnl.AutoSize     = true;
                        pnl.AutoSizeMode = AutoSizeMode.GrowAndShrink;
                        pnl.BorderStyle  = BorderStyle.FixedSingle;

                        string text = pr.pgroup.GroupName;
                        if (text.Trim().StartsWith("{"))
                        {
                            var id = LocalizedTextManager.GetStringId(text);
                            text = LocalizedTextManager.GetTranslatedText(ddlLanguage.SelectedItem.ToString(), id);
                        }

                        pnl.Controls.Add(new Label()
                        {
                            AutoSize = true, MinimumSize = new Size(700, 50), Text = text, Font = new System.Drawing.Font("Arial Narrow", 22F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0)))
                        });
                        groupPanels.Add(pnl);
                        groupcount++;
                        groups.Add(pr.pgroup.GroupName);
                    }
                }

                var uc = new XPSettingControlBase(ddlLanguage.SelectedItem.ToString());
                uc.Anchor = AnchorStyles.Top;
                uc.SetProperty(pr.attribute, pr.propertyInfo, _settings);
                pnl.Controls.Add(uc);
                settingprops.Add(uc);
#if DEBUG
                descriptions.Add(pr.attribute.DisplayName);
                if (!string.IsNullOrWhiteSpace(pr.attribute.HintText))
                {
                    hints.Add(pr.attribute.HintText);
                }
#endif
            }

            foreach (var pnl in groupPanels)
            {
                if (pnl.Controls.Count > 0)
                {
                    pnlSettings.Controls.Add(pnl);
                }
            }

            pnlSettings.Refresh();
#if DEBUG
            using (var sw = new System.IO.StreamWriter("E:\\texts.json"))
            {
                var count = 0;
                foreach (var s in groups)
                {
                    count++;
                    string id = ("000" + count.ToString());
                    id = id.Substring(id.Length - 4);
                    sw.WriteLine("<string id=\"txpg" + id + "\" text=\"" + s + "\" />");
                }
                foreach (var s in descriptions)
                {
                    count++;
                    string id = ("000" + count.ToString());
                    id = id.Substring(id.Length - 4);
                    sw.WriteLine("<string id=\"txpd" + id + "\" text=\"" + s + "\" />");
                }
                foreach (var s in hints)
                {
                    count++;
                    string id = ("000" + count.ToString());
                    id = id.Substring(id.Length - 4);
                    sw.WriteLine("<string id=\"txph" + id + "\" text=\"" + s + "\" />");
                }
            }
#endif
        }