public void _on_Usables_item_activated(int index) { Usable.Type type = (Usable.Type)index; Player.UsableSelected = type; ToolBar.SendRefresh(); Delay.StartDelay(this, 0.1f, () => Close(PlayerState.State.Normal)); }
/// Verifie si il y a assez de blocks du type type public bool CanRemove(Usable.Type type, int amount) { if (Usable.category[(int)type] == Usable.Category.Tool) { return(false); } return(stokage[type] - amount >= 0); }
/// Verifie si il n'y a pas trop de blocks public bool CanAdd(Usable.Type type, int amount) { if (Usable.category[(int)type] == Usable.Category.Tool) { return(false); } return(GetCount() + amount <= max); }
/// Ajoute des blocks dans le stokage public bool Add(Usable.Type type, int amount) { if (CanAdd(type, amount)) { stokage[type] += amount; return(true); } return(false); }
/// Enleve des blocks de le stokage public bool Remove(Usable.Type type, int amount) { if (CanRemove(type, amount)) { stokage[type] -= amount; return(true); } return(false); }
public void _on_BlocksList_item_selected(int index) { Usable.Type type = (Usable.Type)Enum.Parse(typeof(Usable.Type), blocksSelector.GetItemText(index)); if (Usable.category[(int)type] == Usable.Category.Block) { SetDescription(type); blockSelected = type; RefreshBtnCompact(); } }
private void InitBlocksSelector() { blocksSelector.Clear(); for (int i = 0; i < Usable.nbUsables; i++) { Usable.Type type = (Usable.Type)i; if (Usable.category[(int)type] == Usable.Category.Block) { blocksSelector.AddItem(type.ToString(), Usable.textures[(int)type]); } } }
private void SetDescription(Usable.Type type) { imageDesc.Texture = Usable.textures[(int)type]; titleDesc.Text = type.ToString(); energyDesc.Text = "-> " + Usable.energyToCreat[type] + "e"; descriptionDesc.Text = "Health : " + Block.durabilities[Usable.blocks[type]]; ClearItemsList(); foreach (var loot in Usable.crafts[type].loots) { Control it = (Control)itemBox.Instance(); it.GetNode <TextureRect>("img").Texture = Item.textures[(int)loot.type]; it.GetNode <Label>("texte").Text = Player.inventoryItems.GetItemCount(loot.type) + "/" + loot.amount; itemListDesc.AddChild(it); } }
public static void Revive() { if (health <= 0) { FillHealth(); FillOxygene(); FillEnergy(); inventoryUsables = new StorageUsables(inventoryUsablesSize); inventoryItems = new StorageItems(inventoryItemsSize); inventoryLiquids = new StorageLiquids(inventoryLiquidsSize); inventoryBuildings = new StorageBuildings(inventoryBuildingsSize); UsableSelected = Usable.Type.Laser; BuildingSelected = Building.Type.SolarPanel; PlayerMouvements.Teleport(World.spawn.x, World.spawn.y); PlayerMouvements.canMove = true; } }
private void NormalState() { Usable.Type type = Player.UsableSelected; Usable.Category cat = Usable.category[(int)type]; if (cat == Usable.Category.Block) { World.UIBlockTilemap.Clear(); int amount = Player.inventoryUsables.GetItemCount(type); bool canPlace = PlaceBlock.CanPlace((int)mousePos.x, (int)mousePos.y, out canPlace); if (amount > 0 && canPlace && MouseInRange(9, false)) { World.UIBlockTilemap.SetCell((int)mousePos.x, -(int)mousePos.y + Chunk.height, 1); } else { World.UIBlockTilemap.SetCell((int)mousePos.x, -(int)mousePos.y + Chunk.height, 0); } } }
private void ClickNormalState() { Usable.Type type = Player.UsableSelected; Usable.Category cat = Usable.category[(int)type]; if (MouseInRange(9, false)) { if (cat == Usable.Category.Block) { int amount = Player.inventoryUsables.GetItemCount(type); if (amount > 0) { bool succeed = PlaceBlock.Place((int)mousePos.x, (int)mousePos.y, Usable.blocks[type]); if (succeed) { Player.inventoryUsables.Remove(type, 1); if (ToolBar.GetInstance() != null) { ToolBar.SendRefresh(); } } } } } }
/// Recupere le nombre d'item du type type dans le stokage public float GetItemCount(Usable.Type type) { return(stokage[type]); }
public override void _Process(float delta) { if (!playerInputActive) { return; } if (lastState != PlayerState.GetState() || lastSelectedUsable != Player.UsableSelected) { World.UIBlockTilemap.Clear(); lastSelectedUsable = Player.UsableSelected; lastState = PlayerState.GetState(); } mousePos = Convertion.Location2WorldFloor(GetGlobalMousePosition()); //Affichage if (PlayerState.GetState() == PlayerState.State.Normal) { NormalState(); } else if (PlayerState.GetState() == PlayerState.State.Build) { BuildState(); } /* Inventory Click */ if (Input.IsActionJustPressed("inventory")) { InventoryClick(); } /*Escape*/ if (Input.IsActionJustPressed("escape")) { if (PlayerState.GetState() == PlayerState.State.Pause) { PlayerState.SetState(PlayerState.prec_state); PauseMenu.Close(); } else if (PlayerState.GetState() == PlayerState.State.Normal) { PlayerState.SetState(PlayerState.State.Pause); PauseMenu.Open(); } else if (PlayerState.GetState() == PlayerState.State.Inventory) { UI_PlayerInventory2.Close(); } else if (PlayerState.GetState() == PlayerState.State.Build) { PlayerState.SetState(PlayerState.State.Normal); } else if (PlayerState.GetState() == PlayerState.State.BuildingInterface) { BuildingInterface.CloseInterface(); } else if (PlayerState.GetState() == PlayerState.State.Link) { Link._Link(); Link.Reset(); PlayerState.SetState(PlayerState.State.Normal); } } //Inputs if (Input.IsActionJustPressed("mouse1")) { if (PlayerState.GetState() == PlayerState.State.Normal) { ClickNormalState(); } else if (PlayerState.GetState() == PlayerState.State.Build) { ClickBuildState(); } if (PlayerState.GetState() == PlayerState.State.Normal || PlayerState.GetState() == PlayerState.State.Build || PlayerState.GetState() == PlayerState.State.BuildingInterface) { if (Building.HasBuildingSelected) { ClickOnBuilding(); } if (SpaceShip.ShipSelected) { SpaceShipClick(); } } if (PlayerState.GetState() == PlayerState.State.Link) { if (Building.HasBuildingSelected) { ClickOnBuilding2Link(); } } } }