Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Source/Client/Session/SessionDisconnectInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ public static SessionDisconnectInfo From(MpDisconnectReason reason, ByteReader r
if (reason == MpDisconnectReason.ServerPacketRead) descKey = "MpPacketErrorRemote";
if (reason == MpDisconnectReason.BadGamePassword) descKey = "MpBadGamePassword";

if (reason == MpDisconnectReason.BootstrapCompleted)
{
titleKey = "MpBootstrapCompleted";
descKey = "MpBootstrapCompletedDesc";
}

disconnectInfo.titleTranslated ??= titleKey?.Translate();
disconnectInfo.descTranslated ??= descKey?.Translate();

Expand Down
270 changes: 15 additions & 255 deletions Source/Client/Windows/HostWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using Verse;
using Verse.Profile;
using Verse.Sound;
using Verse.Steam;
using Multiplayer.Client.Util;
using Multiplayer.Common.Util;

Expand Down Expand Up @@ -67,7 +66,6 @@ public HostWindow(SaveFile file = null)

private const int MaxGameNameLength = 70;
private const float LabelWidth = 110f;
private const float CheckboxWidth = LabelWidth + 30f;

public override void DoWindowContents(Rect inRect)
{
Expand Down Expand Up @@ -134,268 +132,30 @@ private void DoTabButton(Rect r, Tab tab)

private void DoConnecting(Rect entry)
{
// Max players
MpUI.TextFieldNumericLabeled(entry.Width(LabelWidth + 35f), $"{"MpMaxPlayers".Translate()}: ", ref serverSettings.maxPlayers, ref maxPlayersBuffer, LabelWidth, 0, 999);
entry = entry.Down(30);

// Password
MpUI.CheckboxLabeled(entry.Width(CheckboxWidth), $"{"MpHostGamePassword".Translate()}: ", ref serverSettings.hasPassword, order: ElementOrder.Right);
if (serverSettings.hasPassword)
MpUI.DoPasswordField(entry.Right(CheckboxWidth + 10).MaxX(entry.xMax), "PasswordField", ref serverSettings.password);
entry = entry.Down(30);

// Direct hosting
var directLabel = $"{"MpHostDirect".Translate()}: ";
MpUI.CheckboxLabeled(entry.Width(CheckboxWidth), directLabel, ref serverSettings.direct, order: ElementOrder.Right);
TooltipHandler.TipRegion(entry.Width(LabelWidth), MpUtil.TranslateWithDoubleNewLines("MpHostDirectDesc", 4));
if (serverSettings.direct)
serverSettings.directAddress = Widgets.TextField(entry.Right(CheckboxWidth + 10).MaxX(entry.xMax), serverSettings.directAddress);

entry = entry.Down(30);

// LAN hosting
var lanRect = entry.Width(CheckboxWidth);
MpUI.CheckboxLabeled(lanRect, $"{"MpLan".Translate()}: ", ref serverSettings.lan, order: ElementOrder.Right);
TooltipHandler.TipRegion(lanRect, $"{"MpLanDesc1".Translate()}\n\n{"MpLanDesc2".Translate(serverSettings.lanAddress)}");

entry = entry.Down(30);

// Steam hosting
if (SteamManager.Initialized)
var buffers = new ServerSettingsUI.BufferSet
{
MpUI.CheckboxLabeled(entry.Width(CheckboxWidth), $"{"MpSteam".Translate()}: ", ref serverSettings.steam, order: ElementOrder.Right);
entry = entry.Down(30);
}

// Sync configs
TooltipHandler.TipRegion(entry.Width(CheckboxWidth), MpUtil.TranslateWithDoubleNewLines("MpSyncConfigsDescNew", 3));
MpUI.CheckboxLabeled(entry.Width(CheckboxWidth), $"{"MpSyncConfigs".Translate()}: ", ref serverSettings.syncConfigs, order: ElementOrder.Right);
entry = entry.Down(30);
}

private void DoGameplay(Rect entry)
{
// Autosave interval
var autosaveUnitKey = serverSettings.autosaveUnit == AutosaveUnit.Days
? "MpAutosavesDays"
: "MpAutosavesMinutes";

bool changeAutosaveUnit = false;

LeftLabel(entry, $"{"MpAutosaves".Translate()}: ");
TooltipHandler.TipRegion(entry.Width(LabelWidth), MpUtil.TranslateWithDoubleNewLines("MpAutosavesDesc", 3));

using (MpStyle.Set(TextAnchor.MiddleRight))
DoRow(
entry.Right(LabelWidth + 10),
rect => MpUI.LabelFlexibleWidth(rect, "MpAutosavesEvery".Translate()) + 6,
rect =>
{
Widgets.TextFieldNumeric(
rect.Width(50f),
ref serverSettings.autosaveInterval,
ref autosaveBuffer,
0,
999
);
return 50f + 6;
},
rect =>
{
changeAutosaveUnit = CustomButton(rect, autosaveUnitKey.Translate(), out var width);
return width;
}
);

if (changeAutosaveUnit)
{
serverSettings.autosaveUnit = serverSettings.autosaveUnit.Cycle();
serverSettings.autosaveInterval *=
serverSettings.autosaveUnit == AutosaveUnit.Minutes ?
8f : // Days to minutes
0.125f; // Minutes to days
autosaveBuffer = serverSettings.autosaveInterval.ToString();
}

entry = entry.Down(30);

// Multifaction
MpUI.CheckboxLabeled(entry.Width(CheckboxWidth), $"Multifaction: ", ref serverSettings.multifaction, order: ElementOrder.Right, disabled: multifactionLocked);
entry = entry.Down(30);

// Async time
TooltipHandler.TipRegion(entry.Width(CheckboxWidth), $"{"MpAsyncTimeDesc".Translate()}\n\n{"MpExperimentalFeature".Translate()}");
MpUI.CheckboxLabeled(entry.Width(CheckboxWidth), $"{"MpAsyncTime".Translate()}: ", ref serverSettings.asyncTime, order: ElementOrder.Right, disabled: asyncTimeLocked);
entry = entry.Down(30);

// Time control
LeftLabel(entry, $"{"MpTimeControl".Translate()}: ");
DoTimeControl(entry.Right(LabelWidth + 10));

entry = entry.Down(30);

// Log desync traces
MpUI.CheckboxLabeledWithTipNoHighlight(
entry.Width(CheckboxWidth),
$"{"MpLogDesyncTraces".Translate()}: ",
MpUtil.TranslateWithDoubleNewLines("MpLogDesyncTracesDesc", 2),
ref serverSettings.desyncTraces,
placeTextNearCheckbox: true
);
entry = entry.Down(30);

// Arbiter
if (MpVersion.IsDebug) {
TooltipHandler.TipRegion(entry.Width(CheckboxWidth), "MpArbiterDesc".Translate());
MpUI.CheckboxLabeled(entry.Width(CheckboxWidth), $"{"MpRunArbiter".Translate()}: ", ref serverSettings.arbiter, order: ElementOrder.Right);
entry = entry.Down(30);
}

// Dev mode
MpUI.CheckboxLabeledWithTipNoHighlight(
entry.Width(CheckboxWidth),
$"{"MpHostingDevMode".Translate()}: ",
MpUtil.TranslateWithDoubleNewLines("MpHostingDevModeDesc", 2),
ref serverSettings.debugMode,
placeTextNearCheckbox: true
);

// Dev mode scope
if (serverSettings.debugMode)
if (CustomButton(entry.Right(CheckboxWidth + 10f), $"MpHostingDevMode{serverSettings.devModeScope}".Translate()))
{
serverSettings.devModeScope = serverSettings.devModeScope.Cycle();
SoundDefOf.Checkbox_TurnedOn.PlayOneShotOnCamera();
}

entry = entry.Down(30);

// Auto join-points
DrawJoinPointOptions(entry);
entry = entry.Down(30);

// Pause on letter
LeftLabel(entry, $"{"MpPauseOnLetter".Translate()}: ");
DoPauseOnLetter(entry.Right(LabelWidth + 10));
entry = entry.Down(30);

// Pause on (join, desync)
LeftLabel(entry, $"{"MpPauseOn".Translate()}: ");
DoRow(
entry.Right(LabelWidth + 10),
rect => MpUI.CheckboxLabeled(
rect.Width(CheckboxWidth),
"MpPauseOnJoin".Translate(),
ref serverSettings.pauseOnJoin,
size: 20f,
order: ElementOrder.Left).width + 15,
rect => MpUI.CheckboxLabeled(
rect.Width(CheckboxWidth),
"MpPauseOnDesync".Translate(),
ref serverSettings.pauseOnDesync,
size: 20f,
order: ElementOrder.Left).width
);

entry = entry.Down(30);
}

private void DoTimeControl(Rect entry)
{
if (CustomButton(entry, $"MpTimeControl{serverSettings.timeControl}".Translate()))
Find.WindowStack.Add(new FloatMenu(Options().ToList()));

IEnumerable<FloatMenuOption> Options()
{
foreach (var opt in Enum.GetValues(typeof(TimeControl)).OfType<TimeControl>())
yield return new FloatMenuOption($"MpTimeControl{opt}".Translate(), () =>
{
serverSettings.timeControl = opt;
});
}
}

private void DoPauseOnLetter(Rect entry)
{
if (CustomButton(entry, $"MpPauseOnLetter{serverSettings.pauseOnLetter}".Translate()))
Find.WindowStack.Add(new FloatMenu(Options().ToList()));

IEnumerable<FloatMenuOption> Options()
{
foreach (var opt in Enum.GetValues(typeof(PauseOnLetter)).OfType<PauseOnLetter>())
yield return new FloatMenuOption($"MpPauseOnLetter{opt}".Translate(), () =>
{
serverSettings.pauseOnLetter = opt;
});
}
}
MaxPlayersBuffer = maxPlayersBuffer,
AutosaveBuffer = autosaveBuffer
};

static float LeftLabel(Rect entry, string text, string desc = null)
{
using (MpStyle.Set(TextAnchor.MiddleRight))
MpUI.LabelWithTip(
entry.Width(LabelWidth + 1),
text,
desc
);
return Text.CalcSize(text).x;
}
ServerSettingsUI.DrawNetworkingSettings(entry, serverSettings, buffers);

static void DoRow(Rect inRect, params Func<Rect, float>[] drawers)
{
foreach (var drawer in drawers)
{
inRect.xMin += drawer(inRect);
}
maxPlayersBuffer = buffers.MaxPlayersBuffer;
autosaveBuffer = buffers.AutosaveBuffer;
}

private static Color CustomButtonColor = new(0.15f, 0.15f, 0.15f);

private void DrawJoinPointOptions(Rect entry)
private void DoGameplay(Rect entry)
{
LeftLabel(entry, $"{"MpAutoJoinPoints".Translate()}: ", MpUtil.TranslateWithDoubleNewLines("MpAutoJoinPointsDesc", 3));

var flags = Enum.GetValues(typeof(AutoJoinPointFlags))
.OfType<AutoJoinPointFlags>()
.Where(f => serverSettings.autoJoinPoint.HasFlag(f))
.Select(f => $"MpAutoJoinPoints{f}".Translate())
.Join(", ");
if (flags.Length == 0) flags = "Off";

if (CustomButton(entry.Right(LabelWidth + 10), flags))
Find.WindowStack.Add(new FloatMenu(Flags().ToList()));

IEnumerable<FloatMenuOption> Flags()
var buffers = new ServerSettingsUI.BufferSet
{
foreach (var flag in Enum.GetValues(typeof(AutoJoinPointFlags)).OfType<AutoJoinPointFlags>())
yield return new FloatMenuOption($"MpAutoJoinPoints{flag}".Translate(), () =>
{
if (serverSettings.autoJoinPoint.HasFlag(flag))
serverSettings.autoJoinPoint &= ~flag;
else
serverSettings.autoJoinPoint |= flag;
});
}
}

private static bool CustomButton(Rect rect, string label)
=> CustomButton(rect, label, out _);

private static bool CustomButton(Rect rect, string label, out float width)
{
using var _ = MpStyle.Set(TextAnchor.MiddleLeft);
var flagsWidth = Text.CalcSize(label).x;

const float btnMargin = 5f;

var flagsBtn = rect.Width(flagsWidth + btnMargin * 2);
Widgets.DrawRectFast(flagsBtn.Height(24).Down(3), CustomButtonColor);
Widgets.DrawHighlightIfMouseover(flagsBtn.Height(24).Down(3));
MpUI.Label(rect.Right(btnMargin).Width(flagsWidth), label);
MaxPlayersBuffer = maxPlayersBuffer,
AutosaveBuffer = autosaveBuffer
};

width = flagsBtn.width;
ServerSettingsUI.DrawGameplaySettings(entry, serverSettings, buffers, asyncTimeLocked, multifactionLocked);

return Widgets.ButtonInvisible(flagsBtn);
maxPlayersBuffer = buffers.MaxPlayersBuffer;
autosaveBuffer = buffers.AutosaveBuffer;
}

private void TryHost()
Expand Down
Loading
Loading