Exemple #1
0
        public static void FavouriteFloatMenuFor(Pawn pawn)
        {
            // create new
            var options = new List <FloatMenuOption>();

            options.Add(new FloatMenuOption(
                            "Fluffy.WorkTab.CreateFavourite".Translate(),
                            () => Favourite.From(pawn, true)));

            // load from disk
            options.Add(new FloatMenuOption(
                            "Fluffy.WorkTab.LoadFavourite".Translate(),
                            () => LoadFavouriteFloatMenu(pawn)));

            // clear
            if (Get[pawn] != null)
            {
                options.Add(new FloatMenuOption(
                                "Fluffy.WorkTab.ClearFavourite".Translate(),
                                () => Get[pawn] = null));
            }

            // set favourite in favourites
            foreach (var favourite in Favourites)
            {
                options.Add(new FloatMenuOption_Aligned(
                                favourite.Label,
                                () => Get[pawn] = favourite,
                                extraPartWidth: 38,
                                extraPartOnGUI: (rect) => ExtraPart(rect, favourite)));
            }
            Find.WindowStack.Add(new FloatMenu(options));
        }
Exemple #2
0
        public static void Delete(Favourite favourite, bool remove = false)
        {
            if (remove)
            {
                Remove(favourite);
            }
            var path = FavouritePath(favourite);

            if (File.Exists(path))
            {
                File.Delete(path);
            }
        }
Exemple #3
0
        private static bool ExtraPart(Rect rect, Favourite favourite)
        {
            var rects    = new Grid(rect, gutters: Vector2.zero).Columns(1, 1);
            var size     = Mathf.Min(16f, rects[0].Rect.width, rects[0].Rect.height);
            var iconRect = new Rect(0f, 0f, size, size);

            GUI.DrawTexture(iconRect.CenteredIn(rects[0]), favourite.Icon);
            if (Widgets.ButtonImage(new Rect(0f, 0f, size, size).CenteredIn(rects[1]), Resources.Edit))
            {
                Find.WindowStack.Add(new Dialog_EditFavourite(favourite));
            }

            return(false);
        }
Exemple #4
0
        public static void Remove(Favourite favourite)
        {
            Favourites.Remove(favourite);

            // remove from pawns
            var affected = _favourites
                           .Where(f => f.Value == favourite)
                           .Select(f => f.Key)
                           .ToArray();

            foreach (var pawn in affected)
            {
                _favourites.Remove(pawn);
            }
        }
Exemple #5
0
        private static void LoadFavourite(string path, Pawn pawn)
        {
            var favourite = new Favourite();

            Scribe.loader.InitLoading(path);
            favourite.ExposeData();
            Scribe.loader.crossRefs.RegisterForCrossRefResolve(favourite);
            Scribe.loader.initer.RegisterForPostLoadInit(favourite);
            Scribe.loader.FinalizeLoading();

            favourite.SetLoadID();
            Favourites.Add(favourite);
            if (pawn != null)
            {
                Get[pawn] = favourite;
            }
        }
Exemple #6
0
 public Dialog_EditFavourite(Favourite favourite) : base(favourite)
 {
 }
Exemple #7
0
 public static void Save(Favourite favourite)
 {
     Scribe.saver.InitSaving(FavouritePath(favourite), "Favourite");
     favourite.ExposeData();
     Scribe.saver.FinalizeSaving();
 }
Exemple #8
0
 private static string FavouritePath(Favourite favourite)
 {
     return(FavouritePath(favourite.Label));
 }
Exemple #9
0
 public Dialog_Favourite(Favourite favourite)
 {
     this.favourite = favourite;
     label          = favourite.Label ?? "Fluffy.WorkTab.DefaultFavouriteLabel".Translate();
     textureChooser = new TextureChooser(Resources.Icons);
 }
 public Dialog_CreateFavourite(Favourite favourite, Pawn pawn) : base(favourite)
 {
     this.pawn = pawn;
 }