public void Initialize(Vector2 northPole) { Vector2 empty = new Vector2(); foreach (KeyValuePair <Player.Stats, Color> kvPair in STAT_BAR_COLORS) { Player.Stats stat = kvPair.Key; statBars[stat] = new GUIVerticalBar(empty, BAR_LENGTH, kvPair.Value, () => player[stat], () => player[stat] < STAT_LEVEL_MAX_SHOW[stat]); AddChild(statBars[stat]); Sprite sprite = STAT_BAR_SPRITES[stat](); sprite.Scale = ICON_SCALE; sprite.Position = ICON_OFFSET; statBars[stat].AddChild(sprite); } foreach (KeyValuePair <Gas, Color> kvPair in GAS_BAR_COLORS) { Gas g = kvPair.Key; gasBars[g] = new GUIHorizontalBar(empty, ATM_BAR_LENGTH, kvPair.Value, () => atm.GetGasProgress(g), () => atm.GetGasProgress(g) > 0 && atm.GetGasProgress(g) < 1); AddChild(gasBars[g]); } // debugSheet = new GUIBox(empty, COMPASS_SIZE); // AddChild(debugSheet); compass = new GUICompass(empty, COMPASS_SIZE, northPole, () => new Vector2(player.Translation.x, player.Translation.z) / Block.SIZE, viewDirSupplier, () => (player.Translation / Block.SIZE - northMonopole).LengthSquared() >= MIN_RADIUS_FOR_COMPASS * MIN_RADIUS_FOR_COMPASS); AddChild(compass); // hacky, works for now, TODO: fix inHandLabel = new GUILabel(() => { bool showLabel = !BackgroundMode && player.ItemInHand != null; if (showLabel) { inHandLabel.Text = "Currently in hand: " + player.ItemInHand.Item.Name + ", Quantity : " + player.ItemInHand.Count; } return(showLabel); }); AddChild(inHandLabel); Texture tex = Game.guiResourceLoader.GetResource(CROSSHAIR_TEX) as Texture; crosshair = new GUIObject(empty, tex.GetSize(), tex, () => !BackgroundMode); AddChild(crosshair); Visible = true; }
// 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); }