Skip to content
This repository has been archived by the owner on Jan 4, 2024. It is now read-only.

Commit

Permalink
experimental light mode
Browse files Browse the repository at this point in the history
  • Loading branch information
SunakazeKun committed Apr 24, 2022
1 parent e12ff02 commit a7e6106
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 52 deletions.
3 changes: 0 additions & 3 deletions src/whitehole/MainFrame.form
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@
<Property name="text" type="java.lang.String" value="Ready!"/>
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
<AuxValues>
<AuxValue name="JavaCodeGenerator_VariableModifier" type="java.lang.Integer" value="9"/>
</AuxValues>
</Component>
<Container class="javax.swing.JScrollPane" name="scrGalaxy">
<AuxValues>
Expand Down
6 changes: 3 additions & 3 deletions src/whitehole/MainFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ private void btnBcsvEditorActionPerformed(java.awt.event.ActionEvent evt) {//GEN
}//GEN-LAST:event_btnBcsvEditorActionPerformed

private void btnSettingsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSettingsActionPerformed
new SettingsForm().setVisible(true);
new SettingsForm(this).setVisible(true);
}//GEN-LAST:event_btnSettingsActionPerformed

private void btnAboutActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnAboutActionPerformed
Expand All @@ -312,7 +312,7 @@ private void listGalaxyKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:eve
return;
}

if(evt.getKeyCode() == KeyEvent.VK_ENTER) {
if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
openGalaxy();
}
}//GEN-LAST:event_listGalaxyKeyReleased
Expand All @@ -327,7 +327,7 @@ private void listGalaxyKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:eve
private javax.swing.JToolBar.Separator jSeparator2;
private javax.swing.JToolBar.Separator jSeparator3;
private javax.swing.JToolBar.Separator jSeparator6;
public static javax.swing.JLabel lbStatusBar;
private javax.swing.JLabel lbStatusBar;
private javax.swing.JList listGalaxy;
private javax.swing.JScrollPane scrGalaxy;
private javax.swing.JToolBar toolbar;
Expand Down
5 changes: 2 additions & 3 deletions src/whitehole/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ private Settings() {}
public static String getLastGameDir() { return PREFERENCES.get("whitehole_lastGameDir", null); }
public static boolean getSJISNotSupported() { return PREFERENCES.getBoolean("whitehole_sjisNotSupported", false); }
public static boolean getDisplaySimpleNameDB() { return PREFERENCES.getBoolean("whitehole_displaySimpleNameDB", true); }
public static boolean getUseDarkMode() { return PREFERENCES.getBoolean("whitehole_useDarkMode", true); }

public static void setLastGameDir(String val) { PREFERENCES.put("whitehole_lastGameDir", val); }
public static void setSJISNotSupported(boolean val) { PREFERENCES.putBoolean("whitehole_sjisNotSupported", val); }
public static void setDisplaySimpleNameDB(boolean val) { PREFERENCES.putBoolean("whitehole_displaySimpleNameDB", val); }
public static void setUseDarkMode(boolean val) { PREFERENCES.putBoolean("whitehole_useDarkMode", val); }

// Rendering
public static boolean getShowAxis() { return PREFERENCES.getBoolean("whitehole_showAxis", true); }
Expand Down Expand Up @@ -64,7 +66,4 @@ private Settings() {}
public static void setKeyPosition(int val) { PREFERENCES.putInt("whitehole_keyPosition", val); }
public static void setKeyRotation(int val) { PREFERENCES.putInt("whitehole_keyRotation", val); }
public static void setKeyScale(int val) { PREFERENCES.putInt("whitehole_keyScale", val); }

@Deprecated
public static boolean legacy;
}
16 changes: 16 additions & 0 deletions src/whitehole/SettingsForm.form
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JCheckBox" name="chkUseDarkMode">
<Properties>
<Property name="selected" type="boolean" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
<Connection code="Settings.getUseDarkMode()" type="code"/>
</Property>
<Property name="text" type="java.lang.String" value="Use Dark Mode"/>
</Properties>
<Events>
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="chkUseDarkModeItemStateChanged"/>
</Events>
<Constraints>
<Constraint layoutClass="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout" value="org.netbeans.modules.form.compat2.layouts.DesignGridBagLayout$GridBagConstraintsDescription">
<GridBagConstraints gridX="0" gridY="-1" gridWidth="1" gridHeight="1" fill="1" ipadX="0" ipadY="0" insetsTop="2" insetsLeft="2" insetsBottom="2" insetsRight="2" anchor="10" weightX="0.0" weightY="0.0"/>
</Constraint>
</Constraints>
</Component>
<Component class="javax.swing.JCheckBox" name="chkDisplaySimpleNameDB">
<Properties>
<Property name="selected" type="boolean" editor="org.netbeans.modules.form.RADConnectionPropertyEditor">
Expand Down
28 changes: 26 additions & 2 deletions src/whitehole/SettingsForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@
import java.awt.event.KeyEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

public class SettingsForm extends javax.swing.JDialog {
public SettingsForm() {
super((JFrame)null, true);
public SettingsForm(JFrame parent) {
super(parent, true);

initComponents();

Expand All @@ -46,6 +47,7 @@ private void initComponents() {
pnlSettings = new javax.swing.JPanel();
lblAppearance = new javax.swing.JLabel();
lblControls = new javax.swing.JLabel();
chkUseDarkMode = new javax.swing.JCheckBox();
chkDisplaySimpleNameDB = new javax.swing.JCheckBox();
chkUseShaders = new javax.swing.JCheckBox();
chkDebugFakeColor = new javax.swing.JCheckBox();
Expand Down Expand Up @@ -88,6 +90,19 @@ public void windowClosing(java.awt.event.WindowEvent evt) {
gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
pnlSettings.add(lblControls, gridBagConstraints);

chkUseDarkMode.setSelected(Settings.getUseDarkMode());
chkUseDarkMode.setText("Use Dark Mode");
chkUseDarkMode.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
chkUseDarkModeItemStateChanged(evt);
}
});
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
pnlSettings.add(chkUseDarkMode, gridBagConstraints);

chkDisplaySimpleNameDB.setSelected(Settings.getDisplaySimpleNameDB());
chkDisplaySimpleNameDB.setText("Display object database names");
chkDisplaySimpleNameDB.addItemListener(new java.awt.event.ItemListener() {
Expand Down Expand Up @@ -260,6 +275,14 @@ private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:even
Settings.setKeyRotation(((KeybindButton)btnRotation).keybind);
Settings.setKeyScale(((KeybindButton)btnScale).keybind);
}//GEN-LAST:event_formWindowClosing

private void chkUseDarkModeItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_chkUseDarkModeItemStateChanged
Settings.setUseDarkMode(evt.getStateChange() == ItemEvent.SELECTED);

Whitehole.updateLAF();
SwingUtilities.updateComponentTreeUI(this);
pack();
}//GEN-LAST:event_chkUseDarkModeItemStateChanged

private static class KeybindButton extends JButton {
boolean binding = false;
Expand Down Expand Up @@ -310,6 +333,7 @@ public void setKeyBind(int key) {
private javax.swing.JCheckBox chkDebugFakeColor;
private javax.swing.JCheckBox chkDebugFastDrag;
private javax.swing.JCheckBox chkDisplaySimpleNameDB;
private javax.swing.JCheckBox chkUseDarkMode;
private javax.swing.JCheckBox chkUseReverseRot;
private javax.swing.JCheckBox chkUseShaders;
private javax.swing.JCheckBox chkUseWASD;
Expand Down
39 changes: 36 additions & 3 deletions src/whitehole/Whitehole.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package whitehole;

import com.formdev.flatlaf.FlatDarkLaf;
import com.formdev.flatlaf.FlatLightLaf;
import whitehole.db.GalaxyNames;
import whitehole.smg.GameArchive;
import java.awt.Image;
Expand All @@ -35,11 +36,18 @@ public class Whitehole {
public static final String WEB_URL = "https://discord.gg/k7ZKzSDsVq";
public static final Image ICON = Toolkit.getDefaultToolkit().createImage(Whitehole.class.getResource("/res/icon.png"));

private static FlatDarkLaf DARK_THEME;
private static FlatLightLaf LIGHT_THEME;

public static void main(String[] args) throws IOException {
// Set look and feel if applicable
// Setup look and feel and set if applicable
FlatDarkLaf.setup();
FlatLightLaf.setup();
DARK_THEME = new FlatDarkLaf();
LIGHT_THEME = new FlatLightLaf();

try {
FlatDarkLaf.setup();
UIManager.setLookAndFeel(new FlatDarkLaf());
UIManager.setLookAndFeel(Settings.getUseDarkMode() ? DARK_THEME : LIGHT_THEME);
}
catch (Exception ex) {
System.err.println(ex);
Expand All @@ -55,6 +63,7 @@ public static void main(String[] args) throws IOException {
);
}

// Initialize data
FieldHashes.init();
GalaxyNames.init();
ObjectDB.init();
Expand All @@ -63,6 +72,30 @@ public static void main(String[] args) throws IOException {
new MainFrame().setVisible(true);
}

public static void updateLAF() {
LookAndFeel next = null;

if (Settings.getUseDarkMode()) {
if (UIManager.getLookAndFeel() != DARK_THEME) {
next = DARK_THEME;
}
}
else {
if (UIManager.getLookAndFeel() != LIGHT_THEME) {
next = LIGHT_THEME;
}
}

if (next != null) {
try {
UIManager.setLookAndFeel(next);
}
catch(Exception ex) {
System.err.println(ex);
}
}
}

// -------------------------------------------------------------------------------------------------------------------------
// Game Util

Expand Down
57 changes: 26 additions & 31 deletions src/whitehole/editor/GalaxyEditorForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -244,11 +244,8 @@ public GalaxyEditorForm(GalaxyEditorForm gal_parent, StageArchive zone) {
scrLayers.setViewportView(listLayerCheckboxes);

zoneModeLayerBitmask = 0;
JCheckBox[] cblayers = new JCheckBox[curZoneArc.objects.keySet().size()];
JCheckBox[] cblayers = new JCheckBox[curZoneArc.objects.keySet().size() - 1];
int i = 0;
cblayers[i] = new JCheckBox("Common");
cblayers[i].setSelected(true);
i++;
for(int l = 0; l < 16; l++) {
String ls = String.format("Layer%1$c", (char) ('A' + l));
if(curZoneArc.objects.containsKey(ls.toLowerCase())) {
Expand Down Expand Up @@ -1348,7 +1345,7 @@ private void setStatusText() {
*/
private void layerSelectChange(int index, boolean status) {
JCheckBox cbx =(JCheckBox)listLayerCheckboxes.getModel().getElementAt(index);
int layer = cbx.getText().equals("Common") ? 1 :(2 <<(cbx.getText().charAt(5) - 'A'));
int layer = (1 <<(cbx.getText().charAt(5) - 'A'));

if(status)
zoneModeLayerBitmask |= layer;
Expand Down Expand Up @@ -2358,6 +2355,8 @@ private void addObject(Object point) {
String objname = addingObject.substring(addingObject.indexOf('|') + 1);
addingObjectOnLayer = addingObjectOnLayer.toLowerCase();

TreeNode newNode;

// Add new path?
if(objtype.equals("path")) {
int newPathLinkID = 0;
Expand All @@ -2373,29 +2372,22 @@ private void addObject(Object point) {
globalPathList.put(thepath.uniqueID, thepath);
curZoneArc.paths.add(thepath);

//thepath.createStorage();

PathPointObj thepoint = new PathPointObj(thepath, position);
thepoint.uniqueID = maxUniqueID;
maxUniqueID++;
maxUniqueID += 3;

globalObjList.put(thepoint.uniqueID, thepoint);
globalPathPointList.put(thepoint.uniqueID, thepoint);
thepath.getPoints().add(thepoint);

DefaultTreeModel objlist =(DefaultTreeModel) treeObjects.getModel();
ObjListTreeNode listnode =(ObjListTreeNode)((DefaultMutableTreeNode) objlist.getRoot()).getChildAt(StageArchive.game == 2 ? 10 : 11);
ObjListTreeNode newnode =(ObjListTreeNode) listnode.addObject(thepath);
objlist.nodesWereInserted(listnode, new int[] { listnode.getIndex(newnode) });
ObjListTreeNode newnode = (ObjListTreeNode)objListPathRootNode.addObject(thepath);
treeNodeList.put(thepath.uniqueID, newnode);

TreeNode newpointnode = newnode.addObject(thepoint);
objlist.nodesWereInserted(newnode, new int[] { newnode.getIndex(newpointnode) });
treeNodeList.put(thepoint.uniqueID, newpointnode);
newNode = newnode.addObject(thepoint);
treeNodeList.put(thepoint.uniqueID, newNode);

rerenderTasks.add("path:" + thepath.uniqueID);
rerenderTasks.add("zone:" + curZone);
glCanvas.repaint();
unsavedChanges = true;
}
// Add new path point?
else if (objtype.equals("pathpoint")) {
Expand All @@ -2417,18 +2409,14 @@ else if (objtype.equals("pathpoint")) {
globalPathPointList.put(thepoint.uniqueID, thepoint);
thepath.getPoints().add(thepoint);

DefaultTreeModel objlist =(DefaultTreeModel) treeObjects.getModel();
ObjListTreeNode listnode =(ObjListTreeNode)((DefaultMutableTreeNode) objlist.getRoot()).getChildAt(StageArchive.game == 2 ? 10 : 11);
ObjListTreeNode listnode = objListPathRootNode;
listnode =(ObjListTreeNode) listnode.children.get(thepath.uniqueID);

TreeNode newnode = listnode.addObject(thepoint);
objlist.nodesWereInserted(listnode, new int[] { listnode.getIndex(newnode) });
treeNodeList.put(thepoint.uniqueID, newnode);

newNode = listnode.addObject(thepoint);
treeNodeList.put(thepoint.uniqueID, newNode);

rerenderTasks.add("path:" + thepath.uniqueID);
rerenderTasks.add("zone:" + thepath.stage.stageName);
glCanvas.repaint();
unsavedChanges = true;
}
else {
newobj = null;
Expand Down Expand Up @@ -2465,15 +2453,22 @@ else if (objtype.equals("pathpoint")) {
globalObjList.put(uniqueID, newobj);
curZoneArc.objects.get(addingObjectOnLayer).add(newobj);

ObjTreeNode newnode = objListTreeNodes.get(objtype).addObject(newobj);
treeNodeList.put(uniqueID, newnode);
newNode = objListTreeNodes.get(objtype).addObject(newobj);
treeNodeList.put(uniqueID, newNode);

// Update rendering
rerenderTasks.add(String.format("addobj:%1$d", uniqueID));
rerenderTasks.add("zone:" + curZone);
glCanvas.repaint();
unsavedChanges = true;
}

// Update tree node model and scroll to new node
objListModel.reload();
TreePath path = new TreePath(objListModel.getPathToRoot(newNode));
treeObjects.setSelectionPath(path);
treeObjects.scrollPathToVisible(path);

glCanvas.repaint();
unsavedChanges = true;
}

private void deleteObject(int uniqueID) {
Expand Down Expand Up @@ -3323,8 +3318,8 @@ private void renderZone(GL2 gl, Bcsv.Entry scenario, String zone, int layermask,

gl.glCallList(objDisplayLists.get(zone + "/common")[mode]);

for(int l = 0; l < 16; l++) {
if((layermask &(1 << l)) != 0)
for (int l = 0; l < 16; l++) {
if((layermask & (1 << l)) != 0)
gl.glCallList(objDisplayLists.get(zone + "/layer" + alphabet.charAt(l))[mode]);
}

Expand Down
3 changes: 2 additions & 1 deletion src/whitehole/editor/ObjectSelectForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,9 @@ public void showNewObject(String objectType, List<String> layerNames) {

populate();

cmoLayer.removeAllItems();

for (String layer : layerNames) {
System.out.println(layer);
cmoLayer.addItem(layer);
}

Expand Down
2 changes: 1 addition & 1 deletion src/whitehole/io/ExternalFilesystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public List<String> getDirectories(String directory) {
ret.add(file.getName());
}
} catch(Exception ex) {
MainFrame.lbStatusBar.setText("Failed to open game directory.");
System.err.println(ex);
}

return ret;
Expand Down
7 changes: 2 additions & 5 deletions src/whitehole/rendering/BmdRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -581,8 +581,7 @@ protected final void ctor_uploadData(RenderInfo info) throws GLException {
}
for(int i = 0; i < model.materials.length; i++) {
try {
if(!Settings.legacy)
generateShaders(gl, i);
generateShaders(gl, i);
}
catch(GLException ex) {
// really ugly hack
Expand Down Expand Up @@ -731,11 +730,9 @@ public void render(RenderInfo info) throws GLException {
if(info.renderMode != RenderMode.PICKING) {
if((mat.drawFlag == 4) ^(info.renderMode == RenderMode.TRANSLUCENT))
continue;
if(Settings.legacy)
hasShaders = false;
if(hasShaders) {
// shader: handles multitexturing, color combination, alpha test
if(gl.isFunctionAvailable("glUseProgram") && !Settings.legacy)
if(gl.isFunctionAvailable("glUseProgram"))
gl.glUseProgram(shaders[node.materialID].program);

// do multitexturing
Expand Down

0 comments on commit a7e6106

Please sign in to comment.