Skip to content

Commit

Permalink
now using action metadata, actions tooltips
Browse files Browse the repository at this point in the history
  • Loading branch information
shnok committed Aug 26, 2024
1 parent f105883 commit 29e9d05
Show file tree
Hide file tree
Showing 7 changed files with 285 additions and 272 deletions.
13 changes: 9 additions & 4 deletions l2-unity/Assets/Scripts/Database/ActionNameTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.IO;
using UnityEngine;

public class ActionNameTable
public class ActionNameTable
{
private static ActionNameTable _instance;

Expand All @@ -22,10 +22,11 @@ public static ActionNameTable Instance

private Dictionary<int, ActionData> _actions;

public ActionData GetAciton(int id)
public ActionData GetAction(ActionType type)
{
return (_actions.ContainsKey(id)) ? _actions[id] : null;
return _actions.ContainsKey((int)type) ? _actions[(int)type] : null;
}

public Dictionary<int, ActionData> Actions { get { return _actions; } }

public void Initialize()
Expand Down Expand Up @@ -71,13 +72,17 @@ private void ReadActions()
case "cmd":
actionData.Name = DatUtils.CleanupString(value);
break;
case "icon":
string[] iconSplit = DatUtils.CleanupString(value).Split(".");
actionData.Icon = iconSplit.Length > 1 ? iconSplit[1] : iconSplit[0];
break;
case "name":
actionData.Descripion = DatUtils.CleanupString(value);
break;
}
}

if (_actions.ContainsKey(actionData.Id) != true)
if (!_actions.ContainsKey(actionData.Id))
{
_actions.TryAdd(actionData.Id, actionData);
}
Expand Down
10 changes: 5 additions & 5 deletions l2-unity/Assets/Scripts/Database/Model/ActionData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
using System.Xml.Linq;
using UnityEngine;

public class ActionData
public class ActionData
{
[SerializeField] public int _id;
[SerializeField] public string _name;
[SerializeField] public string _description;
[SerializeField] public string _icon;
[SerializeField] private int _id;
[SerializeField] private string _name;
[SerializeField] private string _description;
[SerializeField] private string _icon;

public int Id { get => _id; set => _id = value; }
public string Name { get => _name; set => _name = value; }
Expand Down
20 changes: 10 additions & 10 deletions l2-unity/Assets/Scripts/Game/Action/ActionType.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
public enum ActionType : int
{
Sit = 1,
WalkRun = 2,
Attack = 3,
Trade = 5,
NextTarget = 7,
Pickup = 8,
Assist = 10,
PartyInvite = 10,
PartyLeave = 12,
PartyKick = 13
Sit = 0,
WalkRun = 1,
Attack = 2,
Trade = 3,
NextTarget = 4,
Pickup = 5,
Assist = 6,
PartyInvite = 7,
PartyLeave = 8,
PartyKick = 9
}
16 changes: 12 additions & 4 deletions l2-unity/Assets/Scripts/UI/Game/Action/ActionSlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
public class ActionSlot : L2DraggableSlot
{
public int ActionId { get; private set; }
public ActionData Action { get; private set; }

public ActionSlot(VisualElement slotElement, int position, SlotType slotType) : base(position, slotElement, slotType, true, false)
{
Expand All @@ -23,12 +24,19 @@ protected override void HandleMiddleClick()
{
}

public void AssignAction(int actionId)
public void AssignAction(ActionType actionType)
{
ActionId = actionId;
_slotDragManipulator.enabled = true;
ButtonClickSoundManipulator _buttonClickSoundManipulator = new ButtonClickSoundManipulator(_slotElement);
_slotDragManipulator.enabled = true;
_slotElement.RemoveFromClassList("empty");
_slotBg.style.backgroundImage = IconManager.Instance.LoadTextureByName($"action{actionId.ToString().PadLeft(3, '0')}");

ActionId = (int)actionType;
Action = ActionNameTable.Instance.GetAction(actionType);
_slotBg.style.backgroundImage = IconManager.Instance.LoadTextureByName(Action.Icon);

if (_tooltipManipulator != null)
{
_tooltipManipulator.SetText(Action.Name);
}
}
}
12 changes: 6 additions & 6 deletions l2-unity/Assets/Scripts/UI/Game/Action/ActionWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ protected override IEnumerator BuildWindow(VisualElement root)
AddSlot(position++, _socialContainer);
}

_slots[0].AssignAction((int)ActionType.Sit);
_slots[1].AssignAction((int)ActionType.WalkRun);
_slots[2].AssignAction((int)ActionType.Attack);
_slots[3].AssignAction((int)ActionType.NextTarget);
_slots[4].AssignAction((int)ActionType.Pickup);
_slots[5].AssignAction((int)ActionType.Assist);
_slots[0].AssignAction(ActionType.Sit);
_slots[1].AssignAction(ActionType.WalkRun);
_slots[2].AssignAction(ActionType.Attack);
_slots[3].AssignAction(ActionType.NextTarget);
_slots[4].AssignAction(ActionType.Pickup);
_slots[5].AssignAction(ActionType.Assist);
}

private void AddSlot(int position, VisualElement container)
Expand Down
2 changes: 1 addition & 1 deletion l2-unity/Assets/Scripts/UI/Game/Skillbar/SkillbarSlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void AssignItem(int objectId)
public void AssignAction(int objectId)
{
_innerSlot = new ActionSlot(_slotElement, _position, SlotType.SkillBar);
((ActionSlot)_innerSlot).AssignAction(objectId);
((ActionSlot)_innerSlot).AssignAction((ActionType)objectId);
((L2ClickableSlot)_innerSlot).UnregisterClickableCallback();

_slotElement.RemoveFromClassList("empty");
Expand Down
Loading

0 comments on commit 29e9d05

Please sign in to comment.