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
10 changes: 7 additions & 3 deletions FactionRelationships/COMPILATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ FactionRelationships/
│ └── com/factionrelationships/
│ ├── FactionRelationshipsPlugin.java
│ ├── FactionRelationshipsUIRenderer.java
│ └── FactionRelationshipsKeybindScript.java
│ ├── FactionRelationshipsCampaignInputListener.java
│ ├── FactionRelationshipsKeybindScript.java # stub for save compatibility
│ ├── FactionRelationshipChangeListener.java
│ ├── RelationshipChangeStore.java
│ └── SystemFactionRelationshipsIntel.java
├── compile.local.example.bat # copy to compile.local.bat (gitignored) to set GAME_DIR
└── COMPILATION.md
```
Expand All @@ -62,7 +66,7 @@ set LUNALIB=%GAME_DIR%\mods\LunaLib\jars\LunaLib.jar
set LAZYLIB=%GAME_DIR%\mods\LazyLib\jars\LazyLib.jar
set CORE=%GAME_DIR%\starsector-core
set VERSION=1.3.0
javac -encoding UTF-8 -cp "%CORE%\starfarer.api.jar;%CORE%\starfarer_obf.jar;%CORE%\json.jar;%CORE%\log4j-1.2.9.jar;%CORE%\lwjgl.jar;%CORE%\lwjgl_util.jar;%LAZYLIB%;%LUNALIB%" -d FactionRelationships-%VERSION%\classes FactionRelationships\src\com\factionrelationships\FactionRelationshipsPlugin.java FactionRelationships\src\com\factionrelationships\FactionRelationshipsUIRenderer.java FactionRelationships\src\com\factionrelationships\FactionRelationshipsKeybindScript.java
javac -encoding UTF-8 -cp "%CORE%\starfarer.api.jar;%CORE%\starfarer_obf.jar;%CORE%\json.jar;%CORE%\log4j-1.2.9.jar;%CORE%\lwjgl.jar;%CORE%\lwjgl_util.jar;%LAZYLIB%;%LUNALIB%" -d FactionRelationships-%VERSION%\classes FactionRelationships\src\com\factionrelationships\FactionRelationshipsPlugin.java FactionRelationships\src\com\factionrelationships\FactionRelationshipsUIRenderer.java FactionRelationships\src\com\factionrelationships\FactionRelationshipsCampaignInputListener.java FactionRelationships\src\com\factionrelationships\FactionRelationshipsKeybindScript.java FactionRelationships\src\com\factionrelationships\FactionRelationshipChangeListener.java FactionRelationships\src\com\factionrelationships\RelationshipChangeStore.java FactionRelationships\src\com\factionrelationships\SystemFactionRelationshipsIntel.java
jar cvf FactionRelationships-%VERSION%\jars\FactionRelationships.jar -C FactionRelationships-%VERSION%\classes .
```

Expand Down Expand Up @@ -92,7 +96,7 @@ Set `GAME_DIR` (and optionally `LUNALIB`, `LAZYLIB`) before running (e.g. via `c
└── FactionRelationships.jar
```

Configure max factions, text size, overlay keybind (toggle or hold), and hostile-only filter in **Mod Settings** (F2 in campaign).
Configure max factions, text size, overlay keybind (toggle or hold), hostile-only filter, relationship-change display, and auto-show overlay on change in **Mod Settings** (F2 in campaign).

## Quick Reference

Expand Down
2 changes: 1 addition & 1 deletion FactionRelationships/compile.bat
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if not exist "%OUT%" mkdir "%OUT%"
if not exist "..\%PKG%\jars" mkdir "..\%PKG%\jars"

echo Compiling...
javac -encoding UTF-8 -cp "%CORE%\starfarer.api.jar;%CORE%\starfarer_obf.jar;%CORE%\json.jar;%CORE%\log4j-1.2.9.jar;%CORE%\lwjgl.jar;%CORE%\lwjgl_util.jar;%LAZYLIB%;%LUNALIB%" -d "%OUT%" "%SRC%\FactionRelationshipsPlugin.java" "%SRC%\FactionRelationshipsUIRenderer.java" "%SRC%\FactionRelationshipsKeybindScript.java"
javac -encoding UTF-8 -cp "%CORE%\starfarer.api.jar;%CORE%\starfarer_obf.jar;%CORE%\json.jar;%CORE%\log4j-1.2.9.jar;%CORE%\lwjgl.jar;%CORE%\lwjgl_util.jar;%LAZYLIB%;%LUNALIB%" -d "%OUT%" "%SRC%\FactionRelationshipsPlugin.java" "%SRC%\FactionRelationshipsUIRenderer.java" "%SRC%\FactionRelationshipsCampaignInputListener.java" "%SRC%\FactionRelationshipsKeybindScript.java" "%SRC%\FactionRelationshipChangeListener.java" "%SRC%\RelationshipChangeStore.java" "%SRC%\SystemFactionRelationshipsIntel.java"
if errorlevel 1 (
echo Compilation failed.
exit /b 1
Expand Down
3 changes: 3 additions & 0 deletions FactionRelationships/data/config/LunaSettings.csv
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ showOnlyHostile,Show Only Hostile Factions,Boolean,false,,Only display factions
textSize,Text Size,Radio,Medium,"Small,Medium,Large",Text size for the overlay. Use [Large] for 4K or high-DPI displays.,,,General
overlayKeybindMode,Overlay Keybind Mode,Radio,Toggle,"Toggle,Hold",[Toggle]: Press key to show or hide overlay. [Hold]: Overlay only visible while key is held.,,,General
toggleOverlayKeybind,Toggle Overlay Keybind,Keycode,0,,Key to show or hide the faction relationship overlay on the campaign map. Set in Mod Settings (F2). Keycode 0 = unbound.,,,General
showRelationshipChangeInOverlay,Show Relationship Change in Overlay,Boolean,true,,"When a faction relationship changes, show the change (e.g. +5 or -10) next to that faction for the duration set below.",,,General
relationshipChangeDisplaySeconds,Relationship Change Display (seconds),Int,30,,"How long to show the change next to a faction in the overlay, in seconds.",5,120,General
autoShowOverlayOnRelationshipChange,Auto-Show Overlay When Relationship Changes,Boolean,false,,"When a faction relationship changes, automatically show the overlay (for the duration set above).",,,General
2 changes: 1 addition & 1 deletion FactionRelationships/mod_info.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"id": "factionrelationships",
"name": "Faction Relationships",
"author": "boop",
"version": "1.3.1",
"version": "1.4.8",
"description": "Shows a list of factions and their relationship with the player on the main navigation screen.",
"gameVersion": "0.98a-RC8",
"jars": ["jars/FactionRelationships.jar"],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.factionrelationships;

import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.campaign.BaseCampaignEventListener;
import com.fs.starfarer.api.characters.PersonAPI;
import lunalib.lunaSettings.LunaSettings;

/**
* Listens for faction relationship changes and records them for the overlay.
* Registered as a transient listener in onGameLoad so it is not saved with the game.
*/
public class FactionRelationshipChangeListener extends BaseCampaignEventListener {

private static final String AUTO_SHOW_SETTING = "autoShowOverlayOnRelationshipChange";
private static final String DISPLAY_SECONDS_SETTING = "relationshipChangeDisplaySeconds";
private static final int DEFAULT_DISPLAY_SECONDS = 30;
private static final int MIN_DISPLAY_SECONDS = 5;
private static final int MAX_DISPLAY_SECONDS = 120;

public FactionRelationshipChangeListener() {
super(false);
}

private static int getDisplayDurationSeconds() {
if (!FactionRelationshipsPlugin.isLunaLibEnabled()) {
return DEFAULT_DISPLAY_SECONDS;
}
Integer v = LunaSettings.getInt(FactionRelationshipsPlugin.MOD_ID, DISPLAY_SECONDS_SETTING);
if (v == null) {
return DEFAULT_DISPLAY_SECONDS;
}
int sec = v.intValue();
if (sec < MIN_DISPLAY_SECONDS) sec = MIN_DISPLAY_SECONDS;
if (sec > MAX_DISPLAY_SECONDS) sec = MAX_DISPLAY_SECONDS;
return sec;
}

@Override
public void reportPlayerReputationChange(String factionId, float delta) {
long durationMs = getDisplayDurationSeconds() * 1000L;
RelationshipChangeStore.record(factionId, delta, durationMs);
if (FactionRelationshipsPlugin.isLunaLibEnabled()) {
Boolean autoShow = LunaSettings.getBoolean(FactionRelationshipsPlugin.MOD_ID, AUTO_SHOW_SETTING);
if (Boolean.TRUE.equals(autoShow)) {
FactionRelationshipsPlugin.setOverlayVisible(true);
RelationshipChangeStore.setAutoShowExpiry(System.currentTimeMillis() + durationMs);
}
}
}

@Override
public void reportPlayerReputationChange(PersonAPI person, float delta) {
if (person == null || person.getFaction() == null) {
return;
}
reportPlayerReputationChange(person.getFaction().getId(), delta);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package com.factionrelationships;

import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.campaign.listeners.CampaignInputListener;
import com.fs.starfarer.api.input.InputEventAPI;
import lunalib.lunaSettings.LunaSettings;

import java.util.List;

/**
* Handles the overlay toggle keybind on the campaign map using the game's input
* event stream. This runs when the campaign is active (and while paused when
* registered with addListener(..., true)), so the key is detected reliably
* instead of polling {@code Keyboard.isKeyDown} in an EveryFrameScript.
* <p>
* Pattern used by mods like Console Commands and Advanced Weapon Control:
* implement {@link CampaignInputListener} and handle keys in
* {@link #processCampaignInputPreCore(List)}.
*/
public class FactionRelationshipsCampaignInputListener implements CampaignInputListener {

@Override
public int getListenerInputPriority() {
return 0;
}

@Override
public void processCampaignInputPreCore(List<InputEventAPI> events) {
if (!FactionRelationshipsPlugin.isLunaLibEnabled()) {
return;
}
Integer keycodeObj = LunaSettings.getInt(FactionRelationshipsPlugin.MOD_ID, "toggleOverlayKeybind");
if (keycodeObj == null || keycodeObj.intValue() == 0) {
FactionRelationshipsPlugin.setOverlayKeyHeld(false);
return;
}
final int keycode = keycodeObj.intValue();
final String mode = FactionRelationshipsPlugin.getOverlayKeybindMode();

for (InputEventAPI event : events) {
if (event.isConsumed()) {
continue;
}
if (event.isKeyDownEvent() && event.getEventValue() == keycode) {
RelationshipChangeStore.clearAutoShowExpiry();
if ("Hold".equals(mode)) {
FactionRelationshipsPlugin.setOverlayKeyHeld(true);
} else {
FactionRelationshipsPlugin.setOverlayVisible(!FactionRelationshipsPlugin.isOverlayVisible());
}
event.consume();
break;
}
if ("Hold".equals(mode) && event.isKeyUpEvent() && event.getEventValue() == keycode) {
RelationshipChangeStore.clearAutoShowExpiry();
FactionRelationshipsPlugin.setOverlayKeyHeld(false);
event.consume();
break;
}
}
}

@Override
public void processCampaignInputPreFleetControl(List<InputEventAPI> events) {
}

@Override
public void processCampaignInputPostCore(List<InputEventAPI> events) {
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
package com.factionrelationships;

import com.fs.starfarer.api.Global;
import com.fs.starfarer.api.EveryFrameScript;
import lunalib.lunaSettings.LunaSettings;
import org.lwjgl.input.Keyboard;

/**
* Polls the LunaLib keybind. In Toggle mode: press to show/hide overlay (edge detection).
* In Hold mode: overlay visible only while key is held.
* Stub for save compatibility only. Old saves serialized this script in the
* campaign engine; this class allows them to load. The script reports itself
* done immediately so the engine removes it after load.
*/
public class FactionRelationshipsKeybindScript implements EveryFrameScript {

private boolean keyWasDown;

@Override
public boolean isDone() {
return false;
return true;
}

@Override
Expand All @@ -25,25 +21,5 @@ public boolean runWhilePaused() {

@Override
public void advance(float amount) {
if (!Global.getSettings().getModManager().isModEnabled("lunalib")) {
return;
}
Integer keycodeObj = LunaSettings.getInt("factionrelationships", "toggleOverlayKeybind");
if (keycodeObj == null || keycodeObj.intValue() == 0) {
FactionRelationshipsPlugin.setOverlayKeyHeld(false);
return;
}
int keycode = keycodeObj.intValue();
boolean keyDown = Keyboard.isKeyDown(keycode);
String mode = FactionRelationshipsPlugin.getOverlayKeybindMode();
if ("Hold".equals(mode)) {
FactionRelationshipsPlugin.setOverlayKeyHeld(keyDown);
} else {
FactionRelationshipsPlugin.setOverlayKeyHeld(false);
if (!keyWasDown && keyDown) {
FactionRelationshipsPlugin.setOverlayVisible(!FactionRelationshipsPlugin.isOverlayVisible());
}
}
keyWasDown = keyDown;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@

public class FactionRelationshipsPlugin extends BaseModPlugin {

/** Mod ID for LunaSettings and mod manager; must match mod_info.json "id". */
public static final String MOD_ID = "factionrelationships";

private static Logger log;

/** Overlay visibility toggle; read by renderer, written by keybind script (Toggle mode). Default true. */
/** Overlay visibility toggle; read by renderer, written by campaign input listener (Toggle mode). Default true. */
private static volatile boolean overlayVisible = true;

/** Key currently held; used in Hold mode so overlay shows only while key is down. */
Expand Down Expand Up @@ -41,8 +44,8 @@ public static String getOverlayKeybindMode() {
return cachedOverlayKeybindMode;
}
String mode = "Toggle";
if (Global.getSettings().getModManager().isModEnabled("lunalib")) {
String s = LunaSettings.getString("factionrelationships", "overlayKeybindMode");
if (FactionRelationshipsPlugin.isLunaLibEnabled()) {
String s = LunaSettings.getString(MOD_ID, "overlayKeybindMode");
if (s != null && ("Hold".equalsIgnoreCase(s) || "Toggle".equalsIgnoreCase(s))) {
mode = "Hold".equalsIgnoreCase(s) ? "Hold" : "Toggle";
}
Expand All @@ -51,6 +54,11 @@ public static String getOverlayKeybindMode() {
return mode;
}

/** Whether LunaLib is enabled; used for settings and keybinds. */
public static boolean isLunaLibEnabled() {
return Global.getSettings().getModManager().isModEnabled("lunalib");
}

/** Called when LunaSettings change so mode and other caches are re-read. */
public static void invalidateSettingsCache() {
cachedOverlayKeybindMode = null;
Expand All @@ -60,11 +68,11 @@ public static void invalidateSettingsCache() {
public void onApplicationLoad() throws Exception {
log = Global.getLogger(FactionRelationshipsPlugin.class);
log.info("Faction Relationships mod loaded.");
if (Global.getSettings().getModManager().isModEnabled("lunalib")) {
if (FactionRelationshipsPlugin.isLunaLibEnabled()) {
LunaSettings.addSettingsListener(new LunaSettingsListener() {
@Override
public void settingsChanged(String modID) {
if ("factionrelationships".equals(modID)) {
if (MOD_ID.equals(modID)) {
FactionRelationshipsPlugin.invalidateSettingsCache();
FactionRelationshipsUIRenderer.invalidateSettingsCache();
}
Expand All @@ -76,11 +84,10 @@ public void settingsChanged(String modID) {
@Override
public void onGameLoad(boolean newGame) {
Global.getSector().getListenerManager().addListener(new FactionRelationshipsUIRenderer(), true);
if (Global.getSettings().getModManager().isModEnabled("lunalib")) {
Global.getSector().addScript(new FactionRelationshipsKeybindScript());
}
Global.getSector().getListenerManager().addListener(new FactionRelationshipsCampaignInputListener(), true);
Global.getSector().addTransientListener(new FactionRelationshipChangeListener());
if (log != null) {
log.info("Faction Relationships UI renderer and keybind script registered.");
log.info("Faction Relationships UI renderer, campaign input listener, and relationship change listener registered.");
}
}
}
Loading