Exemplo n.º 1
0
        public ColorField(PropertyInfo property, object obj, Context context, DisplayableAttribute attribute)
        {
            this.property = property;
            this.obj      = (IGUIComplete)obj;
            this.context  = context;

            Label label = new Label(UIFactory.ToReadable(property.Name) + ": ");

            PackStart(label, false, false, 0);

            colorButton = new ClickableEventBox {
                VisibleWindow = true, BorderWidth = 1
            };
            Graphics.SetAllBg(colorButton, (Gdk.Color)property.GetValue(obj));
            PackStart(colorButton, false, false, 0);

            if (attribute.tooltipText != "")
            {
                HasTooltip    = true;
                TooltipMarkup = attribute.tooltipText;
            }

            colorButton.SetSizeRequest(0, 0);

            SizeAllocated             += InitializeDisplay;
            colorButton.DoubleClicked += OpenPicker;
        }
Exemplo n.º 2
0
        public TabularContainerField(PropertyInfo property, object obj, Context context, DisplayableAttribute attribute) : base(1, 1, false)
        {
            // arg ought to be a string[] containing the names of child properties. Here we turn it into a list and
            // use ConvertAll() to obtain the list of actual PropertyInfos.
            children     = Array.ConvertAll((object[])attribute.arg, (str) => (string)str);
            this.context = context;

            ColumnSpacing = 5;
            RowSpacing    = 2;

            Label label = new Label(UIFactory.ToReadable(property.Name) + ": ");

            if (attribute.tooltipText != "")
            {
                label.HasTooltip    = true;
                label.TooltipMarkup = attribute.tooltipText;
            }

            Attach(label, 0, 1, 0, (uint)(2 * children.Length - 1), AttachOptions.Shrink, AttachOptions.Fill, 0, 0);
            Attach(new VSeparator(), 1, 2, 0, (uint)(2 * children.Length - 1), AttachOptions.Shrink, AttachOptions.Fill, 0, 0);

            for (int i = 0; i < children.Length; i++)
            {
                Widget childWidget = UIFactory.Fabricate(obj, children[i], context);
                Attach(childWidget, 2, 3, 2 * (uint)i, 2 * (uint)i + 1);
                if (i != children.Length - 1)
                {
                    Attach(new HSeparator(), 2, 3, 2 * (uint)i + 1, 2 * (uint)i + 2);
                }
            }
        }
Exemplo n.º 3
0
        int activeIndex;         //the index of the child that's "active": the entry or the clickable thingy.

        public TextEditableField(PropertyInfo property, object obj, Context context, DisplayableAttribute attribute)
        {
            this.property = property;
            this.obj      = (IDependable)obj;
            this.context  = context;
            editable      = attribute.EditAuthorized(obj);

            if (!context.compact)
            {
                activeIndex = 1;
                Label label = new Label((attribute.overrideLabel ?? UIFactory.ToReadable(property.Name)) + ": ");
                PackStart(label, false, false, 0);
            }

            if (attribute.tooltipText != "")
            {
                HasTooltip    = true;
                TooltipMarkup = attribute.tooltipText;
            }

            rightclickMenu = new Menu();
            MenuItem edit = new MenuItem("Edit");

            edit.Activated += Open;
            rightclickMenu.Append(edit);
            Reload();
        }
Exemplo n.º 4
0
 public ReadonlyField(PropertyInfo property, object obj, Context context, DisplayableAttribute attribute)
 {
     this.property = property;
     this.obj      = obj;
     this.context  = context;
     text          = GetValueAsString();
     if (context.compact)
     {
         Text = text;
     }
     else
     {
         Text = (attribute.overrideLabel ?? UIFactory.ToReadable(property.Name)) + ": " + text;
     }
     SetAlignment(0, 0.5f);
 }
Exemplo n.º 5
0
        public SlashDelimitedContainerField(PropertyInfo property, object obj, Context context, DisplayableAttribute attribute)
        {
            string[] children = Array.ConvertAll((object[])attribute.arg, (str) => (string)str);
            Label    label    = new Label(UIFactory.ToReadable(property.Name) + ": ");

            if (attribute.tooltipText != "")
            {
                label.HasTooltip    = true;
                label.TooltipMarkup = attribute.tooltipText;
            }
            PackStart(label, false, false, 0);
            for (int i = 0; i < children.Length; i++)
            {
                Widget childWidget = UIFactory.Fabricate(obj, children[i], context.butCompact);
                PackStart(childWidget, false, false, 0);
                if (i != children.Length - 1)
                {
                    PackStart(new Label("/"), false, false, 0);
                }
            }
        }
Exemplo n.º 6
0
        public ObjectField(PropertyInfo property, object obj, Context context, DisplayableAttribute attribute) : base(0, 0, 1, 1)
        {
            this.property = property;
            this.obj      = (IGUIComplete)property.GetValue(obj);
            this.context  = context;

            title = attribute.overrideLabel ?? UIFactory.ToReadable(property.Name);

            if (this.obj != null)
            {
                DependencyManager.Connect(this.obj, this);
                Destroyed += (o, a) => DependencyManager.DisconnectAll(this);
                Reload();
            }
            else
            {
                Label label = new Label(title + ": None");
                label.SetAlignment(0, 0);
                Add(label);
            }
        }
Exemplo n.º 7
0
        public DeploymentForceSelectionField(PropertyInfo property, object obj, Context context, DisplayableAttribute attribute) : base(false, 0)
        {
            deployment = (Deployment)obj;
            bool editable = attribute.EditAuthorized(obj);

            PackStart(new Label(UIFactory.ToReadable(property.Name) + ": "), false, false, 0);
            buttons    = new RadioButton[4];
            buttons[0] = new RadioButton("C");
            buttons[1] = new RadioButton(buttons[0], "B");
            buttons[2] = new RadioButton(buttons[0], "A");
            buttons[3] = new RadioButton(buttons[0], "S");
            buttons[(int)deployment.force_employed].Active = true;
            foreach (RadioButton button in buttons)
            {
                button.Toggled += OnThreatToggled;
                if (!editable || (deployment.affiliation != Game.player && !Game.omnipotent))
                {
                    button.State = StateType.Insensitive;
                }
                PackStart(button, false, false, 0);
            }
        }
Exemplo n.º 8
0
        public ExpressionField(PropertyInfo property, object obj, Context context, DisplayableAttribute attribute) : base(0, 0, 1, 1)
        {
            this.property = property;
            this.obj      = obj;
            exp           = (Expression)property.GetValue(obj);
            this.context  = context;
            title         = attribute.overrideLabel ?? UIFactory.ToReadable(property.Name);

            Label label = new Label();

            label.UseMarkup = true;
            label.Justify   = Justification.Right;
            label.SetAlignment(0, 0);

            //Multi-line expressions are put in an expander with the label text being the formattedResult of the expression.
            if (exp.text.Contains("\n"))
            {
                Expander expander = new Expander(title + ": " + exp.formattedResult);
                expander.Activated += (o, a) => ReloadLabel();
                label.Markup        = exp.ToString();
                expander.Add(new Gtk.Alignment(0, 0, 1, 1)
                {
                    Child = label, LeftPadding = 10, BottomPadding = 5
                });
                Add(expander);
            }
            else
            {
                label.Markup = title + ": " + exp;
                Add(label);
            }

            if (attribute.tooltipText != "")
            {
                HasTooltip    = true;
                TooltipMarkup = attribute.tooltipText;
            }
        }
Exemplo n.º 9
0
 public void OpenDialog(object widget, EventArgs args)
 {
     TextEditingDialog dialog = new TextEditingDialog(
         "Edit " + UIFactory.ToReadable(property.Name),
         (Window)Toplevel,
         () => (string)property.GetValue(obj),
         delegate(string input) {
         try {                                                      // Muahahahaha I'm evil
             property.SetValue(obj, input);
         } catch (Exception e) {
             e = e.InnerException;
             return(false);
         }
         IDependable dependable = obj as IDependable;
         if (dependable != null)
         {
             DependencyManager.Flag(obj);
             DependencyManager.TriggerAllFlags();
         }
         return(true);
     }
         );
 }
Exemplo n.º 10
0
        public DialogTextEditableField(PropertyInfo property, object obj, Context context, DisplayableAttribute attribute) : base(false, 2)
        {
            this.property = property;
            this.obj      = (IDependable)obj;
            this.context  = context;
            editable      = attribute.EditAuthorized(obj);
            // Create the label
            if (!context.compact)
            {
                Label label = new Label(attribute.overrideLabel ?? UIFactory.ToReadable(property.Name) + ": ");
                label.SetAlignment(0, 1);
                if (attribute.tooltipText != null)
                {
                    label.HasTooltip    = true;
                    label.TooltipMarkup = attribute.tooltipText;
                }
                PackStart(label, false, false, 0);
            }
            // Create the text body
            Label val = new Label((string)property.GetValue(obj));

            if (val.Text == "")
            {
                val.Text = "-";
            }
            val.SetAlignment(0, 0);
            if (!context.compact)
            {
                val.LineWrap = true;
                val.Justify  = Justification.Fill;
                val.SetSizeRequest(0, -1);
                val.SizeAllocated += (o, a) => val.SetSizeRequest(a.Allocation.Width, -1);
                val.LineWrapMode   = Pango.WrapMode.WordChar;
            }
            //Create the "clickable" functionality
            ClickableEventBox eventBox = new ClickableEventBox();

            eventBox.DoubleClicked += OpenDialog;
            eventBox.RightClicked  += delegate {
                rightclickMenu.Popup();
                rightclickMenu.ShowAll();
            };

            if (context.compact)
            {
                Gtk.Alignment alignment = UIFactory.Align(val, 0, 0, 1, 1);
                alignment.BorderWidth = 5;
                if (editable)
                {
                    eventBox.Add(alignment);
                    PackStart(eventBox);
                }
                else
                {
                    PackStart(alignment);
                }
            }
            else
            {
                Gtk.Alignment alignment = new Gtk.Alignment(0, 0, 1, 1);
                if (editable)
                {
                    eventBox.Add(val);
                    alignment.Add(eventBox);
                }
                else
                {
                    alignment.Add(val);
                }
                alignment.LeftPadding = 10;
                PackStart(alignment, true, true, 0);
            }

            rightclickMenu = new Menu();
            MenuItem edit = new MenuItem("Edit");

            edit.Activated += OpenDialog;
            rightclickMenu.Append(edit);
        }
Exemplo n.º 11
0
        public FractionsBar(PropertyInfo property, object obj, Context context, DisplayableAttribute attribute) : base(1, 3, false)
        {
            fractions    = (Fraction[])property.GetValue(obj);
            this.context = context;

            if ((bool)attribute.arg != false)
            {
                RowSpacing = 2;
                Label title = new Label("[ " + UIFactory.ToReadable(property.Name) + " ]");
                Attach(title, 0, 1, 0, 1, AttachOptions.Fill, AttachOptions.Fill, 0, 2);
            }

            if (attribute.tooltipText != "")
            {
                HasTooltip    = true;
                TooltipMarkup = attribute.tooltipText;
            }

            float leftspace = 0;

            for (int i = 0; i < fractions.Length; i++)
            {
                float spaceAlloc;
                if (fractions[i].val > 0.99)
                {
                    spaceAlloc = 0;
                }
                else if (fractions[i].val < 0.01)
                {
                    leftspace += fractions[i].val;
                    continue;
                }
                else
                {
                    spaceAlloc = leftspace / (1 - fractions[i].val);
                    //xalign = % of free space allocated to the left = (free space to left)/(total free space).
                    //Conditional eliminates division by zero issue
                }

                Frame frame = new Frame();
                Graphics.SetAllBg(frame, fractions[i].color);

                Gtk.Alignment alignment = new Gtk.Alignment(spaceAlloc, 0, fractions[i].val, 1);
                alignment.Add(frame);
                frame.SetSizeRequest(0, -1);

                Attach(alignment, 0, 1, 1, 2);

                //A bunch of logic to try and make sure the label fits in the box.
                if (fractions[i].val > 0.1 || fractions.Length <= 2)
                {
                    if (fractions[i].val <= 0.2)
                    {
                        frame.Child = new Label(fractions[i].val.ToString("P0"));
                    }
                    else
                    {
                        frame.Child = new Label(fractions[i].val.ToString("P1"));
                    }
                    frame.Child.SetSizeRequest(0, -1);
                    Label label = new Label {
                        UseMarkup = true, Markup = "<small>" + fractions[i].name + "</small>"
                    };
                    label.SetAlignment(spaceAlloc, 0);
                    label.SetSizeRequest(0, -1);
                    Attach(label, 0, 1, 2, 3);
                }

                leftspace += fractions[i].val;
            }
        }
Exemplo n.º 12
0
        public TabularListField(PropertyInfo property, object obj, Context context, DisplayableAttribute attribute)            //obj must be an IContainer.
        {
            VisibleWindow = false;

            parent       = (IContainer)obj;
            this.context = context;
            editable     = attribute.EditAuthorized(obj);

            // Local convenience variable
            List <T> list = (List <T>)property.GetValue(obj);

            // To align contents properly.
            Gtk.Alignment alignment = new Gtk.Alignment(0, 0, 1, 1)
            {
                TopPadding = 3, BottomPadding = 3
            };
            Add(alignment);

            if (editable)
            {
                // Creates rightclick menu for listwide management
                rightclickMenu = new Menu();

                // "Clear" button
                MenuItem clearButton = new MenuItem("Clear");                 //Clears list
                clearButton.Activated += delegate {
                    ((IContainer)obj).RemoveRange(new List <T>(list));
                    DependencyManager.TriggerAllFlags();
                };
                rightclickMenu.Append(clearButton);

                // "Add existing" button, but only if it's a list of GameObjects which can be searched from SelectorDialog.
                if (typeof(T).IsSubclassOf(typeof(GameObject)))
                {
                    MenuItem addExistingButton = new MenuItem("Add");
                    rightclickMenu.Append(addExistingButton);
                    addExistingButton.Activated += (o, a) => new SelectorDialog(
                        "Select new addition to " + UIFactory.ToReadable(property.Name) + " (shift to add multiple)",
                        AddExistingFilter,
                        delegate(GameObject returned) {
                        ((IContainer)obj).Add(returned);
                        DependencyManager.TriggerAllFlags();
                    }, true);
                }

                // "Add new" button
                if (Game.omnipotent)
                {
                    MenuItem addNewButton = new MenuItem("Add New");
                    addNewButton.Activated += delegate {
                        object          newElement;
                        ConstructorInfo constructor = typeof(T).GetConstructor(new Type[] { });
                        if (constructor != null)
                        {
                            newElement = constructor.Invoke(new object[0]);
                        }
                        else
                        {
                            MethodInfo method = typeof(T).GetMethod("Create");
                            if (method != null)
                            {
                                newElement = method.Invoke(null, new object[0]);
                                if (newElement == null)
                                {
                                    return;
                                }
                            }
                            else
                            {
                                throw new NotImplementedException();
                            }
                        }
                        ((IContainer)obj).Add(newElement);
                        if (newElement is GameObject)
                        {
                            Game.city.Add((GameObject)newElement);
                        }
                        DependencyManager.TriggerAllFlags();
                    };
                    rightclickMenu.Append(addNewButton);
                }
            }

            // Load tooltip (if exists)
            if (attribute.tooltipText != "")
            {
                HasTooltip    = true;
                TooltipMarkup = attribute.tooltipText;
            }

            if (context.vertical)
            {
                int columns = (int)attribute.arg;
                if (columns < 0)
                {
                    columns *= -1;
                }
                DynamicTable table = new DynamicTable(list.ConvertAll((element) => GetElementWidget(element)), (uint)columns);

                if (context.compact)
                {
                    if (editable)
                    {
                        EventBox eventBox = new EventBox {
                            Child = table, VisibleWindow = false
                        };
                        alignment.Add(eventBox);
                        eventBox.ButtonPressEvent += ListPressed;                         //Set up right-click menu
                        MyDragDrop.DestSet(eventBox, typeof(T).Name);                     //Set up
                        MyDragDrop.DestSetDropAction(eventBox, AttemptDrag);              //drag support
                    }
                    else
                    {
                        alignment.Add(table);
                    }
                }
                else
                {
                    Expander expander = new Expander(attribute.overrideLabel ?? UIFactory.ToReadable(property.Name));
                    expander.Expanded = (int)attribute.arg > 0;
                    expander.Add(table);
                    alignment.Add(expander);
                    if (editable)
                    {
                        expander.ButtonPressEvent += ListPressed;                         //Set up right-click menu
                        MyDragDrop.DestSet(expander, typeof(T).Name);                     //Set up
                        MyDragDrop.DestSetDropAction(expander, AttemptDrag);              //drag support
                    }
                }
            }
            else
            {
                HBox  box   = new HBox(false, 5);
                Label label = new Label(UIFactory.ToReadable(property.Name))
                {
                    Angle = 90
                };
                if (editable)
                {
                    ClickableEventBox labelEventBox = new ClickableEventBox {
                        Child = label
                    };
                    labelEventBox.RightClicked += delegate {
                        rightclickMenu.Popup();
                        rightclickMenu.ShowAll();
                    };
                    box.PackStart(labelEventBox, false, false, 2);
                    //Set up drag support
                    MyDragDrop.DestSet(this, typeof(T).Name);
                    MyDragDrop.DestSetDropAction(this, AttemptDrag);
                }
                else
                {
                    box.PackStart(label, false, false, 2);
                }
                for (int i = 0; i < list.Count; i++)
                {
                    box.PackStart(GetElementWidget(list[i]), false, false, 0);
                }
                alignment.Add(box);
            }
        }
Exemplo n.º 13
0
        public RatingsListField(PropertyInfo property, object obj, Context context, DisplayableAttribute attribute) : base(0, 0, 1, 1)
        {
            RatingsProfile profile = ((Func <Context, RatingsProfile>)property.GetValue(obj))(context);

            float[,] values = profile.values;
            int[,] o_vals   = profile.o_vals;

            Gtk.Alignment alignment = new Gtk.Alignment(0, 0, 1, 0);

            if (context.vertical && !context.compact)
            {
                Frame frame = new Frame(UIFactory.ToReadable(property.Name));
                VBox  box   = new VBox(false, 4)
                {
                    BorderWidth = 5
                };
                frame.Add(box);
                alignment.Add(frame);

                for (int i = 1; i <= 8; i++)
                {
                    if (o_vals[0, i] != Ratings.O_NULL)
                    {
                        Label ratingLabel = new Label(Ratings.PrintSingle(i, values[0, i]));
                        ratingLabel.SetAlignment(0, 0);
                        box.PackStart(ratingLabel);
                    }
                }

                for (int k = 1; k <= 3; k++)
                {
                    if (o_vals[k, 0] != Ratings.O_NULL)
                    {
                        Label wrapperLabel = new Label(Ratings.PrintSingle(k + 8, values[k, 0]));
                        wrapperLabel.SetAlignment(0, 0);

                        VBox ratingBox = new VBox(false, 5)
                        {
                            BorderWidth = 5
                        };
                        Frame ratingFrame = new Frame {
                            LabelWidget = wrapperLabel, Child = ratingBox
                        };

                        for (int i = 1; i <= 8; i++)
                        {
                            if (o_vals[k, i] != Ratings.O_NULL)
                            {
                                Label ratingLabel = new Label(Ratings.PrintSingle(i, values[k, i]));
                                ratingLabel.SetAlignment(0, 0);
                                ratingBox.PackStart(ratingLabel, false, false, 0);
                            }
                        }

                        box.PackStart(ratingFrame);
                    }
                }
            }
            else
            {
                Box box;
                if (context.compact)
                {
                    box = new VBox(false, 0)
                    {
                        BorderWidth = 5
                    };
                }
                else
                {
                    box = new HBox(false, 0)
                    {
                        BorderWidth = 5
                    };
                }
                alignment.Add(box);
                for (int i = 1; i <= 8; i++)
                {
                    if (o_vals[0, i] != Ratings.O_NULL)
                    {
                        bool  comma       = !context.compact && box.Children.Length > 0;
                        Label ratingLabel = new Label((comma ? ", " : "")                         //Commas to delimit ratings
                                                      + Ratings.PrintSingle(i, values[0, i]));
                        ratingLabel.SetAlignment(0, 0);
                        box.PackStart(ratingLabel, false, false, 0);
                    }
                }
                for (int k = 1; k <= 3; k++)
                {
                    if (o_vals[k, 0] != Ratings.O_NULL)
                    {
                        bool  comma       = !context.compact && box.Children.Length > 0;
                        Label ratingLabel = new Label((comma ? ", " : "")                         //Commas to delimit ratings
                                                      + Ratings.PrintSingle(k + 8, values[k, 0], true));
                        ratingLabel.SetAlignment(0, 0);
                        List <String> subratings = new List <String>();
                        for (int i = 1; i <= 8; i++)
                        {
                            if (o_vals[k, i] != Ratings.O_NULL)
                            {
                                subratings.Add(Ratings.PrintSingle(i, values[k, i]));
                            }
                        }
                        ratingLabel.TooltipText = String.Join("\n", subratings);
                        box.PackStart(ratingLabel, false, false, 0);
                    }
                }
            }
            if (attribute.EditAuthorized(obj))
            {
                ClickableEventBox clickableEventBox = new ClickableEventBox {
                    Child = alignment
                };
                clickableEventBox.DoubleClicked += delegate {
                    // The property this is attached to gets the *current ratings*, not the *base ratings*, which are
                    // what we logically want to let the user manipulate. Hence, the optional arg supplied is the name
                    // of the base profile.
                    PropertyInfo      baseProfileProperty = obj.GetType().GetProperty((string)attribute.arg);
                    TextEditingDialog dialog = new TextEditingDialog(
                        "Edit ratings",
                        (Window)Toplevel,
                        delegate {
                        RatingsProfile baseProfile = (RatingsProfile)baseProfileProperty.GetValue(obj);
                        return(Ratings.Print(baseProfile.values, baseProfile.o_vals));
                    },
                        delegate(string input) {
                        if (Ratings.TryParse(input, out RatingsProfile? newRatings))
                        {
                            baseProfileProperty.SetValue(obj, (RatingsProfile)newRatings);
                            IDependable dependable = obj as IDependable;
                            if (dependable != null)
                            {
                                DependencyManager.Flag(dependable);
                                DependencyManager.TriggerAllFlags();
                            }
                            return(true);
                        }
                        return(false);
                    }
                        );
                };
                Add(clickableEventBox);
            }
            else
            {
                Add(alignment);
            }
        }