Ejemplo n.º 1
0
        // GET: Admin/SocialPages/AddCuratedPage/town
        public ActionResult EditCuratedPage(int id)
        {
            SocialPage page = new SocialPage();
            SocialSite site = page.GetPage(id);

            List <SelectListItem> typeList = new List <SelectListItem>();

            typeList.Add(new SelectListItem {
                Value = "Facebook", Text = "Facebook", Selected = (site.PageType == "Facebook")
            });
            typeList.Add(new SelectListItem {
                Value = "InstagramEmbed", Text = "InstagramEmbed", Selected = (site.PageType == "InstagramEmbed")
            });
            typeList.Add(new SelectListItem {
                Value = "InstagramTag", Text = "InstagramTag", Selected = (site.PageType == "InstagramTag")
            });
            typeList.Add(new SelectListItem {
                Value = "InstagramUser", Text = "InstagramUser", Selected = (site.PageType == "InstagramUser")
            });
            typeList.Add(new SelectListItem {
                Value = "PinterestBoard", Text = "PinterestBoard", Selected = (site.PageType == "PinterestBoard")
            });
            typeList.Add(new SelectListItem {
                Value = "PinterestPin", Text = "PinterestPin", Selected = (site.PageType == "PinterestPin")
            });
            ViewBag.PageType = typeList;

            return(View(site));
        }
Ejemplo n.º 2
0
        private void InitializeProperties()
        {
            if (Game1.activeClickableMenu is GameMenu gameMenu)
            {
                foreach (var menu in gameMenu.pages)
                {
                    if (menu is SocialPage socialPage)
                    {
                        _socialPage  = socialPage;
                        _friendNames = _socialPage.names
                                       .Select(name => name.ToString())
                                       .ToArray();
                        break;
                    }
                }

                _townsfolk.Clear();
                foreach (var location in Game1.locations)
                {
                    foreach (var npc in location.characters)
                    {
                        if (Game1.player.friendshipData.ContainsKey(npc.Name))
                        {
                            _townsfolk.Add(npc);
                        }
                    }
                }

                _checkboxes.Clear();
                foreach (var friendName in _friendNames)
                {
                    int             hashCode = friendName.GetHashCode();
                    OptionsCheckbox checkbox = new OptionsCheckbox("", hashCode);
                    _checkboxes.Add(checkbox);

                    //default to on
                    bool optionForThisFriend = true;
                    if (!Game1.player.friendshipData.ContainsKey(friendName))
                    {
                        checkbox.greyedOut  = true;
                        optionForThisFriend = false;
                    }
                    else
                    {
                        string optionValue = _options.SafeGet(hashCode.ToString());

                        if (string.IsNullOrEmpty(optionValue))
                        {
                            _options[hashCode.ToString()] = optionForThisFriend.ToString();
                        }
                        else
                        {
                            optionForThisFriend = optionValue.SafeParseBool();
                        }
                    }
                    checkbox.isChecked = optionForThisFriend;
                }
            }
        }
Ejemplo n.º 3
0
        public ActionResult PageDelete(string id, string SocialPageSerial)
        {
            SocialPage page = new SocialPage(id);

            page.RemoveCuratedPage(Convert.ToInt32(SocialPageSerial));

            return(Json(true));
        }
Ejemplo n.º 4
0
 public static void Serialize_GiftLog(dynamic menu, SocialPage page, Point mousePosition)
 {
     menu.menuType       = "socialPage";
     menu.downArrow      = (ClickableTextureComponent)Utils.GetPrivateField(page, "downButton");
     menu.upArrow        = (ClickableTextureComponent)Utils.GetPrivateField(page, "upButton");
     menu.slotPosition   = (int)Utils.GetPrivateField(page, "slotPosition");
     menu.characterSlots = page.characterSlots.GetRange(menu.slotPosition, 5);
 }
Ejemplo n.º 5
0
        public ActionResult EditCuratedPage(int id, SocialSite data)
        {
            SocialPage page = new SocialPage();

            page.EditCuratedPage(data);

            return(Redirect("/admin/socialpages/curatepages/" + data.Town));
        }
        /// <summary>
        /// Resets and populates the list of townsfolk and checkboxes to display every time the game menu is called
        /// </summary>
        private void onMenuChange(object sender, EventArgsClickableMenuChanged e)
        {
            if (!(Game1.activeClickableMenu is GameMenu))
            {
                return;
            }

            // Get pages from GameMenu
            var pages = (List <IClickableMenu>) typeof(GameMenu).GetField("pages", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Game1.activeClickableMenu);

            // Save variables needed for mod
            for (int k = 0; k < pages.Count; k++)
            {
                if (pages[k] is SocialPage)
                {
                    socialPage  = ( SocialPage )pages[k];
                    friendNames = (List <ClickableTextureComponent>) typeof(SocialPage).GetField("friendNames", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(pages[k]);
                }
            }

            townsfolk.Clear();
            foreach (GameLocation location in Game1.locations)
            {
                foreach (NPC npc in location.characters)
                {
                    if (Game1.player.friendships.ContainsKey(npc.name))
                    {
                        townsfolk.Add(npc);
                    }
                }
            }

            checkboxes.Clear();

            // Create checkboxes in the same order as friends are
            foreach (ClickableTextureComponent friend in friendNames)
            {
                int optionIndex = friend.name.GetHashCode();

                var checkbox = new OptionsCheckbox("", optionIndex);
                checkboxes.Add(checkbox);

                // Disable checkbox if player has not talked to npc yet
                if (!(Game1.player.friendships.ContainsKey(friend.name)))
                {
                    checkbox.greyedOut = true;
                    checkbox.isChecked = false;
                }

                // Ensure an entry exists
                if (ModEntry.modData.locationOfTownsfolkOptions.ContainsKey(optionIndex) == false)
                {
                    ModEntry.modData.locationOfTownsfolkOptions.Add(optionIndex, false);
                }

                checkbox.isChecked = ModEntry.modData.locationOfTownsfolkOptions[optionIndex];
            }
        }
Ejemplo n.º 7
0
        public ActionResult AddCuratedPage(string id, SocialSite data)
        {
            SocialPage page = new SocialPage(id);

            data.Town = id;
            page.AddCuratedPage(data);

            return(Redirect("/admin/socialpages/curatepages/" + id));
        }
        public ActionResult Edit(SocialPage socialPage)
        {
            if (!ModelState.IsValid)
            {
                return(HttpNotFound());
            }

            return(View());
        }
Ejemplo n.º 9
0
        // GET: Admin/Pages/module/<PageID>
        public ActionResult CuratePages(string id)
        {
            SocialPage page = new SocialPage(id);

            ViewBag.Town          = page.Town;
            ViewBag.TownFormatted = page.TownFormatted;

            return(View(page.GetPages()));
        }
Ejemplo n.º 10
0
        private void ExtendMenuIfNeeded()
        {
            if (Game1.activeClickableMenu is GameMenu)
            {
                List <IClickableMenu> clickableMenuList = typeof(GameMenu)
                                                          .GetField("pages", BindingFlags.Instance | BindingFlags.NonPublic)
                                                          .GetValue(Game1.activeClickableMenu) as List <IClickableMenu>;

                foreach (var menu in clickableMenuList)
                {
                    if (menu is SocialPage)
                    {
                        _socialPage  = menu as SocialPage;
                        _friendNames = (typeof(SocialPage).GetField("names", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(menu) as List <object>)
                                       .Select(name => name.ToString())
                                       .ToArray();
                        break;
                    }
                }
                _townsfolk.Clear();
                foreach (var location in Game1.locations)
                {
                    foreach (var npc in location.characters)
                    {
                        if (Game1.player.friendshipData.ContainsKey(npc.Name))
                        {
                            _townsfolk.Add(npc);
                        }
                    }
                }
                _checkboxes.Clear();
                foreach (var friendName in _friendNames)
                {
                    int             which    = Array.IndexOf(_friendNames, friendName) + which_offset;
                    OptionsCheckbox checkbox = new OptionsCheckbox("", which);
                    _checkboxes.Add(checkbox);

                    bool optionForThisFriend = true;    // default is show in menu
                    if (Game1.player.friendshipData.ContainsKey(friendName))
                    {
                        if (_options.TryGetValue(OptionKey(friendName), out string value) &&
                            bool.TryParse(value, out bool result))
                        {
                            optionForThisFriend = result;
                        }
                    }
                    else
                    {
                        checkbox.greyedOut  = true;
                        optionForThisFriend = false;
                    }
                    checkbox.isChecked = optionForThisFriend;
                }
            }
        }
Ejemplo n.º 11
0
        // GET: Admin/SocialPages/editlodging/<id>
        public ActionResult EditLodging(string id)
        {
            SocialPage page = new SocialPage(id);

            if (string.IsNullOrEmpty(page.TownFormatted))
            {
                return(RedirectToAction("index"));
            }

            return(View(page));
        }
Ejemplo n.º 12
0
        public ActionResult EditLodging(string id, SocialPage data)
        {
            SocialPage page = new SocialPage(id);

            if (string.IsNullOrEmpty(page.TownFormatted))
            {
                return(RedirectToAction("index"));
            }

            page.Col3 = data.Col3;

            return(RedirectToAction("index"));;
        }
Ejemplo n.º 13
0
        public static void Postfix(SocialPage __instance)
        {
            var r       = ModEntry.BRGame.ModHelper.Reflection;
            var names   = r.GetField <List <object> >(__instance, "names").GetValue();
            var sprites = r.GetField <List <ClickableTextureComponent> >(__instance, "sprites").GetValue();

            for (int i = names.Count - 1; i >= 0; i--)
            {
                if (names[i] is string)                //NPCs are string, players are long
                {
                    names.RemoveAt(i);
                    sprites.RemoveAt(i);
                }
            }
        }
Ejemplo n.º 14
0
        public ActionResult PageReorder(string order)
        {
            order = "&" + order;
            int pos = 1;

            string[]   arOrder = order.Split(new string[] { "&row[]=" }, StringSplitOptions.RemoveEmptyEntries);
            SocialPage page    = new SocialPage();

            foreach (string SocialPageSerial in arOrder)
            {
                page.UpdateSortOrder(Convert.ToInt32(SocialPageSerial), pos);
                pos++;
            }

            return(Json("success"));
        }
Ejemplo n.º 15
0
            public static void Postfix(SocialPage __instance, SpriteBatch b, int i, List <ClickableTextureComponent> ___sprites)
            {
                if (!Config.EnableMod)
                {
                    return;
                }

                string name = __instance.names[i] as string;
                int    extraFriendshipPixels = Game1.player.getFriendshipLevelForNPC(name) % 250;

                if (extraFriendshipPixels == 0)
                {
                    return;
                }
                int heartLevel = Game1.player.getFriendshipHeartLevelForNPC(name);

                if (heartLevel == Utility.GetMaximumHeartsForCharacter(Game1.getCharacterFromName(name, true, false)))
                {
                    return;
                }

                Texture2D texture;
                Rectangle source;
                float     scale;

                if (Config.Granular)
                {
                    texture = heartTexture;
                    source  = new Rectangle(0, 0, (int)Math.Round(28 * (extraFriendshipPixels / 250f)), 24);
                    scale   = 1;
                }
                else
                {
                    texture = Game1.mouseCursors;
                    source  = new Rectangle(211, 428, (int)Math.Round(7 * (extraFriendshipPixels / 250f)), 6);
                    scale   = 4;
                }

                if (heartLevel < 10)
                {
                    b.Draw(texture, new Vector2(__instance.xPositionOnScreen + 320 - 4 + heartLevel * 32, ___sprites[i].bounds.Y + 64 - 28), source, Color.White, 0f, Vector2.Zero, scale, SpriteEffects.None, 0.88f);
                }
                else
                {
                    b.Draw(Game1.mouseCursors, new Vector2(__instance.xPositionOnScreen + 320 - 4 + (heartLevel - 10) * 32, ___sprites[i].bounds.Y + 64), new Rectangle?(new Rectangle(211, 428, (int)Math.Round(7 * (extraFriendshipPixels / 250f)), 6)), Color.White, 0f, Vector2.Zero, 4f, SpriteEffects.None, 0.88f);
                }
            }
Ejemplo n.º 16
0
        private void ExtendMenuIfNeeded()
        {
            if (Game1.activeClickableMenu is GameMenu gameMenu)
            {
                foreach (var menu in gameMenu.pages)
                {
                    if (menu is SocialPage socialPage)
                    {
                        _socialPage  = socialPage;
                        _friendNames = _socialPage.names
                                       .Select(name => name.ToString())
                                       .ToArray();
                        break;
                    }
                }

                _checkboxes.Clear();
                foreach (var friendName in _friendNames)
                {
                    var hashCode = friendName.GetHashCode();
                    var checkbox = new OptionsCheckbox("", hashCode);
                    _checkboxes.Add(checkbox);

                    //default to on
                    var optionForThisFriend = true;
                    if (!Game1.player.friendshipData.ContainsKey(friendName))
                    {
                        checkbox.greyedOut  = true;
                        optionForThisFriend = false;
                    }
                    else
                    {
                        var optionValue = _options.SafeGet(hashCode.ToString());

                        if (string.IsNullOrEmpty(optionValue))
                        {
                            _options[hashCode.ToString()] = optionForThisFriend.ToString();
                        }
                        else
                        {
                            optionForThisFriend = optionValue.SafeParseBool();
                        }
                    }
                    checkbox.isChecked = optionForThisFriend;
                }
            }
        }
Ejemplo n.º 17
0
        private void OnMenuChange(object sender, EventArgsClickableMenuChanged e)
        {
            if (Game1.activeClickableMenu is GameMenu)
            {
                List <IClickableMenu> menuList = typeof(GameMenu).GetField("pages", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(Game1.activeClickableMenu) as List <IClickableMenu>;

                foreach (var menu in menuList)
                {
                    if (menu is SocialPage)
                    {
                        _socialPage  = menu as SocialPage;
                        _friendNames = typeof(SocialPage).GetField("friendNames", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(_socialPage) as List <ClickableTextureComponent>;
                        break;
                    }
                }
            }
        }
 private void ExtendMenuIfNeeded()
 {
     if (Game1.activeClickableMenu is GameMenu gameMenu)
     {
         foreach (var menu in gameMenu.pages)
         {
             if (menu is SocialPage page)
             {
                 _socialPage  = page;
                 _friendNames = _socialPage.names
                                .Select(name => name.ToString())
                                .ToArray();
                 break;
             }
         }
     }
 }
Ejemplo n.º 19
0
 public static void SocialPage_drawNPCSlot(SocialPage __instance, int i, List <string> ___kidsNames, ref Dictionary <string, string> ___npcNames)
 {
     try
     {
         string name = __instance.names[i] as string;
         if (___kidsNames.Contains(name))
         {
             if (___npcNames[name].EndsWith(")"))
             {
                 ___npcNames[name] = string.Join(" ", ___npcNames[name].Split(' ').Reverse().Skip(1).Reverse());
             }
         }
     }
     catch (Exception ex)
     {
         Monitor.Log($"Failed in {nameof(SocialPage_drawNPCSlot)}:\n{ex}", LogLevel.Error);
     }
 }
        private void ExtendMenuIfNeeded()
        {
            if (Game1.activeClickableMenu is GameMenu)
            {
                List <IClickableMenu> menuList = typeof(GameMenu).GetField("pages", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(Game1.activeClickableMenu) as List <IClickableMenu>;

                foreach (var menu in menuList)
                {
                    if (menu is SocialPage page)
                    {
                        _socialPage  = page;
                        _friendNames = (typeof(SocialPage).GetField("names", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(_socialPage) as List <object>)
                                       .Select(name => name.ToString())
                                       .ToArray();
                        break;
                    }
                }
            }
        }
Ejemplo n.º 21
0
        /// <summary>
        /// Stores the useful data from the social page when the GameMenu is brought up
        /// </summary>
        internal void OnMenuChange(object sender, EventArgsClickableMenuChanged e)
        {
            StardewValley.Farmer x = Game1.player;
            if (!(Game1.activeClickableMenu is GameMenu))
            {
                return;
            }

            var pages = (List <IClickableMenu>) typeof(GameMenu).GetField("pages", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(Game1.activeClickableMenu);

            // Get the list of friends in their correct order
            for (int k = 0; k < pages.Count; k++)
            {
                if (pages[k] is SocialPage)
                {
                    socialPage  = (SocialPage)pages[k];
                    friendNames = (List <ClickableTextureComponent>) typeof(SocialPage).GetField("friendNames", BindingFlags.NonPublic | BindingFlags.Instance).GetValue(pages[k]);
                }
            }
        }
        public ActionResult Edit(string type, int id)
        {
            var        currentUserId  = User.Identity.GetUserId();
            SocialPage page           = null;
            var        SocialPageEdit = new EditViewModel();


            if (type.Equals("facebook"))
            {
                page = _context.Facebooks.SingleOrDefault(fb => fb.Id == id);
                SocialPageEdit.SocialNetworkId = SocialNetwork.FacebookPageLikes;
            }
            else if (type.Equals("twitter"))
            {
                page = _context.Twitters.SingleOrDefault(twt => twt.Id == id);
                SocialPageEdit.SocialNetworkId = SocialNetwork.TwitterFollowers;
            }
            else if (type.Equals("youtube"))
            {
                page = _context.Youtubes.SingleOrDefault(yt => yt.Id == id);
                SocialPageEdit.SocialNetworkId = SocialNetwork.YoutubeSubscribers;
            }
            else
            {
                return(HttpNotFound());
            }
            if (page == null)
            {
                return(HttpNotFound());
            }


            SocialPageEdit.Id     = page.Id;
            SocialPageEdit.Name   = page.Name;
            SocialPageEdit.Cpc    = page.Cpc;
            SocialPageEdit.Active = page.Active;

            return(View(SocialPageEdit));
        }
Ejemplo n.º 23
0
        private void InitializeProperties()
        {
            if (Game1.activeClickableMenu is GameMenu gameMenu)
            {
                foreach (var menu in gameMenu.pages)
                {
                    if (menu is SocialPage socialPage)
                    {
                        _socialPage  = socialPage;
                        _friendNames = _socialPage.names
                                       .Select(name => name.ToString())
                                       .ToArray();
                        break;
                    }
                }

                _checkboxes.Clear();
                for (int i = 0; i < _friendNames.Length; i++)
                {
                    var             friendName = _friendNames[i];
                    OptionsCheckbox checkbox   = new OptionsCheckbox("", i);
                    if (Game1.player.friendshipData.ContainsKey(friendName))
                    {
                        // npc
                        checkbox.greyedOut = false;
                        checkbox.isChecked = _options.ShowLocationOfFriends.SafeGet(friendName, true);
                    }
                    else
                    {
                        // player
                        checkbox.greyedOut = true;
                        checkbox.isChecked = true;
                    }
                    _checkboxes.Add(checkbox);
                }
            }
        }
Ejemplo n.º 24
0
        /// <summary>The event called after a new menu is opened.</summary>
        /// <param name="sender">The event sender.</param>
        /// <param name="e">The event arguments.</param>
        private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e)
        {
            // remove tractor from social menu
            if (e.NewMenu is GameMenu gameMenu && this.Tractor != null && !this.Tractor.IsRiding)
            {
                SocialPage socialPage = (SocialPage)this.Helper.Reflection.GetField <List <IClickableMenu> >(gameMenu, "pages").GetValue()[GameMenu.socialTab];
                List <ClickableTextureComponent> friendNames = this.Helper.Reflection.GetField <List <ClickableTextureComponent> >(socialPage, "friendNames").GetValue();
                IDictionary <string, string>     npcNames    = this.Helper.Reflection.GetField <Dictionary <string, string> >(socialPage, "npcNames").GetValue();

                friendNames.RemoveAll(p => p.name == this.Tractor.Current.name);
                npcNames.Remove(this.Tractor.Current.name);

                socialPage.updateSlots();
            }

            // add blueprint to carpenter menu
            if (Context.IsWorldReady && !this.HasAnyGarages)
            {
                // default menu
                if (e.NewMenu is CarpenterMenu)
                {
                    this.Helper.Reflection
                    .GetField <List <BluePrint> >(e.NewMenu, "blueprints")
                    .GetValue()
                    .Add(this.GetBlueprint());
                }

                // modded menus
                else if (this.IsPelicanFiberLoaded && e.NewMenu.GetType().FullName == this.PelicanFiberMenuFullName)
                {
                    this.Helper.Reflection
                    .GetField <List <BluePrint> >(e.NewMenu, "Blueprints")
                    .GetValue()
                    .Add(this.GetBlueprint());
                }
            }
        }
        public ActionResult Save(EditViewModel editSocial)
        {
            if (!ModelState.IsValid)
            {
                return(HttpNotFound());
            }
            var        userId     = User.Identity.GetUserId();
            SocialPage socialPage = null;

            if (editSocial.SocialNetworkId == 1)
            {
                socialPage = _context.Facebooks.SingleOrDefault(fb => fb.Id == editSocial.Id && fb.UserId == userId);
            }
            else if (editSocial.SocialNetworkId == 2)
            {
                socialPage = _context.Twitters.SingleOrDefault(twt => twt.Id == editSocial.Id && twt.UserId == userId);
            }
            else if (editSocial.SocialNetworkId == 3)
            {
                socialPage = _context.Youtubes.SingleOrDefault(yt => yt.Id == editSocial.Id && yt.UserId == userId);
            }
            else
            {
                return(HttpNotFound());
            }

            if (socialPage == null)
            {
                return(HttpNotFound());
            }
            socialPage.Active = editSocial.Active;
            socialPage.Cpc    = editSocial.Cpc;
            socialPage.Name   = editSocial.Name;

            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 26
0
            public static bool Prefix(DialogueBox __instance, SpriteBatch b)
            {
                if (!Config.EnableMod)
                {
                    return(true);
                }
                string name = __instance.characterDialogue.speaker.Name;

                if (!dataDict.TryGetValue(name, out DialogueDisplayData data))
                {
                    data = dataDict[defaultKey];
                }

                if (data == null || data.disabled)
                {
                    return(true);
                }

                // Dividers

                var dividers = data.dividers is null ? dataDict[defaultKey].dividers : data.dividers;

                if (dividers != null)
                {
                    foreach (var divider in dividers)
                    {
                        if (divider.horizontal)
                        {
                            DrawHorizontalPartition(b, __instance, divider);
                        }
                        else
                        {
                            DrawVerticalPartition(b, __instance, divider);
                        }
                    }
                }


                // Images

                var images = data.images is null ? dataDict[defaultKey].images : data.images;

                if (images != null)
                {
                    foreach (var image in images)
                    {
                        b.Draw(imageDict[image.texturePath], GetDataVector(__instance, image), new Rectangle(image.x, image.y, image.w, image.h), Color.White * image.alpha, 0, Vector2.Zero, image.scale, SpriteEffects.None, image.layerDepth);
                    }
                }


                // NPC Portrait

                var portrait = data.portrait is null ? dataDict[defaultKey].portrait : data.portrait;

                if (portrait is not null && !portrait.disabled)
                {
                    Texture2D portraitTexture;
                    Rectangle portraitSource;

                    if (portrait.texturePath != null)
                    {
                        portraitTexture = imageDict[portrait.texturePath];
                    }
                    else
                    {
                        if (__instance.characterDialogue.overridePortrait != null)
                        {
                            portraitTexture = __instance.characterDialogue.overridePortrait;
                        }
                        else
                        {
                            portraitTexture = __instance.characterDialogue.speaker.Portrait;
                        }
                    }
                    if (!portrait.tileSheet)
                    {
                        portraitSource = new Rectangle(portrait.x, portrait.y, portrait.w, portrait.h);
                    }
                    else
                    {
                        portraitSource = Game1.getSourceRectForStandardTileSheet(portraitTexture, __instance.characterDialogue.getPortraitIndex(), portrait.w, portrait.h);
                        if (!portraitTexture.Bounds.Contains(portraitSource))
                        {
                            portraitSource = new Rectangle(0, 0, portrait.w, portrait.h);
                        }
                    }


                    int xOffset = (bool)AccessTools.Method(typeof(DialogueBox), "shouldPortraitShake").Invoke(__instance, new object[] { __instance.characterDialogue }) ? Game1.random.Next(-1, 2) : 0;
                    b.Draw(portraitTexture, GetDataVector(__instance, portrait) + new Vector2(xOffset, 0), new Rectangle?(portraitSource), Color.White * portrait.alpha, 0f, Vector2.Zero, portrait.scale, SpriteEffects.None, portrait.layerDepth);
                }



                // Sprite

                var sprite = data.sprite is null ? dataDict[defaultKey].sprite : data.sprite;

                if (sprite is not null && !sprite.disabled && npcSpriteMenu is not null)
                {
                    var pos = GetDataVector(__instance, sprite);

                    if (sprite.background)
                    {
                        b.Draw((Game1.timeOfDay >= 1900) ? Game1.nightbg : Game1.daybg, pos, Color.White);
                    }

                    if (sprite.frame >= 0)
                    {
                        AccessTools.FieldRefAccess <ProfileMenu, AnimatedSprite>(npcSpriteMenu, "_animatedSprite").CurrentFrame = sprite.frame;
                    }
                    else
                    {
                        npcSpriteMenu.update(Game1.currentGameTime);
                    }
                    AccessTools.FieldRefAccess <ProfileMenu, AnimatedSprite>(npcSpriteMenu, "_animatedSprite").draw(b, pos + new Vector2(32, 32), sprite.layerDepth, 0, 0, Color.White, false, sprite.scale, 0, false);
                }


                // NPC Name

                var npcName = data.name != null ? data.name : dataDict[defaultKey].name;

                if (npcName is not null && !npcName.disabled)
                {
                    var namePos  = GetDataVector(__instance, npcName);
                    var realName = __instance.characterDialogue.speaker.getName();
                    if (npcName.centered)
                    {
                        if (npcName.scroll)
                        {
                            SpriteText.drawStringWithScrollCenteredAt(b, realName, (int)namePos.X, (int)namePos.Y, npcName.placeholderText is null ? realName : npcName.placeholderText, npcName.alpha, npcName.color, npcName.scrollType, npcName.layerDepth, npcName.junimo);
                        }
                        else
                        {
                            SpriteText.drawStringHorizontallyCenteredAt(b, realName, (int)namePos.X, (int)namePos.Y, 999999, npcName.width, 999999, npcName.alpha, npcName.layerDepth, npcName.junimo, npcName.color);
                        }
                    }
                    else
                    {
                        if (npcName.right)
                        {
                            namePos.X -= SpriteText.getWidthOfString(realName);
                        }

                        if (npcName.scroll)
                        {
                            SpriteText.drawStringWithScrollBackground(b, realName, (int)namePos.X, (int)namePos.Y, npcName.placeholderText is null ? realName : npcName.placeholderText, npcName.alpha, npcName.color, npcName.alignment);
                        }
                        else
                        {
                            SpriteText.drawString(b, realName, (int)namePos.X, (int)namePos.Y, 999999, npcName.width, 999999, npcName.alpha, npcName.layerDepth, npcName.junimo, npcName.color);
                        }
                    }
                }


                // Texts

                var texts = data.texts is null ? dataDict[defaultKey].texts : data.texts;

                if (texts != null)
                {
                    foreach (var text in texts)
                    {
                        var pos = GetDataVector(__instance, text);
                        if (text.centered)
                        {
                            if (text.variable && text.right)
                            {
                                pos.X -= SpriteText.getWidthOfString(text.text) / 2;
                            }

                            if (text.scroll)
                            {
                                SpriteText.drawStringWithScrollCenteredAt(b, text.text, (int)pos.X, (int)pos.Y, text.placeholderText, text.alpha, text.color, text.scrollType, text.layerDepth, text.junimo);
                            }
                            else
                            {
                                SpriteText.drawStringHorizontallyCenteredAt(b, text.text, (int)pos.X, (int)pos.Y, 999999, text.width, 999999, text.alpha, text.layerDepth, text.junimo, text.color);
                            }
                        }
                        else
                        {
                            if (text.variable && text.right)
                            {
                                pos.X -= SpriteText.getWidthOfString(text.text);
                            }

                            if (text.scroll)
                            {
                                SpriteText.drawStringWithScrollBackground(b, text.text, (int)pos.X, (int)pos.Y, text.placeholderText, text.alpha, text.color, text.alignment);
                            }
                            else
                            {
                                SpriteText.drawString(b, text.text, (int)pos.X, (int)pos.Y, 999999, text.width, 999999, text.alpha, text.layerDepth, text.junimo, text.color);
                            }
                        }
                    }
                }


                if (Game1.player.friendshipData.ContainsKey(name))
                {
                    // Hearts

                    var hearts = data.hearts is null ? dataDict[defaultKey].hearts : data.hearts;
                    if (hearts is not null && !hearts.disabled)
                    {
                        var pos                   = GetDataVector(__instance, hearts);
                        int heartLevel            = Game1.player.getFriendshipHeartLevelForNPC(name);
                        int extraFriendshipPixels = Game1.player.getFriendshipLevelForNPC(name) % 250;

                        bool datable = SocialPage.isDatable(name);
                        bool spouse  = false;
                        if (Game1.player.friendshipData.TryGetValue(name, out Friendship friendship))
                        {
                            spouse = friendship.IsMarried();
                        }
                        int maxHearts = Math.Max(Utility.GetMaximumHeartsForCharacter(Game1.getCharacterFromName(name, true, false)), 10);
                        if (hearts.centered)
                        {
                            int maxDisplayedHearts = hearts.showEmptyHearts ? maxHearts : heartLevel;
                            if (extraFriendshipPixels > 0)
                            {
                                maxDisplayedHearts++;
                            }
                            pos -= new Vector2(Math.Min(hearts.heartsPerRow, maxDisplayedHearts) * 32 / 2, 0);
                        }
                        for (int h = 0; h < maxHearts; h++)
                        {
                            if (h > heartLevel && !hearts.showEmptyHearts)
                            {
                                break;
                            }
                            if (h == heartLevel && extraFriendshipPixels == 0)
                            {
                                break;
                            }
                            int xSource = (h < heartLevel) ? 211 : 218;
                            if (datable && !friendship.IsDating() && !spouse && h >= 8)
                            {
                                xSource = 211;
                            }
                            int x = h % hearts.heartsPerRow;
                            int y = h / hearts.heartsPerRow;
                            b.Draw(Game1.mouseCursors, pos + new Vector2(x * 32, y * 32), new Rectangle?(new Rectangle(xSource, 428, 7, 6)), (datable && !friendship.IsDating() && !spouse && h >= 8) ? (Color.Black * 0.35f) : Color.White, 0f, Vector2.Zero, 4f, SpriteEffects.None, 0.88f);
                            if (h == heartLevel && extraFriendshipPixels > 0)
                            {
                                b.Draw(Game1.mouseCursors, pos + new Vector2(x * 32, y * 32), new Rectangle?(new Rectangle(211, 428, (int)Math.Round(7 * (extraFriendshipPixels / 250f)), 6)), Color.White, 0f, Vector2.Zero, 4f, SpriteEffects.None, 0.88f);
                            }
                        }
                    }


                    // Gifts

                    var gifts = data.gifts is null ? dataDict[defaultKey].gifts : data.gifts;
                    if (gifts is not null && !gifts.disabled && !Game1.player.friendshipData[name].IsMarried() && Game1.getCharacterFromName(name) is not Child)
                    {
                        var pos = GetDataVector(__instance, gifts);
                        Utility.drawWithShadow(b, Game1.mouseCursors2, pos + new Vector2(6, 0), new Rectangle(166, 174, 14, 12), Color.White, 0f, Vector2.Zero, 4f, false, 0.88f, 0, -1, 0.2f);
                        b.Draw(Game1.mouseCursors, pos + (gifts.inline ? new Vector2(64, 8) : new Vector2(0, 56)), new Rectangle?(new Rectangle(227 + ((Game1.player.friendshipData[name].GiftsThisWeek >= 2) ? 9 : 0), 425, 9, 9)), Color.White, 0f, Vector2.Zero, 4f, SpriteEffects.None, 0.88f);
                        b.Draw(Game1.mouseCursors, pos + (gifts.inline ? new Vector2(96, 8) : new Vector2(32, 56)), new Rectangle?(new Rectangle(227 + (Game1.player.friendshipData[name].GiftsThisWeek >= 1 ? 9 : 0), 425, 9, 9)), Color.White, 0f, Vector2.Zero, 4f, SpriteEffects.None, 0.88f);
                    }

                    // Jewel

                    if (__instance.shouldDrawFriendshipJewel())
                    {
                        var jewel = data.jewel is null ? dataDict[defaultKey].jewel : data.jewel;
                        if (jewel != null && !jewel.disabled)
                        {
                            var pos = GetDataVector(__instance, jewel);
                            b.Draw(Game1.mouseCursors, pos, new Rectangle?((Game1.player.getFriendshipHeartLevelForNPC(__instance.characterDialogue.speaker.Name) >= 10) ? new Rectangle(269, 494, 11, 11) : new Rectangle(Math.Max(140, 140 + (int)(Game1.currentGameTime.TotalGameTime.TotalMilliseconds % 1000.0 / 250.0) * 11), Math.Max(532, 532 + Game1.player.getFriendshipHeartLevelForNPC(__instance.characterDialogue.speaker.Name) / 2 * 11), 11, 11)), Color.White * jewel.alpha, 0f, Vector2.Zero, jewel.scale, SpriteEffects.None, jewel.layerDepth);
                        }
                    }
                }



                // Dialogue String

                var dialogue    = data.dialogue is null ? dataDict[defaultKey].dialogue : data.dialogue;
                var dialoguePos = GetDataVector(__instance, dialogue);

                preventGetCurrentString = false;
                SpriteText.drawString(b, __instance.getCurrentString(), (int)dialoguePos.X, (int)dialoguePos.Y, __instance.characterIndexInDialogue, dialogue.width >= 0 ? dialogue.width : __instance.width - 8, 999999, dialogue.alpha, dialogue.layerDepth, false, -1, "", dialogue.color, dialogue.alignment);


                // Close Icon

                if (__instance.dialogueIcon != null)
                {
                    var button = data.button is null ? dataDict[defaultKey].button : data.button;

                    if (button != null && !button.disabled)
                    {
                        __instance.dialogueIcon.position = GetDataVector(__instance, button);
                    }
                }


                preventGetCurrentString = true;
                return(false);
            }
Ejemplo n.º 27
0
        private void ResortSocialList()
        {
            if (Game1.activeClickableMenu is GameMenu)
            {
                SocialPage page = (Game1.activeClickableMenu as GameMenu).pages[GameMenu.socialTab] as SocialPage;

                List <ClickableTextureComponent> sprites     = new List <ClickableTextureComponent>(Helper.Reflection.GetField <List <ClickableTextureComponent> >(page, "sprites").GetValue());
                List <NameSpriteSlot>            nameSprites = new List <NameSpriteSlot>();
                for (int i = 0; i < page.names.Count; i++)
                {
                    nameSprites.Add(new NameSpriteSlot(page.names[i], sprites[i], page.characterSlots[i]));
                }
                switch (Config.CurrentSort)
                {
                case 0:     // friend asc
                    Monitor.Log("sorting by friend asc");
                    nameSprites.Sort(delegate(NameSpriteSlot x, NameSpriteSlot y)
                    {
                        if (x.name is long && y.name is long)
                        {
                            return(0);
                        }
                        else if (x.name is long)
                        {
                            return(-1);
                        }
                        else if (y.name is long)
                        {
                            return(1);
                        }
                        return(Game1.player.getFriendshipLevelForNPC(x.name as string).CompareTo(Game1.player.getFriendshipLevelForNPC(y.name as string)));
                    });
                    break;

                case 1:     // friend desc
                    Monitor.Log("sorting by friend desc");
                    nameSprites.Sort(delegate(NameSpriteSlot x, NameSpriteSlot y)
                    {
                        if (x.name is long && y.name is long)
                        {
                            return(0);
                        }
                        else if (x.name is long)
                        {
                            return(-1);
                        }
                        else if (y.name is long)
                        {
                            return(1);
                        }
                        return(-(Game1.player.getFriendshipLevelForNPC(x.name as string).CompareTo(Game1.player.getFriendshipLevelForNPC(y.name as string))));
                    });
                    break;

                case 2:     // alpha asc
                    Monitor.Log("sorting by alpha asc");
                    nameSprites.Sort(delegate(NameSpriteSlot x, NameSpriteSlot y)
                    {
                        return((x.name is long?Game1.getFarmer((long)x.name).name: GetNPCDisplayName(x.name as string)).CompareTo(y.name is long?Game1.getFarmer((long)y.name).name: GetNPCDisplayName(y.name as string)));
                    });
                    break;

                case 3:     // alpha desc
                    Monitor.Log("sorting by alpha desc");
                    nameSprites.Sort(delegate(NameSpriteSlot x, NameSpriteSlot y)
                    {
                        return(-((x.name is long?Game1.getFarmer((long)x.name).name: GetNPCDisplayName(x.name as string)).CompareTo(y.name is long?Game1.getFarmer((long)y.name).name: GetNPCDisplayName(y.name as string))));
                    });
                    break;
                }
                for (int i = 0; i < nameSprites.Count; i++)
                {
                    ((Game1.activeClickableMenu as GameMenu).pages[GameMenu.socialTab] as SocialPage).names[i] = nameSprites[i].name;
                    sprites[i] = nameSprites[i].sprite;
                    ((Game1.activeClickableMenu as GameMenu).pages[GameMenu.socialTab] as SocialPage).characterSlots[i] = nameSprites[i].slot;
                }
                Helper.Reflection.GetField <List <ClickableTextureComponent> >((Game1.activeClickableMenu as GameMenu).pages[GameMenu.socialTab], "sprites").SetValue(new List <ClickableTextureComponent>(sprites));

                int first_character_index = 0;
                for (int l = 0; l < page.names.Count; l++)
                {
                    if (!(((SocialPage)(Game1.activeClickableMenu as GameMenu).pages[GameMenu.socialTab]).names[l] is long))
                    {
                        first_character_index = l;
                        break;
                    }
                }
                Helper.Reflection.GetField <int>((Game1.activeClickableMenu as GameMenu).pages[GameMenu.socialTab], "slotPosition").SetValue(first_character_index);
                Helper.Reflection.GetMethod((Game1.activeClickableMenu as GameMenu).pages[GameMenu.socialTab], "setScrollBarToCurrentIndex").Invoke();
                ((SocialPage)(Game1.activeClickableMenu as GameMenu).pages[GameMenu.socialTab]).updateSlots();
            }
        }
Ejemplo n.º 28
0
        private void ExtendMenuIfNeeded()
        {
            if (Game1.activeClickableMenu is GameMenu)
            {
                List <IClickableMenu> clickableMenuList = typeof(GameMenu)
                                                          .GetField("pages", BindingFlags.Instance | BindingFlags.NonPublic)
                                                          .GetValue(Game1.activeClickableMenu) as List <IClickableMenu>;

                foreach (var menu in clickableMenuList)
                {
                    if (menu is SocialPage)
                    {
                        _socialPage  = menu as SocialPage;
                        _friendNames = (typeof(SocialPage).GetField("names", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(menu) as List <object>)
                                       .Select(name => name.ToString())
                                       .ToArray();
                        break;
                    }
                }
                _townsfolk.Clear();
                foreach (var location in Game1.locations)
                {
                    foreach (var npc in location.characters)
                    {
                        if (Game1.player.friendshipData.ContainsKey(npc.Name))
                        {
                            _townsfolk.Add(npc);
                        }
                    }
                }
                _checkboxes.Clear();
                foreach (var friendName in _friendNames)
                {
                    int             hashCode = friendName.GetHashCode();
                    OptionsCheckbox checkbox = new OptionsCheckbox("", hashCode);
                    _checkboxes.Add(checkbox);

                    //default to on
                    bool optionForThisFriend = true;
                    if (!Game1.player.friendshipData.ContainsKey(friendName))
                    {
                        checkbox.greyedOut  = true;
                        optionForThisFriend = false;
                    }
                    else
                    {
                        String optionValue = _options.SafeGet(hashCode.ToString());

                        if (String.IsNullOrEmpty(optionValue))
                        {
                            _options[hashCode.ToString()] = optionForThisFriend.ToString();
                        }
                        else
                        {
                            optionForThisFriend = optionValue.SafeParseBool();
                        }
                    }
                    checkbox.isChecked = optionForThisFriend;
                }
            }
        }