/// <summary> /// Set server slot text /// </summary> /// <param name="server"></param> public void SetupLAN(LanEntry server) { isLAN = true; ipAddress = server.ipAddress; transform.Find("Name").GetComponent <TMP_Text>().text = "LAN: " + server.hostName; gameObject.tag = "LAN"; }
/// <summary> /// Adds new slot to the UI /// </summary> /// <param name="server"></param> public void AddLANServerSlot(LanEntry server) { if (serverList != null) { ServerSlot item = Instantiate(serverItem); item.SetupLAN(server); item.transform.SetParent(serverList.transform); } }
public void draw(SpriteBatch b) { IClickableMenu.drawTextureBox(b, Game1.mouseCursors, new Rectangle(384, 373, 18, 18), x, y, w, h, Color.White, (float)Game1.pixelZoom, true); b.End(); b.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, new RasterizerState() { ScissorTestEnable = true }); b.GraphicsDevice.ScissorRectangle = new Rectangle(x + 24, y + 20, scrollbarBack.Left - (x + 24), h - 36); { int si = scroll / -80; for (int i = Math.Max(0, si - 1); i < Math.Min(entries.Count, si + h / 80 + 1); ++i) { LanEntry entry = entries[i]; int ix = x + 32; int iy = y + 32 + 4 + i * 80 + scroll; Rectangle area = new Rectangle(ix - 8, iy - 8, w - 40 - Game1.pixelZoom * 6, 80); if (area.Contains(Game1.getMouseX(), Game1.getMouseY())) { b.Draw(Util.WHITE_1X1, area, new Color(200, 32, 32, 64)); if (justClicked) { Log.trace("Clicked on " + entry.name); if (onEntrySelected != null) { onEntrySelected.Invoke(entry); } } } SpriteText.drawString(b, entry.name, ix + 8, iy + 8); SpriteText.drawString(b, entry.server.Address + ":" + entry.port, ix + area.Width - SpriteText.getWidthOfString(entry.server.Address + ":" + entry.port), iy + 8); } } b.End(); b.Begin(SpriteSortMode.Deferred, BlendState.AlphaBlend, SamplerState.PointClamp, null, null); if (entries.Count > 5) { scrollbar.Y = scrollbarBack.Y + 2 + ( int )(((scroll / -80f) / (entries.Count - (h - 64 + 8) / 80f)) * (scrollbarBack.Height - scrollbar.Height)); IClickableMenu.drawTextureBox(b, Game1.mouseCursors, new Rectangle(403, 383, 6, 6), scrollbarBack.X, scrollbarBack.Y, scrollbarBack.Width, scrollbarBack.Height, Color.DarkGoldenrod, (float)Game1.pixelZoom, false); IClickableMenu.drawTextureBox(b, Game1.mouseCursors, new Rectangle(403, 383, 6, 6), scrollbar.X, scrollbar.Y, scrollbar.Width, scrollbar.Height, Color.Gold, (float)Game1.pixelZoom, false); } justClicked = false; }
/// <summary> /// Add broadcaster to the list if it do not already exist /// </summary> /// <param name="fromAddress"></param> /// <param name="data"></param> public override void OnReceivedBroadcast(string fromAddress, string data) { base.OnReceivedBroadcast(fromAddress, data); LanEntry le = new LanEntry(fromAddress, data); bool exist = false; foreach (LanEntry entry in serverEntries) { if (entry.hostName == le.hostName) { exist = true; } } if (!exist) { serverEntries.Add(le); } }
/// <summary> /// Handles "ready" button action /// </summary> public void ReadyGame() { networkDiscovery = FindObjectOfType <OxyniteNetworkDiscovery>(); if (roomList.Count > 0) { ServerSlot serverSlot = roomList[Random.Range(0, roomList.Count)]; JoinRoom(serverSlot.GetMatch()); } else if (networkDiscovery.GetLanEntries() != null) { List <LanEntry> entries = networkDiscovery.GetLanEntries(); LanEntry server = entries[Random.Range(0, entries.Count)]; networkManager.StartGame(server.ipAddress); } else { HostGame(); } }