Skip to content
WeAthFoLD edited this page Jan 26, 2016 · 4 revisions

CGUI is a flexible GUI framework provided in LambdaLib. Everything in CGUI is treated as a Widget, where it can handle mouse events, draw objects, being dragged around, and create many other complex effects. Widgets are also hierarchy based so you can create complex tree gui scructure very easily.

Quick glance:

Hard-coding

public MyGuiScreen extends CGuiScreen {

    {
        EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    
        // Setup the window at center of screen and the background texture
        Widget window = new Widget()
            .size(300, 200)
            .walign(WidthAlign.CENTER)
            .halign(HeightAlign.CENTER)
            .addComponent(new DrawTexture().setTex("mymod:textures/window.png"));
        
        // Setup a button and add it to the window
        window.addWidget(new Widget()
            .walign(WidthAlign.CENTER)
            .pos(0, 170)
            .size(40, 20)
            .addComponent(new Tint(Color.mono(0.4), Color.mono(0.6)))
            .addComponent(new TextBox().setContent("OK"))
            .listen(LeftClickEvent.class, (wid, evt) -> {
                player.sendChat("Niconiconi!");
            });
        
        // Text display
        window.addWidget(new Widget()
            .walign(WidthAlign.CENTER)
            .halign(HeightAlign.CENTER)
            .size(250, 20)
            .addComponent(new TextBox().setContent("Niconiconi~"));
        
        // Add to the GUI and make things alive
        gui.addWidget(window);
    }
    
}

With XML loading

Yet... what makes CGUI really powerful is that it has a in-game editor!

You can edit everything visually and the above code become:

public MyEpicGuiScreen extends CGuiScreen {

    static final WidgetContainer document = CGUIDocument.panicRead(new ResourceLocation("mymod:guis/epic.xml"));

    {
        EntityPlayer player = Minecraft.getMinecraft().thePlayer;
    
        // Make a duplication of the whole window, including sub widgets
        Widget window = document.getWidget("window").copy();
        
        // Attach event at runtime
        window.getWidget("button").listen(LeftClickEvent.class, (wid, evt) -> {
            player.sendChat("Niconiconi!");
        });
        
        // Add to the GUI and make things alive
        gui.addWidget(window);
    }
    
}

Getting a hang of this? Dig deeper by going through Getting Started.

Clone this wiki locally