Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QoL: Added extra copy/paste buttons #105

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/at/vintagestory/modelcreator/gui/GuiMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ private void initMenu()

itemPreviewWind = new JMenu("Wind preview mode");
itemPreviewWind.setIcon(Icons.wind);
itemPreviewWind.setToolTipText("Makes elements sway if configured so, please not that the sway is not the same as in game");
itemPreviewWind.setToolTipText("Makes elements sway if configured so, please note that the sway is not the same as in game");
{
itemPreviewWindOff = createItem("Off", null, KeyEvent.VK_B, Icons.clear);
itemPreviewWindSelected = createItem("Only selected element", null, KeyEvent.VK_B, Icons.wind);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.MouseEvent;
Expand All @@ -18,16 +19,21 @@
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;
import javax.swing.JButton;

import at.vintagestory.modelcreator.ModelCreator;
import at.vintagestory.modelcreator.Start;
import at.vintagestory.modelcreator.enums.BlockFacing;
import at.vintagestory.modelcreator.gui.ComponentUtil;
import at.vintagestory.modelcreator.gui.Icons;
import at.vintagestory.modelcreator.interfaces.IElementManager;
import at.vintagestory.modelcreator.interfaces.IValueUpdater;
import at.vintagestory.modelcreator.model.ClipboardTexture;
import at.vintagestory.modelcreator.model.ClipboardWind;
import at.vintagestory.modelcreator.model.Element;
import at.vintagestory.modelcreator.model.Face;
import at.vintagestory.modelcreator.util.AwtUtil;
import at.vintagestory.modelcreator.util.Clipboard;
import at.vintagestory.modelcreator.util.Mat4f;
import at.vintagestory.modelcreator.util.Vec3f;

Expand All @@ -43,19 +49,23 @@ public class FacePropertiesPanel extends JPanel implements IValueUpdater
private JRadioButton boxSnapUv;
private JTextField glowValue;
private JTextField windData;
private JButton btnCopyWind;
private JButton btnPasteWind;

JComboBox<String> bla = new JComboBox<String>();
@SuppressWarnings("unchecked")
private JComboBox<String>[] windModeList = (JComboBox<String>[]) Array.newInstance(bla.getClass(), 4);

private JComboBox<String> reflectiveMode;

Font defaultFont = new Font("SansSerif", Font.BOLD, 14);

public FacePropertiesPanel(IElementManager manager)
{
this.manager = manager;
setLayout(new BorderLayout(0, 5));
setBorder(BorderFactory.createTitledBorder(Start.Border, "<html><b>Properties</b></html>"));
setMaximumSize(new Dimension(250, 400));
setMaximumSize(new Dimension(250, 700));
initComponents();
addComponents();
}
Expand Down Expand Up @@ -170,6 +180,47 @@ public void initComponents()

horizontalBox.add(reflectiveMode);

btnCopyWind = new JButton("Copy Wind");
btnCopyWind.setIcon(Icons.copy);
btnCopyWind.addActionListener(e ->
{
if (manager.getCurrentElement() != null)
{
Face face = manager.getCurrentElement().getSelectedFace();
Clipboard.copyWindSettings(face.WindModes);
}
});
btnCopyWind.setFont(defaultFont);
btnCopyWind.setToolTipText("Copies the wind settings on this face to clipboard");

horizontalBox.add(btnCopyWind);

btnPasteWind = new JButton("Paste Wind");
btnPasteWind.setIcon(Icons.clipboard);
btnPasteWind.addActionListener(e ->
{
ClipboardWind windSettings = Clipboard.getWindSettings();
if (manager.getCurrentElement() != null && windSettings != null)
{
boolean haveShift = (e.getModifiers() & ActionEvent.SHIFT_MASK) > 0;
boolean haveCtrl = (e.getModifiers() & ActionEvent.CTRL_MASK) > 0;

if (haveShift)
{
manager.getCurrentElement().setWindAllFaces(windSettings.getWindSettings(), haveCtrl);
}
else
{
Face face = manager.getCurrentElement().getSelectedFace();
face.WindModes = windSettings.getWindSettings();
}
}
});
btnPasteWind.setFont(defaultFont);
btnPasteWind.setToolTipText("<html>Pastes the clipboard wind settings to this face.<br><b>Hold shift to paste to all faces</b></html>");

horizontalBox.add(btnPasteWind);

for (int i = 0; i < 4; i++) {
int index=i;
JComboBox<String> list = windModeList[i] = new JComboBox<String>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import at.vintagestory.modelcreator.interfaces.IElementManager;
import at.vintagestory.modelcreator.interfaces.ITextureCallback;
import at.vintagestory.modelcreator.model.ClipboardTexture;
import at.vintagestory.modelcreator.model.ClipboardUV;
import at.vintagestory.modelcreator.model.Face;
import at.vintagestory.modelcreator.util.Clipboard;

Expand All @@ -28,13 +29,15 @@ public class FaceTexturePanel extends JPanel implements ITextureCallback
private JButton btnClear;
private JButton btnCopy;
private JButton btnPaste;
private JButton btnCopyUV;
private JButton btnPasteUV;

public static TextureDialog dlg;

public FaceTexturePanel(IElementManager manager)
{
this.manager = manager;
setLayout(new GridLayout(2, 2, 4, 4));
setLayout(new GridLayout(3, 2, 4, 4));
setBorder(BorderFactory.createTitledBorder(Start.Border, "<html><b>Texture</b></html>"));
setMaximumSize(new Dimension(186, 90));
initComponents();
Expand Down Expand Up @@ -119,9 +122,45 @@ public void initComponents()
}
}
});

btnPaste.setFont(defaultFont);
btnPaste.setToolTipText("<html>Pastes the clipboard texture to this face.<br><b>Hold shift to paste to all faces</b></html>");

btnCopyUV = new JButton("Copy UV");
btnCopy.setIcon(Icons.copy);
btnCopyUV.addActionListener(e ->
{
if (manager.getCurrentElement() != null)
{
Face face = manager.getCurrentElement().getSelectedFace();
Clipboard.copyUV(face.getStartU(), face.getStartV(), face.getEndU(), face.getEndV());
}
});
btnCopyUV.setFont(defaultFont);
btnCopyUV.setToolTipText("Copies the UV coordinates on this face to the clipboard");

btnPasteUV = new JButton("Paste UV");
btnPasteUV.setIcon(Icons.clipboard);
btnPasteUV.addActionListener(e ->
{
ClipboardUV uv = Clipboard.getUV();
if (manager.getCurrentElement() != null && uv != null)
{
boolean haveShift = (e.getModifiers() & ActionEvent.SHIFT_MASK) > 0;
boolean haveCtrl = (e.getModifiers() & ActionEvent.CTRL_MASK) > 0;

if (haveShift)
{
manager.getCurrentElement().setUVAllFaces(uv, haveCtrl);
}
else
{
Face face = manager.getCurrentElement().getSelectedFace();
face.setUV(uv.getUStart(), uv.getVStart(), uv.getUEnd(), uv.getVEnd());
}
}
});
btnPasteUV.setFont(defaultFont);
btnPasteUV.setToolTipText("<html>Pastes the clipboard UV to this face.<br><b>Hold shift to paste to all faces</b><br><b>Hold ctrl to paste recursively to all children</b></html>");
}

public void addComponents()
Expand All @@ -130,6 +169,8 @@ public void addComponents()
add(btnClear);
add(btnCopy);
add(btnPaste);
add(btnCopyUV);
add(btnPasteUV);
}

@Override
Expand Down
41 changes: 41 additions & 0 deletions src/at/vintagestory/modelcreator/model/ClipboardUV.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package at.vintagestory.modelcreator.model;

public class ClipboardUV
{
//private String location;
private double us;
private double ue;
private double vs;
private double ve;

public ClipboardUV(double UStart, double VStart, double UEnd, double VEnd)
{
//this.location = location;
this.us = UStart;
this.ue = UEnd;
this.vs = VStart;
this.ve = VEnd;
}

/*public String getLocation()
{
return location;
}*/

public double getUStart()
{
return us;
}
public double getUEnd()
{
return ue;
}
public double getVStart()
{
return vs;
}
public double getVEnd()
{
return ve;
}
}
24 changes: 24 additions & 0 deletions src/at/vintagestory/modelcreator/model/ClipboardWind.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package at.vintagestory.modelcreator.model;


public class ClipboardWind
{
//private String location;
private int[] windSettings;

public ClipboardWind(int[] windSettings)
{
//this.location = location;
this.windSettings = windSettings;
}

/*public String getLocation()
{
return location;
}*/

public int[] getWindSettings()
{
return this.windSettings;
}
}
32 changes: 31 additions & 1 deletion src/at/vintagestory/modelcreator/model/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,38 @@ public void setTextureCode(String texture, boolean recursive)
}
}
}

public void setUVAllFaces(ClipboardUV uv, boolean recursive)
{
for (Face face : faces)
{
face.setStartU(uv.getUStart());
face.setStartV(uv.getVStart());
face.setEndU(uv.getUEnd());
face.setEndV(uv.getVEnd());
}

if (recursive) {
for (Element elem : ChildElements) {
elem.setUVAllFaces(uv, recursive);
}
}
}


public void setWindAllFaces(int[] windModes, boolean recursive)
{

for (Face face : faces)
{
face.WindModes = windModes;
}

if (recursive) {
for (Element elem : ChildElements) {
elem.setWindAllFaces(windModes, recursive);
}
}
}

public void recalculateBrightnessValues(float[] mat) {
for (int i = 0; i < BlockFacing.ALLFACES.length; i++) {
Expand Down
8 changes: 8 additions & 0 deletions src/at/vintagestory/modelcreator/model/Face.java
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,14 @@ public void setEndV(double ve)
textureVEnd = ve;
ModelCreator.DidModify();
}

public void setUV(double us, double vs, double ue, double ve)
{
this.setStartU(us);
this.setStartV(vs);
this.setEndU(ue);
this.setEndV(ve);
}

public String getTextureCode()
{
Expand Down
24 changes: 24 additions & 0 deletions src/at/vintagestory/modelcreator/util/Clipboard.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
package at.vintagestory.modelcreator.util;

import at.vintagestory.modelcreator.model.ClipboardTexture;
import at.vintagestory.modelcreator.model.ClipboardUV;
import at.vintagestory.modelcreator.model.ClipboardWind;

public class Clipboard
{
private static ClipboardTexture texture;
private static ClipboardUV uv;
private static ClipboardWind wind;

public static void copyTexture(String texture)
{
Expand All @@ -15,4 +19,24 @@ public static ClipboardTexture getTexture()
{
return Clipboard.texture;
}

public static void copyUV(double UStart, double VStart, double UEnd, double VEnd)
{
Clipboard.uv = new ClipboardUV(UStart, VStart, UEnd, VEnd);
}

public static ClipboardUV getUV()
{
return Clipboard.uv;
}

public static void copyWindSettings(int[] windSettings)
{
Clipboard.wind = new ClipboardWind(windSettings);
}

public static ClipboardWind getWindSettings()
{
return Clipboard.wind;
}
}