Skip to content

Commit

Permalink
Allow various colors across MHQ to be customized #1480
Browse files Browse the repository at this point in the history
  • Loading branch information
sixlettervariables committed Feb 16, 2020
1 parent a2d91e3 commit c997c91
Show file tree
Hide file tree
Showing 10 changed files with 357 additions and 223 deletions.
12 changes: 7 additions & 5 deletions MekHQ/src/mekhq/gui/ForceRenderer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package mekhq.gui;

import java.awt.Color;
import java.awt.Component;
import java.awt.Image;
import java.util.UUID;
Expand All @@ -24,7 +23,8 @@ public class ForceRenderer extends DefaultTreeCellRenderer {

private static final long serialVersionUID = -553191867660269247L;

private IconPackage icons;
private final IconPackage icons;
private final MekHqColors colors = new MekHqColors();

public ForceRenderer(IconPackage i) {
icons = i;
Expand Down Expand Up @@ -133,12 +133,14 @@ public Component getTreeCellRendererComponent(
}
setText("<html>" + name + ", " + uname + c3network + transport + "</html>");
if(u.isDeployed() && !sel) {
setBackground(Color.LIGHT_GRAY);
colors.getDeployed().getColor().ifPresent(c -> setBackground(c));
colors.getDeployed().getAlternateColor().ifPresent(c -> setForeground(c));
}
}
if(value instanceof Force) {
if(!hasFocus && ((Force)value).isDeployed()) {
setBackground(Color.LIGHT_GRAY);
colors.getDeployed().getColor().ifPresent(c -> setBackground(c));
colors.getDeployed().getAlternateColor().ifPresent(c -> setForeground(c));
}
}
setIcon(getIcon(value));
Expand Down Expand Up @@ -205,4 +207,4 @@ protected Icon getIconFrom(Force force) {
}
return new ImageIcon(forceImage);
}
}
}
158 changes: 158 additions & 0 deletions MekHQ/src/mekhq/gui/MekHqColors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
/*
* Copyright (c) 2020 The MegaMek Team. All rights reserved.
*
* This file is part of MekHQ.
*
* MekHQ is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* MekHQ is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MekHQ. If not, see <http://www.gnu.org/licenses/>.
*/
package mekhq.gui;

import java.awt.Color;

import javax.swing.UIManager;

import mekhq.MekHQ;
import mekhq.gui.preferences.ColorPreference;
import mekhq.preferences.PreferencesNode;

public class MekHqColors {

//
// General Colors
//

private static ColorPreference iconButtonColors;

//
// Force Colors
//

private static ColorPreference deployedColors;
private static ColorPreference belowContractMinimumColors;

//
// Unit Colors
//

private static ColorPreference inTransitColors;
private static ColorPreference refittingColors;
private static ColorPreference mothballingColors;
private static ColorPreference mothballedColors;
private static ColorPreference notRepairableColors;
private static ColorPreference nonfunctionalColors;
private static ColorPreference needsPartsFixedColors;
private static ColorPreference uncrewedColors;

//
// Financial Colors
//

private static ColorPreference loanOverdueColors;

//
// Personnel Colors
//

private static ColorPreference injuredColors;
private static ColorPreference healedInjuriesColors;
private static ColorPreference paidRetirementColors;

static {
final PreferencesNode preferences = MekHQ.getPreferences().forClass(MekHqColors.class);

iconButtonColors = new ColorPreference("iconButton", Color.LIGHT_GRAY, Color.BLACK);

deployedColors = new ColorPreference("deployed", Color.LIGHT_GRAY, Color.BLACK);
belowContractMinimumColors = new ColorPreference("belowContractMinimum", UIManager.getColor("Table.background"), Color.RED);

inTransitColors = new ColorPreference("inTransit", Color.ORANGE, Color.BLACK);
refittingColors = new ColorPreference("refitting", Color.CYAN, Color.BLACK);
mothballingColors = new ColorPreference("mothballing", new Color(153,153,255), Color.BLACK);
mothballedColors = new ColorPreference("mothballed", new Color(204, 204, 255), Color.BLACK);
notRepairableColors = new ColorPreference("notRepairable", new Color(190, 150, 55), Color.BLACK);
nonfunctionalColors = new ColorPreference("nonfunctional", new Color(205, 92, 92), Color.BLACK);
needsPartsFixedColors = new ColorPreference("needsPartsFixed", new Color(238, 238, 0), Color.BLACK);
uncrewedColors = new ColorPreference("uncrewed", Color.RED, Color.BLACK);

loanOverdueColors = new ColorPreference("loanOverdue", Color.RED, Color.BLACK);

injuredColors = new ColorPreference("injured", Color.RED, Color.BLACK);
healedInjuriesColors = new ColorPreference("healed", new Color(0xee9a00), Color.BLACK);
paidRetirementColors = new ColorPreference("paidRetirement", Color.LIGHT_GRAY, Color.BLACK);

preferences.manage(iconButtonColors, deployedColors, belowContractMinimumColors, inTransitColors, refittingColors,
mothballingColors, mothballedColors, notRepairableColors, nonfunctionalColors, needsPartsFixedColors,
uncrewedColors, loanOverdueColors, injuredColors, healedInjuriesColors, paidRetirementColors);
}

public ColorPreference getIconButton() {
return iconButtonColors;
}

public ColorPreference getDeployed() {
return deployedColors;
}

public ColorPreference getBelowContractMinimum() {
return belowContractMinimumColors;
}

public ColorPreference getInTransit() {
return inTransitColors;
}

public ColorPreference getRefitting() {
return refittingColors;
}

public ColorPreference getMothballing() {
return mothballingColors;
}

public ColorPreference getMothballed() {
return mothballedColors;
}

public ColorPreference getNotRepairable() {
return notRepairableColors;
}

public ColorPreference getNonFunctional() {
return nonfunctionalColors;
}

public ColorPreference getNeedsPartsFixed() {
return needsPartsFixedColors;
}

public ColorPreference getUncrewed() {
return uncrewedColors;
}

public ColorPreference getLoanOverdue() {
return loanOverdueColors;
}

public ColorPreference getInjured() {
return injuredColors;
}

public ColorPreference getHealedInjuries() {
return healedInjuriesColors;
}

public ColorPreference getPaidRetirement() {
return paidRetirementColors;
}
}
Loading

0 comments on commit c997c91

Please sign in to comment.