private string GetUserName(ObjectsLoader.RoomObject currentSelectionIn) { string selectedUser = ""; if (objectLoader.users.Count > 0 && currentSelectionIn._user != null && objectLoader.users.ContainsKey(currentSelectionIn._user)) { selectedUser = objectLoader.users[currentSelectionIn._user].username == null ? currentSelectionIn._user : objectLoader.users[currentSelectionIn._user].username; } return(selectedUser); }
public void GoToRoom() { if (ConnectionController.roomName != lastRoomName) { currentSelection = null; updateCurrentSelection(-1); terrLoader.GetTerrainFromConnection(); objectLoader.GetObjectsFromConnection(); mapLoader.GetMapFromConnection(); } }
private void Update() { Vector3 currentPos = Camera.main.ScreenToViewportPoint(Input.mousePosition); if (currentPos.y < 0.75f && currentPos.y > 0.25f && !(currentPos.x > selectMenuMin.x && currentPos.x < selectMenuMax.x && currentPos.y > selectMenuMin.y && currentPos.y < selectMenuMax.y)) { Vector3Int cellPosition = grid.WorldToCell(Camera.main.ScreenToWorldPoint(Input.mousePosition)); Vector2Int worldPosition = new Vector2Int(cellPosition.x, -cellPosition.y + 50); if (xPos != worldPosition.x || yPos != worldPosition.y) { if (worldPosition.x < 0 || worldPosition.x > 49 || worldPosition.y < 0 || worldPosition.y > 49) { if (selector.activeSelf) { selector.SetActive(false); } } else { if (!selector.activeSelf) { selector.SetActive(true); } Vector3 newCursorPos = new Vector3((cellPosition.x * 0.16f) + 0.08f, (cellPosition.y * 0.16f) + 0.08f, -3.0f); selector.transform.position = newCursorPos; } xPos = worldPosition.x; yPos = worldPosition.y; updateCursorText(worldPosition); } if (Input.GetMouseButtonDown(0)) { distance = Vector3.zero; touchStartTile = worldPosition; if (touchStart == Vector3.zero) { touchStart = Camera.main.ViewportToScreenPoint(Input.mousePosition); } if (selectMenu.activeSelf) { //selectMenu.GetComponent<SelectablesMenu>().UpdateSelectablesMenu(sendingPos, selectableObs, callback); selectMenu.SetActive(false); } } if (Input.GetMouseButton(0)) { distance += touchStart - Camera.main.ViewportToScreenPoint(Input.mousePosition); } if (Input.GetMouseButtonUp(0) && touchStartTile == worldPosition && touchStart != Vector3.zero) { //Debug.Log(distance); if (Mathf.Abs(distance.x) < 1000 && Mathf.Abs(distance.y) < 1000) { // this is the selected tile string xOut = worldPosition.x < 10 ? "0" + worldPosition.x.ToString() : worldPosition.x.ToString(); string yOut = worldPosition.y < 10 ? "0" + worldPosition.y.ToString() : worldPosition.y.ToString(); string sendingPos = xOut + yOut; selectableObs = objectLoader.GetSelectablesAtTile(sendingPos); if (selectableObs == null) { updateCurrentSelection(-1); touchStart = Vector3.zero; selectMenuMin = Vector2.zero; selectMenuMax = Vector2.zero; return; } if (selectableObs.Length > 1) { int maxStringLength = 0; foreach (ObjectsLoader.RoomObject t in selectableObs) { maxStringLength = maxStringLength > t.type.Length ? maxStringLength : t.type.Length; } float stringScaler = maxStringLength * 0.03f; float countScaler = selectableObs.Length * 0.08f; Action <int> callback = new Action <int>(updateCurrentSelection); float maxX = (currentPos.x + stringScaler) > 1 ? 1.0f : currentPos.x + stringScaler; float minY = (currentPos.y - countScaler) < 0.25f ? 0.25f : currentPos.y - countScaler; Vector2 maxMenuPos = new Vector2(maxX, minY + countScaler); Vector2 minMenuPos = new Vector2(maxMenuPos.x - stringScaler, minY + countScaler); selectMenu.SetActive(true); selectMenu.GetComponent <RectTransform>().anchorMin = minMenuPos; selectMenu.GetComponent <RectTransform>().anchorMax = maxMenuPos; selectMenu.GetComponent <SelectablesMenu>().UpdateSelectablesMenu(sendingPos, selectableObs, callback); GameObject dropdownMenu; try { dropdownMenu = selectMenu.transform.Find("Dropdown List").gameObject; } catch { // TODO: instantiate a backup, this is a bug when clicking out of menu and it becomes permanantly destroyed Destroy(selectMenu); Debug.Log("fix this ControlsPanel.cs error"); selectMenu = Instantiate(SelectablesDropdown, this.gameObject.transform); selectMenu.SetActive(true); selectMenu.GetComponent <RectTransform>().anchorMin = minMenuPos; selectMenu.GetComponent <RectTransform>().anchorMax = maxMenuPos; selectMenu.GetComponent <SelectablesMenu>().UpdateSelectablesMenu(sendingPos, selectableObs, callback); dropdownMenu = selectMenu.transform.Find("Dropdown List").gameObject; } GameObject selectMenuViewport = dropdownMenu.transform.Find("SelectablesViewport").gameObject; RectTransform openMenu = selectMenuViewport.GetComponent <RectTransform>(); Vector2 openMenuMin = Camera.main.ScreenToViewportPoint(openMenu.rect.min); //Vector2 openMenuMax = Camera.main.ScreenToViewportPoint(openMenu.rect.max); selectMenuMin = minMenuPos + openMenuMin; selectMenuMax = maxMenuPos; } if (selectableObs.Length == 1) { selectMenuMin = Vector2.zero; selectMenuMax = Vector2.zero; updateCurrentSelection(0); } } touchStart = Vector3.zero; } } if (ObjectsLoader.gameTime > lastTime) { if (currentSelection == null) { } else if (currentSelection._id != null) { if (currentSelection._id.Length > 0) { currentSelection = objectLoader.GetObjectByID(currentSelection._id); selectableObs = new ObjectsLoader.RoomObject[] { currentSelection }; updateCurrentSelection(0); } } lastTime = ObjectsLoader.gameTime; updateTimeText(); } }
private void updateCurrentSelection(int menuInput) { // need to test if this is null somehow selectMenu.SetActive(false); if (menuInput == -1 || menuInput >= selectableObs.Length) { DetailsScrollView.SetActive(false); currentSelection = null; return; } DetailsScrollView.SetActive(true); SelectedDetailsText.text = ""; currentSelection = selectableObs[menuInput]; string selectedUser = GetUserName(currentSelection); if (selectedUser == "") { Debug.Log("no user found for : " + objectLoader.users.Count); } SelectedDetailsText.text = "Type : " + selectableObs[menuInput].Type() + System.Environment.NewLine + "Id : " + selectableObs[menuInput].Id() + System.Environment.NewLine; if (selectedUser != "") { SelectedDetailsText.text += "Owner: " + selectedUser + System.Environment.NewLine; } if (currentSelection.hits > 0) { SelectedDetailsText.text += "Hits: " + PrintShorterInt(currentSelection.Hits()) + "/" + PrintShorterInt(currentSelection.MaxHits()) + System.Environment.NewLine; } if (selectableObs[menuInput].Type() == "creep") { Creep selectedCreep = objectLoader.GetSelectedCreep(currentSelection._id); if (selectedCreep.name != null) { SelectedDetailsText.text += "Name: " + selectedCreep.name + System.Environment.NewLine; } //if (selectedCreep.hits != 0) // SelectedDetailsText.text += "Hits: "+selectedCreep.hits + "/" + selectedCreep.creepBody.parts.Length * 100 + System.Environment.NewLine; int counter = 1; SelectedDetailsText.text += "Body:" + "<indent=65%>" + selectedCreep.creepBody.parts.Length + " Parts" + System.Environment.NewLine; SelectedDetailsText.text += "<indent=15%>"; foreach (string b in selectedCreep.creepBody.parts) { SelectedDetailsText.text += "<sprite name=\"" + b + "\"> "; counter++; if (counter > 10) { counter = 1; SelectedDetailsText.text += System.Environment.NewLine + "<indent=15%>"; } } SelectedDetailsText.text += System.Environment.NewLine; //SelectedDetailsText.text = selectableObs[menuInput].type + "<sprite index=2><sprite index=2><sprite index=2><sprite index=2><sprite index=2><sprite index=2><sprite index=2><sprite index=2>"; } if (selectableObs[menuInput].Type() == "controller") { if (currentSelection.downgradeTime > 0) { SelectedDetailsText.text += "Downgrade Time: " + currentSelection.downgradeTime + System.Environment.NewLine; } if (currentSelection.reservationUser != null) { SelectedDetailsText.text += "Reserved by: " + GetUserName(currentSelection.reservationUser) + System.Environment.NewLine; } if (currentSelection.reservationTime > 0) { SelectedDetailsText.text += "Reservation: " + Mathf.Abs(ObjectsLoader.gameTime - currentSelection.reservationTime).ToString() + System.Environment.NewLine; } if (currentSelection.sign != null) { SelectedDetailsText.text += "Sign: User: "******" Time: " + currentSelection.sign.time + System.Environment.NewLine; SelectedDetailsText.text += " Sign: " + currentSelection.sign.text + System.Environment.NewLine; } } if (currentSelection._store != null && currentSelection.storeCapacity > 0) { SelectedDetailsText.text += "<indent=0%>Store: " + PrintShorterInt(currentSelection.storeTotal) + "/" + PrintShorterInt(currentSelection.storeCapacity) + System.Environment.NewLine; //GameObject selectedObject = objectLoader.GetSelectedGameObject(currentSelection); int counter = 1; foreach (KeyValuePair <string, int> kvp in currentSelection.Store()) { SelectedDetailsText.text += "<indent=5%><sprite name=\"" + kvp.Key + "\"><indent=20%>" + kvp.Value + System.Environment.NewLine; counter++; } } if (DetailsScrollViewBar.gameObject.activeSelf) { DetailsScrollViewBar.value = lastMenuPos; } }