public CustomCropMenu() : base((Game1.uiViewport.Width - WIDTH) / 2, (Game1.uiViewport.Height - HEIGHT) / 2, WIDTH, HEIGHT) { ui = new RootElement(); ui.LocalPosition = new Microsoft.Xna.Framework.Vector2(xPositionOnScreen, yPositionOnScreen); seedSlot = new ItemSlot() { ItemDisplay = new DummyItem(I18n.Menu_Seeds_Name(), I18n.Menu_Seeds_Description(), Game1.objectSpriteSheet, Game1.getSourceRectForStandardTileSheet(Game1.objectSpriteSheet, 472, 16, 16)), TransparentItemDisplay = true, }; seedSlot.LocalPosition = new(0, (HEIGHT - seedSlot.Height) / 2 - 125); seedSlot.UserData = (Func <Item, bool>)((item) => (item is StardewValley.Object sobj && sobj.Category == StardewValley.Object.SeedsCategory)); stuff = new StaticContainer() { LocalPosition = new((WIDTH - seedSlot.Width) / 2, 0), }; stuff.AddChild(seedSlot); ui.AddChild(stuff); var statsLebel = new Label() { String = I18n.Stats(), LocalPosition = new((WIDTH - seedSlot.Width) / 2 + seedSlot.Width, 8), }; statsLebel.LocalPosition = new(statsLebel.LocalPosition.X - statsLebel.Measure().X / 2, statsLebel.LocalPosition.Y); stuff.AddChild(statsLebel); stuff.AddChild(growthLabel = new Label() { String = I18n.Stats_Growth(0), LocalPosition = new(150, statsLebel.LocalPosition.Y + statsLebel.Measure().Y + 16), HoverTextColor = Color.Red, IdleTextColor = Color.Red, NonBoldScale = 0.5f, NonBoldShadow = false, });
public MarryMenu() : base((Game1.uiViewport.Width - 800) / 2, (Game1.uiViewport.Height - 700) / 2, 800, 700) { var valid = new List <NPC>(); foreach (var npc in Utility.getAllCharacters()) { if (npc.datable.Value && npc.getSpouse() == null) { valid.Add(npc); } } valid.Sort((a, b) => a.Name.CompareTo(b.Name)); /* * for ( int i = 0; i < valid.Count; ++i ) * { * int oi = Game1.random.Next( valid.Count ); * var other = valid[ oi ]; * valid[ oi ] = valid[ i ]; * valid[ i ] = other; * } */ this.Ui = new RootElement { LocalPosition = new Vector2(this.xPositionOnScreen, this.yPositionOnScreen) }; var title = new Label { String = I18n.Menu_Title(), Bold = true }; title.LocalPosition = new Vector2((800 - title.Measure().X) / 2, 10); this.Ui.AddChild(title); this.Ui.AddChild(new Label { String = I18n.Menu_Text(), LocalPosition = new Vector2(50, 75), NonBoldScale = 0.75f, NonBoldShadow = false }); this.Table = new Table { RowHeight = 200, Size = new Vector2(700, 500), LocalPosition = new Vector2(50, 225) }; for (int row = 0; row < (valid.Count + 2) / 3; ++row) { var rowContainer = new StaticContainer(); for (int col = row * 3; col < (row + 1) * 3; ++col) { if (col >= valid.Count) { continue; } var cont = new StaticContainer { Size = new Vector2(115 * 2, 97 * 2), LocalPosition = new Vector2(250 * (col - row * 3) - 10, 0) }; // Note: This is being called 4 times for some reason // Probably a UI framework bug. string curNpcName = valid[col].Name; // avoid capturing the loop variable in the callback, since it'll change value void SelCallback(Element e) { if (this.SelectedContainer != null) { this.SelectedContainer.OutlineColor = null; } this.SelectedContainer = cont; this.SelectedContainer.OutlineColor = Color.Green; this.SelectedNpc = curNpcName; Log.Trace("Selected " + this.SelectedNpc); } cont.AddChild(new Image { Texture = Game1.mouseCursors, TexturePixelArea = new Rectangle(583, 411, 115, 97), Scale = 2, LocalPosition = new Vector2(0, 0), Callback = SelCallback }); cont.AddChild(new Image { Texture = valid[col].Portrait, TexturePixelArea = new Rectangle(0, 128, 64, 64), Scale = 2, LocalPosition = new Vector2(50, 16) }); var name = new Label { String = valid[col].displayName, NonBoldScale = 0.5f, NonBoldShadow = false }; name.LocalPosition = new Vector2(115 - name.Measure().X / 2, 160); cont.AddChild(name); rowContainer.AddChild(cont); } this.Table.AddRow(new Element[] { rowContainer }); } this.Ui.AddChild(this.Table); this.Ui.AddChild(new Label { String = I18n.Menu_Button_Cancel(), LocalPosition = new Vector2(175, 650), Callback = e => Game1.exitActiveMenu() }); this.Ui.AddChild(new Label { String = I18n.Menu_Button_Accept(), LocalPosition = new Vector2(500, 650), Callback = e => this.DoMarriage() }); }
public MarryMenu() : base((Game1.uiViewport.Width - 800) / 2, (Game1.uiViewport.Height - 700) / 2, 800, 700) { var valid = new List <NPC>(); foreach (var npc in Utility.getAllCharacters()) { if (npc.datable.Value && npc.getSpouse() == null) { valid.Add(npc); } } valid.Sort((a, b) => a.Name.CompareTo(b.Name)); /* * for ( int i = 0; i < valid.Count; ++i ) * { * int oi = Game1.random.Next( valid.Count ); * var other = valid[ oi ]; * valid[ oi ] = valid[ i ]; * valid[ i ] = other; * } */ ui = new RootElement() { LocalPosition = new Vector2(xPositionOnScreen, yPositionOnScreen), }; var title = new Label() { String = Mod.instance.Helper.Translation.Get("menu.title"), Bold = true, }; title.LocalPosition = new Vector2((800 - title.Measure().X) / 2, 10); ui.AddChild(title); ui.AddChild(new Label() { String = Mod.instance.Helper.Translation.Get("menu.text").ToString().Replace("\\n", "\n"), LocalPosition = new Vector2(50, 75), NonBoldScale = 0.75f, NonBoldShadow = false, }); table = new Table() { RowHeight = 200, Size = new Vector2(700, 500), LocalPosition = new Vector2(50, 225), }; for (int i = 0; i < (valid.Count + 2) / 3; ++i) { var row = new StaticContainer(); for (int n_ = i * 3; n_ < (i + 1) * 3; ++n_) { if (n_ >= valid.Count) { continue; } int n = n_; var cont = new StaticContainer() { Size = new Vector2(115 * 2, 97 * 2), LocalPosition = new Vector2(250 * (n - i * 3) - 10, 0), }; // Note: This is being called 4 times for some reason // Probably a UI framework bug. Action <Element> selCallback = (e) => { if (selectedContainer != null) { selectedContainer.OutlineColor = null; } selectedContainer = cont; selectedContainer.OutlineColor = Color.Green; selectedNPC = valid[n].Name; Log.trace("Selected " + selectedNPC); }; cont.AddChild(new Image() { Texture = Game1.mouseCursors, TextureRect = new Rectangle(583, 411, 115, 97), Scale = 2, LocalPosition = new Vector2(0, 0), Callback = selCallback, }); cont.AddChild(new Image() { Texture = valid[n].Portrait, TextureRect = new Rectangle(0, 128, 64, 64), Scale = 2, LocalPosition = new Vector2(50, 16), }); var name = new Label() { String = valid[n].displayName, NonBoldScale = 0.5f, NonBoldShadow = false, }; name.LocalPosition = new Vector2(115 - name.Measure().X / 2, 160); cont.AddChild(name); row.AddChild(cont); } table.AddRow(new Element[] { row }); } ui.AddChild(table); ui.AddChild(new Label() { String = Mod.instance.Helper.Translation.Get("menu.button.cancel"), LocalPosition = new Vector2(175, 650), Callback = (e) => Game1.exitActiveMenu(), }); ui.AddChild(new Label() { String = Mod.instance.Helper.Translation.Get("menu.button.accept"), LocalPosition = new Vector2(500, 650), Callback = (e) => { DoMarriage(); } }); }