Beispiel #1
0
        public static void Devman(this Panel p, Vessel v)
        {
            // avoid corner-case when this is called in a lambda after scene changes
            v = FlightGlobals.FindVessel(v.id);

            // if vessel doesn't exist anymore, leave the panel empty
            if (v == null)
            {
                return;
            }

            // get data
            VesselData vd = v.KerbalismData();

            // if not a valid vessel, leave the panel empty
            if (!vd.IsSimulated)
            {
                return;
            }

            // set metadata
            p.Title(Lib.BuildString(Lib.Ellipsis(v.vesselName, Styles.ScaleStringLength(20)), Lib.Color(Local.UI_devman, Lib.Kolor.LightGrey)));
            p.Width(Styles.ScaleWidthFloat(355.0f));
            p.paneltype = Panel.PanelType.scripts;

            // time-out simulation
            if (!Lib.IsControlUnit(v) && p.Timeout(vd))
            {
                return;
            }

            // get devices
            List <Device> devices     = Computer.GetModuleDevices(v);
            int           deviceCount = 0;

            // direct control
            if (script_index == 0)
            {
                // draw section title and desc
                p.AddSection
                (
                    Local.UI_devices,
                    Description(),
                    () => p.Prev(ref script_index, (int)ScriptType.last),
                    () => p.Next(ref script_index, (int)ScriptType.last),
                    false
                );

                bool hasVesselDeviceSection = false;
                bool hasModuleDeviceSection = false;

                // for each device
                for (int i = devices.Count - 1; i >= 0; i--)
                {
                    Device dev = devices[i];

                    dev.OnUpdate();
                    if (!dev.IsVisible)
                    {
                        continue;
                    }

                    // create vessel device section if necessary
                    if (dev is VesselDevice)
                    {
                        if (!hasVesselDeviceSection)
                        {
                            p.AddSection(Local.DevManager_VESSELDEVICES);                            //"VESSEL DEVICES"
                            hasVesselDeviceSection = true;
                        }
                    }
                    // create module device section if necessary
                    else
                    {
                        if (!hasModuleDeviceSection)
                        {
                            p.AddSection(Local.DevManager_MODULEDEVICES);                            //"MODULE DEVICES"
                            hasModuleDeviceSection = true;
                        }
                    }

                    if (dev.PartId != 0u)
                    {
                        p.AddContent(dev.DisplayName, dev.Status, dev.Tooltip, dev.Toggle, () => Highlighter.Set(dev.PartId, Color.cyan));
                    }
                    else
                    {
                        p.AddContent(dev.DisplayName, dev.Status, dev.Tooltip, dev.Toggle);
                    }

                    if (dev.Icon != null)
                    {
                        p.SetLeftIcon(dev.Icon.texture, dev.Icon.tooltip, dev.Icon.onClick);
                    }

                    deviceCount++;
                }
            }
            // script editor
            else
            {
                // get script
                ScriptType script_type = (ScriptType)script_index;
                string     script_name = script_type.ToString().Replace('_', ' ').ToUpper();
                Script     script      = v.KerbalismData().computer.Get(script_type);

                // draw section title and desc
                p.AddSection
                (
                    script_name,
                    Description(),
                    () => p.Prev(ref script_index, (int)ScriptType.last),
                    () => p.Next(ref script_index, (int)ScriptType.last)
                );

                bool hasVesselDeviceSection = false;
                bool hasModuleDeviceSection = false;

                // for each device
                for (int i = devices.Count - 1; i >= 0; i--)
                {
                    Device dev = devices[i];

                    dev.OnUpdate();
                    if (!dev.IsVisible)
                    {
                        continue;
                    }

                    // determine tribool state
                    int state = !script.states.ContainsKey(dev.Id)
                                          ? -1
                                          : !script.states[dev.Id]
                                          ? 0
                                          : 1;

                    // create vessel device section if necessary
                    if (dev is VesselDevice)
                    {
                        if (!hasVesselDeviceSection)
                        {
                            p.AddSection(Local.DevManager_VESSELDEVICES);                            //"VESSEL DEVICES"
                            hasVesselDeviceSection = true;
                        }
                    }
                    // create module device section if necessary
                    else
                    {
                        if (!hasModuleDeviceSection)
                        {
                            p.AddSection(Local.DevManager_MODULEDEVICES);                            //"MODULE DEVICES"
                            hasModuleDeviceSection = true;
                        }
                    }

                    // render device entry
                    p.AddContent
                    (
                        dev.DisplayName,
                        state == -1 ? Lib.Color(Local.UI_dontcare, Lib.Kolor.DarkGrey) : Lib.Color(state == 0, Local.Generic_OFF, Lib.Kolor.Yellow, Local.Generic_ON, Lib.Kolor.Green),
                        string.Empty,
                        () =>
                    {
                        switch (state)
                        {
                        case -1: script.Set(dev, true); break;

                        case 0: script.Set(dev, null); break;

                        case 1: script.Set(dev, false); break;
                        }
                    },
                        () => Highlighter.Set(dev.PartId, Color.cyan)
                    );
                    deviceCount++;
                }
            }

            // no devices case
            if (deviceCount == 0)
            {
                p.AddContent("<i>" + Local.DevManager_nodevices + "</i>");             //no devices
            }
        }
Beispiel #2
0
        public override void OnLoad(ConfigNode node)
        {
            // everything in there will be called only one time : the first time a game is loaded from the main menu
            if (!IsCoreGameInitDone)
            {
                try
                {
                    // core game systems
                    Sim.Init();                             // find suns (Kopernicus support)
                    Radiation.Init();                       // create the radiation fields
                    ScienceDB.Init();                       // build the science database (needs Sim.Init() and Radiation.Init() first)
                    Science.Init();                         // register the science hijacker

                    // static graphic components
                    LineRenderer.Init();
                    ParticleRenderer.Init();
                    Highlighter.Init();

                    // UI
                    Textures.Init();                                          // set up the icon textures
                    UI.Init();                                                // message system, main gui, launcher
                    KsmGui.KsmGuiMasterController.Init();                     // setup the new gui framework

                    // part prefabs hacks
                    Profile.SetupPods();                     // add supply resources to pods
                    Misc.PartPrefabsTweaks();                // part prefabs tweaks, must be called after ScienceDB.Init()

                    // Create KsmGui windows
                    new ScienceArchiveWindow();

                    // GameEvents callbacks
                    Callbacks = new Callbacks();
                }
                catch (Exception e)
                {
                    string fatalError = "FATAL ERROR : Kerbalism core init has failed :" + "\n" + e.ToString();
                    Lib.Log(fatalError, Lib.LogLevel.Error);
                    LoadFailedPopup(fatalError);
                }

                IsCoreGameInitDone = true;
            }

            // everything in there will be called every time a savegame (or a new game) is loaded from the main menu
            if (!IsSaveGameInitDone)
            {
                try
                {
                    Cache.Init();
                    ResourceCache.Init();

                    // prepare storm data
                    foreach (CelestialBody body in FlightGlobals.Bodies)
                    {
                        if (Storm.Skip_body(body))
                        {
                            continue;
                        }
                        Storm_data sd = new Storm_data {
                            body = body
                        };
                        storm_bodies.Add(sd);
                    }
                }
                catch (Exception e)
                {
                    string fatalError = "FATAL ERROR : Kerbalism save game init has failed :" + "\n" + e.ToString();
                    Lib.Log(fatalError, Lib.LogLevel.Error);
                    LoadFailedPopup(fatalError);
                }

                IsSaveGameInitDone = true;

                Message.Clear();
            }

            // eveything else will be called on every OnLoad() call :
            // - save/load
            // - every scene change
            // - in various semi-random situations (thanks KSP)

            // Fix for background IMGUI textures being dropped on scene changes since KSP 1.8
            Styles.ReloadBackgroundStyles();

            // always clear the caches
            Cache.Clear();
            ResourceCache.Clear();

            // deserialize our database
            try
            {
                UnityEngine.Profiling.Profiler.BeginSample("Kerbalism.DB.Load");
                DB.Load(node);
                UnityEngine.Profiling.Profiler.EndSample();
            }
            catch (Exception e)
            {
                string fatalError = "FATAL ERROR : Kerbalism save game load has failed :" + "\n" + e.ToString();
                Lib.Log(fatalError, Lib.LogLevel.Error);
                LoadFailedPopup(fatalError);
            }

            // I'm smelling the hacky mess in here.
            Communications.NetworkInitialized  = false;
            Communications.NetworkInitializing = false;

            // detect if this is a different savegame
            if (DB.uid != savegame_uid)
            {
                // clear caches
                Message.all_logs.Clear();

                // sync main window pos from db
                UI.Sync();

                // remember savegame id
                savegame_uid = DB.uid;
            }

            Kerbalism.gameLoadTime = Time.time;
        }