1. #1
    U-Labs Routinier
    Avatar von Mentos
    Registriert seit
    18.11.2011
    Beiträge
    451
    Thanked 497 Times in 239 Posts

    Standard [Java] [Knuddels] Toolbar

    Da man dies sicher auch gut für Clientmanipulierungen benutzen kann:
    PHP-Code:
    package Util;

    import java.awt.Color;
    import java.util.List;
    import knuddels.SendOpcode;
    import knuddels.Server;
    import tools.PacketWriter;

    /**
     *
     * @author Hilko/Mentos
     */

    public class Toolbar {
        
        private final static 
    char EMPTY_TEXTVALUE 0x00//Knuddels benutzt 0xFF (=-1), 0x00 (=0) sollte aber auch gehen!

        //Cro - Easy :'D
        /***
         * Creates a new Toolbar for the specified channel
         * @param channel The Channel
         * @param buttons A buttonList
         * @return The final string, which you can send
         */
        
    public static String ToolbarString(String channel, List<Buttonbuttons) {
            return 
    ToolbarString(channelbuttonsnull);
        }

        
    /****
         * Creates a new Toolbar for the specified channel
         * @param channel The Channel
         * @param buttons The buttonList
         * @param analogButtons The analog Buttons
         * @return The final string, which you can send
         */
        
    public static String ToolbarString(String channel, List<Buttonbuttons, List<AnalogButtonanalogButtons) {
            
    PacketWriter packet = new PacketWriter();
            
    packet.writeString(SendOpcode.MODULE.getValue());
            
    packet.write(0x00);
            
    packet.writeShort(Server.get().getModuleTree().getIndex("SHOW_BUTTONS"));
            
    packet.write((bytechannel.length());
            
    packet.writeString(channel);

            for (
    Button button buttons) {
                
    packet.write(0x0B); //New Element
                
    writeButton(packetbutton);
            }
            
    packet.write(0x0C); //List end

            
    if (analogButtons != null) {
                for (
    AnalogButton button analogButtons) {
                    
    packet.write(0x0B);
                    
    writeButton(packetbutton.normalButton);
                    
    packet.writeInt(button.analogSegments);
                    
    packet.writeInt(button.sendIntervalMillis);
                    
    packet.writeInt(button.cooldownIntervalMillis);
                }
            }

            
    packet.write(0x0C);
            return 
    packet.toString();
        }

        
    /***
         * Writes a button into the Packet
         * @param packet The packetwriter
         * @param button  The button
         */
        
    private static void writeButton(PacketWriter packetButton button) {
            if (!
    isNullOrEmpty(button.text)) {
                
    packet.write((bytebutton.text.length());
                
    packet.writeString(button.text);
            } else {
                
    packet.write(EMPTY_TEXTVALUE);
            }

            if (!
    isNullOrEmpty(button.image)) {
                
    packet.write((bytebutton.image.length());
                
    packet.writeString(button.image);
            } else {
                
    packet.write(EMPTY_TEXTVALUE);
            }

            
    packet.writeBoolean(button.showOnTheLeftSide);

            if (!
    isNullOrEmpty(button.chatFunction)) {
                
    packet.write((bytebutton.chatFunction.length());
                
    packet.writeString(button.chatFunction);
            } else {
                
    packet.write(EMPTY_TEXTVALUE);
            }
        }

        
    /***
         * Sets the style of the toolbar
         * @param channel The channel
         * @param barStyle The BarStyle
         * @param buttonStyle The ButtonStyle
         * @param analogButtonStyle The AnalogButtonStyle
         * @return  The settings-string
         */
        
    public static String Settings(String channelShading barStyleShading buttonStyleShading analogButtonStyle) {
            
    PacketWriter packet = new PacketWriter();
            
    packet.writeString(SendOpcode.MODULE.getValue());
            
    packet.write(0x00);
            
    packet.writeShort(Server.get().getModuleTree().getIndex("BUTTON_BAR_SETTINGS"));
            
    packet.write((bytechannel.length());
            
    packet.writeString(channel);

            
    //Write the bar style
            
    writeByteArray(packetgetByteArrayFromColor(barStyle.topFadeFrom));
            
    writeByteArray(packetgetByteArrayFromColor(barStyle.middleFadeTo));
            
    writeByteArray(packetgetByteArrayFromColor(barStyle.bottomSolid));

            
    //Write the button Style
            
    writeByteArray(packetgetByteArrayFromColor(buttonStyle.topFadeFrom));
            
    writeByteArray(packetgetByteArrayFromColor(buttonStyle.middleFadeTo));
            
    writeByteArray(packetgetByteArrayFromColor(buttonStyle.bottomSolid));

            
    //Write the analogButtonStyle
            
    writeByteArray(packetgetByteArrayFromColor(analogButtonStyle.topFadeFrom));
            
    writeByteArray(packetgetByteArrayFromColor(analogButtonStyle.middleFadeTo));
            
    writeByteArray(packetgetByteArrayFromColor(analogButtonStyle.bottomSolid));

            return 
    packet.toString();

        }

        
    /***
         * Writes a ByteArray
         * @param writer The PacketWriter
         * @param array The ByteArray
         */
        
    private static void writeByteArray(PacketWriter writerbyte[] array) {

            for (
    int i 0< array.lengthi++) {
                
    writer.write(array[i]);
            }
        }

        
    /****
         * Gets a ByteArray from a Color
         * @param color The color
         * @return  The ByteArray
         */
        
    private static byte[] getByteArrayFromColor(Color color) {
            return new 
    byte[]{(bytecolor.getRed(), (bytecolor.getGreen(), (bytecolor.getBlue()};
        }

        
    /**
         * Returns whether a String is null or empty
         * @param str The string
         * @return true if the string is null or empty / false if not.
         */
        
    private static boolean isNullOrEmpty(String str) {
            return (
    str == null || str.length() == 0); //Ja, Flav, man kann auch .isEmpty benutzen!
        
    }

        public static class 
    Shading {

            private 
    Color topFadeFrom;
            private 
    Color middleFadeTo;
            private 
    Color bottomSolid;

            
    /***
             * A new Shading
             * @param topFadeFrom  The top color
             * @param middleFadeTo The middle color
             * @param bottomSolid The Bottom color
             */
            
    public Shading(Color topFadeFromColor middleFadeToColor bottomSolid) {
                
    this.topFadeFrom topFadeFrom;
                
    this.middleFadeTo middleFadeTo;
                
    this.bottomSolid bottomSolid;
            }
        }

        public static class 
    Button {

            private 
    String text;
            private 
    String image;
            private 
    String chatFunction;
            private 
    boolean showOnTheLeftSide;

            
    /***
             * Creates a new button
             * @param text The button text
             * @param chatFunction The function which will be called after clicking on it.
             */
            
    public Button(String textString chatFunction) {
                
    this(textchatFunction""true);
            }

            
    /***
             * Creates a new Button
             * @param text The text of the button
             * @param chatFunction The function which will be called after clicking on it
             * @param image The image
             * @param showOnTheLeftSide true => left side; false => right side 
             */
            
    public Button(String textString chatFunctionString imageboolean showOnTheLeftSide) {
                
    this.text text;
                
    this.image image;
                
    this.chatFunction chatFunction;
                
    this.showOnTheLeftSide showOnTheLeftSide;
            }
        }

        public static class 
    AnalogButton {

            private 
    Button normalButton;
            private 
    int analogSegments;
            private 
    int sendIntervalMillis;
            private 
    int cooldownIntervalMillis;

            
    /***
             * Creates a new AnalogButton
             * @param normalButton A normal Button
             * @param analogSegments The analog segments
             * @param sendIntervalMillis The interval in Milliseconds
             * @param cooldownIntervalMillis The interval of the cooldown in MS
             */
            
    public AnalogButton(Button normalButtonint analogSegmentsint sendIntervalMillisint cooldownIntervalMillis) {
                
    this.normalButton normalButton;
                
    this.analogSegments analogSegments;
                
    this.sendIntervalMillis sendIntervalMillis;
                
    this.cooldownIntervalMillis cooldownIntervalMillis;
            }
        }

        
    //Ein paar Styles aus Knuddels
        
    public static String FotoContestStyle(String channel) {
            return 
    Settings(channel,
                    new 
    Shading(new Color(0xFF0xDC0xBA), new Color(0xEB0x970x00), new Color(0xBF0x640x14)),
                    new 
    Shading(new Color(0xE10xEF0xF9), new Color(0xB10xC80xD8), new Color(0x4D0x930xBF)),
                    new 
    Shading(new Color(0xEF0xCA0xB4), new Color(0xE30xCA0xB4), new Color(0xDD0x4A0x3F)));
        }

        public static 
    String FotoContestFlirtStyle(String channel) {
            return 
    Settings(channel,
                    new 
    Shading(new Color(0xFF0x5E0x60), new Color(0x9B0x010x03), new Color(0x5F0x010x02)),
                    new 
    Shading(new Color(0xC60xF30xFF), new Color(0x2F0x610xFF), new Color(0x010x2A0xAE)),
                    new 
    Shading(new Color(0xEF0xCA0xB4), new Color(0xE30x750x67), new Color(0xDD0x4A0x3F)));
        }

        public static 
    String BingoStyle(String channel) {
            return 
    Settings(channel,
                    new 
    Shading(new Color(0x670x9F0xFF), new Color(0x4E0x690xFF), new Color(0x260x3E0xFF)),
                    new 
    Shading(new Color(0x630x9F0xFF), new Color(0x4E0x690xFF), new Color(0x320x4B0xFF)),
                    new 
    Shading(new Color(0x630x9F0xFF), new Color(0x4E0x690xFF), new Color(0x320x4B0xFF)));
        }

        public static 
    String SmileyWarsBetaStyle(String channel) {
            return 
    Settings(channel,
                    new 
    Shading(new Color(0xAE0xB70xFC), new Color(0x760x840xE4), new Color(0x260x370xB9)),
                    new 
    Shading(new Color(0xAE0xB70xFC), new Color(0x760x840xE4), new Color(0x260x370xB9)),
                    new 
    Shading(new Color(0xEF0xCA0xB4), new Color(0xE30x750x67), new Color(0xDD0x4A0x3F)));
        }

    „Es sind nicht unsere Fähigkeiten, die zeigen, wer wir wirklich sind, es sind unsere Entscheidungen.“
    - Albus Dumbledore, Harry Potter 2


    /guestchat registerGuest

  2. The Following 3 Users Say Thank You to Mentos For This Useful Post:

    Comu (02.05.2012), DnL (02.05.2012), Fitty (21.05.2014)

Ähnliche Themen

  1. [Java] TextPanelLight von Knuddels
    Von Brainy im Forum Sourcecode
    Antworten: 1
    Letzter Beitrag: 25.08.2013, 22:34
  2. Probleme mit Knuddels (Java)
    Von masterboy1337 im Forum Fragen & Probleme
    Antworten: 5
    Letzter Beitrag: 15.04.2012, 23:36
  3. Vorschau Knuddels Java Emulator
    Von Sploxfreak im Forum Showroom
    Antworten: 8
    Letzter Beitrag: 14.04.2012, 01:51
  4. [Java] Toolbar
    Von Flav im Forum Sourcecode
    Antworten: 0
    Letzter Beitrag: 02.02.2012, 16:23
  5. Java Fehler bei Knuddels
    Von rVs14 im Forum Fragen & Probleme
    Antworten: 5
    Letzter Beitrag: 12.01.2012, 01:30
Diese Seite nutzt Cookies, um das Nutzererlebnis zu verbessern. Klicken Sie hier, um das Cookie-Tracking zu deaktivieren.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191