Newer
Older
DungeonShooting / DungeonShooting_Godot / src / game / ui / encyclopedia / TabCell.cs
@小李xl 小李xl on 13 Mar 2024 1 KB 制作图鉴
  1. using Godot;
  2.  
  3. namespace UI.Encyclopedia;
  4.  
  5. public class TabCell : UiCell<Encyclopedia.TabButton, TabData>
  6. {
  7. //选中时页签显示的纹理
  8. private const string SelectTexture = ResourcePath.resource_sprite_ui_encyclopedia_TabSelect_png;
  9. private static Texture2D _selectTexture;
  10.  
  11. private static Texture2D GetSelectTexture()
  12. {
  13. if (_selectTexture == null)
  14. {
  15. _selectTexture = ResourceManager.LoadTexture2D(SelectTexture);
  16. }
  17. return _selectTexture;
  18. }
  19. private float _startY;
  20. private Texture2D _originTexture;
  21. public override void OnInit()
  22. {
  23. _originTexture = CellNode.Instance.TextureNormal;
  24. }
  25.  
  26. public override void OnSetData(TabData data)
  27. {
  28. CellNode.L_Icon.Instance.Texture = ResourceManager.LoadTexture2D(data.Icon);
  29. var position = CellNode.L_Icon.Instance.Position;
  30. _startY = position.Y;
  31. }
  32.  
  33. public override void OnClick()
  34. {
  35. Grid.SelectIndex = Index;
  36. }
  37.  
  38. public override void OnSelect()
  39. {
  40. CellNode.Instance.TextureNormal = GetSelectTexture();
  41. CellNode.L_Icon.Instance.Position = new Vector2(CellNode.L_Icon.Instance.Position.X, _startY - 12);
  42. CellNode.UiPanel.SelectTab(Data.Type);
  43. }
  44.  
  45. public override void OnUnSelect()
  46. {
  47. CellNode.Instance.TextureNormal = _originTexture;
  48. CellNode.L_Icon.Instance.Position = new Vector2(CellNode.L_Icon.Instance.Position.X, _startY);
  49. }
  50. }