Du bist nicht angemeldet.

1

Samstag, 14. April 2012, 00:28

Toolbar.java

This.

PHP-Quelltext

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
package Util;

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

/**
 *
 * @author Hilko
 */
public class Toolbar {
    
    //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 Toolbar(String channel, List<Buttonbuttons){
        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
            packet.write((bytebutton.text.length());
            packet.writeString(button.text);
            if(!isNullOrEmpty(button.image)){ //Kann man auch noch bei ChatFunction / anderen Strings so machen
                packet.write((bytebutton.image.length());
                packet.writeString(button.image);
            }else{
                packet.write(0xFF);
            }
            packet.writeBoolean(button.showOnTheLeftSide);
            packet.write((bytebutton.chatFunction.length());
            packet.writeString(button.chatFunction);
        }
        packet.write(0x0C);
        //Implement Analog Buttons here if you want!
        packet.write(0x0C);
        return packet.toString();        
    }
    
    /**
     * 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 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;
        }
        
    }
    
}


Beispiel:

PHP-Quelltext

1
2
3
4
        List<Toolbar.Buttonbuttons = new ArrayList<Button>();
        buttons.add(new Button("HAHA""/w""sm_00.gif"false));// Or
        buttons.add(new Button("Mentos""/w Mentos"));
        client.send(Toolbar.Toolbar(channel.getName(), buttons));

Es haben sich bereits 3 registrierte Benutzer bedankt.

Benutzer, die sich für diesen Beitrag bedankt haben:

Fif, wishdream, Diebspiel

2

Samstag, 14. April 2012, 19:12

Noch ein Hinweis "in eigener Sache":
Diese Klasse ist sehr basic gehalten und das war auch so geplant.
Ihr könnt damit Buttons hinzufügen, aber z.B. den Style der Toolbar verändern könnt ihr mit der Klasse noch nicht.
Soetwas müsst ihr, wenn ihr die Funktion haben wollt, selbst hinzufügen, damit dass klappt.

Denn einfach nur einbauen können die meisten, die Funktionen herstellen, ist da schon etwas schwieriger.

MfG

3

Mittwoch, 2. Mai 2012, 18:07

Da es 'eh kein anderes Schwein releasen wird und ich das ja 'eh habe...
Bevor es aufm Rechner vergammelt:

Java-Quelltext

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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
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<Button> buttons) {
        return ToolbarString(channel, buttons, null);
    }

    /****
     * 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<Button> buttons, List<AnalogButton> analogButtons) {
        PacketWriter packet = new PacketWriter();
        packet.writeString(SendOpcode.MODULE.getValue());
        packet.write(0x00);
        packet.writeShort(Server.get().getModuleTree().getIndex("SHOW_BUTTONS"));
        packet.write((byte) channel.length());
        packet.writeString(channel);

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

        if (analogButtons != null) {
            for (AnalogButton button : analogButtons) {
                packet.write(0x0B);
                writeButton(packet, button.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 packet, Button button) {
        if (!isNullOrEmpty(button.text)) {
            packet.write((byte) button.text.length());
            packet.writeString(button.text);
        } else {
            packet.write(EMPTY_TEXTVALUE);
        }

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

        packet.writeBoolean(button.showOnTheLeftSide);

        if (!isNullOrEmpty(button.chatFunction)) {
            packet.write((byte) button.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 channel, Shading barStyle, Shading buttonStyle, Shading analogButtonStyle) {
        PacketWriter packet = new PacketWriter();
        packet.writeString(SendOpcode.MODULE.getValue());
        packet.write(0x00);
        packet.writeShort(Server.get().getModuleTree().getIndex("BUTTON_BAR_SETTINGS"));
        packet.write((byte) channel.length());
        packet.writeString(channel);

        //Write the bar style
        writeByteArray(packet, getByteArrayFromColor(barStyle.topFadeFrom));
        writeByteArray(packet, getByteArrayFromColor(barStyle.middleFadeTo));
        writeByteArray(packet, getByteArrayFromColor(barStyle.bottomSolid));

        //Write the button Style
        writeByteArray(packet, getByteArrayFromColor(buttonStyle.topFadeFrom));
        writeByteArray(packet, getByteArrayFromColor(buttonStyle.middleFadeTo));
        writeByteArray(packet, getByteArrayFromColor(buttonStyle.bottomSolid));

        //Write the analogButtonStyle
        writeByteArray(packet, getByteArrayFromColor(analogButtonStyle.topFadeFrom));
        writeByteArray(packet, getByteArrayFromColor(analogButtonStyle.middleFadeTo));
        writeByteArray(packet, getByteArrayFromColor(analogButtonStyle.bottomSolid));

        return packet.toString();

    }

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

        for (int i = 0; i < array.length; i++) {
            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[]{(byte) color.getRed(), (byte) color.getGreen(), (byte) color.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 topFadeFrom, Color middleFadeTo, Color 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 text, String chatFunction) {
            this(text, chatFunction, "", 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 text, String chatFunction, String image, boolean 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 normalButton, int analogSegments, int sendIntervalMillis, int 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(0xFF, 0xDC, 0xBA), new Color(0xEB, 0x97, 0x00), new Color(0xBF, 0x64, 0x14)),
                new Shading(new Color(0xE1, 0xEF, 0xF9), new Color(0xB1, 0xC8, 0xD8), new Color(0x4D, 0x93, 0xBF)),
                new Shading(new Color(0xEF, 0xCA, 0xB4), new Color(0xE3, 0xCA, 0xB4), new Color(0xDD, 0x4A, 0x3F)));
    }

    public static String FotoContestFlirtStyle(String channel) {
        return Settings(channel,
                new Shading(new Color(0xFF, 0x5E, 0x60), new Color(0x9B, 0x01, 0x03), new Color(0x5F, 0x01, 0x02)),
                new Shading(new Color(0xC6, 0xF3, 0xFF), new Color(0x2F, 0x61, 0xFF), new Color(0x01, 0x2A, 0xAE)),
                new Shading(new Color(0xEF, 0xCA, 0xB4), new Color(0xE3, 0x75, 0x67), new Color(0xDD, 0x4A, 0x3F)));
    }

    public static String BingoStyle(String channel) {
        return Settings(channel,
                new Shading(new Color(0x67, 0x9F, 0xFF), new Color(0x4E, 0x69, 0xFF), new Color(0x26, 0x3E, 0xFF)),
                new Shading(new Color(0x63, 0x9F, 0xFF), new Color(0x4E, 0x69, 0xFF), new Color(0x32, 0x4B, 0xFF)),
                new Shading(new Color(0x63, 0x9F, 0xFF), new Color(0x4E, 0x69, 0xFF), new Color(0x32, 0x4B, 0xFF)));
    }

    public static String SmileyWarsBetaStyle(String channel) {
        return Settings(channel,
                new Shading(new Color(0xAE, 0xB7, 0xFC), new Color(0x76, 0x84, 0xE4), new Color(0x26, 0x37, 0xB9)),
                new Shading(new Color(0xAE, 0xB7, 0xFC), new Color(0x76, 0x84, 0xE4), new Color(0x26, 0x37, 0xB9)),
                new Shading(new Color(0xEF, 0xCA, 0xB4), new Color(0xE3, 0x75, 0x67), new Color(0xDD, 0x4A, 0x3F)));
    }
}

Usage sollte klar sein!

Es hat sich bereits 1 registrierter Benutzer bedankt.

Benutzer, die sich für diesen Beitrag bedankt haben:

Fif