Jump to content
Frequently Asked Questions
  • Are you not able to open the client? Try following our getting started guide
  • Still not working? Try downloading and running JarFix
  • Help! My bot doesn't do anything! Enable fresh start in client settings and restart the client
  • How to purchase with PayPal/OSRS/Crypto gold? You can purchase vouchers from other users
  • Dont write GUIs - Small framework to never have to write a GUI again


    camelCase

    Recommended Posts

    When making scripts its a common requirement to let users configure certain settings

    problem is that swing is annoying! it is easy to mess things up and easy to write in a way where adding another setting can mess up the entire ui

    for smalls scripts, a gui can easily be the majority of the complexity in the codebase

    instead we will make a framework to take a data class, use reflection and some custom annotations to generate a gui on the fly for us

    * this was written with functionality in mind, its to make writing scripts faster not to be pretty

    * this was written 10 minutes before posting this so theres probably edge cases

     

    usage:

    SwingUtilities.invokeLater(() -> new TabbedUI(TestScriptSettings.getData()));
    

    see below for examples on how UITab annotation works

     

    some examples:

    No sub tabs, just settings

        public static class Data {
            @SerializedName("hoursUntilMuleOff")
            public int hoursUntilMuleOff = 12;
            @SerializedName("initalGP")
            public int initalGP = 16_000_000;
            @SerializedName("slayerLvl")
            public int slayerLvl = 30;
            @SerializedName("slayDragons")
            public boolean slayDragons = false;
            @SerializedName("slayWithWhip")
            public boolean slayWithWhip = true;
            @SerializedName("prayerTarget")
            public int prayerTarget = 60;
            @SerializedName("prayInPOH")
            public boolean prayInPOH = true;
            @SerializedName("moneyLeftAfterMuling")
            public int moneyLeftAfterMuling = 1_000_000;
            @SerializedName("minLootValue")
            public int minLootValue = 1000;
        }

    results in:

    image.png.eba3bb6884f6dc5587b664bd54abc28f.png

     

    1 tab, some in root:

        public static class Data {
            @SerializedName("hoursUntilMuleOff")
            public int hoursUntilMuleOff = 12;
            @SerializedName("initalGP")
            public int initalGP = 16_000_000;
            @SerializedName("slayerLvl")
            @UITab("skilling")
            public int slayerLvl = 30;
            @SerializedName("slayDragons")
            @UITab("skilling")
            public boolean slayDragons = false;
            @SerializedName("slayWithWhip")
            @UITab("skilling")
            public boolean slayWithWhip = true;
            @SerializedName("prayerTarget")
            @UITab("skilling")
            public int prayerTarget = 60;
            @SerializedName("prayInPOH")
            @UITab("skilling")
            public boolean prayInPOH = true;
            @SerializedName("moneyLeftAfterMuling")
            public int moneyLeftAfterMuling = 1_000_000;
            @SerializedName("minLootValue")
            public int minLootValue = 1000;
        }

    results in:

    image.png.c757fd8c695acbd3c07dfd7d3e241864.png

    some in root, skilling has 2 subtabs

        public static class Data {
            @SerializedName("hoursUntilMuleOff")
            public int hoursUntilMuleOff = 12;
            @SerializedName("initalGP")
            public int initalGP = 16_000_000;
            @SerializedName("slayerLvl")
            @UITab("skilling")
            public int slayerLvl = 30;
            @SerializedName("slayDragons")
            @UITab({"skilling", "slayer"} )
            public boolean slayDragons = false;
            @SerializedName("slayWithWhip")
            @UITab({"skilling", "slayer"})
            public boolean slayWithWhip = true;
            @SerializedName("prayerTarget")
            @UITab({"skilling", "prayer"})
            public int prayerTarget = 60;
            @SerializedName("prayInPOH")
            @UITab({"skilling", "prayer"})
            public boolean prayInPOH = true;
            @SerializedName("moneyLeftAfterMuling")
            public int moneyLeftAfterMuling = 1_000_000;
            @SerializedName("minLootValue")
            public int minLootValue = 1000;
        }

    results in:

    image.png.a75a6047229d852e96037b54e4c23c4f.png

    none in root:

            @SerializedName("hoursUntilMuleOff")
            @UITab("script")
            public int hoursUntilMuleOff = 12;
            @SerializedName("initalGP")
            @UITab("script")
            public int initalGP = 16_000_000;
            @SerializedName("slayerLvl")
            @UITab({"skilling", "slayer"})
            public int slayerLvl = 30;
            @SerializedName("slayDragons")
            @UITab({"skilling", "slayer"} )
            public boolean slayDragons = false;
            @SerializedName("slayWithWhip")
            @UITab({"skilling", "slayer"})
            public boolean slayWithWhip = true;
            @SerializedName("prayerTarget")
            @UITab({"skilling", "prayer"})
            public int prayerTarget = 60;
            @SerializedName("prayInPOH")
            @UITab({"skilling", "prayer"})
            public boolean prayInPOH = true;
            @SerializedName("moneyLeftAfterMuling")
            @UITab("script")
            public int moneyLeftAfterMuling = 1_000_000;
            @SerializedName("minLootValue")
            @UITab("script")
            public int minLootValue = 1000;

    results in:

    image.png.c9d2040c4d94e3c5e00659764a508b9c.png

    image.png.dfd7e6239979bd6eab11ad7f9d991393.png

     

    hopefully its evident how this can be used from a quick script with only a couple of settings to a full blown aio with 10-20 settings per skill / activity without ever having to actually write and swing code and read about layouts for 15 hours and give yourself back pain

     

    some updates that are nice if you want to

    - remove requirement for serializedName and just use field name if its not ther

    - add an annotation that gives tooltips in the GuiOption component

    - anything to make it prettier

    contribute and yoink here:https://github.com/camelCaseDB/Reflective-GUI-Generator?tab=readme-ov-filehttps://github.com/Amoz3/Reflective-GUI-Generator

     

    Edited by camelCase
    Link to comment
    Share on other sites

    Thanks @camelCase

    Implementation of ENUM using camelCase code.

    public enum WallSelection {
        WESTWALL,
        EASTWALL,
        AUTOHANDLE
    }
    
    //Prayer Settings
        @SerializedName("Select Wall")
        @UITab("Wall")
        public WallSelection testing = WallSelection.EASTWALL;

    As well as using @mr beautiful swing Function

    SwingUtilities.invokeLater(() -> {
                TabbedUI t = new TabbedUI(new Data());
                t.addWindowListener(new WindowListener() {
                    @Override
                    public void windowOpened(WindowEvent e) {
    
                    }
    
                    @Override
                    public void windowClosing(WindowEvent e) {
                        // save
                        Logger.info("window closing");
                    }
    
                    @Override
                    public void windowClosed(WindowEvent e) {
                    }
    
                    @Override
                    public void windowIconified(WindowEvent e) {
    
                    }
    
                    @Override
                    public void windowDeiconified(WindowEvent e) {
    
                    }
    
                    @Override
                    public void windowActivated(WindowEvent e) {
    
                    }
    
                    @Override
                    public void windowDeactivated(WindowEvent e) {
    
                    }
                });
            });

     

    Link to comment
    Share on other sites

    Create an account or sign in to comment

    You need to be a member in order to leave a comment

    Create an account

    Sign up for a new account in our community. It's easy!

    Register a new account

    Sign in

    Already have an account? Sign in here.

    Sign In Now
    ×
    ×
    • Create New...

    Important Information

    We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.