Skip to content

Commit

Permalink
unequip func, slot cleanup after update, chat autoscroll, systemmessa…
Browse files Browse the repository at this point in the history
…ge fix
  • Loading branch information
shnok committed Aug 15, 2024
1 parent 1d3248e commit 127db89
Show file tree
Hide file tree
Showing 13 changed files with 132 additions and 100 deletions.
115 changes: 40 additions & 75 deletions l2-unity/Assets/Scenes/Menu.unity
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RenderSettings:
m_AmbientSkyColor: {r: 0.212, g: 0.227, b: 0.259, a: 1}
m_AmbientEquatorColor: {r: 0.114, g: 0.125, b: 0.133, a: 1}
m_AmbientGroundColor: {r: 0.047, g: 0.043, b: 0.035, a: 1}
m_AmbientIntensity: 0.2
m_AmbientIntensity: 0.6
m_AmbientMode: 0
m_SubtractiveShadowColor: {r: 0, g: 0, b: 0, a: 1}
m_SkyboxMaterial: {fileID: 2100000, guid: 74e09fc0417b6f94c95b3a55ae362ec9, type: 2}
Expand All @@ -38,7 +38,7 @@ RenderSettings:
m_ReflectionIntensity: 0.245
m_CustomReflection: {fileID: 0}
m_Sun: {fileID: 1061591418}
m_IndirectSpecularColor: {r: 0.009567419, g: 0.010123216, b: 0.010156483, a: 0.245}
m_IndirectSpecularColor: {r: 0.029895507, g: 0.06798504, b: 0.08975239, a: 0.245}
m_UseRadianceAmbientProbe: 0
--- !u!157 &3
LightmapSettings:
Expand Down Expand Up @@ -182,7 +182,7 @@ PrefabInstance:
m_Modifications:
- target: {fileID: 842763773635486120, guid: 2bc6245aea0342f4f8c76719bfe12012, type: 3}
propertyPath: _autoLogin
value: 0
value: 1
objectReference: {fileID: 0}
- target: {fileID: 4644061901774829026, guid: 2bc6245aea0342f4f8c76719bfe12012, type: 3}
propertyPath: m_LocalPosition.x
Expand Down Expand Up @@ -253,41 +253,6 @@ PrefabInstance:
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 2bc6245aea0342f4f8c76719bfe12012, type: 3}
--- !u!21 &493864232
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Height Fog Global
m_Shader: {fileID: 4800000, guid: 3a7ef1b66bafb7a448a880ef76d2e6e6, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs: []
m_Ints: []
m_Floats:
- _AdvancedCat: 1
- _Banner: 1
- _DirectionalCat: 1
- _FogCat: 1
- _HeightFogGlobal: 1
- _IsHeightFogShader: 1
- _NoiseCat: 1
- _SkyboxCat: 1
m_Colors: []
m_BuildTextureStacks: []
--- !u!1 &803395386
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -600,6 +565,41 @@ PrefabInstance:
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 824ee6870a432f9439e35ee4e771a1f5, type: 3}
--- !u!21 &1041848965
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Height Fog Global
m_Shader: {fileID: 4800000, guid: 3a7ef1b66bafb7a448a880ef76d2e6e6, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs: []
m_Ints: []
m_Floats:
- _AdvancedCat: 1
- _Banner: 1
- _DirectionalCat: 1
- _FogCat: 1
- _HeightFogGlobal: 1
- _IsHeightFogShader: 1
- _NoiseCat: 1
- _SkyboxCat: 1
m_Colors: []
m_BuildTextureStacks: []
--- !u!108 &1061591418 stripped
Light:
m_CorrespondingSourceObject: {fileID: 4181994143891002370, guid: 824ee6870a432f9439e35ee4e771a1f5, type: 3}
Expand Down Expand Up @@ -662,41 +662,6 @@ PrefabInstance:
m_AddedGameObjects: []
m_AddedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: de4c4ef119bfe89408906f06fbd31d49, type: 3}
--- !u!21 &1136183139
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: Height Fog Global
m_Shader: {fileID: 4800000, guid: 3a7ef1b66bafb7a448a880ef76d2e6e6, type: 3}
m_Parent: {fileID: 0}
m_ModifiedSerializedProperties: 0
m_ValidKeywords: []
m_InvalidKeywords: []
m_LightmapFlags: 4
m_EnableInstancingVariants: 0
m_DoubleSidedGI: 0
m_CustomRenderQueue: 3000
stringTagMap: {}
disabledShaderPasses: []
m_LockedProperties:
m_SavedProperties:
serializedVersion: 3
m_TexEnvs: []
m_Ints: []
m_Floats:
- _AdvancedCat: 1
- _Banner: 1
- _DirectionalCat: 1
- _FogCat: 1
- _HeightFogGlobal: 1
- _IsHeightFogShader: 1
- _NoiseCat: 1
- _SkyboxCat: 1
m_Colors: []
m_BuildTextureStacks: []
--- !u!1001 &1147827734
PrefabInstance:
m_ObjectHideFlags: 0
Expand All @@ -712,7 +677,7 @@ PrefabInstance:
- target: {fileID: 14083907825353274, guid: 8742fc349ac4f354d9cfb98ebb79a0e3, type: 3}
propertyPath: m_Materials.Array.data[0]
value:
objectReference: {fileID: 493864232}
objectReference: {fileID: 1041848965}
- target: {fileID: 2134954596300280144, guid: 8742fc349ac4f354d9cfb98ebb79a0e3, type: 3}
propertyPath: m_Name
value: Height Fog Global
Expand Down Expand Up @@ -1071,7 +1036,7 @@ Transform:
m_Children: []
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!21 &2048170547
--- !u!21 &1615823495
Material:
serializedVersion: 8
m_ObjectHideFlags: 0
Expand Down
14 changes: 14 additions & 0 deletions l2-unity/Assets/Scripts/Database/ItemTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,18 @@ public EtcItem GetEtcItem(int id) {

return item;
}

public AbstractItem GetItem(int id) {
if(_weapons.TryGetValue(id, out Weapon weapon)) {
return weapon;
}
if(_armors.TryGetValue(id, out Armor armor)) {
return armor;
}
if(_etcItems.TryGetValue(id, out EtcItem etcItem)) {
return etcItem;
}

return null;
}
}
3 changes: 0 additions & 3 deletions l2-unity/Assets/Scripts/Game/Item/PlayerInventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ private void Awake() {
Destroy(this);
}

Debug.LogWarning("Init PlayerInventory");

_playerInventory = new List<ItemInstance>();
}

Expand All @@ -49,7 +47,6 @@ public void SetInventory(ItemInstance[] items, bool openInventory) {
public void UpdateInventory(ItemInstance[] items) {
for(int i = 0; i < items.Length; i++) {
ItemInstance item = items[i];
Debug.Log(item.ToString());
if(item.LastChange == (int) InventoryChange.ADDED) {
_playerInventory.Add(item);
} else if (item.LastChange == (int) InventoryChange.MODIFIED) {
Expand Down
20 changes: 13 additions & 7 deletions l2-unity/Assets/Scripts/UI/Game/Chat/ChatTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
[System.Serializable]
public class ChatTab : L2Tab
{

private Label _content;
public Label Content { get { return _content; } }

Expand All @@ -26,12 +25,19 @@ protected override void OnSwitchTab() {
AudioManager.Instance.PlayUISound("window_open");
}
}

public void AddMessage(string message) {
ConcatMessage(message.ToString());
}

private void ConcatMessage(string message) {
if(_content.text.Length > 0) {
_content.text += "\r\n";
}
_content.text += message;

protected override void RegisterAutoScrollEvent() {
_content.RegisterValueChangedCallback(evt => {
if(_autoscroll) {
ChatWindow.Instance.ScrollDown(_scroller);
}
});
if(_autoscroll) {
ChatWindow.Instance.ScrollDown(_scroller);
}
}
}
11 changes: 2 additions & 9 deletions l2-unity/Assets/Scripts/UI/Game/Chat/ChatWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ public void ReceiveChatMessage(ChatMessage message) {
// ConcatMessage(_tabs[i].Content, message.ToString());
// }
//}
ConcatMessage(_tabs[i].Content, message.ToString());
_tabs[i].AddMessage(message.ToString());
}
}

Expand All @@ -240,17 +240,10 @@ public void ReceiveSystemMessage(SystemMessage message) {
// ConcatMessage(_tabs[i].Content, message.ToString());
// }
//}
ConcatMessage(_tabs[i].Content, message.ToString());
_tabs[i].AddMessage(message.ToString());
}
}

private void ConcatMessage(Label chatContent, string message) {
if(chatContent.text.Length > 0) {
chatContent.text += "\r\n";
}
chatContent.text += message;
}

internal void ScrollDown(Scroller scroller) {
StartCoroutine(ScrollDownWithDelay(scroller));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,13 @@ public override string ToString() {
value = value.Replace($"$s{i}", param.GetLongValue().ToString());
break;
case SMParamType.TYPE_ITEM_NAME:
AbstractItem item = ItemTable.Instance.GetItem(param.GetIntValue());
string itemName = "Unknown";
if(item != null) {
itemName = item.ItemName.Name;
}
value = value.Replace($"$s{i}", itemName);
break;
case SMParamType.TYPE_CASTLE_NAME:
case SMParamType.TYPE_INT_NUMBER:
case SMParamType.TYPE_NPC_NAME:
Expand Down
4 changes: 3 additions & 1 deletion l2-unity/Assets/Scripts/UI/Game/Inventory/GearSlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public GearSlot(int position, VisualElement slotElement, InventoryGearTab tab) :
}

protected override void HandleRightClick() {
GameClient.Instance.ClientPacketHandler.UnEquipItem(_position);
if(!_empty) {
GameClient.Instance.ClientPacketHandler.UnEquipItem(_position);
}
}
}
13 changes: 13 additions & 0 deletions l2-unity/Assets/Scripts/UI/Game/Inventory/InventoryGearTab.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,20 @@ public override void Initialize(VisualElement chatWindowEle, VisualElement tabCo

public void UpdateItemList(List<ItemInstance> items) {
Debug.Log("Update gear slots");

// Clean up slot callbacks and manipulators
if(_gearSlots != null) {
foreach (KeyValuePair<ItemSlot, GearSlot> kvp in _gearSlots) {
if (kvp.Value != null) {
kvp.Value.UnregisterCallbacks();
kvp.Value.ClearSlot();
}
}
_gearSlots.Clear();
}
_gearSlots = new Dictionary<ItemSlot, GearSlot>();

// Clean up gear anchors from any child visual element
foreach (KeyValuePair<ItemSlot, VisualElement> kvp in _gearAnchors) {
if (kvp.Value == null) {
Debug.LogWarning($"Inventory gear slot {kvp.Key} is null.");
Expand Down
26 changes: 23 additions & 3 deletions l2-unity/Assets/Scripts/UI/Game/Inventory/InventorySlot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class InventorySlot : L2Slot
private long _remainingTime;
private TooltipManipulator _tooltipManipulator;
private int _objectId;
protected bool _empty = true;

public int Count { get { return _count; } }
public long RemainingTime { get { return _remainingTime; } }
Expand All @@ -18,6 +19,7 @@ public InventorySlot(int position, VisualElement slotElement, L2Tab tab)
: base(slotElement, position) {
_currentTab = tab;
_slotElement.AddToClassList("inventory-slot");
_empty = true;
}

public void AssignItem(ItemInstance item) {
Expand All @@ -27,6 +29,7 @@ public void AssignItem(ItemInstance item) {
_description = item.ItemData.ItemName.Description;
_icon = item.ItemData.Icon;
_objectId = item.ObjectId;
_empty = false;
} else {
Debug.LogWarning($"Item data is null for item {item.ItemId}.");
_id = 0;
Expand All @@ -35,17 +38,24 @@ public void AssignItem(ItemInstance item) {
_icon = "";
_objectId = -1;
}

_count = item.Count;
_remainingTime = item.RemainingTime;

StyleBackground background = new StyleBackground(IconManager.Instance.GetIcon(_id));
_slotBg.style.backgroundImage = background;

AddTooltip(item);
}

private void AddTooltip(ItemInstance item) {
string tooltipText = $"{_name} ({_count})";
if(item.Category == ItemCategory.Weapon || item.Category == ItemCategory.Jewel || item.Category == ItemCategory.ShieldArmor) {
if(item.Category == ItemCategory.Weapon ||
item.Category == ItemCategory.Jewel ||
item.Category == ItemCategory.ShieldArmor) {
tooltipText = _name;
}

if(_tooltipManipulator == null) {
_tooltipManipulator = new TooltipManipulator(_slotElement, tooltipText);
_slotElement.AddManipulator(_tooltipManipulator);
Expand All @@ -54,13 +64,23 @@ public void AssignItem(ItemInstance item) {
}
}

public void ClearSlot() {
if(_tooltipManipulator != null) {
_tooltipManipulator.Clear();
_slotElement.RemoveManipulator(_tooltipManipulator);
_tooltipManipulator = null;
}
}

protected override void HandleLeftClick() {
AudioManager.Instance.PlayUISound("click_03");
_currentTab.SelectSlot(_position);
}

protected override void HandleRightClick() {
GameClient.Instance.ClientPacketHandler.UseItem(_objectId);
if(!_empty) {
GameClient.Instance.ClientPacketHandler.UseItem(_objectId);
}
}

public void SetSelected() {
Expand Down
Loading

0 comments on commit 127db89

Please sign in to comment.