Skip to content
Merged
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
2 changes: 2 additions & 0 deletions Source/Client/Settings/MpSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class MpSettings : ModSettings
public bool showModCompatibility = true;
public bool hideTranslationMods = true;
public bool enablePings = true;
public bool enableCrossPlanetLayerPings = true;
public KeyCode? sendPingButton = KeyCode.Mouse4;
public KeyCode? jumpToPingButton = KeyCode.Mouse3;
public Rect chatRect;
Expand Down Expand Up @@ -66,6 +67,7 @@ public override void ExposeData()
Scribe_Values.Look(ref showModCompatibility, "showModCompatibility", true);
Scribe_Values.Look(ref hideTranslationMods, "hideTranslationMods", true);
Scribe_Values.Look(ref enablePings, "enablePings", true);
Scribe_Values.Look(ref enableCrossPlanetLayerPings, "enableCrossPlanetLayerPings", true);
Scribe_Values.Look(ref sendPingButton, "sendPingButton", KeyCode.Mouse4);
Scribe_Values.Look(ref jumpToPingButton, "jumpToPingButton", KeyCode.Mouse3);
Scribe_Custom.LookRect(ref chatRect, "chatRect");
Expand Down
2 changes: 2 additions & 0 deletions Source/Client/Settings/MpSettingsUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ public static void DoGeneralSettings(MpSettings settings, Rect inRect, Rect page
listing.CheckboxLabeled("MpShowModCompat".Translate(), ref settings.showModCompatibility,
"MpShowModCompatDesc".Translate());
listing.CheckboxLabeled("MpEnablePingsSetting".Translate(), ref settings.enablePings);
listing.CheckboxLabeled("MpEnableCrossPlanetLayerPings".Translate(), ref settings.enableCrossPlanetLayerPings,
"MpEnableCrossPlanetLayerPingsDesc".Translate());
listing.CheckboxLabeled("MpShowMainMenuAnimation".Translate(), ref settings.showMainMenuAnim);

const string buttonOff = "Off";
Expand Down
21 changes: 21 additions & 0 deletions Source/Client/UI/DrawPingPlanet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,27 @@ static void Postfix()
{
if (ping.mapId != -1) continue;
if (ping.PlayerInfo is not { } player) continue;
if (ping.planetTile.Layer == null) continue;

var layer = Find.WorldSelector.SelectedLayer;
// Only display pings on the current layer or (if enabled) on layers we can zoom to.
if (Multiplayer.settings.enableCrossPlanetLayerPings)
{
// We can either start with the ping layer, and keep zooming out,
// or start with the current player layer, and keep zooming in.
// Or both. This implementation tries to zoom in from the current player's layer.

// Infinite loop prevention.
for (var i = 0; i < 25; i++)
{
// Either can't zoom in more, or we found our target
if (layer == null || layer == ping.planetTile.Layer)
break;

layer = layer.zoomInToLayer;
}
}
if (ping.planetTile.Layer != layer) continue;

var tileCenter = GenWorldUI.WorldToUIPosition(Find.WorldGrid.GetTileCenter(ping.planetTile));
const float size = 30f;
Expand Down
22 changes: 19 additions & 3 deletions Source/Client/UI/LocationPings.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System.Linq;
using Multiplayer.Client.Util;
using Multiplayer.Common.Networking.Packet;
using RimWorld;
Expand All @@ -23,9 +24,19 @@ public void UpdatePing()
if (MultiplayerStatic.PingKeyDef.JustPressed || KeyDown(Multiplayer.settings.sendPingButton))
{
if (WorldRendererUtility.WorldSelected)
PingLocation(-1, GenWorld.MouseTile(), Vector3.zero);
{
// Grab the tile under mouse
var tile = GenWorld.MouseTile();
// If the tile is not valid, snap to expandable world objects (handles orbital locations)
if (!tile.Valid)
tile = GenWorld.MouseTile(true);

// Make sure the tile is valid and that we didn't ping with the mouse outside of map bounds or in space
if (tile.Valid)
PingLocation(-1, tile, Vector3.zero);
}
else if (Find.CurrentMap != null)
PingLocation(Find.CurrentMap.uniqueID, 0, UI.MouseMapPosition());
PingLocation(Find.CurrentMap.uniqueID, PlanetTile.Invalid, UI.MouseMapPosition());
}

for (int i = pings.Count - 1; i >= 0; i--)
Expand Down Expand Up @@ -69,11 +80,16 @@ public void ReceivePing(ServerPingLocPacket packet)
if (!Multiplayer.settings.enablePings) return;

var data = packet.data;
var planetTile = new PlanetTile(data.planetTileId, data.planetTileLayer);
// Return early if both the map and planet tile are invalid
if (data.mapId == -1 && !planetTile.Valid)
return;

pings.RemoveAll(p => p.player == packet.playerId);
pings.Add(new PingInfo {
player = packet.playerId,
mapId = data.mapId,
planetTile = new PlanetTile(data.planetTileId, data.planetTileLayer),
planetTile = planetTile,
mapLoc = new Vector3(data.x, data.y, data.z)
});
alertHidden = false;
Expand Down
Loading