private void AddLeftMenuOption(UIElement leftMenu, MenuItem item, int index, int row = 0) { int maxT = 11; int placeRow = row + (index / options); string placeText = item.Name; if (placeText.Length > maxT + 3) { placeText = placeText.Substring(0, maxT) + "..."; } index = index % options; UIElement button = UIElement.GetImage(PyDraw.getBorderedRectangle(optionWidth, optionHeight - 1, Color.White * 0.2f, 1, Color.White), row == 0 ? Color.CornflowerBlue : Color.LightGreen, item.Id, 1, 0, UIHelper.GetTopLeft(placeRow * (optionWidth + 1), index * (optionHeight + 1), optionWidth, optionHeight - 1)).WithInteractivity(update: UpdateItem, click: ClickItem); float textScale = Math.Min(0.5f * menuScale, 0.7f); if (LocalizedContentManager.CurrentLanguageLatin && menuFont1 != "" && menuFont1 != null) { textScale *= cFontAdjust; } UITextElement text = new UITextElement(placeText, Game1.smallFont, Color.White, textScale, 1, positioner: UIHelper.GetCentered()); if (LocalizedContentManager.CurrentLanguageLatin && menuFont1 != "" && menuFont1 != null) { text.WithFont(menuFont1); } button.Z = row; button.Add(text); leftMenu.Add(button); if (item.Special) { PyTK.PyUtils.setDelayedAction(100, () => button.ClickAction(Point.Zero, false, true, false, button)); } if (row > 0) { button.Disable(); button.Visible = false; text.Visible = false; } for (int i = 0; i < item.Children.Count; i++) { if (item.Children[i] is MenuItem child) { AddLeftMenuOption(leftMenu, child, i, row + 1); } } }
private UIElement GetMenuForLocation(GameLocation location, NPC npc = null, bool artifacts = false, bool structure = false) { var lmenu = UIElement.GetContainer("Location Menu " + location.Name, positioner: UIHelper.GetCentered(0, 0, 1f, 1f)); float textScale = 1.4f; if (LocalizedContentManager.CurrentLanguageLatin && menuFont2 != "" && menuFont2 != null) { textScale *= cFontAdjust; } var lname = !structure ? location.Name : location.uniqueName.Value; if (i18n.GetTranslations().ToList().Exists(t => t.Key == "location." + lname)) { lname = i18n.Get("location." + lname); } var lmenuHead = new UITextElement(lname, Game1.dialogueFont, Color.White, textScale, positioner: UIHelper.GetTopCenter(0, 5)); var back = location.Map.GetLayer("Back"); double w = back.LayerWidth; double h = back.LayerHeight; double s = (h / w); int tw = (menuWidth / 2) - (4 * margins); int th = (int)(tw * s); if (th > menuHeight * 0.75f) { s = (w / h); th = (int)(menuHeight * 0.75f); tw = (int)(th * s); } var lmenuViewer = UIElement.GetImage(PyDraw.getWhitePixel(), Color.Green, positioner: UIHelper.GetTopCenter(0, 50, tw, th)); var lmenuWarp = new UITextElement($"{i18n.Get("menu.locations.warp")} (X:0 Y:0)", Game1.dialogueFont, Color.White, textScale, positioner: UIHelper.GetTopCenter(0, th + 60)); var lmenuLoading = new UITextElement(i18n.Get("menu.locations.loading"), Game1.dialogueFont, Color.White, textScale, positioner: UIHelper.GetCentered()); lmenuViewer.Add(lmenuLoading); if (LocalizedContentManager.CurrentLanguageLatin && menuFont2 != "" && menuFont2 != null) { lmenuHead.WithFont(menuFont2); lmenuWarp.WithFont(menuFont2); lmenuLoading.WithFont(menuFont2); } lmenu.Add(lmenuViewer); Point tPoint = new Point(0, 0); lmenuViewer.WithInteractivity(update: (t, el) => { PlatoWarpMenuMod.GetLocationShot(location, () => { Texture2D screen = PlatoWarpMenuMod.LastScreen; if (PlatoWarpMenuMod.instance.config.UseTempFolder) { screen = Helper.Content.Load <Texture2D>(Path.Combine("Temp", (location.isStructure.Value ? location.uniqueName.Value : location.Name) + ".png")); } var image = UIElement.GetImage(screen, Color.White, positioner: el.Positioner); image.WithInteractivity(click: (point, right, released, hold, imageContainer) => { if (released && !right) { if (!location.isTileLocationTotallyClearAndPlaceableIgnoreFloors(new Vector2(tPoint.X, tPoint.Y))) { return; } Game1.activeClickableMenu = null; Game1.player.warpFarmer(new Warp(0, 0, structure ? location.uniqueName.Value : location.Name, tPoint.X, tPoint.Y, false)); } }, hover: (point, drag, imageContainer) => { var rect = imageContainer.Bounds; int x = (int)(((point.X - rect.X) / (double)rect.Width) * location.Map.GetLayer("Back").LayerWidth); int y = (int)(((point.Y - rect.Y) / (double)rect.Height) * location.Map.GetLayer("Back").LayerHeight); tPoint = new Point(x, y); lmenuWarp.Text = $"{i18n.Get("menu.locations.warp")} (X:{ (int)x} Y:{(int)y})"; if (!location.isTileLocationTotallyClearAndPlaceableIgnoreFloors(new Vector2(x, y))) { lmenuWarp.TextColor = Color.Red; } else { lmenuWarp.TextColor = Color.White; } }); lmenu.Add(image); lmenu.Remove(lmenuViewer); lmenu.UpdateBounds(); if (npc != null) { var rect = image.Bounds; int mx = (int)((npc.getTileX() / (double)location.Map.GetLayer("Back").LayerWidth) * rect.Width); int my = (int)((npc.getTileY() / (double)location.Map.GetLayer("Back").LayerHeight) * rect.Height); var lmenuMarker = UIElement.GetImage(CircleMarker, Color.Magenta * 0.6f, positioner: UIHelper.GetTopLeft(mx - 12, my - 12, 33, 33)); image.Add(lmenuMarker); } if (artifacts) { foreach (var spot in location.Objects.Keys.Where(o => location.Objects[o].ParentSheetIndex == 590)) { var rect = image.Bounds; int mx = (int)((spot.X / (double)location.Map.GetLayer("Back").LayerWidth) * rect.Width); int my = (int)((spot.Y / (double)location.Map.GetLayer("Back").LayerHeight) * rect.Height); var lmenuMarker = UIElement.GetImage(CircleMarker, Color.Red, positioner: UIHelper.GetTopLeft(mx - 5, my - 5, 11, 11)); image.Add(lmenuMarker); } } }); el.WithoutInteractivity(true); }); lmenu.Add(lmenuHead); lmenu.Add(lmenuWarp); return(lmenu); }