Class Layer1ApiAlertGuiMessage

java.lang.Object
velox.api.layer1.messages.Layer1ApiAlertGuiMessage
All Implemented Interfaces:
Layer1ApiStrategiesEchoMessagesLayer.StrategyEchoMessageFromLayer

public class Layer1ApiAlertGuiMessage extends Object implements Layer1ApiStrategiesEchoMessagesLayer.StrategyEchoMessageFromLayer

Use this message to send GUI panels for configuration of Layer1ApiSoundAlertMessage's, created by your addon (specified via source).

Internally Bookmap caches these messages, and if you want to remove your GUI panels - send another Layer1ApiAlertGuiMessage with the same id and isAdd = false


Note: for now multiple GUI's for alerts from the same addon are not allowed. If your addon sends multiple Layer1ApiAlertGuiMessage's with isAdd = true - an exception will be thrown, and the addon will be unloaded. If you want to show a another GUI - you can un-register the previous one and then register another one. However, in most cases the provided functionality of guiPanelsProvider should be enough, as your Function can return different StrategyPanel[]

For an overview of the notification system, take a look at Layer1ApiSoundAlertMessage javadoc

Example of an addon that registers custom GUI panels

To keep the example simple, lets create an addon, whose sole purpose is to add a (very basic) GUI panel to the Bookmap.

As always, we start with defining an entrypoint for our addon:

 @Layer1Attachable
 @Layer1StrategyName("Simple alert GUI demo")
 @Layer1ApiVersion(Layer1ApiVersionValue.VERSION2)
 public class SimpleAlertGuiDemo implements Layer1ApiFinishable {

     private final Layer1ApiProvider provider;

     public SimpleAlertGuiDemo(Layer1ApiProvider provider) {
         this.provider = provider;
     }
 }
 

Next, lets define the panels that we want to show. Here we will implement a rather basic example. However, we are only showing the concept, and you can make your GUIs as complex as you like.

Here we will create an inner class that extends StrategyPanel

 private static class SimpleGuiPanel extends StrategyPanel {

     public SimpleGuiPanel() {
         super("Simple alert GUI demo");
         add(new JLabel("Hello from Simple alert GUI demo!"));
     }
 }
 

Moving on to the key part - sending our GUI to Bookmap. For that we should use Layer1ApiAlertGuiMessage:

 public SimpleAlertGuiDemo(Layer1ApiProvider provider) {
     this.provider = provider;

     guiMessage = Layer1ApiAlertGuiMessage
         .builder()
         .setSource(SimpleAlertGuiDemo.class)
         .setGuiPanelsProvider(declarationMessage -> new StrategyPanel[]{new SimpleGuiPanel()})
         .build();
     provider.sendUserMessage(guiMessage);
 }
 

And this should do the job. New GUI panels should appear in File -> Alerts -> Configure alerts -> Add alert....

It is also important to know that it is possible to remove your custom GUI panels from Bookmap:

 @Override
 public void finish() {
     if (guiMessage != null) {
         Layer1ApiAlertGuiMessage removeGuiMessage = new Builder(guiMessage)
             .setIsAdd(false)
             .build();
         provider.sendUserMessage(removeGuiMessage);
     }
 }
 
Full example source code can be found in DemoStrategies project on Github - check out velox.api.layer1.simpledemo.alerts.simplegui.SimpleAlertGuiDemo
See Also: