コード例 #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);
        }
コード例 #2
0
 protected virtual void AttemptDrag(object data)
 {
     if (AddExistingFilter(data))
     {
         parent.Add(data);
         DependencyManager.TriggerAllFlags();
     }
 }
コード例 #3
0
ファイル: UIFactory.cs プロジェクト: jeffechua/parahumanstbs
        public static MenuItem CreateDeleteButton(IDependable obj)
        {
            MenuItem deleteButton = new MenuItem("Delete");

            deleteButton.Activated += delegate {
                DependencyManager.Destroy(obj);
                DependencyManager.TriggerAllFlags();
            };
            return(deleteButton);
        }
コード例 #4
0
ファイル: UIFactory.cs プロジェクト: jeffechua/parahumanstbs
        public static MenuItem CreateRemoveButton(IContainer container, object child)
        {
            MenuItem removeButton = new MenuItem("Remove");

            removeButton.Activated += delegate {
                container.Remove(child);
                DependencyManager.TriggerAllFlags();
            };
            return(removeButton);
        }
コード例 #5
0
ファイル: UIFactory.cs プロジェクト: jeffechua/parahumanstbs
        public static MenuItem CreateMoveButton(IGUIComplete child)
        {
            MenuItem moveButton = new MenuItem("Move");

            moveButton.Activated += (o, a)
                                    => new SelectorDialog("Select new parent for " + child.name,
                                                          (tested) => tested.Accepts(child),
                                                          delegate(GameObject returned) {
                returned.Add(child);
                DependencyManager.TriggerAllFlags();
            });
            return(moveButton);
        }
コード例 #6
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.
        }
コード例 #7
0
        public void OpenPicker(object eventBox, ButtonPressEventArgs args)
        {
            ColorSelectionDialog dialog = new ColorSelectionDialog("Pick new color for faction.");

            dialog.ColorSelection.PreviousColor = dialog.ColorSelection.CurrentColor = (Gdk.Color)property.GetValue(obj);
            dialog.Response += delegate(object o, ResponseArgs response) {
                if (response.ResponseId == ResponseType.Ok)
                {
                    property.SetValue(obj, dialog.ColorSelection.CurrentColor);
                    DependencyManager.Flag((IDependable)obj);
                    DependencyManager.TriggerAllFlags();
                }
            };
            dialog.Run();
            dialog.Destroy();
        }
コード例 #8
0
 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")
     };
 }
コード例 #9
0
        void OnThreatToggled(object o, EventArgs args)
        {
            int index = 0;

            for (int i = 0; i < 4; i++)
            {
                if (buttons[i] == o)
                {
                    index = i;
                }
            }
            if (buttons[index].Active)
            {
                deployment.proposedForces[deployment.affiliation] = (Threat)index;
                DependencyManager.Flag(deployment);
                DependencyManager.TriggerAllFlags();
            }
        }
コード例 #10
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);
     }
         );
 }
コード例 #11
0
ファイル: IO.cs プロジェクト: jeffechua/parahumanstbs
        public static void Open(string path)
        {
            City city = new City();

            try {
                city.saveFolder = path;
                Game.city       = city;

                Profiler.Log();

                List <string> parahumanAddresses = new List <string>(Directory.GetFiles(path + "/Parahumans"));
                city.AddRange(parahumanAddresses.ConvertAll(
                                  (file) => new Parahuman(JsonConvert.DeserializeObject <ParahumanData>(File.ReadAllText(file)))));

                Profiler.Log(ref Profiler.parahumanLoadTime);

                List <string> teamAddresses = new List <string>(Directory.GetFiles(path + "/Teams"));
                city.AddRange(teamAddresses.ConvertAll(
                                  (file) => new Team(JsonConvert.DeserializeObject <TeamData>(File.ReadAllText(file)))));

                Profiler.Log(ref Profiler.teamLoadTime);

                List <string> structureAddresses = new List <string>(Directory.GetFiles(path + "/Structures"));
                city.AddRange(structureAddresses.ConvertAll(
                                  (file) => new Structure(JsonConvert.DeserializeObject <StructureData>(File.ReadAllText(file)))));


                Profiler.Log(ref Profiler.structureLoadTime);

                List <string> territoryAddresses = new List <string>(Directory.GetFiles(path + "/Territories"));
                city.AddRange(territoryAddresses.ConvertAll(
                                  (file) => new Territory(JsonConvert.DeserializeObject <TerritoryData>(File.ReadAllText(file)))));

                Profiler.Log(ref Profiler.territoryLoadTime);

                List <string> factionAddresses = new List <string>(Directory.GetFiles(path + "/Factions"));
                city.AddRange(factionAddresses.ConvertAll(
                                  (file) => new Faction(JsonConvert.DeserializeObject <FactionData>(File.ReadAllText(file)))));

                Profiler.Log(ref Profiler.factionLoadTime);

                List <DossierData> dossiers = JsonConvert.DeserializeObject <List <DossierData> >(File.ReadAllText(path + "/knowledge.txt"));
                foreach (DossierData data in dossiers)
                {
                    IAgent knower = (IAgent)Game.city.Get(data.knowerID);
                    if (knower != null)
                    {
                        knower.knowledge = new Dossier(data);
                    }
                }
                foreach (GameObject obj in city.gameObjects)
                {
                    if (obj.TryCast(out IAgent agent))
                    {
                        if (obj.parent == null)
                        {
                            agent.active = true;
                        }
                    }
                }

                Profiler.Log(ref Profiler.knowledgeLoadTime);

                city.mapPngSource       = File.ReadAllBytes(path + "/Map/map.png");
                city.mapDefaultWidth    = int.Parse(File.ReadAllText(path + "/Map/dimensions.txt"));
                city.territorySizeScale = int.Parse(File.ReadAllText(path + "/Map/scale.txt"));

                Profiler.Log(ref Profiler.mapDataLoadTime);

                DependencyManager.TriggerAllFlags();

                Profiler.Log(ref Profiler.updateTime);

                Game.player = (IAgent)city.Get <GameObject>(int.Parse(File.ReadAllText(path + "/player.txt")));
            } catch (Exception e) {
                Game.city = null;
                MessageDialog errorMessage =
                    new MessageDialog(MainWindow.main,
                                      DialogFlags.DestroyWithParent,
                                      MessageType.Error,
                                      ButtonsType.Close,
                                      "Error loading save from \"" + path + "\".");
                Console.WriteLine(e.Message);
                Console.WriteLine(e.StackTrace);
                errorMessage.Run();
                errorMessage.Destroy();
                return;
            }

            Game.Load(city);             //Profiler does stuff inside CityInterface constructor.
            Profiler.Report();
        }
コード例 #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);
            }
        }
コード例 #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);
            }
        }
コード例 #14
0
 void Submit(object entry, EventArgs args)
 {
     SetValueFromString(((Entry)entry).Text);
     DependencyManager.Flag(obj);
     DependencyManager.TriggerAllFlags();
 }