public void OnResize(SDVSocialPage nativePage) { this.NativeSocialPage = nativePage; this.FriendSlots = this.Reflection.GetField <List <ClickableTextureComponent> >(this.NativeSocialPage, "sprites").GetValue(); this.Names = this.Reflection.GetField <List <object> >(this.NativeSocialPage, "names").GetValue(); // Mostly arbitrary since there's no nice way (that i know of) to get the slots positioned correctly... this.Offset = new SVector2(Game1.tileSize / 4, Game1.tileSize / 8); this.Zoom = Game1.options.zoomLevel; this.SlotHeight = this.GetSlotHeight(); this.LastSlotIndex = -1; // Invalidate }
public override bool OnOpen(IClickableMenu menu) { // reset this.LastHoveredNpc = string.Empty; SDVSocialPage nativeSocialPage = this.GetNativeSocialPage(menu); if (nativeSocialPage != null) { this.SocialPage.Init(nativeSocialPage, this.Reflection); } return(base.OnOpen(menu)); }
public override bool OnOpen(IClickableMenu menu) { // Reset lastHoveredNPC = string.Empty; SDVSocialPage nativeSocialPage = GetNativeSocialPage(menu); if (nativeSocialPage != null) { socialPage.Init(nativeSocialPage); } return(base.OnOpen(menu)); }
private SDVSocialPage GetNativeSocialPage(IClickableMenu menu) { SDVSocialPage nativeSocialPage = null; try { nativeSocialPage = (SDVSocialPage)( (List <IClickableMenu>) typeof(GameMenu) .GetField("pages", BindingFlags.Instance | BindingFlags.NonPublic) .GetValue(menu))[GameMenu.socialTab]; } catch (Exception ex) { Utils.DebugLog("Failed to get native social page: " + ex.ToString(), StardewModdingAPI.LogLevel.Warn); return(null); } return(nativeSocialPage); }
public void OnResize(SDVSocialPage nativePage) { this.NativeSocialPage = nativePage; this.FriendSlots = this.Reflection.GetField <List <ClickableTextureComponent> >(this.NativeSocialPage, "sprites").GetValue(); this.Names = this.Reflection.GetField <List <object> >(this.NativeSocialPage, "names").GetValue(); if (this.FriendSlots.Count == 0) { Utils.DebugLog("Failed to init SocialPage: No friend slots found.", LogLevel.Error); return; } // The slot bounds begin after a small margin on the top and left side, likely to make it easier to align // the slot contents. We need to offset by this margin so that when you mouse over where the slot actually begins // it's correctly detected. // These offset values are kind of magic based on what looked right as I couldn't find a nice way to get them. this.SlotBoundsOffset = new SVector2(Game1.tileSize / 4, Game1.tileSize / 8); this.SlotHeight = this.GetSlotHeight(); this.PageBounds = this.MakePageBounds(); LastSlotIndex = this.GetSlotIndex(); }
public override void receiveLeftClick(int x, int y, bool playSound = true) { if (upButton.containsPoint(x, y) && slotPosition > 0) { upArrowPressed(); Game1.playSound("shwip"); } else if (downButton.containsPoint(x, y) && slotPosition < sprites.Count - 5) { downArrowPressed(); Game1.playSound("shwip"); } else if (scrollBar.containsPoint(x, y)) { scrolling = true; } else if (!downButton.containsPoint(x, y) && x > xPositionOnScreen + width - 96 && x < xPositionOnScreen + width + 128 && y > yPositionOnScreen && y < yPositionOnScreen + height) { scrolling = true; leftClickHeld(x, y); releaseLeftClick(x, y); } for (int i = 0; i < characterSlots.Count; i++) { if (i < slotPosition || i >= slotPosition + 5 || !characterSlots[i].bounds.Contains(x, y)) { continue; } bool fail = true; if (names[i] is string) { Character character = Game1.getCharacterFromName((string)names[i]); if (character != null && Game1.player.friendshipData.ContainsKey(character.name)) { fail = false; Game1.playSound("bigSelect"); int cached_slot_position = slotPosition; ProfileMenu menu = new ProfileMenu(character); menu.exitFunction = delegate { SocialPage socialPage = ((GameMenu)(Game1.activeClickableMenu = new GameMenu(2, -1, playOpeningSound: false))).GetCurrentPage() as SocialPage; if (socialPage != null) { Character character2 = menu.GetCharacter(); if (character2 != null) { int num = 0; while (true) { if (num >= socialPage.names.Count) { return; } if (socialPage.names[num] is string && character2.Name == (string)socialPage.names[num]) { break; } num++; } socialPage.slotPosition = cached_slot_position; socialPage._SelectSlot(socialPage.characterSlots[num]); } } }; Game1.activeClickableMenu = menu; if (Game1.options.SnappyMenus) { menu.snapToDefaultClickableComponent(); } } } if (fail) { Game1.playSound("shiny4"); } break; } slotPosition = Math.Max(0, Math.Min(sprites.Count - 5, slotPosition)); }
/********* ** Public methods *********/ public void Init(SDVSocialPage nativePage, IReflectionHelper reflection) { this.Reflection = reflection; this.OnResize(nativePage); }