Skip to content

Commit

Permalink
Release 0.8.0
Browse files Browse the repository at this point in the history
Merge branch 'dev'
  • Loading branch information
thomotron committed Jul 22, 2021
2 parents b6c68ca + ec792ca commit d19943d
Show file tree
Hide file tree
Showing 62 changed files with 2,011 additions and 609 deletions.
7 changes: 7 additions & 0 deletions .abstruse.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
image: mono:latest

install:
- nuget restore Phinix.sln

script:
- msbuild /property:Configuration=TravisCI ./Phinix.sln
3 changes: 3 additions & 0 deletions .github/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<a href="https://travis-ci.org/PhinixTeam/Phinix">
<img src="https://img.shields.io/travis/PhinixTeam/Phinix.svg?style=flat-square" alt="Travis CI">
</a>
<a href="https://ci.cocytus.services/repos/64/">
<img src="https://ci.cocytus.services/badge/ca953ca7?branch=master" alt="Abstruse">
</a>
<a href="https://hub.docker.com/r/phinixteam/phinix">
<img alt="Docker Build Status" src="https://img.shields.io/docker/cloud/build/phinixteam/phinix.svg?label=docker&style=flat-square">
</a>
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,6 @@ Client/1.*/Assemblies/*.dll

# Git rubbish
*.orig

# Phinix credentials
**/PhinixCredentials.bin
3 changes: 1 addition & 2 deletions Client/About/About.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@
A total rewrite of Longwelwind's Phi chat mod for RimWorld that allows players to chat and trade items with each other within the game.
</description>
<supportedVersions>
<li>1.0</li>
<li>1.1</li>
<li>1.2</li>
<li>1.3</li>
</supportedVersions>
<modDependencies>
<li>
Expand Down
6 changes: 3 additions & 3 deletions Client/Common/Languages/English/Keyed/English.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
<Phinix_chat_pleaseLogInPlaceholder>You are not logged in.\nTry connecting to a server in the settings menu (top right of the chat tab).</Phinix_chat_pleaseLogInPlaceholder>
<Phinix_chat_contextMenu_tradeWith>Trade with {0}</Phinix_chat_contextMenu_tradeWith>
<Phinix_chat_contextMenu_copyToClipboard>Copy message to clipboard</Phinix_chat_contextMenu_copyToClipboard>
<Phinix_chat_blockedUsers>Blocked users</Phinix_chat_blockedUsers>
<Phinix_chat_contextMenu_blockUser>Block user</Phinix_chat_contextMenu_blockUser>
<Phinix_chat_contextMenu_unblockUser>Unblock user</Phinix_chat_contextMenu_unblockUser>

<Phinix_settings_connectButton>Connect</Phinix_settings_connectButton>
<Phinix_settings_disconnectButton>Disconnect</Phinix_settings_disconnectButton>
Expand All @@ -29,10 +32,7 @@
<Phinix_hugslibsettings_showBlockedUnreadMessageCount_description>Includes blocked users in the total number of unread messages when showing the unread message count</Phinix_hugslibsettings_showBlockedUnreadMessageCount_description>
<Phinix_hugslibsettings_allItemsTradable>Allow trading items that are not in storage</Phinix_hugslibsettings_allItemsTradable>
<Phinix_hugslibsettings_showBlockedTrades>Show trades from blocked users</Phinix_hugslibsettings_showBlockedTrades>

<Phinix_hugslibsettings_blockedUsers>Blocked users</Phinix_hugslibsettings_blockedUsers>
<Phinix_chat_contextMenu_blockUser>Block user</Phinix_chat_contextMenu_blockUser>
<Phinix_chat_contextMenu_unblockUser>Unblock user</Phinix_chat_contextMenu_unblockUser>

<Phinix_login_logInLabel>Log in to</Phinix_login_logInLabel>
<Phinix_login_submitButton>Submit</Phinix_login_submitButton>
Expand Down
29 changes: 29 additions & 0 deletions Client/Source/BlockedUsersChangedEventArgs.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
namespace PhinixClient
{
/// <summary>
/// Event args for when a user is blocked or unblocked.
/// </summary>
public class BlockedUsersChangedEventArgs
{
/// <summary>
/// UUID of the user.
/// </summary>
public readonly string Uuid;

/// <summary>
/// The user's new blocked state.
/// </summary>
public readonly bool IsBlocked;

/// <summary>
/// Creates a new <see cref="BlockedUsersChangedEventArgs"/> with the given user's UUID and blocked state.
/// </summary>
/// <param name="uuid">User's UUID</param>
/// <param name="isBlocked">User's new blocked state</param>
public BlockedUsersChangedEventArgs(string uuid, bool isBlocked)
{
this.Uuid = uuid;
this.IsBlocked = isBlocked;
}
}
}
53 changes: 48 additions & 5 deletions Client/Source/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,24 @@ public class Client : ModBase
public string[] GetUserUuids(bool loggedIn = false) => userManager.GetUuids(loggedIn);
public event EventHandler<LoginEventArgs> OnLoginSuccess;
public event EventHandler<LoginEventArgs> OnLoginFailure;
public event EventHandler<UserDisplayNameChangedEventArgs> OnUserDisplayNameChanged;
public event EventHandler<UserLoginStateChangedEventArgs> OnUserLoggedIn;
public event EventHandler<UserLoginStateChangedEventArgs> OnUserLoggedOut;
public event EventHandler<UserCreatedEventArgs> OnUserCreated;
public event EventHandler OnUserSync;

public bool Online => Connected && Authenticated && LoggedIn;

private ClientChat chat;
public void SendMessage(string message) => chat.Send(message);
public ClientChatMessage[] GetChatMessages() => chat.GetMessages();
public bool TryGetMessage(string messageId, out ClientChatMessage message) => chat.TryGetMessage(messageId, out message);
public void MarkAsRead() => chat.MarkAsRead();
public ClientChatMessage[] GetChatMessages(bool markAsRead = true) => chat.GetMessages(markAsRead);
public ClientChatMessage[] GetUnreadChatMessages(bool markAsRead = true) => chat.GetUnreadMessages(markAsRead);
public int UnreadMessages => chat.UnreadMessages;
public int UnreadMessagesExcludingBlocked => chat.GetUnreadMessagesExcluding(BlockedUsers);
public event EventHandler<ChatMessageEventArgs> OnChatMessageReceived;
public event EventHandler<ClientChatMessageEventArgs> OnChatMessageReceived;
public event EventHandler OnChatSync;

private ClientTrading trading;
public void CreateTrade(string uuid) => trading.CreateTrade(uuid);
Expand All @@ -73,6 +82,9 @@ public class Client : ModBase
public event EventHandler<CompleteTradeEventArgs> OnTradeCancelled;
public event EventHandler<TradeUpdateEventArgs> OnTradeUpdateSuccess;
public event EventHandler<TradeUpdateEventArgs> OnTradeUpdateFailure;
public event EventHandler<TradesSyncedEventArgs> OnTradesSynced;

public event EventHandler<BlockedUsersChangedEventArgs> OnBlockedUsersChanged;

private SettingHandle<string> serverAddressHandle;
public string ServerAddress
Expand Down Expand Up @@ -340,14 +352,30 @@ public override void Initialize()

Disconnect();
};
userManager.OnUserDisplayNameChanged += (sender, args) =>
{
Logger.Trace(string.Format("User with UUID {0} changed their display name from \"{1}\" to \"{2}\"", args.Uuid, args.OldDisplayName, args.NewDisplayName));
};
userManager.OnUserLoggedIn += (sender, args) =>
{
Logger.Trace(string.Format("User {0} logged in", args.Uuid));
};
userManager.OnUserLoggedOut += (sender, args) =>
{
Logger.Trace(string.Format("User {0} logged out", args.Uuid));
};
userManager.OnUserCreated += (sender, args) =>
{
Logger.Trace(string.Format("New user created: {0} ({1}) - {2}gged in", args.DisplayName, args.Uuid, args.LoggedIn ? "L" : "Not l"));
};

// Subscribe to chat events
chat.OnChatMessageReceived += (sender, args) =>
{
Logger.Trace("Received chat message from UUID " + args.OriginUuid);
Logger.Trace("Received chat message from UUID " + args.Message.SenderUuid);

// Check if the message wasn't ours, chat noises are enabled, and if we are in-game before playing a sound
if (args.OriginUuid != Uuid && PlayNoiseOnMessageReceived && Current.Game != null && !BlockedUsers.Contains(args.OriginUuid))
if (args.Message.SenderUuid != Uuid && PlayNoiseOnMessageReceived && Current.Game != null && !BlockedUsers.Contains(args.Message.SenderUuid))
{
lock (soundQueueLock)
{
Expand Down Expand Up @@ -477,9 +505,13 @@ public override void Initialize()

Find.WindowStack.Add(new Dialog_Message("Phinix_error_tradeUpdateFailedTitle".Translate(), "Phinix_error_tradeUpdateFailedMessage".Translate(displayName, args.FailureMessage, args.FailureReason.ToString())));
};
trading.OnTradesSynced += (sender, args) =>
{
Logger.Trace(string.Format("Synced {0} trade{1} from server", args.TradeIds.Length, args.TradeIds.Length != 1 ? "s" : ""));
};

// Subscribe to setting handle value change events
acceptingTradesHandle.OnValueChanged += (newValue) => { userManager.UpdateSelf(acceptingTrades: newValue); };
acceptingTradesHandle.ValueChanged += (handle) => { userManager.UpdateSelf(acceptingTrades: acceptingTradesHandle.Value); };

// Forward events so the UI can handle them
netClient.OnConnecting += (sender, e) => { OnConnecting?.Invoke(sender, e); };
Expand All @@ -488,13 +520,20 @@ public override void Initialize()
authenticator.OnAuthenticationFailure += (sender, e) => { OnAuthenticationFailure?.Invoke(sender, e); };
userManager.OnLoginSuccess += (sender, e) => { OnLoginSuccess?.Invoke(sender, e); };
userManager.OnLoginFailure += (sender, e) => { OnLoginFailure?.Invoke(sender, e); };
userManager.OnUserDisplayNameChanged += (sender, e) => { OnUserDisplayNameChanged?.Invoke(sender, e); };
userManager.OnUserLoggedIn += (sender, e) => { OnUserLoggedIn?.Invoke(sender, e); };
userManager.OnUserLoggedOut += (sender, e) => { OnUserLoggedOut?.Invoke(sender, e); };
userManager.OnUserCreated += (sender, e) => { OnUserCreated?.Invoke(sender, e); };
userManager.OnUserSync += (sender, e) => { OnUserSync?.Invoke(sender, e); };
chat.OnChatMessageReceived += (sender, e) => { OnChatMessageReceived?.Invoke(sender, e); };
chat.OnChatSync += (sender, e) => { OnChatSync?.Invoke(sender, e); };
trading.OnTradeCreationSuccess += (sender, e) => { OnTradeCreationSuccess?.Invoke(sender, e); };
trading.OnTradeCreationFailure += (sender, e) => { OnTradeCreationFailure?.Invoke(sender, e); };
trading.OnTradeCompleted += (sender, e) => { OnTradeCompleted?.Invoke(sender, e); };
trading.OnTradeCancelled += (sender, e) => { OnTradeCancelled?.Invoke(sender, e); };
trading.OnTradeUpdateSuccess += (sender, e) => { OnTradeUpdateSuccess?.Invoke(sender, e); };
trading.OnTradeUpdateFailure += (sender, e) => { OnTradeUpdateFailure?.Invoke(sender, e); };
trading.OnTradesSynced += (sender, e) => { OnTradesSynced?.Invoke(sender, e); };

// Connect to the server set in the config
Connect(ServerAddress, ServerPort);
Expand All @@ -509,6 +548,8 @@ public void BlockUser(string senderUuid)
BlockedUsers.AddDistinct(senderUuid);
blockedUsers.HasUnsavedChanges = true;
HugsLibController.SettingsManager.SaveChanges();

OnBlockedUsersChanged?.Invoke(this, new BlockedUsersChangedEventArgs(senderUuid, true));
}

/// <summary>
Expand All @@ -520,6 +561,8 @@ public void UnBlockUser(string senderUuid)
BlockedUsers.Remove(senderUuid);
blockedUsers.HasUnsavedChanges = true;
HugsLibController.SettingsManager.SaveChanges();

OnBlockedUsersChanged?.Invoke(this, new BlockedUsersChangedEventArgs(senderUuid, false));
}

/// <inheritdoc />
Expand Down
46 changes: 22 additions & 24 deletions Client/Source/Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@
</AssemblyOriginatorKeyFile>
</PropertyGroup>
<ItemGroup>
<Reference Include="0Harmony, Version=2.0.4.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\.nuget\Lib.Harmony.2.0.4\lib\net472\0Harmony.dll</HintPath>
<Reference Include="0Harmony, Version=2.1.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\.nuget\Lib.Harmony.2.1.0\lib\net472\0Harmony.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\GameDlls\Assembly-CSharp.dll</HintPath>
</Reference>
<Reference Include="HugsLib, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\.nuget\UnlimitedHugs.Rimworld.HugsLib.8.0.0\lib\net472\HugsLib.dll</HintPath>
<HintPath>..\..\.nuget\UnlimitedHugs.Rimworld.HugsLib.9.0.0\lib\net472\HugsLib.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="mscorlib" />
Expand All @@ -70,8 +70,10 @@
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="BlockedUsersChangedEventArgs.cs" />
<Compile Include="Client.cs" />
<Compile Include="GUI\Basic Widgets\AdapterWidget.cs" />
<Compile Include="GUI\Basic Widgets\BlankWidget.cs" />
<Compile Include="GUI\Basic Widgets\ButtonWidget.cs" />
<Compile Include="GUI\Basic Widgets\CheckboxLabeledWidget.cs" />
<Compile Include="GUI\Basic Widgets\FittedTextureWidget.cs" />
Expand All @@ -80,18 +82,23 @@
<Compile Include="GUI\Basic Widgets\TextFieldWidget.cs" />
<Compile Include="GUI\Basic Widgets\TextWidget.cs" />
<Compile Include="GUI\Basic Widgets\ThingIconWidget.cs" />
<Compile Include="GUI\Compound Widgets\ChatMessageList.cs" />
<Compile Include="GUI\Compound Widgets\ChatMessageWidget.cs" />
<Compile Include="GUI\Compound Widgets\DynamicTextWidget.cs" />
<Compile Include="GUI\Compound Widgets\ItemStackRow.cs" />
<Compile Include="GUI\Compound Widgets\TradeList.cs" />
<Compile Include="GUI\Compound Widgets\TradeRow.cs" />
<Compile Include="GUI\Compound Widgets\UserList.cs" />
<Compile Include="GUI\Compound Widgets\UserWidget.cs" />
<Compile Include="GUI\Containers\ConditionalContainer.cs" />
<Compile Include="GUI\Containers\Container.cs" />
<Compile Include="GUI\Containers\HeightContainer.cs" />
<Compile Include="GUI\Containers\HorizontalFlexContainer.cs" />
<Compile Include="GUI\Containers\HorizontalPaddedContainer.cs" />
<Compile Include="GUI\Containers\HorizontalScrollContainer.cs" />
<Compile Include="GUI\Containers\MinimumContainer.cs" />
<Compile Include="GUI\Containers\VerticalScrollContainer.cs" />
<Compile Include="GUI\Containers\TabEntry.cs" />
<Compile Include="GUI\Containers\TabContainerEntry.cs" />
<Compile Include="GUI\Containers\TabsContainer.cs" />
<Compile Include="GUI\Containers\VerticalFlexContainer.cs" />
<Compile Include="GUI\Containers\VerticalPaddedContainer.cs" />
Expand Down Expand Up @@ -153,27 +160,18 @@
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="Clean">
<RemoveDir Directories="$(SolutionDir)\Client\1.1\Assemblies\" />
<RemoveDir Directories="$(SolutionDir)\Client\1.2\Assemblies\" />
<RemoveDir Directories="$(SolutionDir)\Client\Common\Assemblies\" />
<RemoveDir Directories="$(SolutionDir)\Client\1.3\Assemblies\" />
</Target>
<Target Name="AfterBuild">
<Copy SourceFiles="$(TargetDir)\LiteNetLib.dll" DestinationFiles="$(SolutionDir)\Client\1.1\Assemblies\1-LiteNetLib.dll" />
<Copy SourceFiles="$(TargetDir)\LiteNetLib.dll" DestinationFiles="$(SolutionDir)\Client\1.2\Assemblies\1-LiteNetLib.dll" />
<Copy SourceFiles="$(TargetDir)\Google.Protobuf.dll" DestinationFiles="$(SolutionDir)\Client\1.1\Assemblies\2-Protobuf.dll" />
<Copy SourceFiles="$(TargetDir)\Google.Protobuf.dll" DestinationFiles="$(SolutionDir)\Client\1.2\Assemblies\2-Protobuf.dll" />
<Copy SourceFiles="$(TargetDir)\Utils.dll" DestinationFiles="$(SolutionDir)\Client\1.1\Assemblies\3-Utils.dll" />
<Copy SourceFiles="$(TargetDir)\Utils.dll" DestinationFiles="$(SolutionDir)\Client\1.2\Assemblies\3-Utils.dll" />
<Copy SourceFiles="$(TargetDir)\Connections.dll" DestinationFiles="$(SolutionDir)\Client\1.1\Assemblies\4-Connections.dll" />
<Copy SourceFiles="$(TargetDir)\Connections.dll" DestinationFiles="$(SolutionDir)\Client\1.2\Assemblies\4-Connections.dll" />
<Copy SourceFiles="$(TargetDir)\Authentication.dll" DestinationFiles="$(SolutionDir)\Client\1.1\Assemblies\5-Authentication.dll" />
<Copy SourceFiles="$(TargetDir)\Authentication.dll" DestinationFiles="$(SolutionDir)\Client\1.2\Assemblies\5-Authentication.dll" />
<Copy SourceFiles="$(TargetDir)\UserManagement.dll" DestinationFiles="$(SolutionDir)\Client\1.1\Assemblies\6-UserManagement.dll" />
<Copy SourceFiles="$(TargetDir)\UserManagement.dll" DestinationFiles="$(SolutionDir)\Client\1.2\Assemblies\6-UserManagement.dll" />
<Copy SourceFiles="$(TargetDir)\Chat.dll" DestinationFiles="$(SolutionDir)\Client\1.1\Assemblies\7-Chat.dll" />
<Copy SourceFiles="$(TargetDir)\Chat.dll" DestinationFiles="$(SolutionDir)\Client\1.2\Assemblies\7-Chat.dll" />
<Copy SourceFiles="$(TargetDir)\Trading.dll" DestinationFiles="$(SolutionDir)\Client\1.1\Assemblies\8-Trading.dll" />
<Copy SourceFiles="$(TargetDir)\Trading.dll" DestinationFiles="$(SolutionDir)\Client\1.2\Assemblies\8-Trading.dll" />
<Copy SourceFiles="$(TargetDir)\PhinixClient.dll" DestinationFiles="$(SolutionDir)\Client\1.1\Assemblies\9-PhinixClient.dll" />
<Copy SourceFiles="$(TargetDir)\PhinixClient.dll" DestinationFiles="$(SolutionDir)\Client\1.2\Assemblies\9-PhinixClient.dll" />
<Copy SourceFiles="$(TargetDir)\LiteNetLib.dll" DestinationFiles="$(SolutionDir)\Client\Common\Assemblies\1-LiteNetLib.dll" />
<Copy SourceFiles="$(TargetDir)\Google.Protobuf.dll" DestinationFiles="$(SolutionDir)\Client\Common\Assemblies\2-Protobuf.dll" />
<Copy SourceFiles="$(TargetDir)\Utils.dll" DestinationFiles="$(SolutionDir)\Client\Common\Assemblies\3-Utils.dll" />
<Copy SourceFiles="$(TargetDir)\Connections.dll" DestinationFiles="$(SolutionDir)\Client\Common\Assemblies\4-Connections.dll" />
<Copy SourceFiles="$(TargetDir)\Authentication.dll" DestinationFiles="$(SolutionDir)\Client\Common\Assemblies\5-Authentication.dll" />
<Copy SourceFiles="$(TargetDir)\UserManagement.dll" DestinationFiles="$(SolutionDir)\Client\Common\Assemblies\6-UserManagement.dll" />
<Copy SourceFiles="$(TargetDir)\Chat.dll" DestinationFiles="$(SolutionDir)\Client\Common\Assemblies\7-Chat.dll" />
<Copy SourceFiles="$(TargetDir)\Trading.dll" DestinationFiles="$(SolutionDir)\Client\Common\Assemblies\8-Trading.dll" />
<Copy SourceFiles="$(TargetDir)\PhinixClient.dll" DestinationFiles="$(SolutionDir)\Client\1.3\Assemblies\9-PhinixClient.dll" />
</Target>
</Project>
14 changes: 13 additions & 1 deletion Client/Source/GUI/Basic Widgets/AdapterWidget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,17 @@ public class AdapterWidget : Displayable
/// </summary>
private Func<float, float> getHeightCallback;

public AdapterWidget(Action<Rect> drawCallback, Func<float, float> getWidthCallback = null, Func<float, float> getHeightCallback = null)
/// <summary>
/// Callback invoked when the adapter is updated.
/// </summary>
private Action updateCallback;

public AdapterWidget(Action<Rect> drawCallback, Func<float, float> getWidthCallback = null, Func<float, float> getHeightCallback = null, Action updateCallback = null)
{
this.drawCallback = drawCallback;
this.getWidthCallback = getWidthCallback;
this.getHeightCallback = getHeightCallback;
this.updateCallback = updateCallback;

IsFluidWidth = getWidthCallback == null;
IsFluidHeight = getHeightCallback == null;
Expand All @@ -44,6 +50,12 @@ public override void Draw(Rect inRect)
drawCallback(inRect);
}

/// <inheritdoc />
public override void Update()
{
updateCallback?.Invoke();
}

/// <inheritdoc />
public override float CalcWidth(float height)
{
Expand Down
14 changes: 14 additions & 0 deletions Client/Source/GUI/Basic Widgets/BlankWidget.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using UnityEngine;

namespace PhinixClient.GUI
{
public class BlankWidget : Displayable
{
/// <inheritdoc />
public override void Draw(Rect inRect)
{
// Don't draw anything, just return
return;
}
}
}
Loading

0 comments on commit d19943d

Please sign in to comment.