Skip to content

Commit

Permalink
2.3
Browse files Browse the repository at this point in the history
Added:

Full !song support with last.fm (closes #53 but see the wiki on github)
Icon enums (one step closer towards #57, thanks @jbzdarkid!)
Donation total for a user printed out upon another donation

Fixed:

FileChooser for Sounds now compares correctly (closes #71)
Channel manager null fix (closes #73)
User Chat index sets correctly (you can up arrow -> enter spam again)
Issue with User Suggestion panel still showing
Imgur URLs are corrected to i.imgur URLs (namefaces)
Luminosity values should be better now
Subscriber count streak does not increase for repeat messages
Minor code improvements (thanks @jbzdarkid and @tsteinholz !)
  • Loading branch information
Gocnak committed Apr 26, 2015
1 parent 11fe14e commit 9bc1c61
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 187 deletions.
22 changes: 22 additions & 0 deletions src/main/java/face/IconEnum.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package face;

public enum IconEnum {
NONE(""),
MOD("Mod"),
BROADCASTER("Broadcaster"),
GLOBALMOD("Global Mod"),
ADMIN("Admin"),
STAFF("Staff"),
TURBO("Turbo"),
SUBSCRIBER("Subscriber"),
DONOR_BASIC("Donor"),
DONOR_LOW("Donor"),
DONOR_MEDIUM("Donor"),
DONOR_HIGH("Donor"),
DONOR_INSANE("Donor");

public String type;
IconEnum(String type) {
this.type = type;
}
}
123 changes: 123 additions & 0 deletions src/main/java/face/Icons.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package face;

import gui.ChatPane;
import gui.GUIMain;
import lib.scalr.Scalr;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.image.BufferedImage;
import java.net.URL;

/**
* A class which specifies special chat icons, or 'badges'.
* This allows for easier creation of custom icons, and
* should be easily adaptable to create custom donation
* levels.
*
* @author Joseph Blackman
* @date 4/10/2015
*/

public class Icons {

/**
* For a specified icon, returns the file containing the
* image, resized to fit into the chat window.
*
* @param i the type of icon to get
* @return the icon along with what type it is
*/

public static BotnakIcon getIcon(IconEnum i, String channel) {
ImageIcon icon = null;
switch (i) {
case MOD:
icon = sizeIcon(GUIMain.currentSettings.modIcon);
break;
case BROADCASTER:
icon = sizeIcon(GUIMain.currentSettings.broadIcon);
break;
case ADMIN:
icon = sizeIcon(GUIMain.currentSettings.adminIcon);
break;
case STAFF:
icon = sizeIcon(GUIMain.currentSettings.staffIcon);
break;
case TURBO:
icon = sizeIcon(GUIMain.currentSettings.turboIcon);
break;
case SUBSCRIBER:
URL subIcon = FaceManager.getSubIcon(channel);
if (subIcon != null) {
icon = sizeIcon(subIcon);
}
break;
case DONOR_BASIC:
icon = sizeIcon(ChatPane.class.getResource("/image/green.png"));
break;
case DONOR_LOW:
icon = sizeIcon(ChatPane.class.getResource("/image/bronze.png"));
break;
case DONOR_MEDIUM:
icon = sizeIcon(ChatPane.class.getResource("/image/silver.png"));
break;
case DONOR_HIGH:
icon = sizeIcon(ChatPane.class.getResource("/image/gold.png"));
break;
case DONOR_INSANE:
icon = sizeIcon(ChatPane.class.getResource("/image/diamond.png"));
break;
case GLOBALMOD:
icon = sizeIcon(ChatPane.class.getResource("/image/globalmod.png"));
break;
case NONE:
break;
default:
break;
}
return new BotnakIcon(i, icon);
}

/**
* Resize an icon to match the chat font size. This has the
* effect of allowing users to submit images of any size.
*
* @param image the image URL
* @return ImageIcon the resized image
*/

private static ImageIcon sizeIcon(URL image) {
ImageIcon icon;
try {
BufferedImage img = ImageIO.read(image);
int size = GUIMain.currentSettings.font.getSize();
img = Scalr.resize(img, Scalr.Method.ULTRA_QUALITY, size, size);
icon = new ImageIcon(img);
icon.getImage().flush();
return icon;
} catch (Exception e) {
icon = new ImageIcon(image);
}
return icon;
}

//Wrapper class for logging purposes
public static class BotnakIcon {
public IconEnum t;
public ImageIcon ii;

public IconEnum getType() {
return t;
}

public ImageIcon getImage() {
return ii;
}

public BotnakIcon(IconEnum type, ImageIcon icon) {
t = type;
ii = icon;
}
}
}
34 changes: 18 additions & 16 deletions src/main/java/gui/ChatPane.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package gui;

import face.FaceManager;
import face.IconEnum;
import face.Icons;
import gui.listeners.ListenerName;
import gui.listeners.ListenerURL;
import gui.Icons;
import gui.IconEnum;
import irc.Donor;
import irc.message.Message;
import irc.message.MessageQueue;
Expand Down Expand Up @@ -327,31 +327,31 @@ public void onMessage(MessageWrapper m, boolean showChannel) {
}
StyleConstants.setForeground(user, c);
if (channel.substring(1).equals(sender)) {
insertIcon(m, IconEnum.Broadcaster, null);
insertIcon(m, IconEnum.BROADCASTER, null);
}
if (u.isOp(channel)) {
if (!channel.substring(1).equals(sender) && !u.isStaff() && !u.isAdmin() && !u.isGlobalMod()) {//not the broadcaster again
insertIcon(m, IconEnum.None, null);
insertIcon(m, IconEnum.MOD, null);
}
}
if (u.isGlobalMod()) {
insertIcon(m, IconEnum.GlobalMod, null);
insertIcon(m, IconEnum.GLOBALMOD, null);
}
if (u.isDonor()) {
insertIcon(m, u.getDonationStatus(), null);
}
if (u.isStaff()) {
insertIcon(m, IconEnum.Staff, null);
insertIcon(m, IconEnum.STAFF, null);
}
if (u.isAdmin()) {
insertIcon(m, IconEnum.Admin, null);
insertIcon(m, IconEnum.ADMIN, null);
}
boolean isSubscriber = u.isSubscriber(channel);
if (isSubscriber) {
insertIcon(m, IconEnum.Subscriber, channel);
insertIcon(m, IconEnum.SUBSCRIBER, channel);
}
if (u.isTurbo()) {
insertIcon(m, IconEnum.Turbo, null);
insertIcon(m, IconEnum.TURBO, null);
}
//name stuff
print(m, " ", GUIMain.norm);
Expand Down Expand Up @@ -467,20 +467,21 @@ public void onIconMessage(MessageWrapper m, IconEnum status) {
Message message = m.getLocal();
print(m, "\n", GUIMain.norm);
for (int i = 0; i < 5; i++) {
insertIcon(m, status, (status == IconEnum.Subscriber ? message.getChannel() : null));
insertIcon(m, status, (status == IconEnum.SUBSCRIBER ? message.getChannel() : null));
}
print(m, " " + message.getContent() + (status == IconEnum.Subscriber ? (" (" + (subCount + 1) + ") ") : " "), GUIMain.norm);
print(m, " " + message.getContent() + (status == IconEnum.SUBSCRIBER ? (" (" + (subCount + 1) + ") ") : " "), GUIMain.norm);
for (int i = 0; i < 5; i++) {
insertIcon(m, status, (status == IconEnum.Subscriber ? message.getChannel() : null));
insertIcon(m, status, (status == IconEnum.SUBSCRIBER ? message.getChannel() : null));
}
} catch (Exception e) {
GUIMain.log(e.getMessage());
}
if (status == IconEnum.Subscriber) subCount++;
boolean shouldIncrement = status == IconEnum.SUBSCRIBER && m.getLocal().getExtra() != null;//checking for repeat messages
if (shouldIncrement) subCount++;
}

public void onSub(MessageWrapper m) {
onIconMessage(m, IconEnum.Subscriber);
onIconMessage(m, IconEnum.SUBSCRIBER);
}

public void onDonation(MessageWrapper m) {
Expand All @@ -490,10 +491,11 @@ public void onDonation(MessageWrapper m) {

public void insertIcon(MessageWrapper m, IconEnum type, String channel) {
SimpleAttributeSet attrs = new SimpleAttributeSet();
ImageIcon icon = Icons.getIcon(type, channel);
StyleConstants.setIcon(attrs, icon);
Icons.BotnakIcon icon = Icons.getIcon(type, channel);
StyleConstants.setIcon(attrs, icon.getImage());
try {
print(m, " ", null);
print(m, icon.getType().type, attrs);
} catch (Exception e) {
GUIMain.log("INSERT ICON " + e.getMessage());
}
Expand Down
17 changes: 0 additions & 17 deletions src/main/java/gui/IconEnum.java

This file was deleted.

121 changes: 0 additions & 121 deletions src/main/java/gui/Icons.java

This file was deleted.

Loading

0 comments on commit 9bc1c61

Please sign in to comment.