static MainMenu() { background = new GUIBox(Engine.MainWindow, new Color(0.03f, 0.78f, 0.77f), Vector2.zero, 0.7f, 1f, 1) { Enabled = false, Pivot = Pivot.Center }; continueButton = new GUIBox(Engine.MainWindow, new Color(0, 0.38f, 0.38f), new Vector2(0, 0.1f), 0.6f, 0.15f, 2) { Enabled = false, Pivot = Pivot.Center, Parent = background }; continueButton.Clicked += i => Enabled = false; continueButtonText = new GUIText(Engine.MainWindow, Color.Red, Vector2.zero, 0.55f, 0.1f, 3, new Font(@"Resources\Fonts\Impact\impact.fnt"), "Continue") { Enabled = false, Clickable = false, Pivot = Pivot.Center, Parent = continueButton }; exitButton = new GUIBox(Engine.MainWindow, new Color(0.5f, 0.38f, 0.38f), new Vector2(0, -0.1f), 0.6f, 0.15f, 2) { Enabled = false, Pivot = Pivot.Center, Parent = background }; exitButton.Clicked += i => Glfw.SetWindowShouldClose(Engine.MainWindow.GlfwWindow, 1); exitButtonText = new GUIText(Engine.MainWindow, Color.Black, Vector2.zero, 0.55f, 0.1f, 3, new Font(@"Resources\Fonts\Tnr\tnr.fnt"), "Exit") { Enabled = false, Clickable = false, Pivot = Pivot.Center, Parent = exitButton }; }
private void Initialize() { floatingSlot = new GUIFloatingSlot { ZAsRelative = true, ZIndex = FLOATING_SLOT_Z }; // this is rather ad-hoc and in general unsafe without thinking about how the slots are synchronized with the inventory // TODO: short-term think of a better solution here // TODO: long-term think of a better slot sync scheme bool offerToMainInventory(ItemStack iStack) { SaveSlotState(); bool result = subInventories[iStack.Item.IType].TryAddItemStack(iStack); UpdateSlots(); return(result); } handSlot = new GUIInventorySlot(floatingSlot, Item.ItemType.ANY, -2, HAND_SLOT_OFFSET, offerToMainInventory) { ZAsRelative = true, ZIndex = HAND_SLOT_Z }; foreach (Item.ItemType type in new List <Item.ItemType>(subInvSlots.Keys)) { Vector2 empty = new Vector2(); subInvSlots[type] = new GUILabeledSlotArray(floatingSlot, type, subInventoryNames[type], SLOT_COUNT, empty, empty, iStack => handSlot.OfferItemStack(iStack) == null) { ZAsRelative = true, ZIndex = ARRAY_SLOT_Z }; } box = new GUIBox(GetViewportDimensions() / 2, BOX_SIZE) { ZAsRelative = true, ZIndex = BOX_Z }; AddChild(box); foreach (GUILabeledSlotArray slotArr in subInvSlots.Values) { box.AddChild(slotArr); } box.AddChild(handSlot); AddChild(floatingSlot); }
// TOOD: inventory / GUI synchronization is a mess // rewrite it (shouldn't change too much, // mainly SaveSlots() and UpdateSlots() methods and immediate neighbours) // using delegates / lambdas / anonymous functions / whatever your favorite term is private void Initialize() { Hide(); Vector2 empty = new Vector2(); bool offerToMainInventory(ItemStack iStack) { SaveSlotState(); bool result = subInventories[iStack.Item.IType].TryAddItemStack(iStack); UpdateSlots(); return(result); } floatingSlot = new GUIFloatingSlot(); inSlotArray = new GUIInventorySlotArray(floatingSlot, Item.ItemType.ANY, IN_SLOT_COUNT, empty, offerToMainInventory, () => inSlotArray.SaveToInventory(defossiliser.InInventory)); progressBar = new GUIVerticalBar(empty, PROGRESS_BAR_HEIGHT, new Color(0, 0.6f, 0)); progressBar.Rotate(Mathf.PI); outSlotArray = new GUIInventorySlotArray(floatingSlot, Item.ItemType.ANY, OUT_SLOT_COUNT, empty, offerToMainInventory, () => outSlotArray.SaveToInventory(defossiliser.OutInventory)); bool offerToInputInventory(ItemStack iStack) { SaveSlotState(); bool result = defossiliser.InInventory.TryAddItemStack(iStack); UpdateSlots(); return(result); } foreach (Item.ItemType type in new List <Item.ItemType>(subArrays.Keys)) { subArrays[type] = new GUILabeledSlotArray(floatingSlot, type, subInventoryNames[type], INVENTORY_SLOT_COUNT, empty, empty, offerToInputInventory); } box = new GUIBox(this.GetViewportDimensions() / 2, BOX_SIZE); AddChild(box); foreach (GUILabeledSlotArray slotArr in subArrays.Values) { box.AddChild(slotArr); } box.AddChild(inSlotArray); box.AddChild(progressBar); box.AddChild(outSlotArray); AddChild(floatingSlot); }
public void SetType( string guiName, GUIEditObject.GUITypes guiType ) { // create based on type if ( guiType == GUITypes.Screen ) { guiScreen = new GUIScreen(); guiScreen.name = guiName; } if ( guiType == GUITypes.Area ) { guiObject = new GUIArea(); guiObject.name = guiName; } if ( guiType == GUITypes.Label ) { guiObject = new GUILabel(); guiObject.name = guiName; } if ( guiType == GUITypes.Button ) { guiObject = new GUIButton(); guiObject.name = guiName; } if ( guiType == GUITypes.Horizontal ) { guiObject = new GUIHorizontalCommand(); guiObject.name = guiName; } if ( guiType == GUITypes.Vertical ) { guiObject = new GUIVerticalCommand(); guiObject.name = guiName; } if ( guiType == GUITypes.Scrollview ) { guiObject = new GUIScrollView(); guiObject.name = guiName; } if ( guiType == GUITypes.Toggle ) { guiObject = new GUIToggle(); guiObject.name = guiName; } if ( guiType == GUITypes.Space ) { guiObject = new GUISpace(); guiObject.name = guiName; } if ( guiType == GUITypes.EditBox ) { guiObject = new GUIEditbox(); guiObject.name = guiName; } if ( guiType == GUITypes.Box ) { guiObject = new GUIBox(); guiObject.name = guiName; } if ( guiType == GUITypes.HorizontalSlider ) { guiObject = new GUIHorizontalSlider(); guiObject.name = guiName; } if ( guiType == GUITypes.VerticalSlider ) { guiObject = new GUIVerticalSlider(); guiObject.name = guiName; } if ( guiType == GUITypes.Movie ) { guiObject = new GUIMovie(); guiObject.name = guiName; } }