Skip to content

Commit

Permalink
Finger - Add settings for pointing (#106)
Browse files Browse the repository at this point in the history
* Add settings for pointing

* Add documentations

* Add settings to mission header
  • Loading branch information
Kexanone authored Sep 23, 2024
1 parent 8888de9 commit 8a0f27c
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 3 deletions.
6 changes: 6 additions & 0 deletions addons/finger/Configs/ACE/Settings.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ACE_SettingsConfig {
m_aInitialModSettings {
ACE_Finger_Settings "{626D5B540473CB13}" {
}
}
}
17 changes: 17 additions & 0 deletions addons/finger/Configs/ACE/Settings.conf.meta
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
MetaFileClass {
Name "{A305FEB7400A2965}Configs/ACE/Settings.conf"
Configurations {
CONFResourceClass PC {
}
CONFResourceClass XBOX_ONE : PC {
}
CONFResourceClass XBOX_SERIES : PC {
}
CONFResourceClass PS4 : PC {
}
CONFResourceClass PS5 : PC {
}
CONFResourceClass HEADLESS : PC {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@ class ACE_Finger_EditorComponentClass: SCR_BaseEditorComponentClass
//! Equivalent to SCR_PingEditorComponent for finger pings
class ACE_Finger_EditorComponent : SCR_BaseEditorComponent
{
[Attribute(defvalue: "1000", desc: "Maximum pointing distance in meters")]
[RplProp(), Attribute(defvalue: "1000", desc: "Maximum pointing distance in meters.")]
protected float m_fMaxPointingDistanceM;

[Attribute(defvalue: "10", desc: "Range of the ping in meters. Only players in range will see it.")]
[Attribute(defvalue: "true", desc: "Whether the ping can attach to entities.")]
bool m_bCanPingAttach;

[RplProp(), Attribute(defvalue: "10", desc: "Range of the ping in meters. Only players in range will see it. Anyone can see it if negative.")]
protected float m_fPingRangeM;

[Attribute(defvalue: "6", desc: "Lifetime of ping in seconds")]
Expand All @@ -27,6 +30,23 @@ class ACE_Finger_EditorComponent : SCR_BaseEditorComponent
protected ref ScriptInvoker Event_OnPingEntityUnregister = new ScriptInvoker;
protected float m_fLastPingTime = 0;

//------------------------------------------------------------------------------------------------
override protected void OnPostInit(IEntity owner)
{
super.OnPostInit(owner);

if (!Replication.IsServer())
return;

ACE_Finger_Settings settings = ACE_SettingsHelperT<ACE_Finger_Settings>.GetModSettings();
if (settings)
{
m_fMaxPointingDistanceM = settings.m_fMaxPointingDistanceM;
m_bCanPingAttach = settings.m_bCanPingAttach;
m_fPingRangeM = settings.m_fPingRangeM;
}
}

//------------------------------------------------------------------------------------------------
//! Method for local player to request pings on a position or target
void SendPing(vector targetPos, SCR_EditableEntityComponent target = null)
Expand All @@ -51,6 +71,10 @@ class ACE_Finger_EditorComponent : SCR_BaseEditorComponent
[RplRpc(RplChannel.Reliable, RplRcver.Server)]
protected void RpcAsk_SendPing(int reporterID, vector reporterPos, vector targetPos, RplId targetID)
{
// Drop target if pings can't be attached
if (!m_bCanPingAttach)
targetID = RplId.Invalid();

// Send ping to server as well if not dedicated
if (RplSession.Mode() != RplMode.Dedicated)
RpcDo_SendPing(reporterID, reporterPos, targetPos, targetID);
Expand All @@ -64,7 +88,10 @@ class ACE_Finger_EditorComponent : SCR_BaseEditorComponent
protected void RpcDo_SendPing(int reporterID, vector reporterPos, vector targetPos, RplId targetID)
{
IEntity player = GetGame().GetPlayerController().GetControlledEntity();
if (!player || vector.Distance(player.GetOrigin(), reporterPos) > m_fPingRangeM)
if (!player)
return;

if (m_fPingRangeM >= 0 && vector.Distance(player.GetOrigin(), reporterPos) > m_fPingRangeM)
return;

SCR_EditableEntityComponent target = SCR_EditableEntityComponent.Cast(Replication.FindItem(targetID));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//------------------------------------------------------------------------------------------------
//! Add mod settings to mission header
[BaseContainerProps()]
modded class ACE_MissionHeaderSettings
{
[Attribute()]
protected ref ACE_Finger_Settings m_ACE_Finger_Settings;

//------------------------------------------------------------------------------------------------
//! Applies settings from mission header to config
override void ApplyToSettingsConfig(notnull ACE_SettingsConfig config)
{
if (m_ACE_Finger_Settings)
config.SetModSettings(m_ACE_Finger_Settings);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//------------------------------------------------------------------------------------------------
//! Settings for a mod
[BaseContainerProps()]
class ACE_Finger_Settings : ACE_ModSettings
{
[RplProp(), Attribute(defvalue: "1000", desc: "Maximum pointing distance in meters.")]
float m_fMaxPointingDistanceM;

[Attribute(defvalue: "true", desc: "Whether the ping can attach to entities.")]
bool m_bCanPingAttach;

[Attribute(defvalue: "10", desc: "Range of the ping in meters. Only players in range will see it. Anyone can see it if negative.")]
float m_fPingRangeM;
}
24 changes: 24 additions & 0 deletions docs/src/content/docs/components/finger.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,27 @@ Allows players to point in a direction with their fingers, when they do so peopl

- Use the `Point with finger briefly` keybind in `Character` category (Default: <kbd>Ctrl</kbd>+<kbd>~</kbd>)

## Settings

Certain aspects of this mod can be configured in the mission header section of a server config file. An overview of available fields is given below in the table:

| Field | Type | Default | Description |
| ----------------------- | ----- | ------- | ---------------------------------------------------------------------------------------------- |
| m_fMaxPointingDistanceM | float | 1000 | Maximum pointing distance in meters. |
| m_bCanPingAttach | bool* | true | Whether the ping can attach to entities. |
| m_fPingRangeM | float | 10 | Range of the ping in meters. Only players in range will see it. Anyone can see it if negative. |

\* Note that bool has to be provided as integer in the config: 1 (true) or 0 (false).

Example for the `missionHeader` in a server config:
```
"missionHeader": {
"m_ACE_Settings": {
"m_ACE_Finger_Settings": {
"m_fMaxPointingDistanceM": 1000,
"m_bCanPingAttach": 1,
"m_fPingRangeM": 10
}
}
}
```

0 comments on commit 8a0f27c

Please sign in to comment.