-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ability to create an easy trigger from a duty callout
- Loading branch information
Showing
12 changed files
with
249 additions
and
22 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
...java/gg/xp/xivsupport/events/triggers/easytriggers/EasyTriggerDutyCalloutExtraAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package gg.xp.xivsupport.events.triggers.easytriggers; | ||
|
||
import gg.xp.reevent.scan.ScanMe; | ||
import gg.xp.xivsupport.callouts.ModifiableCallout; | ||
import gg.xp.xivsupport.callouts.ModifiedCalloutHandle; | ||
import gg.xp.xivsupport.callouts.RawModifiedCallout; | ||
import gg.xp.xivsupport.callouts.gui.ExtraCalloutAction; | ||
import gg.xp.xivsupport.callouts.gui.ExtraCalloutActionInstance; | ||
import gg.xp.xivsupport.events.triggers.easytriggers.actions.CalloutAction; | ||
import gg.xp.xivsupport.events.triggers.easytriggers.conditions.DutyCalloutFilter; | ||
import gg.xp.xivsupport.events.triggers.easytriggers.gui.EasyTriggersTab; | ||
import gg.xp.xivsupport.events.triggers.easytriggers.model.EasyTrigger; | ||
import gg.xp.xivsupport.speech.ProcessedCalloutEvent; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import javax.swing.*; | ||
import java.lang.reflect.Field; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.Objects; | ||
|
||
@ScanMe | ||
public class EasyTriggerDutyCalloutExtraAction implements ExtraCalloutAction { | ||
|
||
public final EasyTriggers et; | ||
private final EasyTriggersTab ett; | ||
|
||
public EasyTriggerDutyCalloutExtraAction(EasyTriggers et, EasyTriggersTab ett) { | ||
this.et = et; | ||
this.ett = ett; | ||
} | ||
|
||
private void showError(String error) { | ||
JOptionPane.showMessageDialog(JFrame.getWindows()[0], "Error: " + error, error, JOptionPane.ERROR_MESSAGE); | ||
|
||
} | ||
|
||
@Nullable | ||
@Override | ||
public ExtraCalloutActionInstance getInstance(ModifiableCallout<?> callout, ModifiedCalloutHandle handle) { | ||
return new ExtraCalloutActionInstance() { | ||
@Override | ||
public String getLabel() { | ||
return "Make Easy Trigger"; | ||
} | ||
|
||
@Override | ||
public boolean isVisible() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isEnabled() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void doAction() { | ||
|
||
Field field = handle.getField(); | ||
if (field == null) { | ||
showError("Field was null!"); | ||
return; | ||
} | ||
String className = field.getDeclaringClass().getSimpleName(); | ||
String fieldName = field.getName(); | ||
DutyCalloutFilter dcf = new DutyCalloutFilter(); | ||
dcf.calloutClass = className; | ||
dcf.calloutField = fieldName; | ||
|
||
CalloutAction ca = new CalloutAction(); | ||
ca.setText("{originalText}"); | ||
ca.setTts("{originalTts}"); | ||
|
||
EasyTrigger<ProcessedCalloutEvent> easyTrigger = new EasyTrigger(); | ||
easyTrigger.setEventType(ProcessedCalloutEvent.class); | ||
easyTrigger.addCondition(dcf); | ||
easyTrigger.addAction(ca); | ||
et.addTrigger(easyTrigger); | ||
ett.bringToFront(); | ||
ett.selectTrigger(easyTrigger); | ||
} | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
...main/java/gg/xp/xivsupport/events/triggers/easytriggers/conditions/DutyCalloutFilter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package gg.xp.xivsupport.events.triggers.easytriggers.conditions; | ||
|
||
import gg.xp.reevent.events.Event; | ||
import gg.xp.xivsupport.callouts.ModifiedCalloutHandle; | ||
import gg.xp.xivsupport.callouts.RawModifiedCallout; | ||
import gg.xp.xivsupport.events.triggers.easytriggers.model.Condition; | ||
import gg.xp.xivsupport.events.triggers.easytriggers.model.EasyTriggerContext; | ||
import gg.xp.xivsupport.events.triggers.easytriggers.model.SimpleCondition; | ||
import gg.xp.xivsupport.speech.ProcessedCalloutEvent; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.lang.reflect.Field; | ||
import java.util.Objects; | ||
import java.util.function.Supplier; | ||
|
||
public class DutyCalloutFilter implements Condition<ProcessedCalloutEvent> { | ||
|
||
@Description("Class") | ||
public String calloutClass; | ||
@Description("Field") | ||
public String calloutField; | ||
|
||
@Override | ||
public @Nullable String fixedLabel() { | ||
return "Callout came from specific duty trigger"; | ||
} | ||
|
||
@Override | ||
public String dynamicLabel() { | ||
return "Callout came from %s:%s".formatted(calloutClass, calloutField); | ||
} | ||
|
||
@Override | ||
public boolean test(EasyTriggerContext ctx, ProcessedCalloutEvent event) { | ||
if (event.getParent() instanceof RawModifiedCallout<?> raw) { | ||
ModifiedCalloutHandle handle = raw.getHandle(); | ||
if (handle == null) { | ||
return false; | ||
} | ||
Field field = handle.getField(); | ||
if (field == null) { | ||
return false; | ||
} | ||
if (Objects.equals(field.getDeclaringClass().getSimpleName(), calloutClass) | ||
&& Objects.equals(field.getName(), calloutField)) { | ||
Event originalEvent = raw.getParent(); | ||
ctx.addVariable("originalEvent", originalEvent); | ||
ctx.addVariable("originalParams", raw.getArguments()); | ||
ctx.addVariable("originalTts", event.getCallText()); | ||
ctx.addVariable("originalText", (Supplier<String>) event::getVisualText); | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.