Sell menu finished
This commit is contained in:
parent
a1c6216e1f
commit
a83c7bcf91
3
.gitignore
vendored
3
.gitignore
vendored
|
|
@ -4,4 +4,5 @@
|
|||
/Logs/*
|
||||
/UserSettings/*
|
||||
/.vscode/*
|
||||
*.csproj
|
||||
*.csproj
|
||||
*.sln
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -513,6 +513,26 @@ public class DBmanager : MonoBehaviour
|
|||
OnStateChanged.Invoke();
|
||||
}
|
||||
|
||||
public async static void RemoveInventoryItem(string item)
|
||||
{
|
||||
InventoryEntry itemToRemove = null;
|
||||
|
||||
foreach(InventoryEntry entry in inventory){
|
||||
if(entry.Item == item){
|
||||
itemToRemove = entry;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(itemToRemove!=null){
|
||||
inventory.Remove(itemToRemove);
|
||||
}else{
|
||||
Debug.LogError("No entry to remove from inventory");
|
||||
}
|
||||
|
||||
await UpdateInventoryToServer();
|
||||
OnStateChanged.Invoke();
|
||||
}
|
||||
|
||||
|
||||
public async static Task UpdateInventoryToServer()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -14,6 +14,10 @@ public class SellMenu : MonoBehaviour
|
|||
public Transform inventoryParent;
|
||||
public Sprite emptySlotImage;
|
||||
|
||||
public Image selectedItemImg;
|
||||
public string selectedItem;
|
||||
|
||||
public Button sellBtn;
|
||||
[Header("Your Request Material Setter")]
|
||||
public GameObject yourReqPopup;
|
||||
public TMP_InputField coinsInput;
|
||||
|
|
@ -24,7 +28,13 @@ public class SellMenu : MonoBehaviour
|
|||
public int gemsAmount;
|
||||
public int oxygenAmount;
|
||||
public int metalAmount;
|
||||
public Image selectedItemImg;
|
||||
public Sprite coinsIcon;
|
||||
public Sprite gemsIcon;
|
||||
public Sprite metalsIcon;
|
||||
public Sprite oxygenIcon;
|
||||
public Sprite addIcon;
|
||||
public Transform resourceIconsParent;
|
||||
|
||||
void Start()
|
||||
{
|
||||
Refresh();
|
||||
|
|
@ -64,24 +74,107 @@ public class SellMenu : MonoBehaviour
|
|||
inventorySlots[i].interactable=false;
|
||||
}
|
||||
}
|
||||
|
||||
if(resourceIconsParent.childCount < 4){
|
||||
Debug.LogError("Not enough buttons for your req section!");
|
||||
return;
|
||||
}
|
||||
int btnIndex = 0;
|
||||
if(coinsAmount > 0){
|
||||
SetResourceSlot(btnIndex, coinsIcon, coinsAmount.ToString());
|
||||
btnIndex++;
|
||||
}else{
|
||||
SetResourceSlot(btnIndex, addIcon, "");
|
||||
}
|
||||
if(gemsAmount > 0){
|
||||
SetResourceSlot(btnIndex, gemsIcon, gemsAmount.ToString());
|
||||
btnIndex++;
|
||||
}else{
|
||||
SetResourceSlot(btnIndex, addIcon, "");
|
||||
}
|
||||
if(metalAmount > 0){
|
||||
SetResourceSlot(btnIndex, metalsIcon, metalAmount.ToString());
|
||||
btnIndex++;
|
||||
}else{
|
||||
SetResourceSlot(btnIndex, addIcon, "");
|
||||
}
|
||||
if(oxygenAmount > 0){
|
||||
SetResourceSlot(btnIndex, oxygenIcon, oxygenAmount.ToString());
|
||||
btnIndex++;
|
||||
}else{
|
||||
SetResourceSlot(btnIndex, addIcon, "");
|
||||
}
|
||||
|
||||
|
||||
for(int i = btnIndex; i < 4; i++){
|
||||
SetResourceSlot(i, addIcon, "");
|
||||
}
|
||||
|
||||
sellBtn.interactable = (btnIndex > 0 && selectedItemImg.sprite != addIcon);
|
||||
}
|
||||
|
||||
void SetResourceSlot(int btnIndex,Sprite icon, string text){
|
||||
|
||||
resourceIconsParent.GetChild(btnIndex).GetChild(0).GetComponent<Image>().sprite = icon;
|
||||
resourceIconsParent.GetChild(btnIndex).GetComponentInChildren<TMP_Text>(true).text = text;
|
||||
|
||||
resourceIconsParent.GetChild(btnIndex).GetComponentInChildren<TMP_Text>(true).gameObject.SetActive((text.Length > 0));
|
||||
|
||||
}
|
||||
|
||||
public void ShowMaterialAmountSetter(){
|
||||
|
||||
// Clear();
|
||||
|
||||
metalInput.text = metalAmount.ToString();
|
||||
oxygenInput.text = oxygenAmount.ToString();
|
||||
coinsInput.text = coinsAmount.ToString();
|
||||
gemsInput.text = gemsAmount.ToString();
|
||||
|
||||
yourReqPopup.gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void OnSetClicked(){
|
||||
try{
|
||||
metalAmount = int.Parse(metalInput.text);
|
||||
oxygenAmount= int.Parse(oxygenInput.text);
|
||||
coinsAmount = int.Parse(coinsInput.text);
|
||||
gemsAmount = int.Parse(gemsInput.text);
|
||||
}catch{
|
||||
|
||||
}
|
||||
|
||||
yourReqPopup.gameObject.SetActive(false);
|
||||
Refresh();
|
||||
}
|
||||
|
||||
public void OpenSellMenu(){
|
||||
Clear();
|
||||
gameObject.SetActive(true);
|
||||
}
|
||||
|
||||
public void CloseSellMenu(){
|
||||
gameObject.SetActive(false);
|
||||
|
||||
Clear();
|
||||
}
|
||||
|
||||
|
||||
public void Clear(){
|
||||
metalAmount = coinsAmount = oxygenAmount = gemsAmount = 0;
|
||||
selectedItemImg.sprite = addIcon;
|
||||
selectedItem = "";
|
||||
// selected
|
||||
Refresh();
|
||||
}
|
||||
public void selectInventoryItem(InventoryItem item){
|
||||
selectedItemImg.sprite = item.image;
|
||||
selectedItem = item.itemName;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
|
||||
public void Sell(){
|
||||
DBmanager.RemoveInventoryItem(selectedItem);
|
||||
Clear();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user