public void SetWithID() { trans = transform; RawImage image = GetComponentInChildren <RawImage>(); image.texture = IItemAsset.LoadTexture(indentification); }
private void InterfaceMinUpdate() { bool sp = character.status.canUseRunes; spellButton.enabled = character.status.rune > -1 && sp; SetTextWithScales(characterInfoText, character.status.GetAllInfo()); spellButton.texture = IItemAsset.LoadTexture(character.status.rune); for (int i = 0; i < runeStats.Length; i++) { string path = "Sprites/UI/Magicka"; if (i < character.status.spellsToday) { path = path + "Active"; } runeStats[i].texture = (Texture)Resources.Load(path); } for (int i = 0; i < armorStats.Length; i++) { string path = "Sprites/UI/Armor"; if (i < character.status.armorProtection) { path = path + "Active"; } armorStats[i].texture = (Texture)Resources.Load(path); } int[] items = character.status.items; bool cur = currentLookableItemIndex > -1 && currentLookableItemIndex < items.Length; inventoryFunctionsLabel.SetActive(cur); if (cur) { IItem current = IItemAsset.items [items [currentLookableItemIndex]]; string t = current.Info(); SetTextWithScales(itemsInfo, t); } else { SetTextWithScales(itemsInfo, "-"); } }
private void OnGUI() { IItem[] basicItems = LoadBasicItems(); if (Exist()) { if (GUILayout.Button("LoadFromFile")) { items = LoadSaved(); } } using (EditorGUILayout.ScrollViewScope s = new EditorGUILayout.ScrollViewScope(scroll)) { scroll = s.scrollPosition; GUILayout.Label("Basic items : "); for (int i = 0; i < basicItems.Length; i++) { GUILayout.Box("" + '\n' + basicItems [i].name); GUILayout.Box(IItemAsset.LoadTexture(IItemAsset.GetIDByName(basicItems[i].name))); GUILayout.Label(basicItems [i].intro); GUILayout.Label("Cost : " + basicItems [i].sellCount); GUILayout.Label("ID : " + i); GUILayout.Label("Type : " + basicItems [i].type); GUILayout.Label("Value : " + basicItems [i].value); } GUILayout.Label("" + '\n' + "Available to edit items : " + '\n'); if (GUILayout.Button("Add item")) { AddItem(); } for (int i = 0; i < items.Length; i++) { items [i].name = EditorGUILayout.TextField("Item name", items [i].name); items [i].intro = EditorGUILayout.TextArea(items [i].intro); items [i].sellCount = EditorGUILayout.IntField("Item cost", items [i].sellCount); items [i].value = EditorGUILayout.IntField("Item value", items [i].value); items [i].type = (IItemType)EditorGUILayout.EnumPopup(items [i].type); if (GUILayout.Button("Remove item")) { RemoveItem(i); } } } if (GUILayout.Button("Save items")) { Save(); } }
public InventorySlot[] FillItemsTo(RectTransform parent, int[] items) { GameObject prefab = (GameObject)Resources.Load("Prefabs/Slot"); Button[] buttons = parent.GetComponentsInChildren <Button>(); for (int i = 0; i < buttons.Length; i++) { Destroy(buttons[i].gameObject); } List <InventorySlot> bts = new List <InventorySlot> (); List <int> has = new List <int> (); List <ISlot> upd = new List <ISlot> (); for (int i = 0; i < items.Length; i++) { if (!HasInt(has.ToArray(), items[i])) { upd.Add(new ISlot(items [i])); has.Add(items [i]); } else { int index = -1; for (int n = 0; n < upd.Count; n++) { if (upd[n].id == items[i]) { index = n; break; } } if (index > -1) { upd [index].Add(); } } } float slotSize = prefab.GetComponent <RectTransform>().rect.height; for (int i = 0; i < upd.Count; i++) { RectTransform trans = ((GameObject)Instantiate(prefab)).GetComponent <RectTransform> (); trans.SetParent(parent); trans.anchoredPosition = -Vector2.up * slotSize * i; trans.GetComponentInChildren <RawImage>().texture = IItemAsset.LoadTexture(upd[i].id); string num = ""; if (upd[i].count > 1) { num = "(" + upd [i].count + ")"; } Text t = trans.GetComponentInChildren <Text> (); IFontSetter.SetFont(t); t.text = IItemAsset.items[upd[i].id].name + num; trans.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, parent.rect.width); Button bt = trans.GetComponent <Button>(); Color c = Color.white; if (!character.status.CanUseItem(upd[i].id)) { c = new Color(1f, 0.5f, 0.5f); } bt.image.color = c; bts.Add(new InventorySlot(upd[i].id, bt)); } parent.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, slotSize * upd.Count); return(bts.ToArray()); }
private void InterfaceMotor() { bool haveToMinUpdate = false; if (MyDebug.haveToUpdate && MyDebug.messages.Count > 0) { SetTextWithScales(messagesText, MyDebug.messages[MyDebug.messages.Count - 1].message); MyDebug.haveToUpdate = false; messagesText.color = MyDebug.messages [MyDebug.messages.Count - 1].color; } if (state != IGameMenuState.Runtime) { drag = false; } if (!toGameImage) { toGameImage = toGame.image; } runtimeTalk.image.enabled = character.canTalk; toGameImage.enabled = (state != IGameMenuState.Runtime && state != IGameMenuState.Dialog); IUsable can = character.canUse; if (useCheck != (can != null)) { CheckUse(can); } int[] items = character.status.items; //float delta = Mathf.Abs(slotsParent.rect.height - slotsMask.rect.height); //slotsParent.anchoredPosition = Vector2.up * delta * inventoryScroll.value; if (!currentItems.Equals(items)) { if (lootableChest) { PrepareLootItems(lootableChest); } InventorySlot[] buttons = FillItemsTo(slotsParent, items); for (int i = 0; i < buttons.Length; i++) { int index = i; Button bt = buttons [i].button; bt.onClick.RemoveAllListeners(); bt.onClick.AddListener(delegate { currentLookableItemIndex = character.status.GetItemByID(buttons[index].id); }); } amuletInv.GetComponentInChildren <RawImage> ().texture = IItemAsset.LoadTexture(character.status.amulet); armorInv.GetComponentInChildren <RawImage> ().texture = IItemAsset.LoadTexture(character.status.armor); weapontInv.GetComponentInChildren <RawImage> ().texture = IItemAsset.LoadTexture(character.status.weapon); runeInv.GetComponentInChildren <RawImage> ().texture = IItemAsset.LoadTexture(character.status.rune); int ru = character.status.rune; ICharacter ch = character; amuletInv.onClick.RemoveAllListeners(); amuletInv.onClick.AddListener(delegate { ch.BackToInv(IItemType.Amulet); }); armorInv.onClick.RemoveAllListeners(); armorInv.onClick.AddListener(delegate { ch.BackToInv(IItemType.Armor); }); weapontInv.onClick.RemoveAllListeners(); weapontInv.onClick.AddListener(delegate { ch.BackToInv(IItemType.Weapon); }); runeInv.onClick.RemoveAllListeners(); runeInv.onClick.AddListener(delegate { if (ru > -1) { ch.BackToInv(IItemAsset.items[ru].type); } }); currentItems = items; haveToMinUpdate = true; } if (probeIndexLookable != currentLookableItemIndex) { int index = currentLookableItemIndex; use.onClick.RemoveAllListeners(); use.onClick.AddListener(delegate { UseItem(index); }); drop.onClick.RemoveAllListeners(); drop.onClick.AddListener(delegate { Drop(index); }); probeIndexLookable = currentLookableItemIndex; haveToMinUpdate = true; } if (haveToMinUpdate) { InterfaceMinUpdate(); } }
private void PrepareToStart() { fontSize.onValueChanged.RemoveAllListeners(); fontSize.onValueChanged.AddListener(delegate { int v = 11 + (int)(fontSize.value * 15); fontSize.GetComponentInChildren <Text>().text = "Размер шрифта : " + v; settings.fontSize = v; IFontSetter.SetFontForall(); }); removeButton.onClick.RemoveAllListeners(); removeButton.onClick.AddListener(delegate { RemoveGame(); CloseRemoveMenu(); Start(); }); cancelRemoveButton.onClick.RemoveAllListeners(); cancelRemoveButton.onClick.AddListener(delegate { CloseRemoveMenu(); }); for (int i = 0; i < removeGame.Length; i++) { int index = i; removeGame [i].onClick.RemoveAllListeners(); removeGame [i].onClick.AddListener(delegate { toRemoveIndex = index; OpenRemoveMenu(); } ); removeGame [i].gameObject.SetActive(IGame.Exist(index)); } for (int i = 0; i < loadGame.Length; i++) { loadGame[i].onClick.RemoveAllListeners(); int index = i; loadGame[i].onClick.AddListener(delegate { LoadGameFromSlot(index); }); string st = "> Пусто <"; if (IGame.Exist(i)) { IGame loaded = IGame.Load(i); st = ((IStatus)loaded.FindByName("Player")).characterName + " : " + loaded.date.ToLongDateString() + " " + loaded.date.ToLongTimeString(); } RawImage img = loadGame [i].GetComponentInChildren <RawImage> (); if (IGame.Exist(i)) { img.texture = IGame.LoadPicture(i); } else { img.texture = IItemAsset.LoadTexture(-1); } loadGame [i].GetComponentInChildren <Text> ().text = st; } for (int i = 0; i < stateControls.Length; i++) { stateControls[i].onClick.RemoveAllListeners(); int index = i; stateControls[i].onClick.AddListener(delegate { state = (MainMenuState)index; SetState(); }); } for (int i = 0; i < startNew.Length; i++) { string text = "Новый персонаж"; startNew[i].onClick.RemoveAllListeners(); if (IGame.Exist(i)) { text = "Слот занят"; } else { int index = i; startNew[i].onClick.AddListener(delegate { LoadCreateScene(index); }); } startNew [i].GetComponentInChildren <Text> ().text = text; } for (int i = 0; i < backControls.Length; i++) { backControls[i].onClick.RemoveAllListeners(); backControls[i].onClick.AddListener(delegate { if (state == MainMenuState.Opts) { SaveSettings(); } state = MainMenuState.Main; SetState(); }); } }