Esempio n. 1
0
        protected override Widget GetElementWidget(T obj)
        {
            Cell cell;

            cell = new Cell(context, obj);

            if (editable)
            {
                MyDragDrop.SetFailAction(cell, delegate {
                    parent.Remove(obj);
                    DependencyManager.TriggerAllFlags();
                });
                MyDragDrop.SetFailAction(cell.frame.LabelWidget, delegate {
                    parent.Remove(obj);
                    DependencyManager.TriggerAllFlags();
                });
            }

            // Rationale for removing only if drag had no target ("fails")
            // - If cellObject is dragged from an aggregative list to another aggregative list,
            //   the Add() function on the second automatically removes it from the first, so calling Remove() is unnecessary.
            // - If cellObject is dragged from an associative list to an aggregative list or vice versa,
            //   We reasonably assume that user doesn't want it removed from the first list since the concept of "moving" doesn't apply in this context.
            // - Only if the user has dragged cellObject from any list to *nothing* can it be assumed that they need it manually removed by us.

            return(cell);
        }
Esempio n. 2
0
        public override Widget GetCellContents(Context context)
        {
            bool editable = UIFactory.EditAuthorized(this, "structures");

            //Creates the cell contents
            VBox structureBox = new VBox(false, 0)
            {
                BorderWidth = 3
            };

            foreach (Structure structure in structures)
            {
                InspectableBox header = (InspectableBox)structure.GetHeader(context.butInUIContext(this));
                if (editable)
                {
                    MyDragDrop.SetFailAction(header, delegate {
                        Remove(structure);
                        DependencyManager.TriggerAllFlags();
                    });
                }
                structureBox.PackStart(header, false, false, 0);
            }

            if (editable)
            {
                //Set up dropping
                EventBox eventBox = new EventBox {
                    Child = structureBox, VisibleWindow = false
                };
                MyDragDrop.DestSet(eventBox, "Structure");
                MyDragDrop.DestSetDropAction(eventBox, delegate {
                    if (Accepts(MyDragDrop.currentDragged))
                    {
                        Add(MyDragDrop.currentDragged);
                        DependencyManager.TriggerAllFlags();
                    }
                });
                return(new Gtk.Alignment(0, 0, 1, 0)
                {
                    Child = eventBox, BorderWidth = 7
                });
            }
            else
            {
                structureBox.BorderWidth += 7;
                return(structureBox);
            }

            //For some reason drag/drop highlights include BorderWidth.
            //The Alignment makes the highlight actually appear at the 3:7 point in the margin.
        }
Esempio n. 3
0
 public SmartCell(Context context, IGUIComplete obj, bool lazy) : base(obj, context)
 {
     //Basic setup
     this.obj  = obj;
     this.lazy = lazy;
     frame     = new Frame();
     Child     = frame;
     prelight  = false;
     MyDragDrop.SourceSet(this, obj);
     // "Removing by dragging away to nothing" functionality should be... [see Cell comment]
     DependencyManager.Connect(obj, this);
     DependencyManager.Connect(Game.UIKey, this);
     Destroyed += (o, a) => DependencyManager.DisconnectAll(this);
     Reload();
 }
Esempio n. 4
0
        public Cell(Context context, IGUIComplete obj) : base(obj, context)
        {
            //Basic setup
            this.obj = obj;
            frame    = new Frame();
            Child    = frame;
            prelight = false;
            MyDragDrop.SourceSet(this, obj);
            // "Removing by dragging away to nothing" functionality should be implemented manually when the Cell is created.
            // It should be implemented via MyDragDrop.SourceSetFailAction
            // The object should generally be removed from the parent list ONLY in this case.
            // Rationale for removing only if drag had no target:
            // - If cellObject is dragged from an aggregative list to another aggregative list,
            //   the Add() function on the second automatically removes it from the first, so calling Remove() is unnecessary.
            // - If cellObject is dragged from an associative list to an aggregative list or vice versa,
            //   We reasonably assume that user doesn't want it removed from the first list since the concept of "moving" doesn't apply in this context.
            // - Only if the user has dragged cellObject from any list to *nothing* can it be assumed that they need it manually removed by us.
            frame.Add(obj.GetCellContents(this.context));
            frame.LabelWidget = obj.GetHeader(this.context);
            InspectableBox inspectableBox = frame.LabelWidget as InspectableBox;

            ShowAll();
        }
Esempio n. 5
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);
            }
        }
Esempio n. 6
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();
        }