-
Notifications
You must be signed in to change notification settings - Fork 0
/
MenuControll.cs
132 lines (114 loc) · 5.24 KB
/
MenuControll.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
using System;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.UI;
using static vehiclemod.data;
namespace vehiclemod
{
public class MenuControll
{
// BODY OF CANVAS
public static Transform openmenu;
private static Transform Content;
public static Transform MenuMainCars;
private static Transform MenuMainStatCar;
private static Transform CarStat;
// INFO COMPONENT
private static Slider Fuel;
private static Slider Speed;
private static Text CountCars;
private static Text CountSpeed;
private static Text NameTag;
private static GameObject template;
public static Dictionary<string, KeyValuePair<string, string>[]> addonData = new Dictionary<string, KeyValuePair<string, string>[]>();
public static void menuc()
{
GameObject key1 = GameObject.Instantiate(main.lb[0].LoadAsset<GameObject>("menucars"), Vector3.zero, Quaternion.identity);
key1.transform.Find("Stat").gameObject.SetActive(false);
key1.transform.Find("Menu").gameObject.SetActive(false);
key1.transform.Find("MenuCar").gameObject.SetActive(false);
key1.transform.Find("CarInfo").gameObject.SetActive(false);
key1.transform.Find("Templates").gameObject.SetActive(false);
CarStat = key1.transform.Find("CarInfo");
MenuMainCars = key1.transform.Find("Menu");
Content = MenuMainCars.transform.Find("FULL/WINDOW/CARS");
MenuMainStatCar = key1.transform.Find("Stat");
openmenu = key1.transform.Find("MenuCar");
template = key1.transform.Find("Templates/CARBTN").gameObject;
Fuel = MenuMainStatCar.Find("Fuel").GetComponent<Slider>();
Speed = MenuMainStatCar.Find("Speed").GetComponent<Slider>();
CountCars = MenuMainCars.transform.Find("CountCar").GetComponent<Text>();
CountSpeed = Speed.transform.Find("Content/Icon/Text").GetComponent<Text>();
NameTag = CarStat.transform.Find("CarTag").GetComponent<Text>();
openmenu.GetComponent<Button>().onClick.AddListener(new Action(() => Open(0)));
ADDCARS();
}
private static void ADDCARS()
{
foreach (var i in addonData)
{
GameObject item = GameObject.Instantiate(template);
item.transform.SetParent(Content);
Button Car = item.GetComponent<Button>();
Text Tag = item.transform.Find("Info").GetComponent<Text>();
RawImage Icon = item.transform.Find("Icon").GetComponent<RawImage>();
Action spawncar = new Action(() => main.SpawnCar(main.MyId, main.levelid, GetInfo(i.Key, "Prefab-Name"), Vector3.zero, Quaternion.identity));
Car.onClick.AddListener(spawncar);
Tag.text = GetInfo(i.Key, "Descriotion").Replace("/n", Environment.NewLine);
item.SetActive(true);
}
}
public static void Update(int i)
{
if (!GetObj(main.targetcar)) return;
InfoMain gg = GetObj(main.targetcar).GetComponent<VehComponent>().vehicleData;
if (i == 0 && CountCars)
{
CountCars.text = main.vehicles.Count.ToString();
}
if (i == 1 && Speed)
{
Speed.maxValue = gg.m_MaxSpeed;
Speed.value = gg.m_CurSpeed;
CountSpeed.text = Mathf.RoundToInt(gg.m_CurSpeed).ToString();
}
if (i == 2 && Fuel)
{
Fuel.maxValue = gg.m_MaxFuel;
Fuel.value = gg.m_CurFuel;
}
}
public static void CarStatScreen(string PlayerName, bool allowsit, bool allowdrive, float fuel)
{
string[] ch = new string[3];
if (allowsit)
ch[0] = "Allowed";
else
ch[0] = "Deny";
if (allowdrive)
ch[1] = "Allowed";
else
ch[1] = "Deny";
if (fuel >= 0) ch[2] = Mathf.Round(fuel).ToString();
if (NameTag) NameTag.text = "Vehicle by: " + PlayerName + Environment.NewLine + "Can you SIT?: " + ch[0] + Environment.NewLine + "CAN You DRIVE?: " + ch[1] + Environment.NewLine + "FUEL: "+ch[2];
}
public static void Open(int i)
{
if (i == 0 && MenuMainCars)
if (MenuMainCars.gameObject.active)
MenuMainCars.gameObject.SetActive(false);
else
MenuMainCars.gameObject.SetActive(true);
if (i == 1 && MenuMainStatCar)
if (MenuMainStatCar.gameObject.active)
MenuMainStatCar.gameObject.SetActive(false);
if (i == 11 && MenuMainStatCar)
MenuMainStatCar.gameObject.SetActive(true);
if (i == 2 && CarStat)
CarStat.gameObject.SetActive(true);
if (i == 22 && CarStat)
CarStat.gameObject.SetActive(false);
}
}
}