static void DrawWindowShortcuts(Rect button, Color bgColor, List <FloatMenuOption> options) { Widgets.DrawRectFast(button, bgColor); using (MpStyle.Set(GameFont.Tiny)) if (Widgets.ButtonText(button, "MpDialogsButton".Translate())) { Find.WindowStack.Add(new FloatMenu(options)); } }
static void DoSwitchToMap(Window window, Rect rect) { if (window is not ISwitchToMap) { return; } using (MpStyle.Set(GameFont.Tiny)) if (Widgets.ButtonText(new Rect(rect.xMax - 105, 5, 100, 24), "Switch to map")) { window.Close(); } }
private void DrawLan(Rect inRect) { using (MpStyle.Set(TextAnchor.MiddleCenter)) Widgets.Label(new Rect(inRect.x, 8f, inRect.width, 40), "MpLanSearching".Translate() + MpUI.FixedEllipsis()); inRect.yMin += 40f; float margin = 100; Rect outRect = new Rect(margin, inRect.yMin + 10, inRect.width - 2 * margin, inRect.height - 20); float height = servers.Count * 40; Rect viewRect = new Rect(0, 0, outRect.width - 16f, height); Widgets.BeginScrollView(outRect, ref lanScroll, viewRect, true); float y = 0; int i = 0; foreach (LanServer server in servers) { Rect entryRect = new Rect(0, y, viewRect.width, 40); if (i % 2 == 0) { Widgets.DrawAltRect(entryRect); } using (MpStyle.Set(TextAnchor.MiddleLeft)) Widgets.Label(entryRect.Right(5), "" + server.endpoint); Rect playButton = new Rect(entryRect.xMax - 75, entryRect.y + 5, 70, 40 - 10); if (Widgets.ButtonText(playButton, ">>")) { Close(false); Log.Message("Connecting to lan server"); var address = server.endpoint.Address.ToString(); var port = server.endpoint.Port; ClientUtil.TryConnectWithWindow(address, port); } y += entryRect.height; i++; } Widgets.EndScrollView(); }
public void DrawAt(Vector2 screenCenter, Color baseColor, float size) { var colorAlpha = baseColor; colorAlpha.a = 0.5f * AlphaMult; using (MpStyle.Set(colorAlpha)) GUI.DrawTexture( new Rect(screenCenter - new Vector2(size / 2 - 1, size / 2), new(size, size)), MultiplayerStatic.PingBase ); var color = baseColor; color.a = AlphaMult; using (MpStyle.Set(color)) GUI.DrawTexture( new Rect(screenCenter - new Vector2(size / 2, size + y * size), new(size, size)), MultiplayerStatic.PingPin ); }
private void DrawList <T>(string label, IList <T> entries, Func <T, string> entryString, ref Rect inRect, ref Vector2 scroll, Action <T> click = null, bool hideEmpty = false, string tooltip = null, Action <T, Rect> extra = null, Func <T, Color?> entryLabelColor = null) { if (hideEmpty && entries.Count == 0) { return; } Widgets.Label(inRect, label); inRect.yMin += 20f; float entryHeight = 24f; float height = entries.Count * entryHeight; Rect outRect = new Rect(0, inRect.yMin, inRect.width, Math.Min(height, Math.Min(230, inRect.height))); Rect viewRect = new Rect(0, 0, outRect.width - 16f, height); if (viewRect.height <= outRect.height) { viewRect.width += 16f; } Widgets.BeginScrollView(outRect, ref scroll, viewRect, true); GUI.color = new Color(1, 1, 1, 0.8f); float y = height; for (int i = entries.Count - 1; i >= 0; i--) { y -= entryHeight; T entry = entries[i]; string entryLabel = entryString(entry); var entryRect = new Rect(0, y, viewRect.width, entryHeight); GUI.BeginGroup(entryRect); entryRect = entryRect.AtZero(); if (i % 2 == 0) { Widgets.DrawAltRect(entryRect); } if (Mouse.IsOver(entryRect)) { GUI.DrawTexture(entryRect, SelectedMsg); if (click != null && Event.current.type == EventType.MouseUp) { click(entry); Event.current.Use(); } } if (tooltip != null) { TooltipHandler.TipRegion(entryRect, tooltip); } var prevColor = GUI.color; var labelColor = entryLabelColor?.Invoke(entry); if (labelColor != null) { GUI.color = labelColor.Value; } using (MpStyle.Set(TextAnchor.MiddleLeft)) Widgets.Label(entryRect, entryLabel.Truncate(entryRect.width)); if (labelColor != null) { GUI.color = prevColor; } extra?.Invoke(entry, entryRect); GUI.EndGroup(); } GUI.color = Color.white; Widgets.EndScrollView(); inRect.yMin += outRect.height; }
private void DrawSteam(Rect inRect) { string info = null; if (!SteamManager.Initialized) { info = "MpNotConnectedToSteam".Translate(); } else if (friends.Count == 0) { info = "MpNoFriendsPlaying".Translate(); } if (info != null) { using (MpStyle.Set(TextAnchor.MiddleCenter)) Widgets.Label(new Rect(0, 8, inRect.width, 40f), info); inRect.yMin += 40f; } float margin = 80; Rect outRect = new Rect(margin, inRect.yMin + 10, inRect.width - 2 * margin, inRect.height - 20); float height = friends.Count * 40; Rect viewRect = new Rect(0, 0, outRect.width - 16f, height); Widgets.BeginScrollView(outRect, ref steamScroll, viewRect, true); float y = 0; int i = 0; foreach (SteamPersona friend in friends) { Rect entryRect = new Rect(0, y, viewRect.width, 40); if (i % 2 == 0) { Widgets.DrawAltRect(entryRect); } if (Event.current.type == EventType.Repaint) { GUI.DrawTextureWithTexCoords(new Rect(5, entryRect.y + 4, 32, 32), SteamImages.GetTexture(friend.avatar), new Rect(0, 1, 1, -1)); } using (MpStyle.Set(TextAnchor.MiddleLeft)) Widgets.Label(entryRect.Right(45).Up(5), friend.username); using (MpStyle.Set(GameFont.Tiny)) using (MpStyle.Set(TextAnchor.MiddleLeft)) using (MpStyle.Set(SteamGreen)) Widgets.Label(entryRect.Right(45).Down(8), "MpPlayingRimWorld".Translate()); if (friend.serverHost != CSteamID.Nil) { Rect playButton = new Rect(entryRect.xMax - 85, entryRect.y + 5, 80, 40 - 10); if (Widgets.ButtonText(playButton, "MpJoinButton".Translate())) { Close(false); ClientUtil.TrySteamConnectWithWindow(friend.serverHost); } } else { Rect playButton = new Rect(entryRect.xMax - 125, entryRect.y + 5, 120, 40 - 10); Widgets.ButtonText(playButton, "MpNotInMultiplayer".Translate(), false, false, false); } y += entryRect.height; i++; } Widgets.EndScrollView(); }
private void DrawSaveList(List <FileInfo> saves, float width, ref float y) { for (int i = 0; i < saves.Count; i++) { var file = saves[i]; var data = reader.GetData(file); Rect entryRect = new Rect(0, y, width, 40); if (file == selectedFile) { Widgets.DrawRectFast(entryRect, new Color(1f, 1f, 0.7f, 0.1f)); var lineColor = new Color(1, 1, 1, 0.3f); Widgets.DrawLine(entryRect.min, entryRect.TopRightCorner(), lineColor, 2f); Widgets.DrawLine(entryRect.min - new Vector2(-1, -5), entryRect.BottomLeftCorner() - new Vector2(-1, -2), lineColor, 2f); Widgets.DrawLine(entryRect.BottomLeftCorner(), entryRect.max, lineColor, 2f); Widgets.DrawLine(entryRect.TopRightCorner() - new Vector2(1, -5), entryRect.max - new Vector2(1, -2), lineColor, 2f); } else if (i % 2 == 0) { Widgets.DrawAltRect(entryRect); } using (MpStyle.Set(TextAnchor.MiddleLeft)) Widgets.Label(entryRect.Right(10), data?.displayName ?? "Loading..."); using var _ = MpStyle.Set(new Color(0.6f, 0.6f, 0.6f)); using var __ = MpStyle.Set(GameFont.Tiny); var infoText = new Rect(entryRect.xMax - 120, entryRect.yMin + 3, 120, entryRect.height); Widgets.Label(infoText, file.LastWriteTime.ToString("yyyy-MM-dd HH:mm")); if (data != null) { if (data.gameName != null) { Widgets.Label(infoText.Down(16), data.gameName.Truncate(110)); } else { GUI.color = data.VersionColor; Widgets.Label(infoText.Down(16), (data.rwVersion ?? "???").Truncate(110)); } if (!data.HasRwVersion) { var rect = new Rect(infoText.x - 80, infoText.y + 8f, 80, 24f); GUI.color = Color.red; Widgets.Label(rect, $"({"EItemUpdateStatus_k_EItemUpdateStatusInvalid".Translate()})"); TooltipHandler.TipRegion(rect, new TipSignal("SaveIsUnknownFormat".Translate())); } else if (data.replay && !data.MajorAndMinorVerEqualToCurrent) { GUI.color = new Color(0.8f, 0.8f, 0, 0.6f); var outdated = new Rect(infoText.x - 80, infoText.y + 8f, 80, 24f); Widgets.Label(outdated, "MpSaveOutdated".Translate()); var text = "MpSaveOutdatedDesc".Translate(data.rwVersion, VersionControl.CurrentVersionString); TooltipHandler.TipRegion(outdated, text); } Text.Font = GameFont.Small; GUI.color = Color.white; if (Widgets.ButtonInvisible(entryRect, false)) { if (Event.current.button == 0) { selectedFile = file; } else if (Event.current.button == 1 && data.HasRwVersion) { Find.WindowStack.Add(new FloatMenu(SaveFloatMenu(data).ToList())); } } } y += 40; } }
private void DrawHost(Rect inRect) { if (!filesRead) { ReloadFiles(); filesRead = true; } inRect.y += 8; float margin = 80; Rect outRect = new Rect(margin, inRect.yMin + 10, inRect.width - 2 * margin, inRect.height - 80); Rect viewRect = new Rect(0, 0, outRect.width - 16f, hostHeight); Widgets.BeginScrollView(outRect, ref hostScroll, viewRect, true); Rect collapseRect = new Rect(0, 4f, 18f, 18f); if (Widgets.ButtonImage(collapseRect, mpCollapsed ? TexButton.Reveal : TexButton.Collapse)) { mpCollapsed = !mpCollapsed; } float y = 0; using (MpStyle.Set(GameFont.Medium)) { float textHeight1 = Text.CalcHeight("MpMultiplayerSaves".Translate(), inRect.width); Widgets.Label(viewRect.Right(18f), "MpMultiplayerSaves".Translate()); y += textHeight1 + 10; } if (!mpCollapsed) { DrawSaveList(reader.MpSaves, viewRect.width, ref y); y += 25; } collapseRect.y += y; if (Widgets.ButtonImage(collapseRect, spCollapsed ? TexButton.Reveal : TexButton.Collapse)) { spCollapsed = !spCollapsed; } viewRect.y = y; using (MpStyle.Set(GameFont.Medium)) { float textHeight2 = Text.CalcHeight("MpSingleplayerSaves".Translate(), inRect.width); Widgets.Label(viewRect.Right(18), "MpSingleplayerSaves".Translate()); y += textHeight2 + 10; } if (!spCollapsed) { DrawSaveList(reader.SpSaves, viewRect.width, ref y); } if (Event.current.type == EventType.Layout) { hostHeight = y; } Widgets.EndScrollView(); if (selectedFile == null) { bool noSaves = reader.SpSaves.Count == 0 && reader.MpSaves.Count == 0; using (MpStyle.Set(TextAnchor.MiddleCenter)) Widgets.Label(new Rect(outRect.x, outRect.yMax, outRect.width, 80), noSaves ? "MpNoSaves".Translate() : "MpNothingSelected".Translate()); } else { float width = 0; GUI.BeginGroup(new Rect(outRect.x + (outRect.width - fileButtonsWidth) / 2, outRect.yMax + 20, fileButtonsWidth, 40)); DrawFileButtons(reader.GetData(selectedFile), ref width); GUI.EndGroup(); if (Event.current.type == EventType.Layout) { fileButtonsWidth = width; } } }
private void DrawInfoButtons() { float x = 0; const string WebsiteLink = "https://rimworldmultiplayer.com"; const string DiscordLink = "https://discord.gg/n5E2cb2Y4Z"; bool Button(Texture2D icon, string labelKey, string tip, Color baseIconColor, float iconSize = 24f) { var label = labelKey.Translate(); var labelWidth = Text.CalcSize(label).x; var btn = new Rect(x, 0, 24 + 1 + labelWidth, 24); var mouseOver = Mouse.IsOver(btn); MouseoverSounds.DoRegion(btn); TooltipHandler.TipRegion(btn, tip); using (MpStyle.Set(mouseOver ? Color.yellow : baseIconColor)) { GUI.DrawTexture(new Rect(x += (24 - iconSize) / 2, (24 - iconSize) / 2, iconSize, iconSize), icon); x += 24; } x += 1; using (MpStyle.Set(mouseOver ? Color.yellow : Color.white)) using (MpStyle.Set(TextAnchor.MiddleCenter)) MpUI.Label(new Rect(x, 0, labelWidth, 24f), labelKey.Translate()); x += labelWidth; x += 10; return(Widgets.ButtonInvisible(btn)); } const string compatLabel = "MpCompatibilityButton"; const string compatLabelDesc = "MpCompatibilityButtonDesc"; if (Button(TexButton.ToggleLog, compatLabel, MpUtil.TranslateWithDoubleNewLines(compatLabelDesc, 2), Color.grey, 20)) { Find.WindowStack.Add(new ModCompatWindow(null, false, false, null)); } if (Button(MultiplayerStatic.WebsiteIcon, "MpWebsiteButton", "MpLinkButtonDesc".Translate() + " " + WebsiteLink, Color.grey, 20)) { Application.OpenURL(WebsiteLink); } if (Button(MultiplayerStatic.DiscordIcon, "MpDiscordButton", "MpLinkButtonDesc".Translate() + " " + DiscordLink, Color.white)) { Application.OpenURL(DiscordLink); } if (false) // todo { Button( TexButton.NewItem, "MpActiveConfigsButton", "MpActiveConfigsButtonDesc1".Translate("Player's game") + "\n\n" + "MpActiveConfigsButtonDesc2".Translate(), Color.grey, 20 ); } }