mmb.content.modular.gui.ModuleOrCoreGUI Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of multimachinebuilder Show documentation
Show all versions of multimachinebuilder Show documentation
Dependency for the MultiMachineBuilder, a voxel game about building an industrial empire in a finite world.
THIS RELEASE IS NOT PLAYABLE. To play the game, donwload from >ITCH.IO LINK HERE< or >GH releases link here<
/**
*
*/
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();
}
}