Skip to content

Commit

Permalink
UI code cleanup and organized - part2
Browse files Browse the repository at this point in the history
  • Loading branch information
shnok committed Jul 6, 2024
1 parent 98965ef commit a709d0d
Show file tree
Hide file tree
Showing 81 changed files with 194 additions and 326 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions l2-unity/Assets/Resources/Data/UI/_Elements/Template.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 0 additions & 9 deletions l2-unity/Assets/Resources/Data/UI/_Elements/TestUI.uxml

This file was deleted.

10 changes: 0 additions & 10 deletions l2-unity/Assets/Resources/Data/UI/_Elements/TestUI.uxml.meta

This file was deleted.

2 changes: 0 additions & 2 deletions l2-unity/Assets/Scripts/Combat/Gear/Gear.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@ public virtual void EquipWeapon(int weaponId, bool leftSlot) {
return;
}

Debug.LogWarning("Equip weapon: " + weaponId);

// Loading from database
Weapon weapon = ItemTable.Instance.GetWeapon(weaponId);
if (weapon == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ public ButtonCharacter(CharacterInfoWindow character)
}


public void RegisterButtonCloseWindow(VisualElement rootWindows, string buttonId)
public void RegisterButtonCloseWindow(string buttonId)
{
var btn = rootWindows.Q<Button>(className: buttonId);
var btn = (Button) character.GetElementByClass(buttonId);

if (btn == null)
{
Expand All @@ -25,7 +25,7 @@ public void RegisterButtonCloseWindow(VisualElement rootWindows, string buttonId

btn.RegisterCallback<MouseUpEvent>(evt => {
Debug.Log("Click event");
character.HideElements(true, rootWindows);
character.HideWindow();

}, TrickleDown.TrickleDown);
}
Expand All @@ -40,12 +40,12 @@ public void RegisterClickWindow(VisualElement rootWindows, VisualElement content
}

contentId.RegisterCallback<MouseDownEvent>(evt => {
character.BringFront();
character.BringToFront();

}, TrickleDown.TrickleDown);

headerId.RegisterCallback<MouseDownEvent>(evt => {
character.BringFront();
character.BringToFront();
}, TrickleDown.TrickleDown);
}
}
48 changes: 48 additions & 0 deletions l2-unity/Assets/Scripts/UI/Game/Character/CharacterWindow.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using UnityEngine;
using UnityEngine.UIElements;

public class CharacterInfoWindow : L2Window
{
public VisualElement minimal_panel;
private VisualElement content;
private ButtonCharacter _buttonCharacter;

private static CharacterInfoWindow _instance;
public static CharacterInfoWindow Instance {
get { return _instance; }
}
private void Awake() {
if (_instance == null) {
_instance = this;
_buttonCharacter = new ButtonCharacter(this);
} else {
Destroy(this);
}
}

private void OnDestroy() {
_instance = null;
}

protected override void LoadAssets() {
_windowTemplate = LoadAsset("Data/UI/_Elements/Game/CharacterInfoWindow");
}

protected override IEnumerator BuildWindow(VisualElement root) {
InitWindow(root);

yield return new WaitForEndOfFrame();

var dragArea = GetElementByClass("drag-area");
content = GetElementByClass("content");
_buttonCharacter.RegisterButtonCloseWindow("btn-close-frame");
_buttonCharacter.RegisterClickWindow(_windowEle, content, dragArea);


DragManipulator drag = new DragManipulator(dragArea, _windowEle);
dragArea.AddManipulator(drag);
}
}
63 changes: 16 additions & 47 deletions l2-unity/Assets/Scripts/UI/Game/Chat/ChatWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@
using UnityEngine;
using UnityEngine.UIElements;

public class ChatWindow : MonoBehaviour {
private VisualTreeAsset _chatWindowTemplate;
public class ChatWindow : L2Window {
private VisualTreeAsset _tabTemplate;
private VisualTreeAsset _tabHeaderTemplate;
private TextField _chatInput;
private VisualElement _chatInputContainer;
private VisualElement _chatTabView;
private VisualElement _chatWindowEle;
private ChatTab _activeTab;

[SerializeField] private float _chatWindowMinWidth = 225.0f;
Expand Down Expand Up @@ -39,49 +37,22 @@ private void OnDestroy() {
_instance = null;
}

void Start() {
LoadAssets();
protected override void LoadAssets() {
_windowTemplate = LoadAsset("Data/UI/_Elements/Game/Chat/ChatWindow");
_tabTemplate = LoadAsset("Data/UI/_Elements/Game/Chat/ChatTab");
_tabHeaderTemplate = LoadAsset("Data/UI/_Elements/Game/Chat/ChatTabHeader");
}

private void LoadAssets() {
if(_chatWindowTemplate == null) {
_chatWindowTemplate = Resources.Load<VisualTreeAsset>("Data/UI/_Elements/ChatWindow");
}
if(_chatWindowTemplate == null) {
Debug.LogError("Could not load chat window template.");
}
if(_tabTemplate == null) {
_tabTemplate = Resources.Load<VisualTreeAsset>("Data/UI/_Elements/ChatTab");
}
if(_tabTemplate == null) {
Debug.LogError("Could not load chat tab template.");
}
if (_tabHeaderTemplate == null) {
_tabHeaderTemplate = Resources.Load<VisualTreeAsset>("Data/UI/_Elements/ChatTabHeader");
}
if (_tabHeaderTemplate == null) {
Debug.LogError("Could not load chat tab header template.");
}
}
protected override IEnumerator BuildWindow(VisualElement root) {
InitWindow(root);

public void AddWindow(VisualElement root) {
if(_chatWindowTemplate == null) {
return;
}
StartCoroutine(BuildWindow(root));
}

IEnumerator BuildWindow(VisualElement root) {

_chatWindowEle = _chatWindowTemplate.Instantiate()[0];
MouseOverDetectionManipulator mouseOverDetection = new MouseOverDetectionManipulator(_chatWindowEle);
_chatWindowEle.AddManipulator(mouseOverDetection);
yield return new WaitForEndOfFrame();

var diagonalResizeHandle = _chatWindowEle.Q<VisualElement>(null, "resize-diag");
var diagonalResizeHandle = GetElementByClass("resize-diag");

DiagonalResizeManipulator diagonalResizeManipulator = new DiagonalResizeManipulator(
diagonalResizeHandle,
_chatWindowEle,
_windowEle,
_chatWindowMinWidth,
_chatWindowMaxWidth,
_chatWindowMinHeight,
Expand All @@ -91,32 +62,30 @@ IEnumerator BuildWindow(VisualElement root) {

diagonalResizeHandle.AddManipulator(diagonalResizeManipulator);

_chatInput = _chatWindowEle.Q<TextField>("ChatInputField");
_chatInput = (TextField) GetElementById("ChatInputField");
_chatInput.RegisterCallback<FocusEvent>(OnChatInputFocus);
_chatInput.RegisterCallback<BlurEvent>(OnChatInputBlur);
_chatInput.maxLength = _chatInputCharacterLimit;

var enlargeTextBtn = _chatWindowEle.Q<Button>("EnlargeTextBtn");
var enlargeTextBtn = (Button) GetElementById("EnlargeTextBtn");
enlargeTextBtn.AddManipulator(new ButtonClickSoundManipulator(enlargeTextBtn));

var chatOptionsBtn = _chatWindowEle.Q<Button>("ChatOptionsBtn");
var chatOptionsBtn = (Button)GetElementById("ChatOptionsBtn");
chatOptionsBtn.AddManipulator(new ButtonClickSoundManipulator(chatOptionsBtn));

_chatInput.AddManipulator(new BlinkingCursorManipulator(_chatInput));

_chatInputContainer = _chatWindowEle.Q<VisualElement>("InnerBar");
_chatInputContainer = GetElementById("InnerBar");

CreateTabs();

root.Add(_chatWindowEle);

yield return new WaitForEndOfFrame();
diagonalResizeManipulator.SnapSize();
}


private void CreateTabs() {
_chatTabView = _chatWindowEle.Q<VisualElement>("ChatTabView");
_chatTabView = GetElementById("ChatTabView");

VisualElement tabHeaderContainer = _chatTabView.Q<VisualElement>("tab-header-container");
if(tabHeaderContainer == null) {
Expand All @@ -141,7 +110,7 @@ private void CreateTabs() {
tabHeaderContainer.Add(tabHeaderElement);
tabContainer.Add(tabElement);

_tabs[i].Initialize(_chatWindowEle, tabElement, tabHeaderElement);
_tabs[i].Initialize(_windowEle, tabElement, tabHeaderElement);
}

if (_tabs.Count > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void Start()
{
if (_overlayTemplate == null)
{
_overlayTemplate = Resources.Load<VisualTreeAsset>("Data/UI/_Elements/IconOverlay");
_overlayTemplate = Resources.Load<VisualTreeAsset>("Data/UI/_Elements/Game/Inventory/IconOverlay");
}
if (_overlayTemplate == null)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public void Start()
{
if (_testUITemplate == null)
{
_testUITemplate = Resources.Load<VisualTreeAsset>("Data/UI/_Elements/Windows/CharacterInventory");
_testUITemplate = Resources.Load<VisualTreeAsset>("Data/UI/_Elements/Game/Inventory/InventoryWindow");
}

if (_testUITemplate == null)
Expand Down
32 changes: 6 additions & 26 deletions l2-unity/Assets/Scripts/UI/Game/MenuWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,7 @@
using UnityEngine.UIElements;

[System.Serializable]
public class MenuWindow : MonoBehaviour {

private VisualTreeAsset _windowTemplate;
private VisualElement _windowEle;

public class MenuWindow : L2Window {
private static MenuWindow _instance;
public static MenuWindow Instance { get { return _instance; } }

Expand All @@ -24,30 +20,14 @@ private void OnDestroy() {
_instance = null;
}

void Start() {
LoadAssets();
protected override void LoadAssets() {
_windowTemplate = LoadAsset("Data/UI/_Elements/Game/MenuWindow");
}

private void LoadAssets() {
if (_windowTemplate == null) {
_windowTemplate = Resources.Load<VisualTreeAsset>("Data/UI/_Elements/MenuWindow");
}
if (_windowTemplate == null) {
Debug.LogError("Could not load menu window template.");
}
}
protected override IEnumerator BuildWindow(VisualElement root) {
InitWindow(root);

public void AddWindow(VisualElement root) {
if (_windowTemplate == null) {
return;
}
StartCoroutine(BuildWindow(root));
}

IEnumerator BuildWindow(VisualElement root) {
_windowEle = _windowTemplate.Instantiate()[0];
MouseOverDetectionManipulator mouseOverDetection = new MouseOverDetectionManipulator(_windowEle);
_windowEle.AddManipulator(mouseOverDetection);
yield return new WaitForEndOfFrame();

var charBtn = _windowEle.Q<Button>("CharacterButton");
charBtn.AddManipulator(new ButtonClickSoundManipulator(charBtn));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ private void OnDestroy() {

void Start() {
if (_nameplateTemplate == null) {
_nameplateTemplate = Resources.Load<VisualTreeAsset>("Data/UI/_Elements/Nameplate");
_nameplateTemplate = Resources.Load<VisualTreeAsset>("Data/UI/_Elements/Game/Nameplate");
}
if (_nameplateTemplate == null) {
Debug.LogError("Could not load chat window template.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ private void OnDestroy() {

void Start() {
if(_nameplateTemplate == null) {
_nameplateTemplate = Resources.Load<VisualTreeAsset>("Data/UI/_Elements/Nameplate");
_nameplateTemplate = Resources.Load<VisualTreeAsset>("Data/UI/_Elements/Game/Nameplate");
}
if(_nameplateTemplate == null) {
Debug.LogError("Could not load chat window template.");
Expand Down
8 changes: 8 additions & 0 deletions l2-unity/Assets/Scripts/UI/Game/Skillbar.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ void Start()
{
if (_shortCutWindowsTemplate == null)
{
_shortCutWindowsTemplate = Resources.Load<VisualTreeAsset>("Data/UI/_Elements/ShortCutPanel");
_shortCutWindowsTemplate = Resources.Load<VisualTreeAsset>("Data/UI/_Elements/Game/Skillbar/SkillbarWindow");

}
if (_shortCutWindowsTemplate == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ private VisualTreeAsset[] CreateObject(VisualTreeAsset[] arrayTemplate)
{
if (arrayTemplate[i] == null)
{
arrayTemplate[i] = Resources.Load<VisualTreeAsset>("Data/UI/_Elements/ShortCutPanelMinimal");
arrayTemplate[i] = Resources.Load<VisualTreeAsset>("Data/UI/_Elements/Game/Skillbar/SkillbarWindowMinimal");
}
}
return arrayTemplate;
Expand Down
Loading

0 comments on commit a709d0d

Please sign in to comment.