Ejemplo n.º 1
0
        public void Reload()
        {
            if (Children.Length > activeIndex)
            {
                Children[activeIndex].Destroy();
            }
            Label val = new Label(GetValueAsString());

            val.SetAlignment(0, 0.5f);
            if (editable)
            {
                ClickableEventBox eventBox = new ClickableEventBox()
                {
                    Child = val
                };
                eventBox.DoubleClicked += Open;
                eventBox.RightClicked  += delegate {
                    rightclickMenu.Popup();
                    rightclickMenu.ShowAll();
                };
                PackStart(eventBox, true, true, 0);
            }
            else
            {
                PackStart(val, true, true, 0);
            }
            ShowAll();
        }
Ejemplo n.º 2
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;
        }
Ejemplo n.º 3
0
 public static void SetCurrentMouseOver(ClickableEventBox widget)
 {
     if (currentMouseOver != null && currentMouseOver.prelight)
     {
         currentMouseOver.State = StateType.Normal;
     }
     currentMouseOver = widget;
     if (currentMouseOver != null && currentMouseOver.prelight)
     {
         currentMouseOver.State = StateType.Prelight;
     }
 }
Ejemplo n.º 4
0
		public EffectiveRatingsMultiview (PropertyInfo property, object obj, Context context, DisplayableAttribute attribute) {

			this.context = context;
			BorderWidth = 5;

			// Nest containers
			VBox mainBox = new VBox();
			HBox navigation = new HBox();
			SquareContainer square = new SquareContainer();
			notebook = new Notebook { ShowTabs = false, ShowBorder = false };
			square.Add(notebook);
			mainBox.PackStart(navigation, false, false, 5);
			mainBox.PackStart(square, true, true, 0);
			Add(mainBox);

			// Navigation
			Label pageLabel = new Label("Table (final)");
			ClickableEventBox leftArrow = new ClickableEventBox();
			leftArrow.Add(Graphics.GetIcon(IconTemplate.LeftArrow, new Gdk.Color(100, 100, 100), Graphics.textSize));
			leftArrow.Clicked += delegate {
				if (notebook.CurrentPage > 0) {
					notebook.CurrentPage--;
				} else {
					notebook.CurrentPage = notebook.NPages - 1;
				}
				pageLabel.Text = labels[notebook.CurrentPage];
			};
			ClickableEventBox rightArrow = new ClickableEventBox();
			rightArrow.Add(Graphics.GetIcon(IconTemplate.RightArrow, new Gdk.Color(100, 100, 100), Graphics.textSize));
			rightArrow.Clicked += delegate {
				if (notebook.CurrentPage < notebook.NPages - 1) {
					notebook.CurrentPage++;
				} else {
					notebook.CurrentPage = 0;
				}
				pageLabel.Text = labels[notebook.CurrentPage];
			};
			navigation.PackStart(leftArrow, false, false, 5);
			navigation.PackStart(pageLabel, true, true, 0);
			navigation.PackStart(rightArrow, false, false, 5);

			// Fill notebook
			EffectiveRatingsProfile erp = (EffectiveRatingsProfile)property.GetValue(obj);
			RatingsRadarChart radar1 = new RatingsRadarChart(context.butCompact, erp.final, erp.multipliers, erp.metamultipliers);
			RatingsTable table1 = new RatingsTable(context.butCompact, erp.final, erp.multipliers, erp.metamultipliers);
			RatingsRadarChart radar2 = new RatingsRadarChart(context.butCompact, erp.original);
			RatingsTable table2 = new RatingsTable(context.butCompact, erp.original);
			notebook.AppendPage(radar1, null);
			notebook.AppendPage(UIFactory.Align(table1, 0.5f, 0.5f, 0, 0), null);
			notebook.AppendPage(radar2, null);
			notebook.AppendPage(UIFactory.Align(table2, 0.5f, 0.5f, 0, 0), null);

		}
Ejemplo n.º 5
0
        Widget SetupHeader(GameObject obj)
        {
            Widget baseHeader = obj.GetHeader(new Context(obj, Game.player, false, true));
            HBox   hbox       = new HBox();

            hbox.PackStart(baseHeader, false, false, 5);
            ClickableEventBox eventbox = new ClickableEventBox {
                Child = hbox
            };

            eventbox.Clicked += (o, a) => OnClicked(obj);
            return(eventbox);
        }
Ejemplo n.º 6
0
        Widget SetupListing(GameObject obj)
        {
            Gtk.Alignment align = new Gtk.Alignment(0, 0, 0, 0)
            {
                Child        = new Listing(obj, lazy),
                BorderWidth  = 5,
                LeftPadding  = 10,
                RightPadding = 10
            };
            ClickableEventBox eventbox = new ClickableEventBox {
                Child = align
            };

            eventbox.Clicked += (o, a) => OnClicked(obj);
            return(eventbox);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
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);
            }
        }
Ejemplo n.º 9
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);
            }
        }
Ejemplo n.º 10
0
        public MainInterface()
        {
            DependencyManager.Connect(Game.city, this);
            DependencyManager.Connect(Game.UIKey, this);

            textBar    = new HBox();
            numbersBar = new HBox();
            VBox topBars = new VBox(false, 2)
            {
                BorderWidth = 5
            };

            topBars.PackStart(textBar);
            topBars.PackStart(numbersBar);
            PackStart(new HSeparator(), false, false, 0);
            PackStart(topBars, false, false, 0);
            PackStart(new HSeparator(), false, false, 0);

            HBox mainHBox = new HBox();

            PackStart(mainHBox, true, true, 0);

            //Set up the containers
            VBox leftVBox = new VBox();

            mainNotebook = new Notebook();
            leftVBox.PackStart(mainNotebook, true, true, 0);
            mainHBox.PackStart(leftVBox, true, true, 0);

            ////Notebook
            ///
            //Map tab
            map = new Map();             //Profiler called inside Map constructor
            mainNotebook.AppendPage(map, new Label("Map"));
            Profiler.Log();
            //Search tab
            Search search = new Search(null, (obj) => Inspector.InspectInNearestInspector(obj, this));

            mainNotebook.AppendPage(search, new Label("Search"));
            //My domain
            Search domain = new Search((obj) => (obj is Territory || obj is Structure) && ((IAffiliated)obj).affiliation == Game.player,
                                       (obj) => Inspector.InspectInNearestInspector(obj, this));

            domain.typesButton.State        = StateType.Insensitive;
            domain.toplevelOnlyButton.State = StateType.Insensitive;
            mainNotebook.AppendPage(domain, new Label("Domain"));
            //Event log tab
            eventLogLabel = new ClickableEventBox {
                Child = new Label("Logs"), prelight = false, depress = false
            };
            eventLogLabel.DoubleClicked += (o, a) => WindowizeEventLog();
            eventLogLabel.ShowAll();
            eventLogsScroller = new ScrolledWindow();
            eventLogsScroller.SetSizeRequest(200, -1);
            eventLogsDisplay = new VBox {
                BorderWidth = 10
            };
            eventLogsScroller.AddWithViewport(eventLogsDisplay);
            mainNotebook.AppendPage(eventLogsScroller, eventLogLabel);

            //Agents bottom bar
            assetsBar = new AssetsBottomBar {
                BorderWidth = 10
            };
            leftVBox.PackStart(assetsBar, false, false, 0);

            //Inspector
            Inspector inspector = new Inspector()
            {
                BorderWidth = 10
            };

            mainHBox.PackStart(inspector, false, false, 0);

            Profiler.Log(ref Profiler.searchCreateTime);

            MainWindow.main.inspector = inspector;

            Destroyed += (o, a) => DependencyManager.Destroy(this);

            Reload();

            mainNotebook.CurrentPage = 0;
        }
Ejemplo n.º 11
0
        public void Reload()
        {
            uint spacing = (uint)(Graphics.textSize / 5);

            Gdk.Color black = new Gdk.Color(0, 0, 0);

            //Destroy previous displays for top bar
            while (textBar.Children.Length > 0)
            {
                textBar.Children[0].Destroy();
            }
            while (numbersBar.Children.Length > 0)
            {
                numbersBar.Children[0].Destroy();
            }

            //Create display for active agent (player)
            textBar.PackStart(new Label("Playing as: "), false, false, spacing);
            InspectableBox player = (InspectableBox)Game.player.GetHeader(new Context(null, Game.player, false, true));

            if (Game.omnipotent)
            {
                MyDragDrop.DestSet(player, "Active IAgent");
                MyDragDrop.DestSetDropAction(player, delegate(object obj) {
                    if (GameObject.TryCast(obj, out IAgent agent))
                    {
                        Game.SetPlayer(agent);
                    }
                });
            }
            textBar.PackStart(player, false, false, 0);

            //Create phase indicator and "next" arrow
            Image             nextPhaseArrow  = Graphics.GetIcon(IconTemplate.RightArrow, black, (int)(Graphics.textSize * 0.75));
            ClickableEventBox nextPhaseButton = new ClickableEventBox {
                Child       = nextPhaseArrow,
                BorderWidth = (uint)(Graphics.textSize * 0.25),
                Sensitive   = Game.CanNext()
            };

            nextPhaseButton.Clicked += (o, a) => Game.Next();
            textBar.PackEnd(nextPhaseButton, false, false, spacing);
            textBar.PackEnd(new Label(Game.phase + " Phase"), false, false, spacing);

            //Update resource and reputation displays
            if (GameObject.TryCast(Game.player, out Faction faction))
            {
                numbersBar.PackStart(Graphics.GetIcon(StructureType.Economic, black, Graphics.textSize), false, false, spacing);
                numbersBar.PackStart(new Label(faction.resources.ToString()), false, false, spacing);
                numbersBar.PackStart(Graphics.GetIcon(StructureType.Aesthetic, black, Graphics.textSize), false, false, spacing);
                numbersBar.PackStart(new Label(faction.reputation.ToString()), false, false, spacing);
            }
            else if (GameObject.TryCast(Game.player, out Team team))
            {
                numbersBar.PackStart(Graphics.GetIcon(StructureType.Aesthetic, black, Graphics.textSize), false, false, spacing);
                numbersBar.PackStart(new Label(team.reputation.ToString()), false, false, spacing);
            }
            else if (GameObject.TryCast(Game.player, out Parahuman parahuman))
            {
                numbersBar.PackStart(Graphics.GetIcon(StructureType.Aesthetic, black, Graphics.textSize), false, false, spacing);
                numbersBar.PackStart(new Label(parahuman.reputation.ToString()), false, false, spacing);
            }

            //Create the icons for each agent and frame the current turn-taker
            if ((Game.phase & (Phase.Resolution | Phase.Event)) == Phase.None)
            {
                for (int i = Game.turnOrder.Count - 1; i >= 0; i--)
                {
                    InspectableBox icon = GetAgentIcon(Game.turnOrder[i]);
                    if (i == Game.turn)
                    {
                        numbersBar.PackEnd(new Frame {
                            Child = icon
                        }, false, false, 0);
                    }
                    else
                    {
                        numbersBar.PackEnd(icon, false, false, 0);
                    }
                }
            }

            ShowAll();
        }