Thema: [Java] [Knuddels] Toolbar
-
02.05.2012, 19:26 #1
[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<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)));
}
}
„Es sind nicht unsere Fähigkeiten, die zeigen, wer wir wirklich sind, es sind unsere Entscheidungen.“
- Albus Dumbledore, Harry Potter 2
/guestchat registerGuest
-
The Following 3 Users Say Thank You to Mentos For This Useful Post:
Ähnliche Themen
-
[Java] TextPanelLight von Knuddels
Von Brainy im Forum SourcecodeAntworten: 1Letzter Beitrag: 25.08.2013, 22:34 -
Probleme mit Knuddels (Java)
Von masterboy1337 im Forum Fragen & ProblemeAntworten: 5Letzter Beitrag: 15.04.2012, 23:36 -
Vorschau Knuddels Java Emulator
Von Sploxfreak im Forum ShowroomAntworten: 8Letzter Beitrag: 14.04.2012, 01:51 -
[Java] Toolbar
Von Flav im Forum SourcecodeAntworten: 0Letzter Beitrag: 02.02.2012, 16:23 -
Java Fehler bei Knuddels
Von rVs14 im Forum Fragen & ProblemeAntworten: 5Letzter Beitrag: 12.01.2012, 01:30
Diese Seite nutzt Cookies, um das Nutzererlebnis zu verbessern. Klicken Sie hier, um das Cookie-Tracking zu deaktivieren.