Exemple #1
0
                /// <summary>
                /// Sets the previously visited node for a given actor.
                /// </summary>
                /// <param name="actor"></param>
                /// <param name="node"></param>
                public static void SetPrevNode(Object actor, Node node)
                {
                    // Make sure we have a valid list.
                    Debug.Assert(nodes != null, "List allocated at startup");

                    // Search through list looking for PrevNode matching actor.
                    // If found, update, if not, create a new PrevNode and add to list.
                    bool found = false;

                    for (int i = 0; i < nodes.Count; i++)
                    {
                        PrevNode p = nodes[i];
                        if (p.actor == actor)
                        {
                            p.node = node;
                            found  = true;
                            break;
                        }
                    }

                    if (!found)
                    {
                        PrevNode p = new PrevNode(actor, node);
                        nodes.Add(p);
                    }
                }   // end of PrevNode SetPrevNode()
Exemple #2
0
                }   // end of PrevNode GetPrevNode()

                public static void ReleasePrevNode(Object actor)
                {
                    for (int i = nodes.Count - 1; i >= 0; --i)
                    {
                        PrevNode p = nodes[i];
                        if (p.actor == actor)
                        {
                            nodes.RemoveAt(i);
                            break;
                        }
                    }
                }
 private double SourceCost()
 {
     if (prevNode == null)
     {
         sourceCost = 0;
     }
     else if (sourceCost < 0)
     {
         sourceCost = PrevNode.SourceCost() + 1;
     }
     return(sourceCost);
 }
Exemple #4
0
 public void Dec()
 {
     if (!IsAtMin())
     {
         _value--;
     }
     else if (PrevNode != null)
     {
         PrevNode.Dec();
         _value = GetMax();
     }
     else
     {
         throw new InvalidOperationException("At min");
     }
 }
Exemple #5
0
 public void Inc()
 {
     if (!IsAtMax())
     {
         _value++;
     }
     else if (PrevNode != null)
     {
         PrevNode.Inc();
         _value = GetMin();
     }
     else
     {
         throw new InvalidOperationException("At max");
     }
 }
Exemple #6
0
                }   // end of PrevNode SetPrevNode()

                /// <summary>
                /// Returns the previously visited node for an actor.  May be null.
                /// </summary>
                /// <param name="actor"></param>
                /// <returns></returns>
                public static Node GetPrevNode(Object actor)
                {
                    // Make sure we have a valid list.
                    Debug.Assert(nodes != null, "List allocated at startup");

                    Node result = null;

                    for (int i = 0; i < nodes.Count; i++)
                    {
                        PrevNode p = nodes[i];
                        if (p.actor == actor)
                        {
                            result = p.node;
                            break;
                        }
                    }

                    return(result);
                }   // end of PrevNode GetPrevNode()
Exemple #7
0
            private bool MoveWorker(int minStartVal, IBoardView boardView)
            {
                Start = minStartVal;

                while (End <= max)
                {
                    if (Verify(boardView))
                    {
                        if (PrevNode.VerifyNextMoved(boardView))
                        {
                            if (NextNode.Reset(boardView))
                            {
                                return(true);
                            }
                        }
                    }

                    Start++;
                }

                return(false);
            }
    public void HandleTurnEnd(Region region, Town town)
    {
        if (_IsBuilding)
        {
            _BuildTimeRemaining--;
            if (_BuildTimeRemaining <= 0)
            {
                _IsBuilding  = false;
                _IsPurchased = true;
                AttachedBuilding.HandleCreation(town, region);

                if (town != null)
                {
                    town.BuildingFinished(this);
                }
                else
                {
                    region.FinishedBuilding(this);
                }

                if (PrevNode != null)
                {
                    PrevNode.SetObsolete(town, region);
                }
                if (NextNode != null)
                {
                    NextNode.Activate();
                }
            }
        }

        if (_IsPurchased && AttachedBuilding && !_IsObsolete)
        {
            AttachedBuilding.HandleTurnEnd(town, region);
        }
    }
Exemple #9
0
        public int CompareTo(DagEdge other)
        {
            int i = NextNode.CompareTo(other.NextNode);

            return((i != 0) ? i : PrevNode.CompareTo(other.PrevNode));
        }
Exemple #10
0
 public override string ToString()
 {
     return("[ " + PrevNode.ToString() + " ] <- ");
 }
        /// <summary>
        /// Initialize the dialog
        /// </summary>
        /// <param name="nodeToEdit">The node we'll be editing</param>
        /// <param name="canEdit">True if we can open the maneuver node editing tools, false otherwise</param>
        public PlanningNodeEditDialog(PlanningNodeModel nodeToEdit, bool canEdit)
            : base(-1, -1, pad, new RectOffset(4, 4, 4, 4), TextAnchor.UpperLeft)
        {
            editingNode = nodeToEdit;

            var toprow = new List <DialogGUIBase>()
            {
                TooltipExtensions.DeferTooltip(new DialogGUIButton(
                                                   "PlanningNode_DeleteButtonCaption",
                                                   () => DeleteNode?.Invoke(),
                                                   buttonWidth, buttonHeight,
                                                   false
                                                   )
                {
                    tooltipText = "PlanningNode_DeleteButtonTooltip"
                }),
                new DialogGUIFlexibleSpace(),
                TooltipExtensions.DeferTooltip(new DialogGUIButton(
                                                   "PlanningNode_CloseButtonCaption",
                                                   () => CloseDialog?.Invoke(),
                                                   buttonWidth, buttonHeight,
                                                   false
                                                   )
                {
                    tooltipText = "PlanningNode_CloseButtonTooltip"
                })
            };

            if (canEdit)
            {
                toprow.Insert(0, TooltipExtensions.DeferTooltip(new DialogGUIButton(
                                                                    "PlanningNode_NewButtonCaption",
                                                                    () => NewNode?.Invoke(),
                                                                    buttonWidth, buttonHeight,
                                                                    false
                                                                    )
                {
                    tooltipText = "PlanningNode_NewButtonTooltip"
                }));
            }
            AddChild(new DialogGUIHorizontalLayout(
                         -1, -1, 8, new RectOffset(0, 0, 0, 0), TextAnchor.MiddleLeft,
                         toprow.ToArray()
                         ));
            AddChild(new DialogGUIHorizontalLayout(
                         -1, -1, pad, new RectOffset(0, 0, 0, 0), TextAnchor.MiddleLeft,
                         new DialogGUILabel("PlanningNode_NameLabelCaption", buttonWidth / 2),
                         NotifyOnFocus(new DialogGUITextInput(
                                           editingNode.name,
                                           false,
                                           24,
                                           s => { return(editingNode.name = s); },
                                           () => { return(editingNode.name); },
                                           TMP_InputField.ContentType.Standard,
                                           buttonHeight
                                           ),
                                       // Don't trigger other parts of the game while they're typing a name in the text field
                                       v => InputLockManager.SetControlLock(MyLocks, "PlanningNodeEditDialogName"),
                                       v => InputLockManager.RemoveControlLock("PlanningNodeEditDialogName")
                                       ),
                         TooltipExtensions.DeferTooltip(new DialogGUIButton(
                                                            "PlanningNode_PrevNodeCaption",
                                                            () => PrevNode?.Invoke(),
                                                            smallBtnWidth, buttonHeight,
                                                            false
                                                            )
            {
                tooltipText = canEdit ? "PlanningNode_PrevNodeTooltip" : "PlanningNode_PrevNodeViewOnlyTooltip"
            }),
                         TooltipExtensions.DeferTooltip(new DialogGUIButton(
                                                            "PlanningNode_NextNodeCaption",
                                                            () => NextNode?.Invoke(),
                                                            smallBtnWidth, buttonHeight,
                                                            false
                                                            )
            {
                tooltipText = canEdit ? "PlanningNode_NextNodeTooltip" : "PlanningNode_NextNodeViewOnlyTooltip"
            })
                         ));
            AddChild(new DialogGUIHorizontalLayout(
                         -1, -1, pad, new RectOffset(0, 0, 0, 0), TextAnchor.MiddleLeft,
                         new DialogGUILabel("PlanningNode_HueLabelCaption", buttonWidth / 2),
                         new DialogGUISlider(
                             () => {
                if (editingNode != null)
                {
                    Color.RGBToHSV(editingNode.color, out float hue, out float _, out float _);
                    return(hue);
                }
                return(0f);
            },
                             0f, 1f, false, -1, buttonHeight,
                             v => {
                if (editingNode != null)
                {
                    editingNode.color = Color.HSVToRGB(v, 0.5f, 0.75f);
                }
            }
                             )
                         ));
            if (canEdit)
            {
                AddChild(new DialogGUIHorizontalLayout(
                             -1, -1, pad, new RectOffset(0, 0, 0, 0), TextAnchor.MiddleLeft,
                             new DialogGUILabel("PlanningNode_BodyLabelCaption", buttonWidth / 2),
                             new DialogGUILabel(
                                 () => editingNode.origin.bodyName,
                                 -1
                                 ),
                             TooltipExtensions.DeferTooltip(new DialogGUIButton(
                                                                "PlanningNode_PrevBodyCaption",
                                                                () => BodyChanged?.Invoke(prevBody(editingNode.origin)),
                                                                smallBtnWidth, buttonHeight,
                                                                false
                                                                )
                {
                    tooltipText = "PlanningNode_PrevBodyTooltip"
                }),
                             TooltipExtensions.DeferTooltip(new DialogGUIButton(
                                                                "PlanningNode_NextBodyCaption",
                                                                () => BodyChanged?.Invoke(nextBody(editingNode.origin)),
                                                                smallBtnWidth, buttonHeight,
                                                                false
                                                                )
                {
                    tooltipText = "PlanningNode_NextBodyTooltip"
                })
                             ));
                AddChild(TooltipExtensions.DeferTooltip(new DialogGUIToggle(
                                                            () => editingNode.vessel == null,
                                                            "PlanningNode_ShowForAllCheckboxCaption",
                                                            b => { editingNode.vessel = b ? null : FlightGlobals.ActiveVessel; }
                                                            )
                {
                    tooltipText = "PlanningNode_ShowForAllCheckboxTooltip"
                }));
            }
            AddChild(TooltipExtensions.DeferTooltip(new DialogGUIButton(
                                                        "PlanningNode_WarpToCaption",
                                                        () => WarpTo?.Invoke(editingNode),
                                                        buttonWidth, buttonHeight,
                                                        false
                                                        )
            {
                tooltipText = "PlanningNode_WarpToTooltip"
            }));

            // Don't try to plot a maneuver from the Sun
            for (int i = 0; i < FlightGlobals.Bodies.Count; ++i)
            {
                var b = FlightGlobals.Bodies[i];
                if (b.referenceBody != null && b.referenceBody != b)
                {
                    allowedBodies.Add(b);
                }
            }
        }