Add igbg, mbg, bc, tc color options in settings menu
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -574,6 +574,51 @@ public class BazookaManager : MonoBehaviour
|
|||||||
return JArray.Parse(saveFile["settings"]["colors"]["background"].ToString());
|
return JArray.Parse(saveFile["settings"]["colors"]["background"].ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetColorSettingMenuBackground(JArray value)
|
||||||
|
{
|
||||||
|
if (saveFile["settings"] == null) saveFile["settings"] = new JObject();
|
||||||
|
if (saveFile["settings"]["colors"] == null) saveFile["settings"]["colors"] = new JObject();
|
||||||
|
saveFile["settings"]["colors"]["menuBackground"] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JArray GetColorSettingMenuBackground()
|
||||||
|
{
|
||||||
|
if (saveFile["settings"] == null) return new JArray(24, 24, 24);
|
||||||
|
if (saveFile["settings"]["colors"] == null) return new JArray(24, 24, 24);
|
||||||
|
if (saveFile["settings"]["colors"]["menuBackground"] == null) return new JArray(24, 24, 24);
|
||||||
|
return JArray.Parse(saveFile["settings"]["colors"]["menuBackground"].ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetColorSettingButton(JArray value)
|
||||||
|
{
|
||||||
|
if (saveFile["settings"] == null) saveFile["settings"] = new JObject();
|
||||||
|
if (saveFile["settings"]["colors"] == null) saveFile["settings"]["colors"] = new JObject();
|
||||||
|
saveFile["settings"]["colors"]["button"] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JArray GetColorSettingButton()
|
||||||
|
{
|
||||||
|
if (saveFile["settings"] == null) return new JArray(255, 255, 255);
|
||||||
|
if (saveFile["settings"]["colors"] == null) return new JArray(255, 255, 255);
|
||||||
|
if (saveFile["settings"]["colors"]["button"] == null) return new JArray(255, 255, 255);
|
||||||
|
return JArray.Parse(saveFile["settings"]["colors"]["button"].ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetColorSettingText(JArray value)
|
||||||
|
{
|
||||||
|
if (saveFile["settings"] == null) saveFile["settings"] = new JObject();
|
||||||
|
if (saveFile["settings"]["colors"] == null) saveFile["settings"]["colors"] = new JObject();
|
||||||
|
saveFile["settings"]["colors"]["text"] = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JArray GetColorSettingText()
|
||||||
|
{
|
||||||
|
if (saveFile["settings"] == null) return new JArray(255, 255, 255);
|
||||||
|
if (saveFile["settings"]["colors"] == null) return new JArray(255, 255, 255);
|
||||||
|
if (saveFile["settings"]["colors"]["text"] == null) return new JArray(255, 255, 255);
|
||||||
|
return JArray.Parse(saveFile["settings"]["colors"]["text"].ToString());
|
||||||
|
}
|
||||||
|
|
||||||
public void SetColorSettingIcon(JArray value)
|
public void SetColorSettingIcon(JArray value)
|
||||||
{
|
{
|
||||||
if (saveFile["settings"] == null) saveFile["settings"] = new JObject();
|
if (saveFile["settings"] == null) saveFile["settings"] = new JObject();
|
||||||
|
|||||||
@@ -17,11 +17,11 @@ public class ColorPanel : MonoBehaviour
|
|||||||
public Button switchModeButton;
|
public Button switchModeButton;
|
||||||
public event Action<JArray> OnColorChanged;
|
public event Action<JArray> OnColorChanged;
|
||||||
|
|
||||||
public void Init(JArray color, Color defaultColor)
|
public void Init(Color color, Color defaultColor)
|
||||||
{
|
{
|
||||||
rSlider.value = (int)color[0];
|
rSlider.value = color.r * 255f;
|
||||||
gSlider.value = (int)color[1];
|
gSlider.value = color.g * 255f;
|
||||||
bSlider.value = (int)color[2];
|
bSlider.value = color.b * 255f;
|
||||||
|
|
||||||
SyncAll();
|
SyncAll();
|
||||||
|
|
||||||
@@ -64,6 +64,12 @@ public class ColorPanel : MonoBehaviour
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Init(JArray color, Color defaultColor)
|
||||||
|
{
|
||||||
|
|
||||||
|
Init(new Color((int)color[0] / 255f, (int)color[1] / 255f, (int)color[2] / 255f), defaultColor);
|
||||||
|
}
|
||||||
|
|
||||||
void SyncAll(bool fromPicker = false)
|
void SyncAll(bool fromPicker = false)
|
||||||
{
|
{
|
||||||
var col = new Color(rSlider.value / 255f, gSlider.value / 255f, bSlider.value / 255f);
|
var col = new Color(rSlider.value / 255f, gSlider.value / 255f, bSlider.value / 255f);
|
||||||
|
|||||||
47
Assets/Scripts/CustomColorObject.cs
Normal file
47
Assets/Scripts/CustomColorObject.cs
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
|
using TMPro;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class CustomColorObject : MonoBehaviour
|
||||||
|
{
|
||||||
|
public ColorObjectType type;
|
||||||
|
public bool invert;
|
||||||
|
|
||||||
|
public void SetColor()
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case ColorObjectType.InGameBackgroundColor:
|
||||||
|
JArray color = BazookaManager.Instance.GetColorSettingBackground();
|
||||||
|
Color colorType = new((int)color[0] / 255f, (int)color[1] / 255f, (int)color[2] / 255f);
|
||||||
|
if (invert) colorType = new(1f - colorType.r, 1f - colorType.g, 1f - colorType.b);
|
||||||
|
gameObject.GetComponent<Camera>().backgroundColor = colorType;
|
||||||
|
break;
|
||||||
|
case ColorObjectType.MenuBackgroundColor:
|
||||||
|
color = BazookaManager.Instance.GetColorSettingMenuBackground();
|
||||||
|
colorType = new((int)color[0] / 255f, (int)color[1] / 255f, (int)color[2] / 255f);
|
||||||
|
if (invert) colorType = new(1f - colorType.r, 1f - colorType.g, 1f - colorType.b);
|
||||||
|
gameObject.GetComponent<Camera>().backgroundColor = colorType;
|
||||||
|
break;
|
||||||
|
case ColorObjectType.ButtonColor:
|
||||||
|
color = BazookaManager.Instance.GetColorSettingButton();
|
||||||
|
colorType = new((int)color[0] / 255f, (int)color[1] / 255f, (int)color[2] / 255f);
|
||||||
|
if (invert) colorType = new(1f - colorType.r, 1f - colorType.g, 1f - colorType.b);
|
||||||
|
gameObject.GetComponent<Image>().color = colorType;
|
||||||
|
break;
|
||||||
|
case ColorObjectType.TextColor:
|
||||||
|
color = BazookaManager.Instance.GetColorSettingText();
|
||||||
|
colorType = new((int)color[0] / 255f, (int)color[1] / 255f, (int)color[2] / 255f);
|
||||||
|
if (invert) colorType = new(1f - colorType.r, 1f - colorType.g, 1f - colorType.b);
|
||||||
|
gameObject.GetComponent<TMP_Text>().color = colorType;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Start()
|
||||||
|
{
|
||||||
|
SetColor();
|
||||||
|
}
|
||||||
|
}
|
||||||
2
Assets/Scripts/CustomColorObject.cs.meta
Normal file
2
Assets/Scripts/CustomColorObject.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 73b30df2b3a7144b99b75ce70168fd50
|
||||||
@@ -1,9 +1,14 @@
|
|||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.UI;
|
using UnityEngine.UI;
|
||||||
|
|
||||||
public class SettingsMenu : MonoBehaviour
|
public class SettingsMenu : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
public GameObject settingsMenu;
|
||||||
|
public ColorPanel colorMenu;
|
||||||
|
public Button toggleButton;
|
||||||
|
|
||||||
public Toggle setting1toggle;
|
public Toggle setting1toggle;
|
||||||
public Toggle setting2toggle;
|
public Toggle setting2toggle;
|
||||||
public Toggle setting3toggle;
|
public Toggle setting3toggle;
|
||||||
@@ -11,25 +16,34 @@ public class SettingsMenu : MonoBehaviour
|
|||||||
public Toggle setting5toggle;
|
public Toggle setting5toggle;
|
||||||
public Slider musicSlider;
|
public Slider musicSlider;
|
||||||
public Slider sfxSlider;
|
public Slider sfxSlider;
|
||||||
public ColorPanel bgColorPanel;
|
|
||||||
public Button bgPreviewModePanel;
|
|
||||||
public GameObject settingsUI;
|
public GameObject settingsUI;
|
||||||
|
|
||||||
|
public Button switchColorTypeButton;
|
||||||
|
public int colorType = 0;
|
||||||
|
public bool colorCanSave = true;
|
||||||
|
|
||||||
private void Start()
|
private void Start()
|
||||||
{
|
{
|
||||||
bgColorPanel.Init(BazookaManager.Instance.GetColorSettingBackground(), new Color(58 / 255f, 58 / 255f, 58 / 255f));
|
colorMenu.Init(Color.white, Color.white);
|
||||||
bgColorPanel.OnColorChanged += color =>
|
colorMenu.OnColorChanged += color =>
|
||||||
{
|
{
|
||||||
BazookaManager.Instance.SetColorSettingBackground(color);
|
if (!colorCanSave) return;
|
||||||
if (!settingsUI.activeSelf) Camera.main.backgroundColor = new Color((int)color[0] / 255f, (int)color[1] / 255f, (int)color[2] / 255f);
|
|
||||||
|
if (colorType == 0) BazookaManager.Instance.SetColorSettingBackground(color);
|
||||||
|
else if (colorType == 1) BazookaManager.Instance.SetColorSettingMenuBackground(color);
|
||||||
|
else if (colorType == 2) BazookaManager.Instance.SetColorSettingButton(color);
|
||||||
|
else if (colorType == 3) BazookaManager.Instance.SetColorSettingText(color);
|
||||||
|
|
||||||
|
foreach (CustomColorObject customColorObject in FindObjectsByType<CustomColorObject>(FindObjectsSortMode.None)) customColorObject.SetColor();
|
||||||
};
|
};
|
||||||
bgPreviewModePanel.onClick.AddListener(() =>
|
toggleButton.onClick.AddListener(() =>
|
||||||
{
|
{
|
||||||
settingsUI.SetActive(!settingsUI.activeSelf);
|
settingsMenu.SetActive(!settingsMenu.activeSelf);
|
||||||
var value = BazookaManager.Instance.GetColorSettingBackground();
|
colorMenu.gameObject.SetActive(!colorMenu.gameObject.activeSelf);
|
||||||
Camera.main.backgroundColor = !settingsUI.activeSelf ? new Color((int)value[0] / 255f, (int)value[1] / 255f, (int)value[2] / 255f) : new Color(24 / 255f, 24 / 255f, 24 / 255f);
|
toggleButton.transform.GetChild(0).GetComponent<TMP_Text>().text = settingsMenu.activeSelf ? "Colors" : "Settings";
|
||||||
bgPreviewModePanel.transform.GetChild(0).GetComponent<TMP_Text>().text = settingsUI.activeSelf ? "Preview On" : "Preview Off";
|
SwitchColorType(0);
|
||||||
});
|
});
|
||||||
|
switchColorTypeButton.onClick.AddListener(() => SwitchColorType());
|
||||||
|
|
||||||
musicSlider.value = BazookaManager.Instance.GetSettingMusicVolume();
|
musicSlider.value = BazookaManager.Instance.GetSettingMusicVolume();
|
||||||
sfxSlider.value = BazookaManager.Instance.GetSettingSFXVolume();
|
sfxSlider.value = BazookaManager.Instance.GetSettingSFXVolume();
|
||||||
@@ -74,4 +88,37 @@ public class SettingsMenu : MonoBehaviour
|
|||||||
});
|
});
|
||||||
sfxSlider.onValueChanged.AddListener(value => BazookaManager.Instance.SetSettingSFXVolume(value));
|
sfxSlider.onValueChanged.AddListener(value => BazookaManager.Instance.SetSettingSFXVolume(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SwitchColorType(int color = -1)
|
||||||
|
{
|
||||||
|
var type = color == -1 ? colorType : color;
|
||||||
|
var text = colorMenu.transform.GetChild(0).GetComponent<TMP_Text>();
|
||||||
|
var colorToSet = new JArray(255, 255, 255);;
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case 0: //IGBGColor
|
||||||
|
text.text = "Menu background color";
|
||||||
|
colorType = 1;
|
||||||
|
colorToSet = BazookaManager.Instance.GetColorSettingMenuBackground();
|
||||||
|
break;
|
||||||
|
case 1: //MBGColor
|
||||||
|
text.text = "Button color";
|
||||||
|
colorType = 2;
|
||||||
|
colorToSet = BazookaManager.Instance.GetColorSettingButton();
|
||||||
|
break;
|
||||||
|
case 2: //BColor
|
||||||
|
text.text = "Text color";
|
||||||
|
colorType = 3;
|
||||||
|
colorToSet = BazookaManager.Instance.GetColorSettingText();
|
||||||
|
break;
|
||||||
|
case 3: //TColor
|
||||||
|
text.text = "In game background color";
|
||||||
|
colorType = 0;
|
||||||
|
colorToSet = BazookaManager.Instance.GetColorSettingBackground();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
colorCanSave = false;
|
||||||
|
colorMenu.SetColor(new Color((int)colorToSet[0] / 255f, (int)colorToSet[1] / 255f, (int)colorToSet[2] / 255f));
|
||||||
|
colorCanSave = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
7
Assets/Scripts/Types/ColorObjectType.cs
Normal file
7
Assets/Scripts/Types/ColorObjectType.cs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
public enum ColorObjectType
|
||||||
|
{
|
||||||
|
InGameBackgroundColor,
|
||||||
|
MenuBackgroundColor,
|
||||||
|
TextColor,
|
||||||
|
ButtonColor
|
||||||
|
}
|
||||||
2
Assets/Scripts/Types/ColorObjectType.cs.meta
Normal file
2
Assets/Scripts/Types/ColorObjectType.cs.meta
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5d4d64e0ea37c40b3a4bb388144188cc
|
||||||
Reference in New Issue
Block a user