Skip to content

Commit

Permalink
Improve new UI
Browse files Browse the repository at this point in the history
  • Loading branch information
stirante committed Apr 23, 2018
1 parent e9dffee commit 63f5620
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 55 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ hs_err_pid*
# IntelliJ
/out/
.idea/
*.iml
*.iml

*.dat
27 changes: 20 additions & 7 deletions src/main/java/com/stirante/RuneChanger/InGameButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.stirante.RuneChanger.model.Rune;
import com.stirante.RuneChanger.model.RunePage;
import com.stirante.RuneChanger.util.LangHelper;
import com.stirante.RuneChanger.util.SimplePreferences;
import com.stirante.lolclient.ClientApi;
import generated.LolChampSelectChampSelectPlayerSelection;
import generated.LolChampSelectChampSelectSession;
Expand All @@ -23,6 +24,9 @@

public class InGameButton {

//Used for testing the UI
private static final boolean MOCK_SESSION = false;

private static ClientApi api;
private static GuiHandler gui;
private static List<RunePage> runes;
Expand All @@ -37,13 +41,17 @@ private static void checkSession() {
if (currentSummoner == null)
currentSummoner = api.getCurrentSummoner();
//get current champion selection session. Throws FileNotFoundException if there is no session
LolChampSelectChampSelectSession session = api.executeGet("/lol-champ-select/v1/session", LolChampSelectChampSelectSession.class);
// LolChampSelectChampSelectSession session = new LolChampSelectChampSelectSession();
// session.myTeam = new ArrayList<>();
// LolChampSelectChampSelectPlayerSelection e = new LolChampSelectChampSelectPlayerSelection();
// e.championId = Champion.DARIUS.getId();
// e.summonerId = currentSummoner.summonerId;
// session.myTeam.add(e);
LolChampSelectChampSelectSession session;
if (MOCK_SESSION) {
session = new LolChampSelectChampSelectSession();
session.myTeam = new ArrayList<>();
LolChampSelectChampSelectPlayerSelection e = new LolChampSelectChampSelectPlayerSelection();
e.championId = Champion.DARIUS.getId();
e.summonerId = currentSummoner.summonerId;
session.myTeam.add(e);
} else {
session = api.executeGet("/lol-champ-select/v1/session", LolChampSelectChampSelectSession.class);
}
//find selected champion
for (LolChampSelectChampSelectPlayerSelection selection : session.myTeam) {
if (Objects.equals(selection.summonerId, currentSummoner.summonerId)) {
Expand Down Expand Up @@ -136,6 +144,11 @@ private static void checkSession() {
}

public static void main(String[] args) {
SimplePreferences.load();
if (!SimplePreferences.containsKey("thanks") || !((boolean) SimplePreferences.getValue("thanks"))) {
JOptionPane.showMessageDialog(null, resourceBundle.getString("thanks"), "RuneChanger", JOptionPane.INFORMATION_MESSAGE);
SimplePreferences.putValue("thanks", true);
}
gui = new GuiHandler();
try {
api = new ClientApi();
Expand Down
18 changes: 11 additions & 7 deletions src/main/java/com/stirante/RuneChanger/gui/Constants.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
package com.stirante.RuneChanger.gui;

public class Constants {
//Button width
public static final int BUTTON_WIDTH = 190;
//Height of single element
public static final int ELEMENT_HEIGHT = 30;
public static final int WINDOW_WIDTH = 280;
public static final int ELEMENT_WIDTH = 192;
public static final int ELEMENT_OFFSET_X = 81;
public static final int ELEMENT_OFFSET_Y = 37;
public static final int ELEMENT_HEIGHT = 37;
public static final int ICON_SIZE = 28;

//Button position percentage relative to client window
public static final double X_PER = 0.370d;
public static final double Y_PER = 0.920d;
//Button margin
public static final double X_PER = 0.305d;
public static final double Y_PER = 0.97d;

public static final int MARGIN = 10;

//version string
public static final String VERSION_STRING = "1.1";
}
4 changes: 2 additions & 2 deletions src/main/java/com/stirante/RuneChanger/gui/GuiHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public void tryClose() {
}

private Dimension getDimension() {
return new Dimension(Constants.BUTTON_WIDTH + 2 * Constants.MARGIN, Constants.ELEMENT_HEIGHT * (runes.size() + 1) + 2 * Constants.MARGIN);
return new Dimension(Constants.WINDOW_WIDTH + 2 * Constants.MARGIN, Constants.ELEMENT_HEIGHT * (runes.size()) + Constants.ELEMENT_OFFSET_Y + 2 * Constants.MARGIN);
}

/**
Expand Down Expand Up @@ -152,7 +152,7 @@ private void handleWindowThread() {
//Create icon in system tray and right click menu
SystemTray systemTray = SystemTray.getSystemTray();
//this actually don't work
Image image = ImageIO.read(GuiHandler.class.getResourceAsStream("/images/tray.png"));
Image image = ImageIO.read(GuiHandler.class.getResourceAsStream("/images/runechanger-runeforge-icon-32x32.png"));
PopupMenu trayPopupMenu = new PopupMenu();
MenuItem action = new MenuItem("RuneChanger v" + Constants.VERSION_STRING);
action.setEnabled(false);
Expand Down
51 changes: 17 additions & 34 deletions src/main/java/com/stirante/RuneChanger/gui/RuneButton.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.stirante.RuneChanger.gui;

import com.stirante.RuneChanger.model.RunePage;
import com.stirante.RuneChanger.util.LangHelper;
import com.stirante.RuneChanger.util.RuneSelectedListener;

import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
Expand All @@ -22,9 +23,9 @@ public class RuneButton extends JPanel {
private int selected = -1;
private Color textColor = new Color(0xc8aa6e);
private Color backgroundColor = new Color(0x010a13);
private Color almostTransparentColor = new Color(0f, 0f, 0f, 0.01f);
private Color ligthenColor = new Color(1f, 1f, 1f, 0.2f);
private Color dividerColor = new Color(0x1e2328);
private BufferedImage icon;

public RuneButton(List<RunePage> pages, RuneSelectedListener runeSelectedListener) {
super();
Expand All @@ -34,6 +35,7 @@ public RuneButton(List<RunePage> pages, RuneSelectedListener runeSelectedListene
InputStream is = getClass().getResourceAsStream("/Beaufort-Bold.ttf");
Font font = Font.createFont(Font.TRUETYPE_FONT, is);
mFont = font.deriveFont(15f);
icon = ImageIO.read(getClass().getResourceAsStream("/images/runechanger-runeforge-icon-28x28.png"));
} catch (IOException | FontFormatException e) {
e.printStackTrace();
}
Expand All @@ -50,62 +52,42 @@ public void paintComponent(Graphics g) {
}
g2d.setFont(mFont);
g2d.setColor(textColor);
drawCenteredString(g2d, getHeight() - Constants.MARGIN, LangHelper.getLang().getString("runeforgePages"));
g2d.drawImage(icon, Constants.MARGIN, getHeight() - Constants.MARGIN - Constants.ICON_SIZE, Constants.ICON_SIZE, Constants.ICON_SIZE, null);
if (opened) {
g2d.setColor(backgroundColor);
g2d.fillRect(Constants.MARGIN, Constants.MARGIN, Constants.BUTTON_WIDTH, Constants.ELEMENT_HEIGHT * pages.size());
g2d.fillRect(Constants.MARGIN + Constants.ELEMENT_OFFSET_X, Constants.MARGIN, Constants.ELEMENT_WIDTH, Constants.ELEMENT_HEIGHT * pages.size());
g2d.setColor(textColor);
g2d.drawRect(Constants.MARGIN, Constants.MARGIN, Constants.BUTTON_WIDTH, Constants.ELEMENT_HEIGHT * pages.size());
g2d.drawRect(Constants.MARGIN + Constants.ELEMENT_OFFSET_X, Constants.MARGIN, Constants.ELEMENT_WIDTH, Constants.ELEMENT_HEIGHT * pages.size());
for (int i = 0; i < pages.size(); i++) {
RunePage page = pages.get(i);
if (selected == i) {
g2d.setColor(ligthenColor);
g2d.fillRect(1 + Constants.MARGIN, i * Constants.ELEMENT_HEIGHT + Constants.MARGIN, Constants.BUTTON_WIDTH, Constants.ELEMENT_HEIGHT);
g2d.fillRect(1 + Constants.MARGIN + Constants.ELEMENT_OFFSET_X, i * Constants.ELEMENT_HEIGHT + Constants.MARGIN, Constants.ELEMENT_WIDTH, Constants.ELEMENT_HEIGHT);
}
g2d.setColor(textColor);
g2d.drawImage(page.getRunes().get(0).getImage(), Constants.MARGIN, i * Constants.ELEMENT_HEIGHT + Constants.MARGIN, Constants.ELEMENT_HEIGHT, Constants.ELEMENT_HEIGHT, null);
drawCenteredHorizontalString(g2d, Constants.ELEMENT_HEIGHT, (i + 1) * Constants.ELEMENT_HEIGHT + Constants.MARGIN, page.getName());
g2d.drawImage(page.getRunes().get(0).getImage(), Constants.MARGIN + Constants.ELEMENT_OFFSET_X, i * Constants.ELEMENT_HEIGHT + Constants.MARGIN, Constants.ELEMENT_HEIGHT, Constants.ELEMENT_HEIGHT, null);
drawCenteredHorizontalString(g2d, Constants.ELEMENT_HEIGHT + Constants.ELEMENT_OFFSET_X, (i + 1) * Constants.ELEMENT_HEIGHT + Constants.MARGIN, page.getName());
if (i != pages.size() - 1) {
g2d.setColor(dividerColor);
g2d.drawLine(1 + Constants.MARGIN, (i + 1) * Constants.ELEMENT_HEIGHT + Constants.MARGIN, getWidth() - 2 - Constants.MARGIN, (i + 1) * Constants.ELEMENT_HEIGHT + Constants.MARGIN);
g2d.drawLine(1 + Constants.MARGIN + Constants.ELEMENT_OFFSET_X, (i + 1) * Constants.ELEMENT_HEIGHT + Constants.MARGIN, getWidth() - 2 - Constants.MARGIN, (i + 1) * Constants.ELEMENT_HEIGHT + Constants.MARGIN);
}
}
}
}

private void drawCenteredHorizontalString(Graphics2D g, int x, int bottom, String text) {
FontMetrics metrics = g.getFontMetrics(g.getFont());
if (metrics.stringWidth(text) > Constants.BUTTON_WIDTH - Constants.ELEMENT_HEIGHT) {
while (metrics.stringWidth(text) > Constants.BUTTON_WIDTH - Constants.ELEMENT_HEIGHT) {
if (metrics.stringWidth(text) > Constants.ELEMENT_WIDTH - Constants.ELEMENT_HEIGHT) {
while (metrics.stringWidth(text) > Constants.ELEMENT_WIDTH - Constants.ELEMENT_HEIGHT) {
text = text.substring(0, text.length() - 1);
}
text = text.substring(0, text.length() - 2) + "...";
}
g.drawString(text, x + Constants.MARGIN, bottom - metrics.getHeight() + (metrics.getAscent() / 2));
}

/**
* Draws centered string
*
* @param g graphics
* @param text text to draw
*/
private void drawCenteredString(Graphics g, int bottom, String text) {
FontMetrics metrics = g.getFontMetrics(g.getFont());
if (metrics.stringWidth(text) > Constants.BUTTON_WIDTH) {
while (metrics.stringWidth(text) > Constants.BUTTON_WIDTH) {
text = text.substring(0, text.length() - 1);
}
text = text.substring(0, text.length() - 2) + "...";
}
int x = (Constants.BUTTON_WIDTH - metrics.stringWidth(text)) / 2;
g.drawString(text, x + Constants.MARGIN, bottom - metrics.getHeight() + (metrics.getAscent() / 2));
g.setColor(almostTransparentColor);
g.fillRect(x + Constants.MARGIN, bottom - metrics.getHeight() - (metrics.getAscent() / 2), metrics.stringWidth(text), metrics.getHeight());
}

public void mouseClicked(MouseEvent e) {
if (selected == pages.size())
if (e.getX() > Constants.MARGIN && e.getX() < Constants.MARGIN + icon.getWidth() && e.getY() > getHeight() - Constants.MARGIN - icon.getHeight() && e.getY() < getHeight() - Constants.MARGIN)
opened = !opened;
else if (selected != -1) {
runeSelectedListener.onRuneSelected(pages.get(selected));
Expand All @@ -116,8 +98,9 @@ else if (selected != -1) {

public void mouseMoved(MouseEvent e) {
int i;
if (e.getY() < Constants.MARGIN || e.getY() > getHeight() - Constants.MARGIN) i = -1;
else if (e.getX() < Constants.MARGIN || e.getX() > Constants.MARGIN + Constants.BUTTON_WIDTH) i = -1;
if (e.getY() < Constants.MARGIN || e.getY() > getHeight() - Constants.MARGIN)
i = -1;
else if (e.getX() < Constants.MARGIN + Constants.ELEMENT_OFFSET_X || e.getX() > getWidth() - Constants.MARGIN) i = -1;
else i = (e.getY() - Constants.MARGIN) / Constants.ELEMENT_HEIGHT;
if (i != selected) {
selected = i;
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/stirante/RuneChanger/model/Champion.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.stirante.RuneChanger.model;

public enum Champion {
//Generated on 2018-04-15 20:25:20
//Generated on 2018-04-23 21:56:47
AATROX(266, "Aatrox", "Aatrox", "Aatrox"),
AHRI(103, "Ahri", "Ahri", "Ahri"),
AKALI(84, "Akali", "Akali", "Akali"),
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/stirante/RuneChanger/model/Rune.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import java.io.IOException;

public enum Rune {
//Generated on 2018-04-15 20:25:20
//Generated on 2018-04-23 21:56:47
RUNE_8005(8005, 8000, 0, "Press the Attack"),
RUNE_8008(8008, 8000, 0, "Lethal Tempo"),
RUNE_8009(8009, 8000, 1, "Presence of Mind"),
Expand Down
58 changes: 58 additions & 0 deletions src/main/java/com/stirante/RuneChanger/util/SimplePreferences.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package com.stirante.RuneChanger.util;

import java.io.*;
import java.util.HashMap;

public class SimplePreferences {

private static HashMap<String, Object> values;

public static void load() {
File prefs = new File("RuneChanger.dat");
try (ObjectInputStream ois = new ObjectInputStream(new FileInputStream(prefs))) {
values = (HashMap<String, Object>) ois.readObject();
} catch (IOException | ClassNotFoundException e) {
if (!(e instanceof FileNotFoundException))
e.printStackTrace();
}
if (values == null)
values = new HashMap<>();
}

public static Object getValue(String key) {
return values.get(key);
}

public static boolean containsKey(String key) {
return values.containsKey(key);
}

public static void putValue(String key, Object value) {
values.put(key, value);
save();
}

public static void removeValue(String key) {
values.remove(key);
save();
}

public static void save() {
File prefs = new File("RuneChanger.dat");
if (!prefs.exists()) {
try {
prefs.createNewFile();
} catch (IOException e) {
e.printStackTrace();
}
}
try (ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(prefs))) {
oos.writeObject(values);
oos.flush();
} catch (IOException e) {
e.printStackTrace();
}
}


}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/main/resources/images/tray.png
Binary file not shown.
2 changes: 1 addition & 1 deletion src/main/resources/lang/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ button.searching=Searching
clientOff=LoL client has shutdown. Program will exit.
exit=Exit
noClient=LoL client not found! Program will exit.
runeforgePages=RUNEFORGE PAGES
thanks=Thanks for using RuneChanger! Be aware that this software is still in beta and it may not always display correctly
2 changes: 1 addition & 1 deletion src/main/resources/lang/messages_pl.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ button.searching=Wyszukiwanie
clientOff=Client LoL wyłšczony. Program zakończy pracę.
exit=Exit
noClient=Nie znaleziono clienta LoL! Program zakończy pracę.
runeforgePages=STRONY RUNEFORGE
thanks=Dzięki za używanie RuneChanger! Pamiętaj, że ten program wcišż jest w fazie testów i lista może nie zawsze pojawiać się prawidłowo

0 comments on commit 63f5620

Please sign in to comment.