void Paste(object obj) { int i = (int)obj; NewItem itm = ItemEditor.CopiedItem; GearSlotAttribute attr = itm.GetAttribute <GearSlotAttribute>(); if (attr == null) { Debug.LogWarning("This Item lack GearSlot Attribute and cannot be added to the Gear slot"); } else { WeaponAttribute weaponAttr = itm.GetAttribute <WeaponAttribute>(); bool weaponCancel = false; if (weaponAttr) { if (!stats.CanEquipWeapons.Contains((int)weaponAttr.WeaponType)) { weaponCancel = true; } } //Add to a slot if (attr.PossibleSlots[i] && !weaponCancel) { Undo.RecordObject(UndoObj, "Modify Stats"); stats.Gear.Equip(itm, i, null); } else { Debug.LogWarning("This items GearSlot attribute does not allow this slot!"); } } RefreshDictionary(); }
private void OpenMiniMenuInventory(NewItem itm) { List <ButtonArgument> buttonArguments = new List <ButtonArgument>(); onCancelActions.Remove(DropDownMenu.Hide); onCancelActions.Add(DropDownMenu.Hide); if (itm.GetAttribute <UseAttribute>() != null) { ButtonArgument UseArgument = new ButtonArgument("Use"); UseArgument.onClickCallback.Add(() => DropDownMenu.Hide()); UseArgument.onClickCallback.Add(() => itm.GetAttribute <UseAttribute>().Use(TurnManager.currentCharacter)); if (itm.GetAttribute <UseAttribute>().destoryOnUse) { UseArgument.onClickCallback.Add(() => inventory.DepleteItem(itm)); } UseArgument.onClickCallback.Add(() => GenerateUI()); UseArgument.onClickCallback.Add(() => UpdateStatLabels()); buttonArguments.Add(UseArgument); } if (itm.GetAttribute <GearSlotAttribute>() != null) { ButtonArgument GearArgument = new ButtonArgument("Equip"); WeaponAttribute weaponAttr = itm.GetAttribute <WeaponAttribute>(); if (weaponAttr) { GearArgument.Interactable = TurnManager.currentCharacter.stats.CanEquipWeapons.Contains((int)weaponAttr.WeaponType) ? true : false; } GearArgument.onClickCallback.Add(() => DropDownMenu.Hide()); GearArgument.onClickCallback.Add(() => gear.Equip(itm, inventory)); GearArgument.onClickCallback.Add(() => UpdateStatLabels()); GearArgument.onClickCallback.Add(() => GenerateUI()); buttonArguments.Add(GearArgument); } ButtonArgument DropArgument = new ButtonArgument("Drop"); DropArgument.onClickCallback.Add(() => DropDownMenu.Hide()); DropArgument.onClickCallback.Add(() => inventory.DepleteItem(itm)); DropArgument.onClickCallback.Add(() => GenerateUI()); buttonArguments.Add(DropArgument); DropDownMenu.Initialize(buttonArguments, null); }
public void Equip(NewItem itm, Inventory inv) { int firstEquip = -1; int firstFreeEquip = -1; GearSlotAttribute attr = itm.GetAttribute <GearSlotAttribute>(); //Look for thew first open slot and unequip all future slots for (int i = 0; i < attr.PossibleSlots.Length; i++) { if (attr.PossibleSlots[i]) { if (firstEquip == -1) { firstEquip = i; } if (items[i] == null && firstFreeEquip == -1) { firstFreeEquip = i; } } } int slot = firstFreeEquip == -1 ? firstEquip : firstFreeEquip; Equip(itm, slot, inv); }
public bool Refresh() { CommonAttributes atr = stack.GetAttribute <CommonAttributes>(); if (atr) { this.image.sprite = atr.GetSprite(); } return(false); }
public void Equip(NewItem itm, int slot, Inventory inv) { GearSlotAttribute attr = itm.GetAttribute <GearSlotAttribute>(); if (attr) { //Unequip item slots for (int i = 0; i < attr.UnequipLots.Length; i++) { if (attr.UnequipLots[i]) { if (gear[i]) { Unequip(i, inv); } } } } //Unequip item that is currently in the slot if (gear[slot]) { NewItem lastItem = gear[slot]; GearSlotAttribute attrLast = lastItem.GetAttribute <GearSlotAttribute>(); for (int q = 0; q < attrLast.UnequipLots.Length; q++) { if (attr.UnequipLots[q]) { gear[q] = null; gearNames[q] = null; } } gear[slot] = null; } gear[slot] = itm; //Fill other slots for (int i = 0; i < attr.UnequipLots.Length; i++) { if (attr.UnequipLots[i]) { gearNames[i] = itm; } } if (Application.isPlaying && inv != null) { inv.DepleteItem(itm); } }
public void BuildUI(NewItem item) { DestroyChildren(); if (item == null) { return; } if (GearHelper) { GearHelper.SetActive(false); } NameField.text = item.GameName; ValueField.text = item.Value.ToString(); coinSprite.enabled = true; SpriteField.sprite = item.Sprite; SpriteField.enabled = true; DecriptionField.text = item.Description; HorizontalLayoutGroup g = BuildLine(Content.gameObject, 5); if (item.GetAttribute <WeaponAttribute>()) { BuildWeaponUI(Content.gameObject, item.GetAttribute <WeaponAttribute>()); g = BuildLine(Content.gameObject, 5); } if (item.GetAttribute <StatsAttribute>()) { BuildStatAttributeUI(Content.gameObject, item.GetAttribute <StatsAttribute>()); } if (item.GetAttribute <GearSlotAttribute>()) { BuildArmorSlotAttributeUI(Content.gameObject, item.GetAttribute <GearSlotAttribute>()); } if (item.GetAttribute <UseAttribute>()) { UseAttribute atr = item.GetAttribute <UseAttribute>(); if (atr.GetType() == typeof(Use_RecoverAttribute)) { BuildRecoveryItemUI(Content.gameObject, atr as Use_RecoverAttribute); } } }
public void SetData(NewItem stack, ButtonArgument arg = null) { this.stack = stack; onPointerEvent.RemoveAllListeners(); CommonAttributes atr = stack.GetAttribute <CommonAttributes>(); if (atr) { this.image.sprite = atr.GetSprite(); } if (arg != null) { foreach (UnityAction argument in arg.onClickCallback) { onPointerEvent.AddListener(argument); } } }
public void AddItem(NewItem itm) { CommonAttributes attr = itm.GetAttribute <CommonAttributes>(); if (attr && attr.isStackable) { int index = Items.FindIndex(a => a.item == itm); if (index != -1) { items[index].amount++; } if (items[index].amount <= 0) { items.Add(new ItemStack(itm)); } } else { items.Add(new ItemStack(itm)); } }
public void Unequip(int slot, Inventory inv) { NewItem lastItem = items[slot]; GearSlotAttribute attrLast = lastItem.GetAttribute <GearSlotAttribute>(); for (int q = 0; q < attrLast.UnequipLots.Length; q++) { if (attrLast.UnequipLots[q]) { gearNames[q] = null; } } if (Application.isPlaying && inv != null) { inv.AddItem(lastItem); } gear[slot] = null; }
public void OnGUI() { if (stats == null || UndoObj == null) { return; } EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.BeginVertical(); EditorGUILayout.LabelField("Base stats"); float baseHP = (int)EditorGUILayout.FloatField("HP", stats.BaseHP); float baseMP = (int)EditorGUILayout.FloatField("MP", stats.BaseMP); float baseAtt = (int)EditorGUILayout.FloatField("Attack", stats.BaseAttack); float baseDef = (int)EditorGUILayout.FloatField("Defence", stats.BaseDef); float baseSpeed = (int)EditorGUILayout.FloatField("Speed", stats.BaseSpeed); EditorGUILayout.EndVertical(); EditorGUILayout.BeginVertical(); stats.CalculateStats(); EditorGUILayout.LabelField("Calculated stats"); EditorGUILayout.SelectableLabel(((int)stats.CalculatedHP).ToString(), GUILayout.Height(EditorGUIUtility.singleLineHeight)); EditorGUILayout.SelectableLabel(((int)stats.CalculatedMP).ToString(), GUILayout.Height(EditorGUIUtility.singleLineHeight)); EditorGUILayout.SelectableLabel(((int)stats.CalculatedAtt).ToString(), GUILayout.Height(EditorGUIUtility.singleLineHeight)); EditorGUILayout.SelectableLabel(((int)stats.CalculatedDef).ToString(), GUILayout.Height(EditorGUIUtility.singleLineHeight)); EditorGUILayout.SelectableLabel(((int)stats.CalculatedSpeed).ToString(), GUILayout.Height(EditorGUIUtility.singleLineHeight)); EditorGUILayout.EndVertical(); EditorGUILayout.EndHorizontal(); if (EditorGUI.EndChangeCheck()) { if (UndoObj != null) { Undo.RegisterCompleteObjectUndo(UndoObj, "Modify Stats"); } stats.BaseHP = Mathf.Max(1, baseHP); stats.BaseMP = Mathf.Max(0, baseMP); stats.BaseAttack = Mathf.Max(1, baseAtt); stats.BaseDef = Mathf.Max(0, baseDef); stats.BaseSpeed = Mathf.Max(0, baseSpeed);; } for (int i = 0; i < stats.Gear.items.Length; i++) { if (stats.Gear.items[i] != null) { if (!dict.ContainsKey(i)) { RefreshDictionary(); break; } } } EditorGUILayout.Space(); EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField("Weapon Types", EditorStyles.boldLabel, GUILayout.Width(120)); if (GUILayout.Button("+", GUILayout.Width(25))) { var myEnumMemberCount = Enum.GetNames(typeof(Stats.WeaponType)).Length; GenericMenu CreateMenu = new GenericMenu(); for (int i = 0; i < myEnumMemberCount; i++) { if (!stats.CanEquipWeapons.Contains(i)) { CreateMenu.AddItem(new GUIContent(((Stats.WeaponType)i).ToString()), false, AddToEquipables, i); } } CreateMenu.ShowAsContext(); } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); int deleteIndex1 = -1; for (int i = 0; i < stats.CanEquipWeapons.Count; i++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(((Stats.WeaponType)stats.CanEquipWeapons[i]).ToString(), GUILayout.Width(75)); if (GUILayout.Button("x", GUILayout.Width(20))) { deleteIndex1 = i; } GUILayout.FlexibleSpace(); EditorGUILayout.EndHorizontal(); } if (deleteIndex1 != -1) { Undo.RecordObject(UndoObj, "Modify Stats"); stats.CanEquipWeapons.RemoveAt(deleteIndex1); } EditorGUILayout.Space(); EditorGUILayout.LabelField("Gear", EditorStyles.boldLabel); int deleteIndex = -1; for (int i = 0; i < stats.Gear.items.Length; i++) { EditorGUILayout.BeginHorizontal(); EditorGUILayout.LabelField(((Stats.GearSlots)i).ToString(), GUILayout.Width(100)); if (stats.Gear.items[i] != null || stats.Gear.Names[i] != null) { EditorGUI.BeginDisabledGroup(stats.Gear.items[i] == null); NewItem item = stats.Gear.items[i] != null ? stats.Gear.items[i] : stats.Gear.Names[i]; EditorGUILayout.BeginVertical(EditorStyles.helpBox); gearFolds[i] = EditorGUILayout.Foldout(gearFolds[i], item.ItemName); if (gearFolds[i]) { if (dict.ContainsKey(i)) { dict[i].OnInspectorGUI(); } else { RefreshDictionary(); } } EditorGUILayout.EndVertical(); if (GUILayout.Button("X", GUILayout.Width(20))) { deleteIndex = i; } EditorGUI.EndDisabledGroup(); } else { EditorGUILayout.HorizontalScope v = new EditorGUILayout.HorizontalScope(); using (v) { EditorGUILayout.HelpBox("No Gear", MessageType.Info); EditorGUI.BeginChangeCheck(); EditorGUILayout.BeginVertical(); EditorGUILayout.Space(); EditorGUILayout.Space(); int select = EditorGUILayout.Popup(0, slotItemStrings[i]); EditorGUILayout.EndVertical(); if (EditorGUI.EndChangeCheck()) { NewItem itm = slotItems[i][slotItemStrings[i][select]]; GearSlotAttribute attr = itm.GetAttribute <GearSlotAttribute>(); if (attr == null) { Debug.LogWarning("This Item lack GearSlot Attribute and cannot be added to the Gear slot"); } else { WeaponAttribute weaponAttr = itm.GetAttribute <WeaponAttribute>(); bool weaponCancel = false; if (weaponAttr) { if (!stats.CanEquipWeapons.Contains((int)weaponAttr.WeaponType)) { weaponCancel = true; Debug.LogWarning("This character cannot equip this weapon type"); } } //Add to a slot if (attr.PossibleSlots[i] && !weaponCancel) { Undo.RecordObject(UndoObj, "Modify Stats"); stats.Gear.Equip(itm, i, null); } } RefreshDictionary(); } } Event e = Event.current; if (e.isMouse && e.button == 1 && v.rect.Contains(e.mousePosition)) { GenericMenu CreateMenu = new GenericMenu(); if (ItemEditor.CopiedItem == null) { CreateMenu.AddDisabledItem(new GUIContent("Paste")); } else { CreateMenu.AddItem(new GUIContent("Paste"), false, Paste, i); } CreateMenu.ShowAsContext(); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); } if (deleteIndex != -1) { Undo.RecordObject(UndoObj, "Modify Stats"); stats.Gear.Unequip(deleteIndex, null); RefreshDictionary(); } }
private System.Collections.IEnumerator ShowDialog() { GiveItemDialog dialog = UIManager._instance.GetItemDialog(); dialog.SetData(Mission.currentMission.FindCharacter(CharacterId)._Name, itemToGive.ItemName, amount, itemToGive.GetAttribute <CommonAttributes>().GetSprite()); dialog.gameObject.SetActive(true); yield return(new WaitUntil(() => dialog.gameObject.activeSelf == false)); Done = true; }