
mmb.content.modular.gui.ModuleOrCoreGUI Maven / Gradle / Ivy
/**
*
*/
package mmb.content.modular.gui;
import java.awt.Component;
import mmb.NN;
import mmb.Nil;
import mmb.content.modular.BlockModuleOrCore;
import mmb.content.modular.Slot;
import mmb.data.reactive.Reactor;
import mmb.menu.components.Placeholder;
import mmb.menu.world.inv.InventoryController;
/**
* A GUI wrapper with buttons, upgrades
* @author oskar
* @param type of elements
* @param type of GUIs
*/
public class ModuleOrCoreGUI, Tgui extends Component&SafeCloseable> extends Placeholder implements AutoCloseable{
private static final long serialVersionUID = 1044001523317555311L;
//Managed resources & components
@NN private final transient Reactor<@Nil Telement, @Nil Tgui> guiReactor;
//GUI definition
@NN public final Slot prop;
@NN public final InventoryController invctrl;
/**
* Creates a module GUI
* @param prop access slot
* @param invctrl inventory controller
*/
public ModuleOrCoreGUI(Slot prop, InventoryController invctrl) {
this.prop = prop;
this.invctrl = invctrl;
this.guiReactor = new Reactor<>(prop, this::createGUI);
guiReactor.listenrem(el -> {if(el != null) el.close();});
setProperty(guiReactor);
}
private @Nil Tgui createGUI(@Nil Telement elem) {
if(elem == null) return null;
@SuppressWarnings("unchecked")
ModuleConfigHandler mch = (ModuleConfigHandler) elem.mch();
if(mch == null) return null;
Tgui gui = mch.newComponent(invctrl, elem);
return gui;
}
@Override
public void close() {
guiReactor.close();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy