UI/UX Polish and improvements

This commit is contained in:
2024-08-19 06:49:22 +02:00
parent 4b01db375e
commit 36a4cee826
22 changed files with 3307 additions and 62 deletions

View File

@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
using TMPro;
@@ -58,17 +59,46 @@ public class GameManager : MonoBehaviour
[SerializeField]
private GameObject mapViewBtn;
[SerializeField]
private Transform targetCameraPos;
private MonumentManager monumentManager;
[SerializeField]
private float cameraSpeed = 5;
[SerializeField]
private GameObject quitPanel, transitionPanel;
[SerializeField]
private float transitionTime = 1f;
private float transitionCounter = 0;
// Start is called before the first frame update
void Start()
{
transitionPanel.SetActive(true);
Camera.main.transform.position = mainCameraPos.position;
targetCameraPos = mainCameraPos;
monumentManager = GameObject.Find("MonumentManager").GetComponent<MonumentManager>();
}
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.Escape))
{
quitPanel.SetActive(!quitPanel.activeSelf);
}
if(transitionCounter <= transitionTime)
{
transitionCounter += Time.deltaTime;
Color c = transitionPanel.GetComponent<Image>().color;
c.a = Mathf.Lerp(1f, 0f, transitionCounter / transitionTime);
transitionPanel.GetComponent<Image>().color = c;
if(transitionCounter > transitionTime) { Destroy(transitionPanel); }
}
float effectiveCamSpeed = Vector3.Distance(Camera.main.transform.position, targetCameraPos.position) * cameraSpeed * Time.deltaTime;
Camera.main.transform.position = Vector3.MoveTowards(Camera.main.transform.position, targetCameraPos.position, effectiveCamSpeed);
debugText.text = "";
foreach (var item in resources)
{
@@ -119,13 +149,13 @@ public class GameManager : MonoBehaviour
switch (view)
{
case 0: //Main view
Camera.main.transform.position = mainCameraPos.position;
targetCameraPos = mainCameraPos;
mainViewBtn.SetActive(false);
mapViewBtn.SetActive(true);
commitBtn.SetActive(false);
break;
case 1: //Map View
Camera.main.transform.position = worldMapCameraPos.position;
targetCameraPos = worldMapCameraPos;
mainViewBtn.SetActive(true);
mapViewBtn.SetActive(false);
commitBtn.SetActive(true);
@@ -134,4 +164,9 @@ public class GameManager : MonoBehaviour
break;
}
}
public void Quit()
{
Application.Quit();
}
}

View File

@@ -9,10 +9,12 @@ public class HouseManager : MonoBehaviour
private float currentTtnw = 0;
private int workerPerHouse = 3;
private GameManager gameManager;
[SerializeField]
private GameObject mouseNotificationLabel;
//House cost: Brick Tile Plank
public int[] cost = new int[3] { 10, 5, 2 };
[SerializeField]
private Transform notificationOrigin;
// Start is called before the first frame update
void Start()
{
@@ -34,6 +36,11 @@ public class HouseManager : MonoBehaviour
int newWorkers = Mathf.CeilToInt((float)freeWorkerSlots / workerPerHouse);
gameManager.AddResource(Resource.WORKER, newWorkers);
gameManager.AddResource(Resource.TOTAL_WORKER, newWorkers);
GameObject infoLabel = Instantiate(mouseNotificationLabel, notificationOrigin.transform.position, Quaternion.identity, GameObject.Find("Canvas").transform);
infoLabel.GetComponent<MousePosLabel>().tmp.text = $"{newWorkers} worker{(newWorkers > 1 ? "s" : "")} moved in";
infoLabel.transform.position = notificationOrigin.transform.position;
infoLabel.GetComponent <MousePosLabel>().direction = new Vector3(0, -2, 0);
}
}
}
@@ -45,6 +52,9 @@ public class HouseManager : MonoBehaviour
gameManager.GetResourceCount(Resource.PLANKS) < cost[2])
{
Debug.Log("Not enough resources to build house!");
GameObject infoLabel = Instantiate(mouseNotificationLabel, GameObject.Find("Canvas").transform);
infoLabel.GetComponent<MousePosLabel>().tmp.text = "Not enough resources to build house!";
infoLabel.GetComponent<MousePosLabel>().direction = new Vector3(0, 4, 0);
return;
}

View File

@@ -0,0 +1,64 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class MainMenu : MonoBehaviour
{
public float transitionTime = 1f;
private float counter, introCounter = 0;
public bool transition, introTransition = false;
public GameObject transitionPanel;
public GameObject introTransitionPanel;
// Start is called before the first frame update
void Start()
{
introTransition = true;
}
// Update is called once per frame
void Update()
{
if(transition)
{
counter += Time.deltaTime;
Color c = transitionPanel.GetComponent<Image>().color;
c.a = Mathf.Lerp(0f, 1f, counter / transitionTime);
transitionPanel.GetComponent<Image>().color = c;
}
if (counter >= transitionTime){
SceneManager.LoadScene("Main");
}
if (introTransition)
{
introCounter += Time.deltaTime;
Color c = introTransitionPanel.GetComponent<Image>().color;
c.a = Mathf.Lerp(1f, 0f, introCounter / transitionTime);
introTransitionPanel.GetComponent<Image>().color = c;
}
if (introCounter >= transitionTime)
{
Destroy(introTransitionPanel);
}
}
public void Quit()
{
Application.Quit();
}
public void OpenKbxLink()
{
Application.OpenURL("https://kittenbox.games");
}
public void StartGame()
{
transitionPanel.SetActive(true);
transition = true;
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: dcb1dd097d5b77c4a88729ee92b6bfdf

View File

@@ -0,0 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MousePosLabel : MonoBehaviour
{
public Vector3 direction = new Vector3(0,1,0);
public float floatSpeed = 20f;
public float lifetime = 5f;
private float counter = 0;
public TMPro.TMP_Text tmp;
// Start is called before the first frame update
void Awake()
{
tmp = GetComponent<TMPro.TMP_Text>();
transform.position = Input.mousePosition;
}
// Update is called once per frame
void Update()
{
transform.position = transform.position + direction * floatSpeed * Time.deltaTime;
counter += Time.deltaTime;
if( counter > lifetime/2)
{
Color32 c = new Color32((byte)tmp.color.r, (byte)tmp.color.g, (byte)tmp.color.b, (byte)tmp.color.a);
c.a = (byte)Mathf.Lerp(255f, 0f, (counter-(lifetime/2)) / (lifetime/2));
tmp.color = c;
tmp.SetAllDirty();
}
if (counter >= lifetime)
{
Destroy(gameObject);
}
}
}

View File

@@ -0,0 +1,2 @@
fileFormatVersion: 2
guid: 1822090174f4dd34ca9c4f0c5533b22e

View File

@@ -1,18 +0,0 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
public class WorldMapUI : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}

View File

@@ -1,2 +0,0 @@
fileFormatVersion: 2
guid: 3f5605aef187419469548c23842f08da