Skip to content

Commit

Permalink
More work on DRMS
Browse files Browse the repository at this point in the history
  • Loading branch information
Retera committed Aug 13, 2022
1 parent e792998 commit cfd5d4a
Show file tree
Hide file tree
Showing 8 changed files with 178 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ public void render(final Geoset geo, final boolean renderOpaque, final boolean o
NGGLDP.pipeline.glFresnelColor3f((float) fresnelColor.z, (float) fresnelColor.y,
(float) fresnelColor.x);
} else {
NGGLDP.pipeline.glFresnelColor3f(0f, 0f, 0f);
NGGLDP.pipeline.glFresnelColor3f(1f, 1f, 1f);
}
NGGLDP.pipeline.glFresnelTeamColor1f(layer.getRenderFresnelTeamColor(timeEnvironment));
NGGLDP.pipeline.glFresnelOpacity1f(layer.getRenderFresnelOpacity(timeEnvironment));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.hiveworkshop.wc3.gui.modeledit.actions.componenttree.timeline;

import com.hiveworkshop.wc3.gui.modeledit.UndoAction;
import com.hiveworkshop.wc3.mdl.Vertex;
import com.hiveworkshop.wc3.util.Callback;

public class SetFloat3StaticValueAction implements UndoAction {
private final String valueTypeName;
private final Vertex oldValue;
private final Vertex newValue;
private final Callback<Vertex> setter;

public SetFloat3StaticValueAction(final String valueTypeName, final Vertex oldValue, final Vertex newValue,
final Callback<Vertex> setter) {
this.valueTypeName = valueTypeName;
this.oldValue = oldValue;
this.newValue = newValue;
this.setter = setter;
}

@Override
public void undo() {
setter.run(oldValue);
}

@Override
public void redo() {
setter.run(newValue);
}

@Override
public String actionName() {
return "set " + valueTypeName;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.hiveworkshop.wc3.gui.modeledit.actions.componenttree.timeline;

import com.hiveworkshop.wc3.gui.modeledit.UndoAction;
import com.hiveworkshop.wc3.util.Callback;

public class SetFloatStaticValueAction implements UndoAction {
private final String valueTypeName;
private final float oldValue;
private final float newValue;
private final Callback<Float> setter;

public SetFloatStaticValueAction(final String valueTypeName, final float oldValue, final float newValue,
final Callback<Float> setter) {
this.valueTypeName = valueTypeName;
this.oldValue = oldValue;
this.newValue = newValue;
this.setter = setter;
}

@Override
public void undo() {
setter.run(oldValue);
}

@Override
public void redo() {
setter.run(newValue);
}

@Override
public String actionName() {
return "set " + valueTypeName;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
package com.hiveworkshop.wc3.gui.modeledit.components.editors;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.BorderFactory;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JComboBox;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTable;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

import com.hiveworkshop.wc3.gui.modeledit.actions.componenttree.timeline.SetFloat3StaticValueAction;
import com.hiveworkshop.wc3.gui.modeledit.actions.newsys.ModelStructureChangeListener;
import com.hiveworkshop.wc3.gui.modeledit.activity.UndoActionListener;
import com.hiveworkshop.wc3.gui.modeledit.components.material.FloatTrackTableModel;
import com.hiveworkshop.wc3.mdl.AnimFlag;
import com.hiveworkshop.wc3.mdl.Vertex;
import com.hiveworkshop.wc3.mdl.v2.timelines.InterpolationType;
import com.hiveworkshop.wc3.util.Callback;
import com.hiveworkshop.wc3.util.IconUtils;

import net.miginfocom.swing.MigLayout;
Expand All @@ -26,6 +35,10 @@ public class ColorValuePanel extends JPanel {
private final JComboBox<InterpolationType> interpTypeBox;
private final FloatTrackTableModel floatTrackTableModel;
private final JButton staticColorButton;
private UndoActionListener undoActionListener;
private ModelStructureChangeListener modelStructureChangeListener;
private Vertex lastLoadedStaticColor;
private Callback<Vertex> setter;

public ColorValuePanel(final String title) {
setBorder(BorderFactory.createTitledBorder(title));
Expand All @@ -38,6 +51,23 @@ public ColorValuePanel(final String title) {
add(staticButton);
staticColorButton = new JButton("Choose Color");
add(staticColorButton, "wrap");
staticColorButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(final ActionEvent e) {
final Color newColor = JColorChooser.showDialog(ColorValuePanel.this.getRootPane(), "Choose " + title,
new Color((float) lastLoadedStaticColor.z, (float) lastLoadedStaticColor.y,
(float) lastLoadedStaticColor.x));

if (newColor != null) {
final SetFloat3StaticValueAction setFloat3StaticValueAction = new SetFloat3StaticValueAction(title,
lastLoadedStaticColor,
new Vertex(newColor.getBlue() / 255f, newColor.getGreen() / 255f, newColor.getRed() / 255f),
setter);
setFloat3StaticValueAction.redo();
undoActionListener.pushAction(setFloat3StaticValueAction);
}
}
});
add(dynamicButton);
interpTypeBox = new JComboBox<InterpolationType>(InterpolationType.values());
add(interpTypeBox, "wrap");
Expand All @@ -57,15 +87,22 @@ public void stateChanged(final ChangeEvent e) {
dynamicButton.addChangeListener(l);
}

public void reloadNewValue(final Vertex color, final AnimFlag colorTrack) {
public void reloadNewValue(final Vertex color, final Callback<Vertex> setter, final AnimFlag colorTrack,
final UndoActionListener undoActionListener,
final ModelStructureChangeListener modelStructureChangeListener) {
this.setter = setter;
this.undoActionListener = undoActionListener;
this.modelStructureChangeListener = modelStructureChangeListener;
if (colorTrack == null) {
staticButton.setSelected(true);
} else {
dynamicButton.setSelected(true);
}
if (color != null) {
this.lastLoadedStaticColor = color;
staticColorButton.setIcon(new ImageIcon(IconUtils.createColorImage(color, 48, 48)));
} else {
this.lastLoadedStaticColor = DEFAULT_COLOR;
staticColorButton.setIcon(new ImageIcon(IconUtils.createColorImage(DEFAULT_COLOR, 48, 48)));
}
floatTrackTableModel.setTrack(colorTrack);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
import javax.swing.event.ChangeListener;
import javax.swing.table.DefaultTableCellRenderer;

import com.hiveworkshop.wc3.gui.modeledit.actions.componenttree.timeline.SetFloatStaticValueAction;
import com.hiveworkshop.wc3.gui.modeledit.actions.newsys.ModelStructureChangeListener;
import com.hiveworkshop.wc3.gui.modeledit.activity.UndoActionListener;
import com.hiveworkshop.wc3.gui.modeledit.components.material.FloatTrackTableModel;
import com.hiveworkshop.wc3.mdl.AnimFlag;
import com.hiveworkshop.wc3.mdl.v2.timelines.InterpolationType;
import com.hiveworkshop.wc3.util.Callback;

import net.miginfocom.swing.MigLayout;

Expand All @@ -27,6 +31,11 @@ public class FloatValuePanel extends JPanel {
private final ComponentEditorJSpinner staticSpinner;
private final JComboBox<InterpolationType> interpTypeBox;
private final FloatTrackTableModel floatTrackTableModel;
private UndoActionListener undoActionListener;
private ModelStructureChangeListener modelStructureChangeListener;
private AnimFlag valueTrack;
private Callback<Float> valueSetter;
private float lastLoadedValue;

public FloatValuePanel(final String title) {
setBorder(BorderFactory.createTitledBorder(title));
Expand All @@ -46,6 +55,17 @@ public FloatValuePanel(final String title) {
staticSpinner.setPreferredSize(standinGuiSpinner.getPreferredSize());
staticSpinner.setMaximumSize(standinGuiSpinner.getMaximumSize());
staticSpinner.setMinimumSize(standinGuiSpinner.getMinimumSize());
staticSpinner.addActionListener(new Runnable() {
@Override
public void run() {
if (staticSpinner.isEnabled()) {
final SetFloatStaticValueAction setFloatStaticValueAction = new SetFloatStaticValueAction(title,
lastLoadedValue, ((Number) staticSpinner.getValue()).floatValue(), valueSetter);
setFloatStaticValueAction.redo();
undoActionListener.pushAction(setFloatStaticValueAction);
}
}
});
add(staticSpinner, "wrap");
add(dynamicButton);
interpTypeBox = new JComboBox<InterpolationType>(InterpolationType.values());
Expand Down Expand Up @@ -81,12 +101,18 @@ public void stateChanged(final ChangeEvent e) {
dynamicButton.addChangeListener(l);
}

public void reloadNewValue(final float value, final AnimFlag valueTrack) {
public void reloadNewValue(final float value, final Callback<Float> valueSetter, final AnimFlag valueTrack,
final UndoActionListener undoActionListener,
final ModelStructureChangeListener modelStructureChangeListener) {
this.lastLoadedValue = value;
this.valueTrack = valueTrack;
this.valueSetter = valueSetter;
this.undoActionListener = undoActionListener;
this.modelStructureChangeListener = modelStructureChangeListener;
if (valueTrack == null) {
staticButton.setSelected(true);
interpTypeBox.setSelectedItem(InterpolationType.DONT_INTERP);
}
else {
} else {
dynamicButton.setSelected(true);
interpTypeBox.setSelectedItem(valueTrack.getInterpTypeAsEnum());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@
import com.hiveworkshop.wc3.mdl.LayerShader;
import com.hiveworkshop.wc3.mdl.ShaderTextureTypeHD;
import com.hiveworkshop.wc3.mdl.TextureAnim;
import com.hiveworkshop.wc3.mdl.Vertex;
import com.hiveworkshop.wc3.mdl.v2.ModelViewManager;
import com.hiveworkshop.wc3.util.Callback;
import com.hiveworkshop.wc3.util.IconUtils;
import com.hiveworkshop.wc3.util.ModelUtils;

Expand Down Expand Up @@ -82,7 +84,7 @@ public ComponentLayerPanel() {
public void actionPerformed(final ActionEvent e) {
if (listenersEnabled) {
final SetLayerFilterModeAction setLayerFilterModeAction = new SetLayerFilterModeAction(layer,
layer.getFilterMode(), ((FilterMode) filterModeDropdown.getSelectedItem()),
layer.getFilterMode(), (FilterMode) filterModeDropdown.getSelectedItem(),
modelStructureChangeListener);
setLayerFilterModeAction.redo();
undoActionListener.pushAction(setLayerFilterModeAction);
Expand Down Expand Up @@ -233,17 +235,47 @@ public void setLayer(final DataSource workingDirectory, final Layer layer, final
}
coordIdSpinner.reloadNewValue(layer.getCoordId());
tVertexAnimButton.setText(layer.getTextureAnim() == null ? "None"
: ("TextureAnim " + modelViewManager.getModel().getTextureAnimId(layer.getTextureAnim())));
alphaPanel.reloadNewValue((float) layer.getStaticAlpha(), layer.getFlag("Alpha"));
: "TextureAnim " + modelViewManager.getModel().getTextureAnimId(layer.getTextureAnim()));
alphaPanel.reloadNewValue((float) layer.getStaticAlpha(), new Callback<Float>() {
@Override
public void run(final Float value) {
layer.setStaticAlpha(value);
modelStructureChangeListener.texturesChanged();
}
}, layer.getFlag("Alpha"), undoActionListener, modelStructureChangeListener);
emissiveGainPanel.setVisible(ModelUtils.isEmissiveLayerSupported(formatVersion) && hdShader);
emissiveGainPanel.reloadNewValue((float) layer.getEmissive(), layer.getFlag("EmissiveGain"));
emissiveGainPanel.reloadNewValue((float) layer.getEmissive(), new Callback<Float>() {
@Override
public void run(final Float value) {
layer.setEmissive(value);
modelStructureChangeListener.texturesChanged();
}
}, layer.getFlag("EmissiveGain"), undoActionListener, modelStructureChangeListener);
final boolean fresnelColorLayerSupported = ModelUtils.isFresnelColorLayerSupported(formatVersion) && hdShader;
fresnelColorPanel.setVisible(fresnelColorLayerSupported);
fresnelColorPanel.reloadNewValue(layer.getFresnelColor(), layer.getFlag("FresnelColor"));
fresnelColorPanel.reloadNewValue(layer.getFresnelColor(), new Callback<Vertex>() {
@Override
public void run(final Vertex value) {
layer.setFresnelColor(value);
modelStructureChangeListener.texturesChanged();
}
}, layer.getFlag("FresnelColor"), undoActionListener, modelStructureChangeListener);
fresnelOpacityPanel.setVisible(fresnelColorLayerSupported);
fresnelOpacityPanel.reloadNewValue((float) layer.getFresnelOpacity(), layer.getFlag("FresnelOpacity"));
fresnelOpacityPanel.reloadNewValue((float) layer.getFresnelOpacity(), new Callback<Float>() {
@Override
public void run(final Float value) {
layer.setFresnelOpacity(value);
modelStructureChangeListener.texturesChanged();
}
}, layer.getFlag("FresnelOpacity"), undoActionListener, modelStructureChangeListener);
fresnelTeamColor.setVisible(fresnelColorLayerSupported);
fresnelTeamColor.reloadNewValue((float) layer.getFresnelTeamColor(), layer.getFlag("FresnelTeamColor"));
fresnelTeamColor.reloadNewValue((float) layer.getFresnelTeamColor(), new Callback<Float>() {
@Override
public void run(final Float value) {
layer.setFresnelTeamColor(value);
modelStructureChangeListener.texturesChanged();
}
}, layer.getFlag("FresnelTeamColor"), undoActionListener, modelStructureChangeListener);
shaderOptionComboBox.setSelectedIndex(layer.getLayerShader().ordinal());
listenersEnabled = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ public void render(final Geoset geo, final boolean renderOpaque, final int forma
NGGLDP.pipeline.glFresnelColor3f((float) fresnelColor.z, (float) fresnelColor.y,
(float) fresnelColor.x);
} else {
NGGLDP.pipeline.glFresnelColor3f(0f, 0f, 0f);
NGGLDP.pipeline.glFresnelColor3f(1f, 1f, 1f);
}
NGGLDP.pipeline.glFresnelTeamColor1f(layer.getRenderFresnelTeamColor(this));
NGGLDP.pipeline.glFresnelOpacity1f(layer.getRenderFresnelOpacity(this));
Expand Down
2 changes: 1 addition & 1 deletion craft3data/src/com/hiveworkshop/wc3/util/IconUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static BufferedImage createBlank(final Color color, final int width, fina
}

public static BufferedImage createColorImage(final Vertex color, final int width, final int height) {
final Color awtColor = new Color((float) color.z, (float) color.y, (float) color.z);
final Color awtColor = new Color((float) color.z, (float) color.y, (float) color.x);
return createBlank(awtColor, width, height);
}

Expand Down

0 comments on commit cfd5d4a

Please sign in to comment.