示例#1
0
        /// <summary>
        /// Prints the programming for the whole level.
        /// </summary>
        static public void PrintProgramming()
        {
            TextWriter tw = null;

            // Try back compat path version first.
            string fullPath = GetFullPath(false);

            try
            {
                tw = OpenFile(fullPath);
            }
            catch { }

            // If prev version failed, try new approach.
            if (tw == null)
            {
                fullPath = GetFullPath(true);
                try
                {
                    tw = OpenFile(fullPath);
                }
                catch { }
            }

            if (tw != null)
            {
                PrintHeading(tw);

                for (int i = 0; i < InGame.inGame.gameThingList.Count; i++)
                {
                    GameActor actor = InGame.inGame.gameThingList[i] as GameActor;
                    if (actor != null)
                    {
                        PrintActorProgramming(tw, actor);
                    }
                }

                // If this level is a tutorial, also print out the tutorial text.
                TutorialManager.Print(tw);

#if NETFX_CORE
                tw.Flush();
                tw.Dispose();
#else
                tw.Close();
#endif

                Instrumentation.IncrementCounter(Instrumentation.CounterId.PrintKode);

                SendToPrinter(fullPath);
            }
        }   // end of PrintProgramming()
            }     // end of Update()

            /// <summary>
            /// What happens if the user chooses one of the pre-programmed options.
            /// </summary>
            private void Select()
            {
                if (parent.parent != null)
                {
                    // Call the OnSelect() method on the pie menu.  This will cause it to go through
                    // its normal process of creating and adding the new actor to the scene.
                    parent.parent.OnSelect(null, null);

                    // Now, need to get the brain of the bot we just added and
                    // stuff it full of code.  Yumm, stuffed bot brains...
                    if (shared.actor != null)
                    {
                        // Got brain?
                        Brain     brain = shared.actor.Brain;
                        ActorHelp help  = shared.actorHelp;
                        if (help.programs != null && help.programs.Count > 0)
                        {
                            ExampleProgram program = help.programs[shared.examplesGrid.SelectionIndex.Y];

                            for (int page = 0; page < program.pages.Count; page++)
                            {
                                Task task = (Task)brain.tasks[page];

                                for (int r = 0; r < program.pages[page].reflexes.Length; r++)
                                {
                                    ReflexData clip   = program.pages[page].reflexes[r];
                                    Reflex     reflex = new Reflex(task);
                                    task.AddReflex(reflex);
                                    reflex.Paste(clip);
                                }
                            }
                        }
                    }

                    Instrumentation.IncrementCounter(Instrumentation.CounterId.AddItemHelpCardInsertExample);
                }

                parent.Deactivate();
            }   // end of Select()
            }   // end of EditObjectUpdateObj CancelNewItemSelector()

            public void SelectNewItemSelector(UiSelector selector)
            {
                UiSelector.GroupData groupData = selector.SelectedItem as UiSelector.GroupData;
                if (groupData != null)
                {
                    // sub group was activated
                    Foley.PlayProgrammingMoveOut();
                }
                else
                {
                    Instrumentation.IncrementCounter(Instrumentation.CounterId.AddItem);

                    GameActor thingToColor   = null;
                    GameActor thingToDistort = null;

                    //Object item = selector.ObjectSelectedItem;

                    ActorMenuItem item = selector.ObjectSelectedItem as ActorMenuItem;
                    if (item != null)
                    {
                        if (item.StaticActor != null)
                        {
                            if (addPositionIsExplicit)
                            {
                                ///Client has requested a specific position to add this guy.
                                ///Give the people what they want.
                                thingToColor = parent.AddActor(
                                    ActorFactory.Create(item.StaticActor),
                                    new Vector3(addPosition, float.MaxValue),
                                    InGame.inGame.shared.camera.Rotation);

                                // Reset
                                addPositionIsExplicit = false;
                            }
                            else
                            {
                                /// Default is to add at the cursor position.
                                thingToColor = parent.AddActorAtCursor(ActorFactory.Create(item.StaticActor));
                            }

                            // Give a ref to the actor to the HelpCard.  If it's active it
                            // can then program the actor's brain.
                            InGame.inGame.shared.addItemHelpCard.Actor = thingToColor as GameActor;
                        }
                        else if (item.TextureFilename.StartsWith("filter.path"))
                        {
                            if (parent.UnderBudget)
                            {
                                /// If the waypoint editor is active, let it handle this.
                                if (!shared.editWayPoint.Active)
                                {
                                    int pathType = 0;
                                    if (item.TextureFilename.EndsWith("road"))
                                    {
                                        pathType = Road.LastRoadCreated;
                                    }
                                    else if (item.TextureFilename.Contains("wall"))
                                    {
                                        pathType = Road.LastWallCreated;
                                    }
                                    else if (item.TextureFilename.Contains("flora"))
                                    {
                                        pathType = Road.LastVegCreated;
                                    }
                                    Road.GenIndex = pathType;
                                    Vector3 pos = addPositionIsExplicit
                                        ? new Vector3(addPosition, float.MaxValue)
                                        : parent.cursor3D.Position;
                                    shared.editWayPoint.NewPath(pos, shared.curObjectColor);
                                }
                            }
                            else
                            {
                                Instrumentation.IncrementCounter(Instrumentation.CounterId.AddItemNoBudget);

                                Foley.PlayNoBudget();
                            }
                        }
                    }
                    else
                    {
                        Debug.Assert(false, "How did this happen?");
                    }


                    if (thingToColor != null)
                    {
                        Foley.PlayProgrammingAdd();

                        shared.curObjectColor = ColorPalette.GetIndexFromColor(thingToColor.ClassColor);
                        //                        thingToColor.Classcolor = ColorPalette.GetColorFromIndex(shared.curObjectColor);
                        thingToDistort = thingToColor;
                    }

                    if (thingToDistort != null)
                    {
                        parent.DistortionPulse(thingToDistort, true);
                    }

                    newItemSelectorShim.Deactivate();

                    InGame.IsLevelDirty = true;
                }
            }   // end of EditObjectUpdateObj SelectNewItemSelector()