private void OKButton_Clicked(object sender, EventArgs e) { //// this.slot.Item = Item; // ////GUI.Windows.MessageBox mb = new GUI.Windows.MessageBox(this, "MessageBox test", "This is a test", GUI.Windows.MessageBox.ButtonOptions.OKCancel); //GUI.Windows.TextPrompt mb = new GUI.Windows.TextPrompt(this, "Text input", "Please enter text:", "default"); ////so modals don't quite work like in winforms but should do the trick in our case: ////an active modal window prevents the mouse from doing anything except in the modal window, ////effectively ensuring the code in the callback attached to the event that fires when ////the window is closed by any means is executed before any other GUI actions can happen ////for example, a callback for a yes/no box may check the result and apply an action to its owner window ////such as proceeding/not proceeding with an action or making a choice ////here we simply change the title of this window based on which button was clicked ////a different modal window may ask for a text input or for a number //mb.ModalWindowClosed += Mb_ModalWindowClosed; ////lambdas are just as good ////mb.ModalWindowClosed+= new ModalWindow.ModalWindowClosedHandler((mbx,result,owner)=> owner.Title = result == ModalWindow.DialogResult.OK ? "Clicked OK" : "Clicked Cancel"); ////this shows the modal, this MUST be the last line in the calling method unless you know what you're doing //WM.Add(mb); ////anything after this WILL execute BEFORE the modal is closed. GameObject.Item newmat = MakeRandomMat(); newmat.StackSize = 10; Player.Inventory.Prepare(); if (Player.Inventory.AddItem(newmat) == null) { Player.Inventory.Commit(); } else { Player.Inventory.Rollback(); } // slot.Item = newmat; }
void CheckItem(object sender, ItemSlot.ItemEventArgs e) { GameObject.Item i = ((e as ItemSlot.ItemEventArgs).Item as GameObject.Item); if (i == null) { e.Cancel = true; } }
ItemSlot makeslot(int id, GameObject.MapEntities.Actors.Player Player) { ItemSlot s = new ItemSlot(Player.Equipment[id]); s.X = 0; s.Y = 0; s.CanGrab = true; s.CanPut = true; s.BeforeItemChanged += new ItemSlot.ItemEventHandler((sender, e) => { GameObject.Item item = (GameObject.Item)(e as ItemSlot.ItemEventArgs).Item; if ((item as GameObject.Items.ItemEquip) == null) { e.Cancel = true; if (item == null) { Console.Write("^FF0000 No item."); } else { List <string> ToolTip = item.GetTooltip(); Console.WriteEx("^BEGINLINK " + GUI.Renderer.ColourToCode(item.NameColour) + "[" + item.GetName() + "] ^ENDLINK ^FF0000 is not a suitable item.", new List <Action> { new Action(() => { GUI.ToolTipWindow tip = new GUI.ToolTipWindow(this.WM, ToolTip, WM.MouseX, WM.MouseY, false); WM.Add(tip); }) }); } } }); s.ItemOut += new ItemSlot.ItemEventHandler((sender, e) => { int thisslot = id; GameObject.Items.ItemEquip item = (GameObject.Items.ItemEquip)(e as ItemSlot.ItemEventArgs).Item; List <string> ToolTip = item.GetTooltip(); Console.WriteEx("^BEGINLINK " + GUI.Renderer.ColourToCode(item.NameColour) + "[" + item.GetName() + "] ^ENDLINK ^FFFFFF is removed.", new List <Action> { new Action(() => { GUI.ToolTipWindow tip = new GUI.ToolTipWindow(this.WM, ToolTip, WM.MouseX, WM.MouseY, false); WM.Add(tip); }) }); Player.UnequipItem(item, thisslot); }); s.ItemIn += new ItemSlot.ItemEventHandler((sender, e) => { int thisslot = id; GameObject.Items.ItemEquip item = (GameObject.Items.ItemEquip)(e as ItemSlot.ItemEventArgs).Item; List <string> ToolTip = item.GetTooltip(); Console.WriteEx("^BEGINLINK " + GUI.Renderer.ColourToCode(item.NameColour) + "[" + item.GetName() + "] ^ENDLINK ^FFFFFF is equipped.", new List <Action> { new Action(() => { GUI.ToolTipWindow tip = new GUI.ToolTipWindow(this.WM, ToolTip, WM.MouseX, WM.MouseY, false); WM.Add(tip); }) }); Player.EquipItem(item, thisslot); }); return(s); }
public InventoryControl(GUI.WindowManager WM, Inventory Inventory, int Width = 8) { this.RowWidth = Width; int slotwidth = 40; this.Width = RowWidth * slotwidth; this.Inventory = Inventory; int Rows = (int)Math.Ceiling((float)Inventory.Items.Length / (float)RowWidth); this.Height = Rows * slotwidth; for (int y = 0; y < Rows; y++) { for (int x = 0; x < RowWidth; x++) { int i = y * RowWidth + x; ItemSlot s = new ItemSlot(Inventory.Items[i]) { X = x * slotwidth, Y = y * slotwidth, CanGrab = true, CanPut = true }; //s.BeforeItemChanged += new ItemSlot.ItemEventHandler((sender, e) => { if(((e as ItemSlot.ItemEventArgs).Item as GameObject.Item) ==null) e.Cancel=true; }); s.BeforeItemChanged += CheckItem; s.ItemOut += new ItemSlot.ItemEventHandler((sender, e) => { Inventory.Items[i] = s.Item as GameObject.Item; Inventory.Prepare(); Inventory.Changed = true; }); s.ItemIn += new ItemSlot.ItemEventHandler((sender, e) => { GameObject.Item itemin = ((e as ItemSlot.ItemEventArgs).Item as GameObject.Item); if (s.Item != null && itemin != null && itemin.CanStackWith(s.Item as GameObject.Item)) { itemin.StackSize += (s.Item as GameObject.Item).StackSize; e.Cancel = true; s.Item = itemin; WM.MouseGrab = null; Inventory.Items[i] = (s.Item as GameObject.Item); Inventory.Prepare(); Inventory.Changed = true; } else { Inventory.Prepare(); Inventory.AddItem(itemin, i); Inventory.Commit(); } }); this.AddControl(s); } } }
private void MakeNewItem() { GameObject.Item Item = MakeRandomMat(); Item = MakeRandomEquip(); Item = MakeRandomGem(); List <string> ToolTip = Item.GetTooltip(); this.slot.Item = Item; Console.WriteEx("New item is ^BEGINLINK " + Renderer.ColourToCode(Item.NameColour) + "[" + Item.GetName() + "] ^ENDLINK .^FFFFFF Click name to see more.", new List <Action> { new Action(() => { ToolTipWindow tip = new ToolTipWindow(this.WM, ToolTip, WM.MouseX, WM.MouseY, false); WM.Add(tip); }) }); }
void AddToBasket(int tab, int Index, int amount) { Tuple <GameObject.Item, int, int> SellEntry = shop.Selling[tab].Item2[Index]; GameObject.Item soldItem = (GameObject.Item)SellEntry.Item1.Clone(); int price = SellEntry.Item2 - ((int)(SellEntry.Item2 * (float)SellEntry.Item3 / 100f)); Tuple <GameObject.Item, int> removed = null; bool stacked = false; foreach (Tuple <GameObject.Item, int> lineItem in _basket) { if (lineItem.Item1.CanStackWith(soldItem)) { lineItem.Item1.StackSize += amount; stacked = true; //if stack size is below 1, mark item to remove from basket - should never happen but you never know... if (lineItem.Item1.StackSize <= 0) { removed = lineItem; } break; } } //if new item and not full yet, add to basket if (!stacked && _basket.Count <= ShopWidth) { _basket.Add(new Tuple <GameObject.Item, int>(soldItem, price)); } //remove zeroed item if (removed != null) { _basket.Remove(removed); } RefreshBasket(); }
public StatusWindow(WindowManager WM, GameObject.MapEntities.Actors.Player Player) { this.Player = Player; this.WM = WM; this.Width = 360; this.Height = 500; this.Title = "Status"; this.HPBar = new GUI.Controls.ProgressBar { DisplayLabel = true, Style = 0, Height = 16, Width = 192, Colour = new Color(255, 0, 80), X = 3, Y = 3 }; this.AddControl(HPBar); this.MPBar = new GUI.Controls.ProgressBar { DisplayLabel = true, Style = 0, Height = 16, Width = 192, Colour = new Color(25, 150, 255), X = 3, Y = 21 }; this.AddControl(MPBar); this.EXPBar = new GUI.Controls.ProgressBar { DisplayLabel = true, Style = 0, Height = 24, Width = 192, Colour = new Color(200, 100, 255), X = 3, Y = 39 }; this.AddControl(EXPBar); //all these will be moved to a separate GUI testing window someday ;_; this.OKButton = new GUI.Controls.Button("Make something!"); this.OKButton.Clicked += OKButton_Clicked; this.OKButton.Width = 128; this.OKButton.Height = 48; this.OKButton.X = 0; this.OKButton.Y = 300; this.AddControl(this.OKButton); this.slot = new ItemSlot(null); this.slot.X = 0; this.slot.Y = 49; this.slot.Y = 0; // this.Controls.Add(this.slot); GUI.Controls.TextBox box = new GUI.Controls.TextBox(); box.Height = 20; box.Width = 200; box.Y = 100; box.Y = 0; // AddControl(box); GUI.Controls.NumberBox nbox = new GUI.Controls.NumberBox(); nbox.Height = 20; nbox.Width = 200; nbox.Y = 130; nbox.Y = 0; nbox.Value = 1204; // AddControl(nbox); //// recipe = new GameObject.ItemLogic.CraftingRecipe(); GameObject.Item result = MakeRandomEquip(); GameObject.Item betterresult = (GameObject.Item)result.Clone(); betterresult.NameColour = Color.Red; GameObject.Item comp = MakeRandomMat(); GameObject.Item comp2 = MakeRandomMat(); comp.SubType = 1; comp2.SubType = 2; recipe.Components.Add(new Tuple <GameObject.Item, int>(comp, 1)); // recipe.Components.Add(new Tuple<GameObject.Item, int>(comp2, 1)); recipe.Outputs[0] = new List <GameObject.Item>() { result }; recipe.Outputs[1] = new List <GameObject.Item>() { betterresult }; recipe.Outputs[2] = new List <GameObject.Item>() { betterresult }; rs = new ItemSlot(result); rs.X = 40; rs.CanGrab = false; rs.CanPut = false; cs = new ItemSlot(comp); cs.X = 10; cs.Y = 50; cs.CanGrab = false; cs.CanPut = false; cs2 = new ItemSlot(comp2); cs2.X = 60; cs2.Y = 50; cs2.CanGrab = false; cs2.CanPut = false; GUI.Controls.Button craftb = new GUI.Controls.Button("Craft"); craftb.Y = 100; craftb.Width = 150; craftb.Height = 32; craftb.OnClick += CraftTest; GUI.Controls.TabbedView tabs = new GUI.Controls.TabbedView(); AddControl(tabs); tabs.Width = 200; tabs.AddTab("first", new List <Control>() { slot }); tabs.AddTab("second", new List <Control>() { cs, cs2, rs, craftb }); tabs.AddTab("thirddd", new List <Control>() { box }); tabs.Y = 100; tabs.Height = 152; tabs.SetActiveTab(0); // this.AddControl(Texst); }