-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from MaxWasUnavailable/improved-modlist-ui
Improved modlist UI & various UI fixes
- Loading branch information
Showing
14 changed files
with
1,099 additions
and
187 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
using LobbyCompatibility.Enums; | ||
using System; | ||
using TMPro; | ||
using UnityEngine; | ||
using UnityEngine.UI; | ||
|
||
namespace LobbyCompatibility.Behaviours; | ||
|
||
/// <summary> | ||
/// Mod list tab used to change the filtering of a <see cref="ModListPanel"/>. | ||
/// </summary> | ||
public class ModListTab : MonoBehaviour | ||
{ | ||
public ModListFilter ModListFilter; | ||
private Image? _tabBackground; | ||
private Image? _tabOutline; | ||
private Button? _button; | ||
private TextMeshProUGUI? _buttonText; | ||
private Color _selectedColor; | ||
private Color _unselectedColor; | ||
|
||
/// <summary> | ||
/// Set up our tab based on precreated UI elements. | ||
/// </summary> | ||
/// <param name="tabBackground"> The image to use as the tab background. </param> | ||
/// <param name="tabOutline"> The image to use as the tab background's outline. </param> | ||
/// <param name="button"> The button to use on the tab. </param> | ||
/// <param name="buttonText"> The button's text. </param> | ||
/// <param name="modListFilter"> The <see cref="ModListFilter"/> to apply when clicking the tab. </param> | ||
/// <param name="selectedColor"> Color to use when the tab is selected. </param> | ||
/// <param name="unselectedColor"> Color to use when the tab is not selected. </param> | ||
public void Setup(Image tabBackground, Image tabOutline, Button button, TextMeshProUGUI buttonText, ModListFilter modListFilter, Color selectedColor, Color unselectedColor) | ||
{ | ||
ModListFilter = modListFilter; | ||
_tabBackground = tabBackground; | ||
_tabOutline = tabOutline; | ||
_button = button; | ||
_buttonText = buttonText; | ||
_selectedColor = selectedColor; | ||
_unselectedColor = unselectedColor; | ||
|
||
// Need to use TMP rich text to set size, because buttons have a custom style that cannot be overridden with normal text properties | ||
_buttonText.text = "<size=13px><cspace=-0.04em>" + modListFilter.ToString(); | ||
} | ||
|
||
/// <summary> | ||
/// Set up events that will be called when the tab is clicked. | ||
/// </summary> | ||
/// <param name="action"> The action that will be called when the tab is clicked. </param> | ||
public void SetupEvents(Action<ModListFilter> action) | ||
{ | ||
if (_button == null) | ||
return; | ||
|
||
// Clear original onClick events | ||
_button.onClick.m_PersistentCalls.Clear(); | ||
_button.onClick.RemoveAllListeners(); | ||
|
||
_button.onClick.AddListener(() => action(ModListFilter)); | ||
} | ||
|
||
/// <summary> | ||
/// Set if the tab visuals should appear selected. | ||
/// </summary> | ||
/// <param name="active"> Whether or not the tab should appear selected. </param> | ||
public void SetSelectionStatus(bool selected) | ||
{ | ||
if (_tabBackground == null || _tabOutline == null) | ||
return; | ||
|
||
_tabBackground.color = selected ? _selectedColor : _unselectedColor; | ||
_tabOutline.color = new Color(_tabOutline.color.r, _tabOutline.color.g, _tabOutline.color.b, selected ? 1f : 0.3f); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using LobbyCompatibility.Enums; | ||
using LobbyCompatibility.Features; | ||
using TMPro; | ||
using UnityEngine; | ||
|
||
namespace LobbyCompatibility.Behaviours; | ||
|
||
/// <summary> | ||
/// Slot used to show a <see cref="PluginDiffResult"/> header in a <see cref="ModListPanel"/>. | ||
/// </summary> | ||
internal class PluginCategorySlot : MonoBehaviour | ||
{ | ||
[field: SerializeField] | ||
public TextMeshProUGUI? CategoryNameText { get; private set; } | ||
[field: SerializeField] | ||
public TextMeshProUGUI? ClientVersionCategoryNameText { get; private set; } | ||
[field: SerializeField] | ||
public TextMeshProUGUI? ServerVersionCategoryNameText { get; private set; } | ||
|
||
/// <summary> | ||
/// Set up the slot using existing text objects. | ||
/// </summary> | ||
/// <param name="categoryNameText"> Text to use to display the category's name. </param> | ||
/// <param name="clientVersionCategoryNameText"> Text to use to display the category's client plugin version header. </param> | ||
/// <param name="serverVersionCategoryNameText"> Text to use to display the category's server plugin version header. </param> | ||
public void SetupText(TextMeshProUGUI categoryNameText, TextMeshProUGUI? clientVersionCategoryNameText = null, TextMeshProUGUI? serverVersionCategoryNameText = null) | ||
{ | ||
CategoryNameText = categoryNameText; | ||
ClientVersionCategoryNameText = clientVersionCategoryNameText; | ||
ServerVersionCategoryNameText = serverVersionCategoryNameText; | ||
|
||
// Make sure text is enabled and setup properly | ||
categoryNameText.gameObject.SetActive(true); | ||
} | ||
|
||
/// <summary> | ||
/// Set the slot's text based on a <see cref="PluginDiffResult"/>. | ||
/// </summary> | ||
/// <param name="pluginDiffResult"> PluginDiffResult to display. </param> | ||
public void SetPluginDiffResult(PluginDiffResult pluginDiffResult) | ||
{ | ||
if (CategoryNameText == null) | ||
return; | ||
|
||
CategoryNameText.text = LobbyHelper.GetCompatibilityHeader(pluginDiffResult); | ||
|
||
SetText(CategoryNameText.text); | ||
} | ||
|
||
/// <summary> | ||
/// Manually set the slot's text. | ||
/// </summary> | ||
/// <param name="text"> The category header to display. </param> | ||
private void SetText(string text) | ||
{ | ||
if (CategoryNameText == null) | ||
return; | ||
|
||
CategoryNameText.text = text + ":"; | ||
|
||
if (ClientVersionCategoryNameText == null || ServerVersionCategoryNameText == null) | ||
return; | ||
|
||
ClientVersionCategoryNameText.text = "You"; | ||
ServerVersionCategoryNameText.text = "Lobby"; | ||
|
||
// TODO: Use color for a little colored icon or something? | ||
} | ||
} |
Oops, something went wrong.