using System; using System.IO; using System.Linq; using UnityEngine; using System.Collections.Generic; public class CTAGUI : MonoBehaviour { private const int BUTTON_HEIGHT_SIZE = 20; private ChallengeThemAll challengeThemAll; private Dictionary> pList = new Dictionary>(); private PANEL tab; private bool ShowWindow; private bool ShowHud = true; private Rect hudWindow = new Rect(40, 50, 200, 150); private Rect principalWindow = new Rect(Screen.width / 2 - 350, Screen.height / 2 - 150, 700, 300); private Rect loginWindow = new Rect(Screen.width / 2 - 115, Screen.height / 2 - 55, 230, 140); private Rect errorWindow = new Rect(Screen.width / 2 - 115, Screen.height / 2 - 55, 230, 140); private bool redim; private Vector2 scroll; private Vector2 scroll2; //FEEDBACK VAR private int type; private string feedback = ""; //MISSION LIST VAR private IEnumerable ordered = new List(); private int order = 7; //0 name, 1 aname, 2 creator, 3 acreator, 4 quality, 5 aquality, 6 players, 7 aplayers, 8 date, 9 adate private Vector2 scroll3; private Vector2 scroll4; private bool lastErrorShow = true; //MISSION INFO VAR private int mts; public int missiontoshow { get { return mts; } set { mts = value; tab = PANEL.MISSION_INFO; } } //CREATE MISSION VAR private MissionData mission = new MissionData(); private int menu = -1; private int showedCond = -1; private string lastPassword = ""; private int flashGC = -1; private int flashMC = -1; private Dictionary> messages = new Dictionary>(); private string message = ""; enum PANEL : int { HOME = 0, PROFILE = 1, GENERAL_CHAT = 2, FEEDBACK = 3, MANAGE_MISSION_GUI = 4, MISSION_CHAT = 5, MISSION_LIST = 6, MISSION_INFO = 7, CREATE_MISSION =8, CREDITS = 9 } public CTAGUI(ChallengeThemAll challengeThemAll) { this.challengeThemAll = challengeThemAll; } public void OnGUI() { GUI.skin = HighLogic.Skin; if (ShowHud) { if (GUI.Button(new Rect(hudWindow.x + hudWindow.width, hudWindow.y, 30, 30), ">>")) ShowHud = false; hudWindow = GUI.Window(1957, hudWindow, DrawHud, ""); } else { if (GUI.Button(new Rect(hudWindow.x + hudWindow.width, hudWindow.y, 30, 30), "<<")) ShowHud = true; if (GUI.Button(new Rect(hudWindow.x + hudWindow.width - 40, hudWindow.y, 40, 40), "M")) ShowWindow = !ShowWindow; } if (ShowWindow) { if (StaticData.isLogged) principalWindow = GUI.Window(1958, principalWindow, DrawPrincipalGui, ""); else loginWindow = GUI.Window(1958, loginWindow, DrawLogginGui, ""); } if (!lastErrorShow) { errorWindow = GUI.Window(1959, errorWindow, DrawErrorWindow, ""); } } private void DrawErrorWindow(int id) { GUI.BeginGroup(new Rect(loginWindow.width / 2 - 110, 20, 220, 110)); GUI.Label(new Rect(10, 0, 100, 30), "error :" + StaticData.errorMessage); if (GUI.Button(new Rect(10, 80, 100, 30), "Ok")) { lastErrorShow = true; } GUI.EndGroup(); } private void DrawPrincipalGui(int id) { /* DRAWING ACTUAL WINDOW */ GUI.BeginGroup(new Rect(140, 20, principalWindow.width - 145, principalWindow.height - 25), GUI.skin.box); switch (tab) { case PANEL.PROFILE: ProfileGui(); break; case PANEL.GENERAL_CHAT: case PANEL.MISSION_CHAT: ChatGui(); break; case PANEL.MISSION_LIST: MissionListGui(); break; case PANEL.MISSION_INFO: MissionInfoGui(); break; case PANEL.CREATE_MISSION: CreateMissionGui(); break; case PANEL.FEEDBACK: FeedBackWindow(); break; case PANEL.MANAGE_MISSION_GUI: ManageMissionGui(); break; case PANEL.CREDITS: CreditsGui(); break; } GUI.EndGroup(); /* DRAW WINDOW SELECTOR */ GUI.BeginGroup(new Rect(5, 20, 135, principalWindow.height - 25), GUI.skin.box); PANEL lastTab = tab; bool isInMission = StaticData.currentMission != null && !StaticData.testMode, isCreator = isInMission && StaticData.currentMission.missionCreator == StaticData.username, isInGame = HighLogic.CurrentGame!=null; GUI.BeginGroup(new Rect(3, 3, 129, BUTTON_HEIGHT_SIZE * 3 + 6), GUI.skin.box); if (GUI.Button(new Rect(2, 2, 123, BUTTON_HEIGHT_SIZE), "Home")) tab = PANEL.HOME; else if (GUI.Button(new Rect(2, 2 + BUTTON_HEIGHT_SIZE, 123, BUTTON_HEIGHT_SIZE), "Profile")) tab = PANEL.PROFILE; if(flashGC!=-1) { if(++flashGC>50) GUI.color = Color.yellow; if (flashGC > 100) flashGC = 0; } if (GUI.Button(new Rect(2, 2 + BUTTON_HEIGHT_SIZE * 2, 123, BUTTON_HEIGHT_SIZE), "Chat")) { tab = PANEL.GENERAL_CHAT; } GUI.color = Color.white; GUI.EndGroup(); GUI.BeginGroup(new Rect(3, (principalWindow.height - 25) / 2 - (BUTTON_HEIGHT_SIZE * (isCreator ? 3 : 2)) / 2, 129, BUTTON_HEIGHT_SIZE * (isCreator ? 3 : 2) + 6), GUI.skin.box); GUI.enabled = isInGame; if (!isInMission && GUI.Button(new Rect(2, 2, 123, BUTTON_HEIGHT_SIZE), "Mission list")) { mts = -1; challengeThemAll.getServerManager().sendPacket(new Packet8RequestMission(true, false, 0)); tab = PANEL.MISSION_LIST; } if ((!isInMission) && GUI.Button(new Rect(2, BUTTON_HEIGHT_SIZE + 2, 123, BUTTON_HEIGHT_SIZE), "Create a mission")) tab = PANEL.CREATE_MISSION; GUI.enabled = true; if (isCreator && GUI.Button(new Rect(2, 2 + BUTTON_HEIGHT_SIZE * 2, 123, BUTTON_HEIGHT_SIZE), "Manage mission")) { tab = PANEL.MANAGE_MISSION_GUI; } else if (isInMission && !StaticData.testMode && GUI.Button(new Rect(2, 2, 123, BUTTON_HEIGHT_SIZE), "Mission info")) { tab = PANEL.MISSION_INFO; } if (flashMC != -1) { if (++flashMC > 50) GUI.color = Color.yellow; if (flashMC > 100) flashMC = 0; } if (isInMission && !StaticData.testMode && GUI.Button(new Rect(2, 2 + BUTTON_HEIGHT_SIZE, 123, BUTTON_HEIGHT_SIZE), "Mission chat")) { tab = PANEL.MISSION_CHAT; } GUI.color = Color.white; GUI.EndGroup(); GUI.BeginGroup(new Rect(3, principalWindow.height - 29 - BUTTON_HEIGHT_SIZE * 3, 129, BUTTON_HEIGHT_SIZE * 3 + 6), GUI.skin.box); if (GUI.Button(new Rect(2, 2, 123, BUTTON_HEIGHT_SIZE), "Feedback")) tab = PANEL.FEEDBACK; else if (GUI.Button(new Rect(2, 2 + BUTTON_HEIGHT_SIZE, 123, BUTTON_HEIGHT_SIZE), "Credit")) { tab = PANEL.CREDITS; } else if (GUI.Button(new Rect(2, 2 + BUTTON_HEIGHT_SIZE * 2, 123, BUTTON_HEIGHT_SIZE), "Disconnect")) challengeThemAll.Disconnect(); GUI.EndGroup(); if (lastTab != tab) GUI.FocusControl(""); GUI.EndGroup(); /* RESIZING SYSTEM */ if (Input.mousePosition.x >= principalWindow.x + principalWindow.width - 10 && Input.mousePosition.x <= principalWindow.x + principalWindow.width && Screen.height - Input.mousePosition.y >= principalWindow.y + principalWindow.height - 10 && Screen.height - Input.mousePosition.y <= principalWindow.y + principalWindow.height) { redim = Input.GetMouseButton(0); } else { if (redim) { redim = Input.GetMouseButton(0); principalWindow.width = Mathf.Max(700, Input.mousePosition.x - principalWindow.x); principalWindow.height = Mathf.Max(Screen.height - Input.mousePosition.y - principalWindow.y, 300); } else GUI.DragWindow(); } } private void CreditsGui() { GUI.Label(new Rect(5, 5, 400, 20), "Team : "); GUI.Label(new Rect(5, 20, 400, 20), "Megatlantis (server and client developer)"); GUI.Label(new Rect(5, 40, 400, 20), "Tavon (gui developer)"); GUI.Label(new Rect(5, principalWindow.height - 55, 1000, 20), "This mod is licensed under Creative Commons BY-NC-DC."); } private void MissionInfoGui() { MissionData missionData; if (StaticData.currentMission != null) missionData = StaticData.currentMission; else StaticData.missionList.TryGetValue(mts, out missionData); if (missionData!=null) { if (!missionData.dataRequested) { missionData.dataRequested = true; challengeThemAll.getServerManager().sendPacket(new Packet8RequestMission(false, false, mts)); } else { if (missionData.containtAllInformation) { GUILayout.BeginArea(new Rect(5, 5, (principalWindow.width - 145)/2, principalWindow.height - 25)); GUILayout.BeginHorizontal(); GUILayout.Label("Name : "); GUILayout.Label(missionData.missionName); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Creator : "); GUILayout.Label(missionData.missionCreator); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Description : "); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(-10); GUILayout.BeginHorizontal(); GUILayout.Label(missionData.missionDesc); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Difficulty : "); GUILayout.Label(missionData.difficulty == 0 ? "Easy" : (missionData.difficulty == 1 ? "Medium" : "Hard")); GUILayout.EndHorizontal(); if (StaticData.currentMission == null) { GUILayout.BeginHorizontal(); GUILayout.BeginHorizontal(); GUILayout.Label("Start in " + Mathf.Abs((challengeThemAll.getServerTime() - missionData.startTime)/1000) + "s"); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if (GUILayout.Button("Return") || ((challengeThemAll.getServerTime() - missionData.startTime) > 0 && StaticData.currentMission == null)) { tab = PANEL.MISSION_LIST; } if (GUILayout.Button("Accept")) { challengeThemAll.getServerManager().sendPacket(new Packet8RequestMission(false, true, mts)); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } GUILayout.EndArea(); GUILayout.BeginArea(new Rect((principalWindow.width - 145) / 2, 5, (principalWindow.width - 145) / 2, principalWindow.height - 25)); GUILayout.Label("Conditions :"); GUILayout.BeginHorizontal(); GUILayout.Space(30); GUILayout.BeginVertical(); foreach (Condition condition in missionData.conditionList) { if (condition.completed) GUI.color = Color.green; else if (StaticData.currentMission != null) GUI.color = Color.red; GUILayout.Label(condition.GetDisplayString(missionData)); GUILayout.Space(-10); GUI.color = Color.white; } GUILayout.EndVertical(); GUILayout.EndHorizontal(); GUILayout.EndArea(); } } } } private void ManageMissionGui() { int width = (int)(principalWindow.width - 145)/2; if(GUI.Button(new Rect(5, 5, width-10, 25), "Participate")) { } if(GUI.Button(new Rect(5, 35, width-10, 25), "Cancel mission")) { } GUILayout.BeginArea(new Rect(width+10, 0, width-15, principalWindow.height - 25)); scroll2 = GUILayout.BeginScrollView(scroll2); foreach (string pname in pList[StaticData.currentMission.missionId]) { GUILayout.BeginHorizontal(); GUILayout.Label(pname); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(-10); } GUILayout.Space(5); GUILayout.EndScrollView(); GUILayout.EndArea(); } private void MissionListGui() { int width = (int)(principalWindow.width - 145); /* ORDERING */ if (GUI.Button(new Rect(0, 0, width / 5, 30), "Name")) { order = order == 0 ? 1 : 0; onMissionListModified(); } if (GUI.Button(new Rect(width / 5, 0, width / 5, 30), "Creator")) { order = order == 2 ? 3 : 2; onMissionListModified(); } if (GUI.Button(new Rect(width / 5 * 2, 0, width / 5, 30), "Quality")) { order = order == 4 ? 5 : 4; onMissionListModified(); } if (GUI.Button(new Rect(width / 5 * 3, 0, width / 5, 30), "Players")) { order = order == 6 ? 7 : 6; onMissionListModified(); } if (GUI.Button(new Rect(width / 5 * 4, 0, width / 5, 30), "Start In")) { order = order == 8 ? 9 : 8; onMissionListModified(); } /* DRAWING LIST */ GUI.BeginScrollView(new Rect(0, 30, width, principalWindow.height - 55), scroll3, new Rect(0, 0, width, ordered.Count() * 30)); for (int i = 0; i < ordered.Count(); i++) { MissionData m = StaticData.missionList[ordered.ElementAtOrDefault(i)]; GUI.BeginGroup(new Rect(0, i * 30, width, 30), GUI.skin.box); if (GUI.Button(new Rect(0, 0, width, 30), "")) { mts = m.missionId; tab = PANEL.MISSION_INFO; } GUI.Label(new Rect(3, 5, 100, 20), m.missionName); GUI.Label(new Rect(width / 5, 5, 100, 20), m.missionCreator); GUI.Label(new Rect(width / 5 * 2, 5, 100, 20), m.rating + ""); GUI.Label(new Rect(width / 5 * 3, 5, 100, 20), m.currentPlayer + "/" + m.maxPlayer); GUI.Label(new Rect(width / 5 * 4, 5, 100, 20), Mathf.Abs((challengeThemAll.getServerTime()-m.startTime)/1000) + ""); if (challengeThemAll.getServerTime() - m.startTime > 0) { challengeThemAll.getServerManager().sendPacket(new Packet8RequestMission(true, false, 0)); } GUI.EndGroup(); } GUI.EndScrollView(); } private void FeedBackWindow() { if (GUI.Toggle(new Rect(5, 5, 60, 20), type == 0, "Bug")) type = 0; if (GUI.Toggle(new Rect(70, 5, 80, 20), type == 1, "Suggestion")) type = 1; if (GUI.Toggle(new Rect(180, 5, 60, 20), type == 2, "Other")) type = 2; if (GUI.Button(new Rect(principalWindow.width - 230, 5, 80, 25), "Send")) { String name = ""; if (type == 0) name = "Bug"; else if (type == 1) name = "Sugg"; else name = "Other"; challengeThemAll.getServerManager().sendPacket(new Packet12FeedBack(name, feedback)); } feedback = GUI.TextArea(new Rect(5, 40, principalWindow.width - 155, principalWindow.height - 70), feedback); } private void CreateMissionGui() { int width = (int)(principalWindow.width - 145) / 2, heigth = (int)(principalWindow.height - 25); if(StaticData.testMode) { if(GUI.Button(new Rect(5, 5, 100, 30), "Stop test")) { challengeThemAll.testMission(null); } return; } /* LEFT PANEL */ GUI.BeginGroup(new Rect(0, 0, width, heigth), GUI.skin.box); /* NAME AND DESCRIPTION */ GUI.skin.textField.padding.top = 7; GUI.SetNextControlName("mn"); mission.missionName = GUI.TextField(new Rect(5, 5, width - 10, 30), mission.missionName); GUI.skin.textField.padding.top = 3; if (mission.missionName.Length == 0 && GUI.GetNameOfFocusedControl() != "mn") GUI.Label(new Rect(11, 10, 300, 30), "Mission name"); if (mission.missionDesc.Length == 0 && GUI.GetNameOfFocusedControl() != "md") GUI.Label(new Rect(11, 42, 300, 30), "Description"); GUI.SetNextControlName("md"); mission.missionDesc = GUI.TextArea(new Rect(5, 37, width - 10, heigth - 137), mission.missionDesc); if (menu > 0 && mission.missionTarget[menu] == null) mission.missionTarget[menu] = new MissionTarget(); /* DIFFICULTY */ int startToggle = GUI.skin.toggle.padding.left; GUI.skin.toggle.padding.left = 10; if (GUI.Toggle(new Rect(0, heigth - 32, 60, 20), mission.difficulty == 0, "Easy")) mission.difficulty = 0; if (GUI.Toggle(new Rect(60, heigth - 32, 80, 20), mission.difficulty == 1, "Medium")) mission.difficulty = 1; if (GUI.Toggle(new Rect(140, heigth - 32, 60, 20), mission.difficulty == 2, "Hard")) mission.difficulty = 2; GUI.skin.toggle.padding.left = startToggle; /* CONTROLS BUTTON */ if (GUI.Button(new Rect(5, heigth - 65, (width - 10) / 3, 30), "Targets")) menu = -3; if (GUI.Button(new Rect(5 + (width - 10) / 3, heigth - 65, (width - 10) / 3, 30), "Condition")) menu = -2; if (GUI.Button(new Rect(5 + (width - 10) / 3 * 2, heigth - 65, (width - 10) / 3, 30), "Test")) { challengeThemAll.testMission(mission); } if (GUI.Button(new Rect(width - 65, heigth - 32, 60, 30), "Create")) { challengeThemAll.createMission(mission); } GUI.Label(new Rect(5, heigth - 93, 300, 20), "Duration :"); int result; if ( int.TryParse( "0" + GUI.TextField(new Rect(70, heigth - 95, 40, 25), mission.missionTime == 0 ? "" : mission.missionTime + ""), out result)) mission.missionTime = result; GUI.EndGroup(); /* RIGHT PANEL */ GUI.BeginGroup(new Rect(width, 0, width + 1, heigth), GUI.skin.box); /* CONDITIONS */ if (menu == -2) { GUI.Label(new Rect(width / 2 - 35, 5, 70, 20), "Conditions"); if (GUI.Button(new Rect(3, 3, 15, 15), "+")) { new CSelector("Choose condition", Condition.conditionsType, delegate(byte b) { onTargetListModified(); mission.conditionList.Add(new Condition(b)); }).OpenWindow(); } scroll4 = GUI.BeginScrollView(new Rect(5, 30, width - 10, heigth - 35), scroll4, new Rect(0, 0, width - 25, mission.conditionList.Count * 30)); for (int i = 0; i < mission.conditionList.Count; i++) { Condition cond = mission.conditionList[i]; GUI.BeginGroup(new Rect(0, i * 30, width - 30, 30), GUI.skin.box); GUI.enabled = i != showedCond; if (GUI.Button(new Rect(0, 0, 20, 30), "-")) { mission.conditionList.RemoveAt(i); onTargetListModified(); i--; continue; } if (GUI.Button(new Rect(20, 0, (width - 50), 30), cond.GetDisplayString(mission))) { new ConditionParameter(mission, i, () => showedCond = -1).OpenWindow(); showedCond = i; } GUI.enabled = true; GUI.EndGroup(); } GUI.EndScrollView(); } /* TARGET SETTER */ else if (menu == -3) { GUI.Label(new Rect(width / 2 - 35, 5, 70, 20), "Targets"); if (GUI.Button(new Rect(3, 3, 15, 15), "+")) { mission.missionTarget.Add(new MissionTarget()); } scroll4 = GUI.BeginScrollView(new Rect(5, 30, width - 10, heigth - 35), scroll4, new Rect(0, 0, width - 25, mission.missionTarget.Count * 30)); for (int i = 0; i < mission.missionTarget.Count; i++) { MissionTarget cond = mission.missionTarget[i]; GUI.BeginGroup(new Rect(0, i * 30, width - 30, 30), GUI.skin.box); GUI.enabled = (i != showedCond); bool used = mission.conditionList.FirstOrDefault(c => c.GetDependencies() == i) != null; if (used) GUI.enabled = false; if (GUI.Button(new Rect(0, 0, 20, 30), "-")) { mission.missionTarget.RemoveAt(i); i--; continue; } if (used && i != showedCond) GUI.enabled = true; if (GUI.Button(new Rect(20, 0, (width - 50), 30), cond != null ? (cond.isKerbal ? "Kerbal " + cond.targetName : "Vessel " + cond.targetName) : "Empty")) { menu = i; } GUI.enabled = true; GUI.EndGroup(); } GUI.EndScrollView(); } /* TARGET */ else if (menu > -1) { MissionTarget target = mission.missionTarget[menu]; if (GUI.Button(new Rect(5, 5, 30, 25), "^")) menu = -3; GUI.enabled = !target.isKerbal; if (GUI.Button(new Rect(width / 2, 10, 70, 25), "Kerbal")) target.isKerbal = true; GUI.enabled = !GUI.enabled; if (GUI.Button(new Rect(width / 2 - 70, 10, 70, 25), "Vessel")) target.isKerbal = false; GUI.enabled = true; if (!target.isKerbal) { GUI.Label(new Rect(5, 38, 100, 20), "Vessel : "); if (GUI.Button(new Rect(60, 40, width - 70, 20), target.filepath.Split('\\').Last())) { new Selector("Select vessel", new DirectoryInfo(KSPUtil.ApplicationRootPath + "/saves/" + HighLogic.SaveFolder + "/Ships/VAB/").GetFiles("*.craft") . Select(fi => fi.FullName).ToList() , s => s.ToString().Split('\\').Last(), s => mission.missionTarget[menu].filepath = s).OpenWindow(); } } GUI.Label(new Rect(5, 60, 100, 20), "Celestial body :"); if (GUI.Button(new Rect(100, 62, width - 110, 20), target.celestialBody)) new Selector("Select celestial body", FlightGlobals.Bodies, s => s.name, body => mission.missionTarget[menu].celestialBody = body.name). OpenWindow(); GUI.Label(new Rect(5, 85, 100, 20), "Target name :"); target.targetName = GUI.TextField(new Rect(90, 85, width - 100, 20), target.targetName); float a; GUI.Toggle(new Rect(5, 101, 100, 20), target.isLanded, "Landed (wip)"); if (target.isLanded) { GUI.Label(new Rect(5, 135 + 20, 100, 20), "Longitude :"); if ( float.TryParse( "0" + GUI.TextField(new Rect(75, 136 + 20, 100, 20), target.SMA_long.ToString().Contains(".") ? target.SMA_long + "" : target.SMA_long + ".0"), out a)) target.SMA_long = a; GUI.Label(new Rect(5, 110 + 20, 100, 20), "Lattitude :"); if ( float.TryParse( "0" + GUI.TextField(new Rect(70, 111 + 20, 100, 20), target.inclinaison_lat.ToString().Contains(".") ? target.inclinaison_lat + "" : target.inclinaison_lat + ".0"), out a)) target.inclinaison_lat = a; } else { GUI.Label(new Rect(5, 110 + 20, 100, 20), "Apoapsis :"); if ( float.TryParse( "0" + GUI.TextField(new Rect(70, 111 + 20, 100, 20), target.SMA_long.ToString().Contains(".") ? target.SMA_long + "" : target.SMA_long + ".0"), out a)) target.SMA_long = a; GUI.Label(new Rect(5, 135 + 20, 100, 20), "Eccentricity :"); if ( float.TryParse( "0" + GUI.TextField(new Rect(86, 136 + 20, 100, 20), target.eccentricity.ToString().Contains(".") ? target.eccentricity + "" : target.eccentricity + ".0"), out a)) target.eccentricity = a; GUI.Label(new Rect(5, 160 + 20, 100, 20), "Inclinaison :"); if ( float.TryParse( "0" + GUI.TextField(new Rect(80, 161 + 20, 100, 20), target.inclinaison_lat.ToString().Contains(".") ? target.inclinaison_lat + "" : target.inclinaison_lat + ".0"), out a)) target.inclinaison_lat = a; GUI.Label(new Rect(5, 185 + 20, 100, 20), "LAN :"); if ( float.TryParse( "0" + GUI.TextField(new Rect(45, 185 + 20, 100, 20), target.LAN.ToString().Contains(".") ? target.LAN + "" : target.LAN + ".0"), out a)) target.LAN = a; } } GUI.EndGroup(); } private void ProfileGui() { GUI.Label(new Rect(10, 5, 400, 20), "Username : " + StaticData.username); GUI.Label(new Rect(10, 25, 400, 20), "Rank : " + StaticData.rank); GUI.Label(new Rect(10, 45, 400, 20), "Missions completed : " + StaticData.missionAccomplished); GUI.Label(new Rect(10, 65, 400, 20), "Gold Badge : " + StaticData.goldMedal); GUI.Label(new Rect(10, 85, 400, 20), "Silver Badge : " + StaticData.silverMedal); GUI.Label(new Rect(10, 105, 400, 20), "Copper Badge : " + StaticData.bronzeMedal); GUI.Label(new Rect(10, 125, 400, 20), "Elo : " + StaticData.elo); } private void ChatGui() { if (tab == PANEL.MISSION_CHAT) flashMC = -1; else flashGC = -1; /* DRAW MESSAGES */ GUILayout.BeginArea(new Rect(0, 0, principalWindow.width - 290, principalWindow.height - 45)); scroll = GUILayout.BeginScrollView(scroll); if (!messages.ContainsKey(tab == PANEL.MISSION_CHAT ? StaticData.currentMission.missionId : -1)) messages.Add(tab == PANEL.MISSION_CHAT ? StaticData.currentMission.missionId : -1, new List()); foreach (string messagea in messages[tab == PANEL.MISSION_CHAT ? StaticData.currentMission.missionId : -1]) { GUILayout.BeginHorizontal(); GUILayout.Label(messagea); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(-10); } GUILayout.Space(5); GUILayout.EndScrollView(); GUILayout.EndArea(); /* TEXT FIELD */ GUI.SetNextControlName("md"); message = GUI.TextField(new Rect(0, principalWindow.height - 45, principalWindow.width - 290, 20), message); if (Event.current.isKey && Event.current.keyCode == KeyCode.Return && GUI.GetNameOfFocusedControl() == "md") { if (message.Length > 0) SendMessage(tab==PANEL.MISSION_CHAT?StaticData.currentMission.missionId:-1, message); message = ""; } /* PLAYERNAMES */ GUILayout.BeginArea(new Rect(principalWindow.width - 290, 0, 145, principalWindow.height - 25), GUI.skin.box); scroll2 = GUILayout.BeginScrollView(scroll2); if (!pList.ContainsKey(tab == PANEL.MISSION_CHAT ? StaticData.currentMission.missionId : -1)) pList.Add(tab == PANEL.MISSION_CHAT ? StaticData.currentMission.missionId : -1, new List()); foreach (string pname in pList[tab == PANEL.MISSION_CHAT ? StaticData.currentMission.missionId : -1]) { GUILayout.BeginHorizontal(); GUILayout.Label(pname); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); GUILayout.Space(-10); } GUILayout.Space(5); GUILayout.EndScrollView(); GUILayout.EndArea(); } private void DrawLogginGui(int id) { GUI.BeginGroup(new Rect(loginWindow.width / 2 - 110, 20, 220, 110)); GUI.Label(new Rect(10, 0, 100, 30), "Username : "); StaticData.username = GUI.TextField(new Rect(10, 20, 200, 18), StaticData.username); GUI.Label(new Rect(10, 40, 220, 30), lastPassword.Length > 0 ? "Please retype your password :" : "Password : "); StaticData.password = GUI.PasswordField(new Rect(10, 60, 200, 18), StaticData.password, 'ยค', 25); if (GUI.Button(new Rect(10, 80, 100, 30), "Create account")) { StaticData.createAccount = true; new CreateAccountWindow(StaticData.username, CreateAccount).OpenWindow(); } if (GUI.Button(new Rect(110, 80, 100, 30), "Connect")) { StaticData.createAccount = false; tab = PANEL.HOME; challengeThemAll.connectToServer(); } GUI.EndGroup(); } private void DrawHud(int id)//200, 150 { if(GUI.Button(new Rect(80, 10, 40, 40), "M")) ShowWindow = !ShowWindow; GUI.DragWindow(); if(StaticData.currentMission==null) { GUI.Label(new Rect(10, 55, 150, 140), "You do not have mission"); return; } MissionData m = StaticData.currentMission; GUI.Box(new Rect(10, 55, 180, 25), ""); int startSize = GUI.skin.label.fontSize; GUI.skin.label.fontSize = 20; GUI.skin.label.alignment = TextAnchor.MiddleCenter; GUI.Label(new Rect(10, 55, 180, 25), "" + Convert.ToString(Mathf.Abs((challengeThemAll.getServerTime() - m.startTime) / 1000))); GUI.skin.label.fontSize = startSize; GUI.skin.label.alignment = TextAnchor.UpperLeft; GUI.Label(new Rect(10, 90, 300, 20), "Mission name : " + m.missionName); if (challengeThemAll.missionManager.getNextCondition()!=null) GUI.Label(new Rect(10, 110, 180, 300), "Actual target : " + challengeThemAll.missionManager.getNextCondition().GetDisplayString(m)); else GUI.Label(new Rect(10, 110, 300, 20), "Actual target : none"); } private void onTargetListModified() { //List toOrder = mission.missionTarget.Select((t, i) => i).ToList(); //condOrder = toOrder.OrderBy(test => mission.missionTarget[test].targetId); } public void addChatMessage(String message, int roomId) { if (roomId == -1) flashGC = 0; else flashMC = 0; if(!messages.ContainsKey(roomId)) messages.Add(roomId, new List()); messages[roomId].Add(message); } public void onMissionListModified() { List toOrder = new List(); foreach (int key in StaticData.missionList.Keys) toOrder.Add(key); switch (order) { case 0: ordered = toOrder.OrderBy(test => StaticData.missionList[test].missionName); break; case 1: ordered = toOrder.OrderByDescending(test => StaticData.missionList[test].missionName); break; case 2: ordered = toOrder.OrderBy(test => StaticData.missionList[test].missionCreator); break; case 3: ordered = toOrder.OrderByDescending(test => StaticData.missionList[test].missionCreator); break; case 4: ordered = toOrder.OrderBy(test => StaticData.missionList[test].rating); break; case 5: ordered = toOrder.OrderByDescending(test => StaticData.missionList[test].rating); break; case 6: ordered = toOrder.OrderBy(test => StaticData.missionList[test].currentPlayer); break; case 7: ordered = toOrder.OrderByDescending(test => StaticData.missionList[test].currentPlayer); break; case 8: ordered = toOrder.OrderBy(test => StaticData.missionList[test].startTime); break; case 9: ordered = toOrder.OrderByDescending(test => StaticData.missionList[test].startTime); break; } } public void onErrorMessage() { lastErrorShow = false; } private void SendMessage(int roomId, String message) { challengeThemAll.getServerManager().sendPacket(new Packet5ChatMessage(roomId, message)); } public void onPlayerListReceived(Packet10PlayerList data) { if(!pList.ContainsKey(data.id)) pList.Add(data.id, new List()); switch (data.mode) { case 0: pList[data.id].Remove(data.playerList[0]); break; case 1: pList[data.id].Add(data.playerList[0]); break; case 2: pList[data.id].Clear(); for (int i = 0; i < data.playerList.Length; i++) { pList[data.id].Add(data.playerList[i]); } break; } } private void CreateAccount(string email, string username, string password) { StaticData.username = username; StaticData.password = password; StaticData.email = email; challengeThemAll.connectToServer(); } }