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(); }
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; }
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); } } }
public override Widget GetHeader(Context context) { if (context.compact) { HBox header = new HBox(false, 0); header.PackStart(new Label(name), false, false, 0); header.PackStart(Graphics.GetIcon(Threat.C, Graphics.GetColor(affiliation), Graphics.textSize), false, false, (uint)(Graphics.textSize / 5)); return(new InspectableBox(header, this, context)); } else { VBox headerBox = new VBox(false, 5); InspectableBox namebox = new InspectableBox(new Label(name), this, context); Gtk.Alignment align = new Gtk.Alignment(0.5f, 0.5f, 0, 0) { Child = namebox, WidthRequest = 200 }; headerBox.PackStart(align, false, false, 0); if (parent != null) { headerBox.PackStart(UIFactory.Align(Graphics.GetSmartHeader(context.butCompact, parent), 0.5f, 0.5f, 0, 0)); } return(headerBox); } }
public virtual Widget GetCellContents(Context context) { DialogTextEditableField field = (DialogTextEditableField)UIFactory.Fabricate(this, "effect", context.butCompact); field.BorderWidth = 5; return(field); }
public override void ContributeMemberRightClickMenu(object member, Menu rightClickMenu, Context context, Widget rightClickedWidget) { if (member is Trait && UIFactory.EditAuthorized(this, "traits")) { rightClickMenu.Append(new SeparatorMenuItem()); rightClickMenu.Append(MenuFactory.CreateRemoveButton(this, member)); } }
public BasicHContainerField(PropertyInfo property, object obj, Context context, DisplayableAttribute attribute) : base(true, 10) { string[] children = Array.ConvertAll((object[])attribute.arg, (str) => (string)str); for (int i = 0; i < children.Length; i++) { Widget childWidget = UIFactory.Fabricate(obj, children[i], context.butCompact); PackStart(childWidget, true, true, 0); } BorderWidth = 10; }
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); }
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 override Menu GetRightClickMenu(Context context, Widget rightClickedWidget) { Menu rightClickMenu = base.GetRightClickMenu(context, rightClickedWidget); if (UIFactory.ViewAuthorized(this, "attack")) { rightClickMenu.Append(new SeparatorMenuItem()); rightClickMenu.Append(MenuFactory.CreateActionButton(attack, context)); } if (UIFactory.ViewAuthorized(this, "defend")) { rightClickMenu.Append(new SeparatorMenuItem()); rightClickMenu.Append(MenuFactory.CreateActionButton(defend, context)); } return(rightClickMenu); }
public Widget GenerateDeploymentInterface(Deployment deployment, string label) { VBox mainBox = new VBox { BorderWidth = 10 }; mainBox.PackStart(UIFactory.Align(new Label(label), 0, 0, 1, 1), false, false, 10); mainBox.PackStart(new HSeparator(), false, false, 0); ScrolledWindow scrolledWindow = new ScrolledWindow { HscrollbarPolicy = PolicyType.Never }; scrolledWindow.AddWithViewport(UIFactory.Generate(new Context(battle), deployment)); mainBox.PackStart(scrolledWindow, true, true, 5); return(mainBox); }
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); }
public void Redraw() { SetSizeRequest(-1, -1); if (Child != null) { Child.Destroy(); } if (LabelWidget != null) { LabelWidget.Destroy(); } Add(UIFactory.GenerateHorizontal(obj)); LabelWidget = obj.GetHeader(new Context(obj, Game.player, false, true)); ShowAll(); redrawQueued = false; }
public Widget GenerateEventCenter() { Context context = new Context(battle); VBox mainBox = new VBox { BorderWidth = 10 }; mainBox.PackStart(battle.GetHeader(context), false, false, 10); mainBox.PackStart(new HSeparator(), false, false, 0); ScrolledWindow scrolledWindow = new ScrolledWindow { HscrollbarPolicy = PolicyType.Never }; scrolledWindow.AddWithViewport(UIFactory.Generate(context, battle)); mainBox.PackStart(scrolledWindow, true, true, 5); return(mainBox); }
public Territory(TerritoryData data) { name = data.name; ID = data.ID; position = data.position; size = data.size; reputation = data.reputation; structures = data.structures.ConvertAll((structure) => Game.city.Get <Structure>(structure)); foreach (Structure structure in structures) { DependencyManager.Connect(structure, this); structure.parent = this; } traits = data.mechanics.ConvertAll((input) => Trait.Load(input)); foreach (Trait mechanic in traits) { DependencyManager.Connect(mechanic, this); mechanic.parent = this; } attack = new GameAction { name = "Attack", description = "Launch an attack on " + name, action = delegate(Context context) { attackers = new Attack(this); Game.city.activeBattlegrounds.Add(this); DependencyManager.Connect(this, attackers); DependencyManager.Flag(this); DependencyManager.TriggerAllFlags(); Inspector.InspectInNearestInspector(attackers, MainWindow.main); }, condition = (context) => attackers == null && UIFactory.EditAuthorized(this, "attack") }; defend = new GameAction { name = "Defend", description = "Mount a defense of " + name, action = delegate(Context context) { defenders = new Defense(this); DependencyManager.Connect(this, defenders); DependencyManager.Flag(this); DependencyManager.TriggerAllFlags(); Inspector.InspectInNearestInspector(defenders, MainWindow.main); }, condition = (context) => attackers != null && defenders == null && UIFactory.EditAuthorized(this, "defend") }; }
protected override Widget GetElementWidget(Trait obj) { if (!obj.Known(context)) { Table table = new Table(1, 1, true); Label number = new Label { UseMarkup = true, Markup = "<big><b>" + obj.secrecy + "</b></big>" }; Gtk.Image image = new Gtk.Image(Stock.DialogAuthentication, IconSize.Dnd); table.Attach(UIFactory.Align(number, 0.5f, 0.5f, 0, 0), 0, 1, 0, 1); table.Attach(UIFactory.Align(image, 0.5f, 0.5f, 0, 0), 0, 1, 0, 1); table.BorderWidth = 10; return(new Frame { Child = table, Label = "???" }); } return(base.GetElementWidget(obj)); }
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); } } }
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); } }
//IGUIComplete stuff public virtual Widget GetHeader(Context context) { if (context.compact) { return(new InspectableBox(new Label(name), this, context)); } else { VBox headerBox = new VBox(false, 5); InspectableBox namebox = new InspectableBox(new Label(name), this, context); Gtk.Alignment align = new Gtk.Alignment(0.5f, 0.5f, 0, 0) { Child = namebox, WidthRequest = 200 }; headerBox.PackStart(align, false, false, 0); if (parent != null) { headerBox.PackStart(UIFactory.Align(Graphics.GetSmartHeader(context.butCompact, parent), 0.5f, 0.5f, 0, 0)); } return(headerBox); } }
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); } }
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; } }
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); } ); }
public void Inspect(IGUIComplete obj) { // Clean up prior attachments if (Child != null) { Child.Destroy(); } DependencyManager.DisconnectAll(this); ShowAll(); // Handle inspection request this.obj = obj; if (obj == null) { Hide(); } else { DependencyManager.Connect(obj, this); DependencyManager.Connect(Game.UIKey, this); if (Child != null) { Child.Destroy(); } VBox mainbox = new VBox(false, 0); mainbox.PackStart(obj.GetHeader(new Context(obj)), false, false, 10); mainbox.PackStart(new HSeparator(), false, false, 0); mainbox.PackStart(UIFactory.GenerateVertical(obj), true, true, 5); AddWithViewport(mainbox); if (!Visible) { Unhidden.Invoke(this, new EventArgs()); } ShowAll(); } }
public void Reload() { if (Child != null) { Child.Destroy(); } if (context.vertical) { Expander expander = new Expander(title + ": " + obj.name) { Expanded = true }; expander.Add(UIFactory.GenerateVertical(obj)); Add(expander); } else { HBox headerBox = new HBox(false, 0); headerBox.PackStart(new Label(title + ": "), false, false, 0); headerBox.PackStart(obj.GetHeader(context.butCompact), false, false, 0); Add(headerBox); } ShowAll(); }
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 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); }
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); } }
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; } }