Exemplo n.º 1
0
        public void Start()
        {
            Log.SetTitle("TotalTime");
            Log.Info("Start");
            DontDestroyOnLoad(this);
            config.LoadConfiguration();
#if (DEBUG)
            Log.SetLevel(Log.LEVEL.INFO);
#else
            Log.SetLevel(config.logLevel);
#endif
            // Add a callback to load the data for the game after it is loaded
            GameEvents.onGameStateCreated.Add(CallbackGameStateCreated);

            if (config.logInstallTime)
            {
                FileOperations.getData(Configuration.dataLevel.install);
            }
            if (config.logGameTime)
            {
                FileOperations.getData(Configuration.dataLevel.global);
            }

            GameEvents.onGamePause.Add(OnPause);
            GameEvents.onGameUnpause.Add(OnResume);
            GameEvents.onLevelWasLoaded.Add(CallbackLevelWasLoaded);

            GameEvents.onGUIAdministrationFacilitySpawn.Add(CallbackAdminFacility);
            GameEvents.onGUIAdministrationFacilityDespawn.Add(CallbackAdminFacility);
            GameEvents.onGUIMissionControlSpawn.Add(CallbackAdminFacility);
            GameEvents.onGUIMissionControlDespawn.Add(CallbackAdminFacility);
            GameEvents.onGUIRnDComplexSpawn.Add(CallbackAdminFacility);
            GameEvents.onGUIRnDComplexDespawn.Add(CallbackAdminFacility);
            GameEvents.onGUIAstronautComplexSpawn.Add(CallbackAdminFacility);
            GameEvents.onGUIAstronautComplexDespawn.Add(CallbackAdminFacility);


            StartCoroutine(TimeIncrement());
        }
Exemplo n.º 2
0
 private void CallbackGameStateCreated(Game g)
 {
     Log.Info("CallbackGameStateCreated: " + g.Title);
     strSecInGameTime = "";
     FileOperations.getData(Configuration.dataLevel.game);
 }
Exemplo n.º 3
0
        private void ConfigWindow(int id)
        {
            if (cfgWinData == false)
            {
                cfgWinData = true;

                setGuiVars(ref TotalTime.config);
            }

            //SetConfigVisible (true);
            GUI.enabled = true;

            GUILayout.BeginVertical();
            GUILayout.BeginHorizontal();
            GUILayout.EndHorizontal();

            //GUILayout.BeginArea (new Rect (10, 50, 375, 500));

            GUILayout.BeginHorizontal();
            GUILayout.Label("Save total time for individual saves:");
            GUILayout.FlexibleSpace();
            boollogGameTime = GUILayout.Toggle(boollogGameTime, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Save total time for this KSP install:");
            GUILayout.FlexibleSpace();
            boollogInstallTime = GUILayout.Toggle(boollogInstallTime, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Save total time for all KSP games in external file:");
            GUILayout.FlexibleSpace();
            boollogGlobalTime = GUILayout.Toggle(boollogGlobalTime, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Directory for global count file:");
            GUILayout.FlexibleSpace();
            strtotalTimeDataPath = GUILayout.TextField(strtotalTimeDataPath, GUILayout.MinWidth(30F), GUILayout.MaxWidth(300F));
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Update interval:");
            GUILayout.FlexibleSpace();
            strinterval = GUILayout.TextField(strinterval, GUILayout.MinWidth(30F), GUILayout.MaxWidth(30F));
            GUILayout.EndHorizontal();


            GUILayout.BeginHorizontal();
            GUILayout.Label("Include time while paused:");
            GUILayout.FlexibleSpace();
            boolincludePauseTime = GUILayout.Toggle(boolincludePauseTime, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Enable Escape key in the Editors and SpaceCenter scenes:");
            GUILayout.FlexibleSpace();
            boolenableEscapePause = GUILayout.Toggle(boolenableEscapePause, "");
            GUILayout.EndHorizontal();


            GUILayout.BeginHorizontal();
            GUILayout.Label("Display on screen:");
            GUILayout.FlexibleSpace();
            booldisplayOnScreen = GUILayout.Toggle(booldisplayOnScreen, "");
            GUILayout.EndHorizontal();


            GUILayout.BeginHorizontal();
            GUILayout.Label("Display in window:");
            GUILayout.FlexibleSpace();
            booldisplayInWindow = GUILayout.Toggle(booldisplayInWindow, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Display game time:");
            GUILayout.FlexibleSpace();
            booldisplayGameTime = GUILayout.Toggle(booldisplayGameTime, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Display install time:");
            GUILayout.FlexibleSpace();
            booldisplayInstallTime = GUILayout.Toggle(booldisplayInstallTime, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Display total time:");
            GUILayout.FlexibleSpace();
            booldisplayGlobalTime = GUILayout.Toggle(booldisplayGlobalTime, "");
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            GUILayout.Label("Display session time:");
            GUILayout.FlexibleSpace();
            booldisplaySessionTime = GUILayout.Toggle(booldisplaySessionTime, "");
            GUILayout.EndHorizontal();



            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Defaults", GUILayout.Width(125.0f)))
            {
                Configuration c = new Configuration();
                //TotalTime.config.setDefaults ();
                //cfgWinData = false;
                setGuiVars(ref c);
                return;
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Save", GUILayout.Width(125.0f)))
            {
                //writeConfig (newconfig);
                //	bool hasWriteAccess = true;
#if false
                string   tmpFileName  = strtotalTimeDataPath + "/tmp.tmp";
                FileInfo testfileInfo = new FileInfo(tmpFileName);

                Log.Info("testing write access to: " + tmpFileName);

                try {
                    Log.Info("testfileInfo.Directory.Create");
                    testfileInfo.Directory.Create();
                } catch (Exception SystemSecurityException) {
                    //hasWriteAccess = false;
                    Log.Info("SystemSecurityException");
                    Log.Info(SystemSecurityException.ToString());
                    TotalTime.config.totalTimeDataPath = "";
                    boollogGlobalTime = false;
                }

                if (File.Exists(tmpFileName))
                {
                    testfileInfo.Delete();
                    TotalTime.config.totalTimeDataPath = strtotalTimeDataPath;
                }
                else
                {
                    TotalTime.config.totalTimeDataPath = "";
                    boollogGlobalTime = false;
                }
#else
                TotalTime.config.totalTimeDataPath = strtotalTimeDataPath;
#endif
                if (TotalTime.config.totalTimeDataPath == "")
                {
                    booldisplayGlobalTime = false;
                }
                TotalTime.config.logGameTime = boollogGameTime;
                if (TotalTime.config.logInstallTime == false && boollogInstallTime)
                {
                    FileOperations.getData(Configuration.dataLevel.install);
                }
                TotalTime.config.logInstallTime = boollogInstallTime;
                if (TotalTime.config.logGlobalTime == false && boollogGameTime)
                {
                    FileOperations.getData(Configuration.dataLevel.global);
                }
                TotalTime.config.logGlobalTime = boollogGlobalTime;

                TotalTime.config.displayGameTime    = booldisplayGameTime;
                TotalTime.config.displayInstallTime = booldisplayInstallTime;
                TotalTime.config.displayGlobalTime  = booldisplayGlobalTime;
                TotalTime.config.displayOnScreen    = booldisplayOnScreen;

                TotalTime.config.displayInWindow = booldisplayInWindow;

                TotalTime.config.displaySessionTime = booldisplaySessionTime;
                TotalTime.config.includePauseTime   = boolincludePauseTime;
                TotalTime.config.enableEscapePause  = boolenableEscapePause;

                try
                {
                    TotalTime.config.interval = Convert.ToUInt16(strinterval);
                }
                catch (Exception)
                {
                }
                GUIToggleConfig();
                TotalTime.config.SaveConfiguration();
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Cancel", GUILayout.Width(125.0f)))
            {
                GUIToggleConfig();
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.Label("");
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Set global file counter file in home directory", GUILayout.Width(300.0f)))
            {
                strtotalTimeDataPath = FileOperations.GetHomeDir();
                strtotalTimeDataPath = strtotalTimeDataPath.Replace("\\", "/");

                int i = TotalTime.secTotal;
                FileOperations.getData(Configuration.dataLevel.global);
                TotalTime.secTotal += i;
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Reset Save counter", GUILayout.Width(150.0f)))
            {
                TotalTime.secInGame = 0;
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Reset Install counter", GUILayout.Width(150.0f)))
            {
                TotalTime.secInInstall = 0;
            }
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Reset Global counter", GUILayout.Width(150.0f)))
            {
                TotalTime.secTotal = 0;
            }
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
            GUI.DragWindow();
        }