Skip to content

Commit

Permalink
Merge pull request #1537 from WEKIT-ECS/labelImprovments
Browse files Browse the repository at this point in the history
Label improvments
  • Loading branch information
robhillman97 authored Aug 14, 2023
2 parents c3b00ed + 8721609 commit 8a5f308
Show file tree
Hide file tree
Showing 14 changed files with 14,143 additions and 1,869 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
using System.Collections;
using System.Collections.Generic;


namespace MirageXR
{
Expand All @@ -11,6 +15,24 @@ public class LabelEditor : MonoBehaviour
[SerializeField] private StepTrigger stepTrigger;
[SerializeField] private GameObject acceptButton;

[SerializeField] private GameObject _settingsPannel;
[SerializeField] private GameObject _textPannel;

[SerializeField] private TMP_Text _exampleLabel;
[SerializeField] private Image _exampleLabelBackground;
[SerializeField] private TMP_InputField _fontSize;

[SerializeField] private Image _fontColourButtonImage;
[SerializeField] private Image _backgroundColourButtonImage;

[SerializeField] private ColourSelector _colourPickerScript;

private enum ColourPickerOption { NA, Font, Background};

private ColourPickerOption _colourPickerOption = ColourPickerOption.NA;



public GameObject AcceptButton => acceptButton;

private Action action;
Expand All @@ -33,6 +55,8 @@ public void SetAnnotationStartingPoint(Transform startingPoint)

public void Open(Action action, ToggleObject annotation)
{
_colourPickerScript.onColourSelected.AddListener(OnColourPickerChange);

gameObject.SetActive(true);
this.action = action;
annotationToEdit = annotation;
Expand All @@ -44,14 +68,33 @@ public void Open(Action action, ToggleObject annotation)
var duration = trigger != null ? trigger.duration : 1;
var stepNumber = trigger != null ? trigger.value : "1";
stepTrigger.Initiate(annotationToEdit, duration, stepNumber);

if (annotationToEdit.option != "")
{
string[] splitArray = annotationToEdit.option.Split(char.Parse("-"));

_exampleLabel.text = annotationToEdit.text;

_exampleLabel.fontSize = int.Parse(splitArray[0]);

_exampleLabel.color = GetColorFromString(splitArray[1]);
_exampleLabelBackground.color = GetColorFromString(splitArray[2]);
}
}

UpdateButtonColours();

this.textInputField.onValueChanged.AddListener(delegate { EventManager.NotifyOnLabelEditorTextChanged(); });
this.acceptButton = this.gameObject.transform.Find("AcceptButton").gameObject;
// this.acceptButton = this.gameObject.transform.Find("AcceptButton").gameObject;
}

public void OnAccept()
{
if (string.IsNullOrEmpty(textInputField.text))
{
Toast.Instance.Show("Input field is empty.");
return;
}

if (annotationToEdit != null)
{
Expand All @@ -73,6 +116,8 @@ public void OnAccept()
}
annotationToEdit.text = textInputField.text;

annotationToEdit.option = _exampleLabel.fontSize.ToString() + "-" + _exampleLabel.color.ToString() + "-" + _exampleLabelBackground.color.ToString();

stepTrigger.MyPoi = annotationToEdit;
stepTrigger.SetupTrigger();

Expand All @@ -81,5 +126,68 @@ public void OnAccept()
Close();
}

public void OpenSettings(bool open)
{
_settingsPannel.SetActive(open);
_textPannel.SetActive(!open);
}

public void OnFontSizeChanged()
{
_exampleLabel.fontSize = int.Parse(_fontSize.text);
}


public void OnFontColourChange()
{
// _colourPickerObject.SetActive(true);
_colourPickerScript.Open();
_colourPickerOption = ColourPickerOption.Font;
}

public void OnBackgroundColourChanged()
{
//_colourPickerObject.SetActive(true);
_colourPickerScript.Open();
_colourPickerOption = ColourPickerOption.Background;
}

public void OnColourPickerChange()
{
switch (_colourPickerOption)
{
case ColourPickerOption.Font:
_exampleLabel.color = _colourPickerScript._selectedColour;
break;
case ColourPickerOption.Background:
_exampleLabelBackground.color = _colourPickerScript._selectedColour;
break;
default:
break;
}

UpdateButtonColours();

_colourPickerOption = ColourPickerOption.NA;
}

private Color GetColorFromString(string rgb)
{
string[] rgba = rgb.Substring(5, rgb.Length - 6).Split(", ");
Color color = new Color(float.Parse(rgba[0]), float.Parse(rgba[1]), float.Parse(rgba[2]), float.Parse(rgba[3]));

return color;
}

public void onInputChanged()
{
_exampleLabel.text = textInputField.text;
}

private void UpdateButtonColours()
{
_fontColourButtonImage.color = _exampleLabel.color;
_backgroundColourButtonImage.color = _exampleLabelBackground.color;
}
}
}

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

Loading

0 comments on commit 8a5f308

Please sign in to comment.