Esempio n. 1
0
        /// <summary>
        ///     Saves a button def to file
        /// </summary>
        /// <param name="FileName">The filename that should be used to save the def</param>
        /// <param name="def">The ButtonDef object to save</param>
        private void Save(string FileName, ButtonDef def)
        {
            Utility.EnsureDirectory(Path.GetDirectoryName(FileName));

            var serializer = new XmlSerializer(typeof(ButtonDef));

            var stream = new FileStream(FileName, FileMode.Create, FileAccess.Write, FileShare.None);

            serializer.Serialize(stream, def);

            stream.Close();
        }
Esempio n. 2
0
        /// <summary>
        ///     Localizes the text of a control and all of its children controls
        /// </summary>
        /// <param name="control">The control that should be localized</param>
        public void LocalizeControl(Control control)
        {
            if (control is Form)
            {
                // Set options on controls
                var f = control as Form;

                f.TopMost = Pandora.Profile.General.TopMost;
                f.Opacity = Pandora.Profile.General.Opacity / 100.0;
            }

            if (control is BoxButton)
            {
                // Box button
                var b = control as BoxButton;

                ButtonDef def = null;

                if (b.ButtonID >= 0)
                {
                    def = Pandora.Buttons[b];
                }

                Pandora.Profile.ButtonIndex.DoButton(b);
            }
            else
            {
                // Classic control
                var text = control.Text;

                var path = text.Split('.');

                if (path.Length == 2)
                {
                    control.Text = Pandora.Localization.GetTextProvider()[text];
                }

                if (control is LinkLabel)
                {
                    (control as LinkLabel).LinkColor        = Pandora.Profile.General.Links.Color;
                    (control as LinkLabel).VisitedLinkColor = Pandora.Profile.General.Links.Color;
                    (control as LinkLabel).LinkBehavior     = LinkBehavior.HoverUnderline;
                }

                if (control.Controls.Count > 0)
                {
                    foreach (Control c in control.Controls)
                    {
                        LocalizeControl(c);
                    }
                }
            }
        }
        /// <summary>
        /// Localizes the text of a control and all of its children controls
        /// </summary>
        /// <param name="control">The control that should be localized</param>
        public void LocalizeControl(Control control)
        {
            if (control is Form)
            {
                // Set options on controls
                Form f = control as Form;

                f.TopMost = Pandora.Profile.General.TopMost;
                f.Opacity = (double)Pandora.Profile.General.Opacity / 100.0;
            }

            if (control is TheBox.Buttons.BoxButton)
            {
                // Box button
                TheBox.Buttons.BoxButton b = control as TheBox.Buttons.BoxButton;

                ButtonDef def = null;

                if (b.ButtonID >= 0)
                {
                    def = Pandora.Buttons[b];
                }

                Pandora.Profile.ButtonIndex.DoButton(b);
            }
            else
            {
                // Classic control
                string text = control.Text;

                string[] path = text.Split(new char[] { '.' });

                if (path.Length == 2)
                {
                    control.Text = Pandora.Localization.TextProvider[text];
                }

                if (control is LinkLabel)
                {
                    (control as LinkLabel).LinkColor        = Pandora.Profile.General.Links.Color;
                    (control as LinkLabel).VisitedLinkColor = Pandora.Profile.General.Links.Color;
                    (control as LinkLabel).LinkBehavior     = System.Windows.Forms.LinkBehavior.HoverUnderline;
                }

                if (control.Controls.Count > 0)
                {
                    foreach (Control c in control.Controls)
                    {
                        LocalizeControl(c);
                    }
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Loads a ButtonDef
        /// </summary>
        /// <param name="FileName">The filename that should be loaded from</param>
        /// <returns>A ButtonDef object read from the file</returns>
        private ButtonDef Load(string FileName)
        {
            XmlSerializer serializer = new XmlSerializer(typeof(ButtonDef));

            FileStream stream = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);

            ButtonDef def = serializer.Deserialize(stream) as ButtonDef;

            stream.Close();

            return(def);
        }
Esempio n. 5
0
 public BaseDemoGUI()
 {
     ButtonDefs = new ButtonDef[] {
         new ButtonDef(new Rect(230, 45, 180, 32), "Named Event"),
         new ButtonDef(new Rect(230, 85, 180, 32), "User update"),
         new ButtonDef(new Rect(230, 125, 180, 32), "Purchase Item"),
         new ButtonDef(new Rect(230, 165, 180, 32), "IAP: Item"),
         new ButtonDef(new Rect(230, 205, 180, 32), "IAP: Virtual Currency"),
         new ButtonDef(new Rect(230, 245, 180, 32), "Apple IAP"),
         new ButtonDef(new Rect(230, 285, 180, 32), "Currency Given"),
         new ButtonDef(new Rect(230, 325, 180, 32), "AB Test Resources"),
         new ButtonDef(new Rect(110, 405, 112, 32), "Send To Swrve"),
         new ButtonDef(new Rect(418, 405, 112, 32), "Save To Disk"),
         new ButtonDef(new Rect(230, 405, 180, 32), "Trigger message")
     };
     buttonPressed = new bool[System.Enum.GetNames(typeof(Buttons)).Length];
 }
Esempio n. 6
0
 /// <summary>
 ///     Sets the button in a blank state
 /// </summary>
 /// <param name="button">The BoxButton object to set</param>
 public void ClearButton(BoxButton button)
 {
     this[button] = new ButtonDef();
 }
Esempio n. 7
0
        /// <summary>
        /// Gets the ButtonDef object given the button's ID
        /// </summary>
        public ButtonDef this[BoxButton button]
        {
            get
            {
                string filename = GetFile(button.ButtonID);

                if (File.Exists(filename))
                {
                    // There's a custom def

                    try
                    {
                        ButtonDef def = Load(filename);
                        button.Def = def;
                        return(def);
                    }
                    catch (Exception err)
                    {
                        Pandora.Log.WriteError(err, string.Format("Custom file for button {0} was corrupted. It has been renamed to {0}.old.xml", filename));

                        try
                        {
                            File.Move(filename, string.Format("{0}.old.xml", filename));
                        }
                        catch
                        {
                            Pandora.Log.WriteError(null, "Cannot rename file");
                        }
                    }
                }
                // Get default

                // TODO : Read the def from the correct memory location instead for the release

                try
                {
                    string    defaultFile = string.Format(@"D:\Dev\Pandora 2.0\Data\Buttons\{0}.xml", button.ButtonID);
                    ButtonDef def         = Load(defaultFile);
                    button.Def = def;
                    return(def);
                }
                catch (Exception err)
                {
                    Pandora.Log.WriteError(err, string.Format("Cannot read default def file for button #{0}", button.ButtonID));
                }

                button.Def = null;
                return(null);
            }
            set
            {
                // TODO : Add correct code to save in custom folder
                string filename = string.Format(@"D:\Dev\Pandora 2.0\Data\Buttons\{0}.xml", button.ButtonID);

                try
                {
                    Save(filename, value);
                    button.Def = value;
                }
                catch (Exception err)
                {
                    Pandora.Log.WriteError(err, string.Format("Error occurred when setting the def object for button #{0}", button.ButtonID));
                    button.Def = null;
                }
            }
        }
Esempio n. 8
0
        /// <summary>
        /// Gets the ButtonDef object given the button's ID
        /// </summary>
        public ButtonDef this[BoxButton button]
        {
            get
            {
                string filename = GetFile(button.ButtonID);

                if (File.Exists(filename))
                {
                    // There's a custom def

                    try
                    {
                        ButtonDef def = Load(filename);
                        button.Def = def;
                        return(def);
                    }
                    catch (Exception err)
                    {
                        Pandora.Log.WriteError(err, string.Format("Custom file for button {0} was corrupted. It has been renamed to {0}.old.xml", filename));

                        try
                        {
                            File.Move(filename, string.Format("{0}.old.xml", filename));
                        }
                        catch
                        {
                            Pandora.Log.WriteError(null, "Cannot rename file");
                        }
                    }
                }
                // Get default

                string resource = string.Format("DefaultButtons.{0}.xml", button.ButtonID);

                try
                {
                    Stream stream = DefaultAssembly.GetManifestResourceStream(resource);

                    if (stream != null)
                    {
                        XmlSerializer serializer = new XmlSerializer(typeof(ButtonDef));
                        button.Def = serializer.Deserialize(stream) as ButtonDef;
                        stream.Close();

                        return(button.Def);
                    }
                }
                catch (Exception err)
                {
                    Pandora.Log.WriteError(err, "Error when loading defaults for button {0}", button.ButtonID);
                }

                button.Def = null;
                return(null);
            }
            set
            {
                string filename = GetFile(button.ButtonID);

                try
                {
                    Save(filename, value);
                    button.Def = value;
                }
                catch (Exception err)
                {
                    Pandora.Log.WriteError(err, string.Format("Error occurred when setting the def object for button #{0}", button.ButtonID));
                    button.Def = null;
                }
            }
        }