private void DoExport(string name)
        {
            try
            {
                try
                {
                    Scribe.InitWriting(FilePath(name), "ManagerJobs");
                }
                catch (Exception ex)
                {
                    GenUI.ErrorDialog("ProblemSavingFile".Translate(ex.ToString()));
                    throw;
                }

                ScribeMetaHeaderUtility.WriteMetaHeader();

                _jobStackIO = Manager.For(manager).JobStack;
                Scribe_Deep.LookDeep(ref _jobStackIO, "JobStack");
            }
            catch (Exception ex2)
            {
                Log.Error("Exception while saving jobstack: " + ex2);
            }
            finally
            {
                Scribe.FinalizeWriting();
                Messages.Message("FM.JobsExported".Translate(_jobStackIO.FullStack().Count), MessageSound.Standard);
                Refresh();
            }
        }
        private void DoImport(SaveFileInfo file)
        {
            try
            {
                // load stuff
                Scribe.InitLoading(_folder + "/" + file.FileInfo.Name);
                Manager.LoadSaveMode = Manager.Modes.ImportExport;
                ScribeMetaHeaderUtility.LoadGameDataHeader(ScribeMetaHeaderUtility.ScribeHeaderMode.Map, false);
                Scribe.EnterNode("JobStack");
                _jobStackIO.ExposeData();
                Scribe.ExitNode();
                Scribe.FinalizeLoading();

                // resolve crossreferences
                // these are registered during the loading stage, and cleared afterwards
                // will most definitely give errors/warnings on crossgame imports
                CrossRefResolver.ResolveAllCrossReferences();

                // replace the old jobstack
                Manager.For(manager).NewJobStack(_jobStackIO);

                // remove invalid jobs
                var invalid = 0;
                foreach (ManagerJob job in Manager.For(manager).JobStack.FullStack())
                {
                    if (!job.IsValid)
                    {
                        invalid++;
                        job.Delete(false);
                    }
                }

                // provide some feedback on failed import(s)
                // if debug is enabled the screen will also pop up with reference errors.
                if (invalid > 0)
                {
                    Messages.Message("FM.InvalidJobsDeleted".Translate(invalid), MessageSound.SeriousAlert);
                }
            }
            catch (Exception e)
            {
                Log.Error("Exception while loading jobstack: " + e);
            }
            finally
            {
                // done?
                Scribe.mode          = LoadSaveMode.Inactive;
                Manager.LoadSaveMode = Manager.Modes.Normal;
                Messages.Message("FM.JobsImported".Translate(_jobStackIO.FullStack().Count), MessageSound.Standard);
                Refresh();
            }
        }
Пример #3
0
        /// <summary>
        /// Draw a square group of ordering buttons for a job in rect.
        /// This is an LOCAL method that within the specified job type.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="rect"></param>
        /// <param name="job"></param>
        /// <returns></returns>
        public static bool DrawOrderButtons <T>(Rect rect, Manager manager, T job) where T : ManagerJob
        {
            var      ret      = false;
            JobStack jobStack = manager.JobStack;

            float width  = rect.width / 2,
                  height = rect.height / 2;

            Rect upRect     = new Rect(rect.xMin, rect.yMin, width, height).ContractedBy(1f),
                 downRect   = new Rect(rect.xMin, rect.yMin + height, width, height).ContractedBy(1f),
                 topRect    = new Rect(rect.xMin + width, rect.yMin, width, height).ContractedBy(1f),
                 bottomRect = new Rect(rect.xMin + width, rect.yMin + height, width, height).ContractedBy(1f);

            List <T> jobsOfType = jobStack.FullStack <T>();

            bool top    = jobsOfType.IndexOf(job) == 0,
                 bottom = jobsOfType.IndexOf(job) == jobsOfType.Count - 1;

            if (!top)
            {
                DrawOrderTooltips(upRect, topRect);
                if (Widgets.ButtonImage(topRect, Resources.ArrowTop))
                {
                    jobStack.TopPriority(job);
                    ret = true;
                }

                if (Widgets.ButtonImage(upRect, Resources.ArrowUp))
                {
                    jobStack.IncreasePriority(job);
                    ret = true;
                }
            }

            if (!bottom)
            {
                DrawOrderTooltips(downRect, bottomRect, false);
                if (Widgets.ButtonImage(downRect, Resources.ArrowDown))
                {
                    jobStack.DecreasePriority(job);
                    ret = true;
                }

                if (Widgets.ButtonImage(bottomRect, Resources.ArrowBottom))
                {
                    jobStack.BottomPriority(job);
                    ret = true;
                }
            }
            return(ret);
        }
Пример #4
0
        internal void NewJobStack(JobStack jobstack)
        {
            // clean up old jobs
            foreach (var job in _stack.FullStack())
            {
                job.CleanUp();
            }

            // replace stack
            _stack = jobstack;

            // touch new jobs in inappropriate places (reset timing so they are properly performed)
            foreach (var job in _stack.FullStack())
            {
                job.manager = this;
                job.Touch();
            }
        }