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. }
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); } }
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(); }