Skip to content

Commit

Permalink
Add toggle to hide overlays out of combat
Browse files Browse the repository at this point in the history
  • Loading branch information
xpdota committed Jul 2, 2024
1 parent 310a182 commit 0995712
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 20 deletions.
1 change: 1 addition & 0 deletions xivsupport/src/main/java/gg/xp/xivsupport/gui/GuiMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -1083,6 +1083,7 @@ public boolean isCellEditable(int row, int column) {
};
CustomTableModel<XivOverlay> tableModel = CustomTableModel.builder(overlayMain::getOverlays)
.addColumn(StandardColumns.booleanSettingColumn("On", XivOverlay::getEnabled, 50, visibleSetting))
.addColumn(StandardColumns.booleanSettingColumn("Combat", XivOverlay::getHideInCombatSetting, 70, visibleSetting))
.addColumn(new CustomColumn<>("Name", XivOverlay::getTitle, col -> col.setCellEditor(new NoCellEditor())))
.addColumn(StandardColumns.longSettingBoxColumn("X", XivOverlay::getXSetting, 100))
.addColumn(StandardColumns.longSettingBoxColumn("Y", XivOverlay::getYSetting, 100))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

import com.sun.jna.platform.win32.User32;
import com.sun.jna.platform.win32.WinDef;
import gg.xp.reevent.events.EventContext;
import gg.xp.reevent.events.EventMaster;
import gg.xp.reevent.events.InitEvent;
import gg.xp.reevent.scan.HandleEvents;
import gg.xp.xivsupport.events.actlines.events.OnlineStatus;
import gg.xp.xivsupport.events.debug.DebugCommand;
import gg.xp.xivsupport.events.state.InCombatChangeEvent;
import gg.xp.xivsupport.events.state.PrimaryPlayerOnlineStatusChangedEvent;
import gg.xp.xivsupport.persistence.PersistenceProvider;
import gg.xp.xivsupport.persistence.Platform;
import gg.xp.xivsupport.persistence.settings.BooleanSetting;
import org.picocontainer.PicoContainer;
Expand All @@ -28,10 +27,10 @@ public final class OverlayMain {
private final BooleanSetting forceShow;
private final PicoContainer container;
private final EventMaster master;

private volatile boolean inCombat;

@HandleEvents
public void commands(EventContext context, DebugCommand dbg) {
public void commands(DebugCommand dbg) {
String command = dbg.getCommand();
switch (command) {
case "overlay:lock":
Expand Down Expand Up @@ -68,7 +67,7 @@ public void commands(EventContext context, DebugCommand dbg) {
}

@HandleEvents
public void handlePlayerStatusChanged(EventContext context, PrimaryPlayerOnlineStatusChangedEvent event) {
public void handlePlayerStatusChanged(PrimaryPlayerOnlineStatusChangedEvent event) {
OnlineStatus status = event.getPlayerOnlineStatus();
this.cutscene = status == OnlineStatus.CUTSCENE || status == OnlineStatus.GPOSE;
recalc();
Expand All @@ -77,25 +76,18 @@ public void handlePlayerStatusChanged(EventContext context, PrimaryPlayerOnlineS
private boolean windowActive;
private boolean editing;
private boolean cutscene;
// TODO: Linux support
private final boolean isNonWindows;
private final boolean isWindows;

public OverlayMain(PicoContainer container, OverlayConfig config, EventMaster master) {
this.master = master;
if (!Platform.isWindows()) {
log.warn("Not running on Windows - disabling overlay support");
isNonWindows = true;
}
else {
isNonWindows = false;
}
isWindows = Platform.isWindows();
show = config.getShow();
forceShow = config.getForceShow();
this.container = container;
}

@HandleEvents
public void init(EventContext context, InitEvent init) {
public void init(InitEvent init) {
new Thread(() -> {

show.addListener(this::recalc);
Expand All @@ -120,11 +112,16 @@ public void init(EventContext context, InitEvent init) {
}
master.pushEvent(new OverlaysInitEvent());
}, "OverlayStartupHelper").start();
}

@HandleEvents
public void inCombatChange(InCombatChangeEvent event) {
this.inCombat = event.isInCombat();
recalc();
}

private boolean isGameWindowActive() {
if (isNonWindows) {
if (!isWindows) {
return true;
}
String window = getActiveWindowText();
Expand Down Expand Up @@ -163,11 +160,20 @@ private void recalc() {
windowActive = isGameWindowActive();
// Always show if editing
// If not editing, show if the user has turned overlay on, and ffxiv is the active window
boolean shouldShow = editing || (show.get() && (windowActive || forceShow.get()) && !cutscene);
log.debug("New Overlay State: WindowActive {}; Visible {}; Editing {}", windowActive, shouldShow, editing);
boolean cutScene = cutscene;
boolean shouldShow = editing || (show.get() && (windowActive || forceShow.get()) && !cutScene);
boolean inCombat = this.inCombat;
log.debug("New Overlay State: WindowActive {}; Visible {}; Editing {}; inCombat {}; cutScene {}", windowActive, shouldShow, editing, inCombat, cutScene);
SwingUtilities.invokeLater(() -> {
if (shouldShow) {
overlays.forEach(o -> o.setVisible(true));
overlays.forEach(o -> {
if (!inCombat && o.getHideInCombatSetting().get()) {
o.setVisible(false);
}
else {
o.setVisible(true);
}
});
overlays.forEach(o -> o.setEditMode(editing));
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.awt.geom.AffineTransform;
import java.util.List;
import java.util.concurrent.atomic.AtomicLong;

// TODO: also have a method for getting a config panel, much like PluginTab
Expand Down Expand Up @@ -50,6 +50,7 @@ public class XivOverlay {
private final DoubleSetting scaleFactor;
private final BooleanSetting enabled;
private final String title;
private final BooleanSetting hideInCombat;

private volatile int x;
private volatile int y;
Expand Down Expand Up @@ -79,6 +80,7 @@ public XivOverlay(String title, String settingKeyBase, OverlayConfig oc, Persist
frame = ScalableJFrameLinuxRealImpl.construct(title, scaleFactor.get());
}
enabled = new BooleanSetting(persistence, String.format("xiv-overlay.enable.%s.enabled", settingKeyBase), false);
hideInCombat = new BooleanSetting(persistence, String.format("xiv-overlay.hide-in-combat.%s.enabled", settingKeyBase), false);
enabled.addListener(this::recalc);
frame.setIgnoreRepaint(oc.getIgnoreRepaint().get());
opacity.addListener(() -> frame.setOpacity((float) opacity.get()));
Expand Down Expand Up @@ -286,4 +288,7 @@ protected long calculateUnscaledFrameTime(long basis) {
return Math.min(Math.max(basis, maxFrameTime), minFrameTime);
}

public BooleanSetting getHideInCombatSetting() {
return hideInCombat;
}
}

0 comments on commit 0995712

Please sign in to comment.