You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
145 lines
4.8 KiB
145 lines
4.8 KiB
using System.Collections.Generic; |
|
using UnityEditor; |
|
using UnityEngine.UIElements; |
|
|
|
namespace PVSkill |
|
{ |
|
public class SkillBuffElement |
|
{ |
|
private VisualElement root; |
|
private SkillBuffConfig curSkillBuffConfig; |
|
|
|
// elem |
|
private Label buffDescLbl; |
|
private Label triggerEventLbl; |
|
private Label objectTypeLbl; |
|
private Label scopeTypeLbl; |
|
private Label gainLbl; |
|
private Label disperseLbl; |
|
private Label continuedTypeLbl; |
|
|
|
private ListView effectListView; |
|
private SkillEffectElement effectElement; |
|
|
|
public SkillBuffElement(VisualElement root) |
|
{ |
|
var visualTree = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>("Assets/Editor/SkillEditor/SkillBuffElement.uxml"); |
|
visualTree.CloneTree(root); |
|
|
|
this.root = root; |
|
this.buffDescLbl = root.Q<Label>("BuffDescLbl"); |
|
this.triggerEventLbl = root.Q<Label>("TriggerEventLbl"); |
|
this.objectTypeLbl = root.Q<Label>("ObjectTypeLbl"); |
|
this.scopeTypeLbl = root.Q<Label>("ScopeTypeLbl"); |
|
this.gainLbl = root.Q<Label>("GainLbl"); |
|
this.disperseLbl = root.Q<Label>("DisperseLbl"); |
|
this.continuedTypeLbl = root.Q<Label>("ContinuedTypeLbl"); |
|
|
|
this.effectListView = root.Q<ListView>("EffectListView"); |
|
this.effectListView.bindItem = this.BindEffectListItem; |
|
this.effectListView.makeItem = this.MakeEffectListItem; |
|
this.effectListView.onSelectionChange += this.OnEffectItemChosen; |
|
|
|
var effectInfo = root.Q<VisualElement>("EffectInfo"); |
|
this.effectElement = new SkillEffectElement(effectInfo); |
|
} |
|
|
|
private void RefreshEffectItems(int[] effects) |
|
{ |
|
if (effects == null || effects[0] == 0) |
|
{ |
|
this.effectListView.itemsSource = new List<int>(); |
|
this.effectListView.ClearSelection(); |
|
this.effectElement.Hide(); |
|
} |
|
else |
|
{ |
|
this.effectListView.itemsSource = effects; |
|
this.effectListView.selectedIndex = 0; |
|
} |
|
|
|
this.effectListView.RefreshItems(); |
|
} |
|
|
|
private void BindEffectListItem(VisualElement ve, int index) |
|
{ |
|
Label label = ve as Label; |
|
var effectId = this.curSkillBuffConfig.LinkEffect[index]; |
|
var config = SkillEffectConfigCategory.Instance.Get(effectId); |
|
label.text = SkillEditorDefines.EffectTypeMap[config.EffectConfig]; |
|
} |
|
|
|
private VisualElement MakeEffectListItem() |
|
{ |
|
var label = new Label(); |
|
// label.AddToClassList("FatherSkillLabel"); |
|
return label; |
|
} |
|
|
|
private void OnEffectItemChosen(IEnumerable<object> obj) |
|
{ |
|
foreach (object o in obj) |
|
{ |
|
int effectId = (int) o; |
|
var config = SkillEffectConfigCategory.Instance.Get(effectId); |
|
this.effectElement.SetDataByConfig(config); |
|
} |
|
} |
|
|
|
public void SetObjectType(int type) |
|
{ |
|
this.objectTypeLbl.text = SkillEditorDefines.ObjectTypeMap[type]; |
|
} |
|
|
|
public void SetTriggerEventType(int type) |
|
{ |
|
this.triggerEventLbl.text = SkillEditorDefines.TriggerEventMap[type]; |
|
} |
|
|
|
public void SetScopeType(int type) |
|
{ |
|
this.scopeTypeLbl.text = SkillEditorDefines.ScopeTypeMap[type]; |
|
} |
|
|
|
public void SetGain(int gain) |
|
{ |
|
this.gainLbl.text = SkillEditorDefines.GainMap[gain]; |
|
} |
|
|
|
public void SetDisperse(int disperse) |
|
{ |
|
this.disperseLbl.text = SkillEditorDefines.CanOrNot[disperse]; |
|
} |
|
|
|
public void SetContinuedType(int type) |
|
{ |
|
this.continuedTypeLbl.text = SkillEditorDefines.ContinuedTypeMap[type]; |
|
} |
|
|
|
public void SetDesc(string desc) |
|
{ |
|
this.buffDescLbl.text = desc; |
|
} |
|
|
|
public void Hide() |
|
{ |
|
this.root.style.display = DisplayStyle.None; |
|
} |
|
|
|
public void SetDataByConfig(SkillBuffConfig config) |
|
{ |
|
this.curSkillBuffConfig = config; |
|
this.root.style.display = DisplayStyle.Flex; |
|
this.SetDesc(config.Describe); |
|
this.SetObjectType(config.ObjectType); |
|
this.SetScopeType(config.ScopeType); |
|
this.SetTriggerEventType(config.TriggerEvent); |
|
this.SetGain(config.Gain); |
|
this.SetDisperse(config.Disperse); |
|
this.SetContinuedType(config.ContinuedType); |
|
|
|
var effects = config.LinkEffect; |
|
RefreshEffectItems(effects); |
|
} |
|
} |
|
} |