コード例 #1
0
 public void RemoveRange <T> (IEnumerable <T> objs)
 {
     foreach (object obj in objs)
     {
         GameObject removedGO = (GameObject)obj;
         gameObjects.Remove(removedGO);
         foreach (IAgent agent in activeAgents)
         {
             if (agent.knowledge != null)
             {
                 agent.knowledge.Remove(removedGO);
             }
         }
         if (removedGO.TryCast(out IAgent tryAgent))
         {
             activeAgents.Remove(tryAgent);
         }
         if (GameObject.TryCast(obj, out MapMarked mapMarked))
         {
             Map.Deregister(mapMarked);
         }
         DependencyManager.Disconnect((IDependable)obj, this);
         DependencyManager.Flag((IDependable)obj);
     }
     DependencyManager.Flag(this);
 }
コード例 #2
0
 public void OnTriggerDestroyed(IDependable trigger)
 {
     if (Contains(trigger))
     {
         Remove(trigger);
         DependencyManager.Flag(this);
     }
 }
コード例 #3
0
ファイル: Structure.cs プロジェクト: jeffechua/parahumanstbs
 public override void RemoveRange <T> (IEnumerable <T> objs)
 {
     foreach (object obj in objs)
     {
         Trait trait = (Trait)obj;
         traits.Remove(trait);
         trait.parent = null;
         DependencyManager.Destroy(trait);
         DependencyManager.Disconnect(trait, this);
     }
     DependencyManager.Flag(this);
 }
コード例 #4
0
 public override void RemoveRange <T> (IEnumerable <T> objs)
 {
     foreach (object element in objs)
     {
         GameObject obj = (GameObject)element;
         structures.Remove((Structure)obj);
         obj.parent = null;
         DependencyManager.Disconnect(obj, this);
         DependencyManager.Flag(obj);
     }
     DependencyManager.Flag(this);
 }
コード例 #5
0
ファイル: Structure.cs プロジェクト: jeffechua/parahumanstbs
 public override void AddRange <T> (IEnumerable <T> objs)
 {
     foreach (object obj in objs)
     {
         Trait trait = (Trait)obj;
         traits.Add(trait);
         trait.parent = this;
         DependencyManager.Flag(trait);
         DependencyManager.Connect(trait, this);
     }
     traits.Sort((a, b) => a.secrecy.CompareTo(b.secrecy));
     DependencyManager.Flag(this);
 }
コード例 #6
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();
        }
コード例 #7
0
 public override void AddRange <T> (IEnumerable <T> objs)
 {
     foreach (object element in objs)
     {
         GameObject obj = (GameObject)element;
         if (obj.parent != null)
         {
             obj.parent.Remove(obj);
         }
         obj.parent = this;
         structures.Add((Structure)obj);
         DependencyManager.Connect(obj, this);
         DependencyManager.Flag(obj);
     }
     DependencyManager.Flag(this);
 }
コード例 #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 AddRange <T> (IEnumerable <T> objs)
 {
     foreach (object obj in objs)
     {
         GameObject newGO = (GameObject)obj;
         gameObjects.Add(newGO);
         foreach (IAgent agent in activeAgents)
         {
             if (agent.knowledge != null)
             {
                 agent.knowledge.Add(newGO, 0);
             }
         }
         if (GameObject.TryCast(obj, out MapMarked mapMarked))
         {
             Map.Register(mapMarked);
         }
         DependencyManager.Connect(newGO, this);
         DependencyManager.Flag(newGO);
     }
     DependencyManager.Flag(this);
 }
コード例 #11
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);
     }
         );
 }
コード例 #12
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);
            }
        }
コード例 #13
0
 void Submit(object entry, EventArgs args)
 {
     SetValueFromString(((Entry)entry).Text);
     DependencyManager.Flag(obj);
     DependencyManager.TriggerAllFlags();
 }