Allow customizing both button image color and text

This commit is contained in:
Lonami Exo 2017-05-07 15:40:13 +02:00
parent 5281be4dd4
commit fbff065a8d
10 changed files with 240 additions and 250 deletions

View file

@ -24,12 +24,14 @@ public class Theme {
private int price;
public Color background;
public Color foreground;
public Color emptyCell;
public Color currentScore;
public Color highScore;
public Color bonus;
public Color bandColor;
public Color textColor;
private Color[] cells;
private Color[] buttons;
@ -84,6 +86,20 @@ public class Theme {
return new Theme().update(handle);
}
// Used to determine the best foreground color (black or white) given a background color
// Formula took from http://alienryderflex.com/hsp.html
// Not used yet, but may be useful
private final static double BRIGHTNESS_CUTOFF = 0.5;
public static boolean shouldUseWhite(Color color) {
double brightness = Math.sqrt(
color.r * color.r * .299 +
color.g * color.g * .587 +
color.b * color.b * .114);
return brightness < BRIGHTNESS_CUTOFF;
}
//endregion
//region Theme updating
@ -105,8 +121,9 @@ public class Theme {
price = json.getInt("price");
JsonValue colors = json.get("colors");
background = new Color( // Java won't allow unsigned integers, we need to use Long
(int)Long.parseLong(colors.getString("background"), 16));
// Java won't allow unsigned integers, we need to use Long
background = new Color((int)Long.parseLong(colors.getString("background"), 16));
foreground = new Color((int)Long.parseLong(colors.getString("foreground"), 16));
JsonValue buttonColors = colors.get("buttons");
buttons = new Color[buttonColors.size];
@ -125,6 +142,7 @@ public class Theme {
highScore = new Color((int)Long.parseLong(colors.getString("high_score"), 16));
bonus = new Color((int)Long.parseLong(colors.getString("bonus"), 16));
bandColor = new Color((int)Long.parseLong(colors.getString("band"), 16));
textColor = new Color((int)Long.parseLong(colors.getString("text"), 16));
emptyCell = new Color((int)Long.parseLong(colors.getString("empty_cell"), 16));

View file

@ -65,9 +65,11 @@ public class Band extends Actor {
scoreLabel.setBounds(x + scoreBounds.x, y + scoreBounds.y, scoreBounds.width, scoreBounds.height);
scoreLabel.setText(Integer.toString(scorer.getCurrentScore()));
scoreLabel.setColor(Klooni.theme.textColor);
scoreLabel.draw(batch, parentAlpha);
infoLabel.setBounds(x + infoBounds.x, y + infoBounds.y, infoBounds.width, infoBounds.height);
infoLabel.setColor(Klooni.theme.textColor);
infoLabel.draw(batch, parentAlpha);
}

View file

@ -182,6 +182,7 @@ public class MoneyBuyBand extends Table {
}
}
setColor(Klooni.theme.bandColor);
infoLabel.setColor(Klooni.theme.textColor);
super.draw(batch, parentAlpha);
}

View file

@ -1,5 +1,6 @@
package io.github.lonamiwebs.klooni.actors;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.scenes.scene2d.ui.ImageButton;
import com.badlogic.gdx.scenes.scene2d.utils.Drawable;
@ -44,6 +45,7 @@ public class SoftButton extends ImageButton {
Klooni.theme.updateStyle(style, styleIndex);
style.imageUp = image;
getImage().setColor(Klooni.theme.foreground);
super.draw(batch, parentAlpha);
}

View file

@ -30,12 +30,6 @@ public class ThemeCard extends Actor {
//endregion
//region Static members
private final static double BRIGHTNESS_CUTOFF = 0.5;
//endregion
//region Constructor
public ThemeCard(final Klooni game, final GameLayout layout, final Theme theme) {
@ -48,9 +42,8 @@ public class ThemeCard extends Actor {
priceLabel = new Label("", labelStyle);
nameLabel = new Label(theme.getDisplay(), labelStyle);
Color labelColor = shouldUseWhite(theme.background) ? Color.WHITE : Color.BLACK;
priceLabel.setColor(labelColor);
nameLabel.setColor(labelColor);
priceLabel.setColor(theme.textColor);
nameLabel.setColor(theme.textColor);
priceBounds = new Rectangle();
nameBounds = new Rectangle();
@ -112,19 +105,4 @@ public class ThemeCard extends Actor {
}
//endregion
//region Private methods
// Used to determine the best foreground color (black or white) given a background color
// Formula took from http://alienryderflex.com/hsp.html
private static boolean shouldUseWhite(Color color) {
double brightness = Math.sqrt(
color.r * color.r * .299 +
color.g * color.g * .587 +
color.b * color.b * .114);
return brightness < BRIGHTNESS_CUTOFF;
}
//endregion
}