Skip to content

Commit

Permalink
Added 2 new element specific attributes: tintIndex (already supported…
Browse files Browse the repository at this point in the history
… by the engine) and renderPass (not yet supported by the engine)
  • Loading branch information
tyronx committed Sep 23, 2017
1 parent 4157e30 commit 6dae65f
Show file tree
Hide file tree
Showing 11 changed files with 165 additions and 59 deletions.
42 changes: 42 additions & 0 deletions linecounter.php
@@ -0,0 +1,42 @@
<?php

$subcounts = array();
$totallines = countLines("src/at/vintagestory", array(""), array("Mat4f.java"));
$subcounts = array_reverse($subcounts);

foreach ($subcounts as $subcount) {
echo $subcount;
}

echo "\r\nTotal lines: " . number_format($totallines);




function countLines($folder, $excludefoldernames, $excludefilenames, $depth = 0) {
global $subcounts;

$lines = 0;

$dir = opendir($folder);
while ($file = readdir($dir)) {

if (preg_match("#\.java$#", $file) && !in_array($file, $excludefilenames)) {
$lines += count(file($folder . '/' . $file));
}
if (is_dir($folder . '/' . $file) && $file != '.' && $file != '..' && !in_array($file, $excludefoldernames)) {
$linesOfDir = countLines($folder . '/' . $file, $excludefoldernames, $excludefilenames, $depth + 1);
if ($depth < 3 && $linesOfDir > 0) {
$prefix = pad($depth) . $file;
$subcounts[] = $prefix . pad(15 - strlen($prefix)/2) . number_format($linesOfDir ) . "\r\n";
}
$lines += $linesOfDir ;
}
}
return $lines;
}

function pad($depth) {
if ($depth <= 0) return "";
return str_repeat(" ", $depth);
}
5 changes: 5 additions & 0 deletions src/at/vintagestory/modelcreator/Exporter.java
Expand Up @@ -349,6 +349,11 @@ private void writeElement(BufferedWriter writer, Element cuboid, int indentation
writer.write(space(indentation) + "\"tintIndex\": " + cuboid.getTintIndex() + ",");
writer.newLine();
}
if (cuboid.getRenderPass() > 0)
{
writer.write(space(indentation) + "\"renderPass\": " + cuboid.getRenderPass() + ",");
writer.newLine();
}

if (project.EntityTextureMode) {
if (cuboid.getUnwrapMode() > 0)
Expand Down
5 changes: 5 additions & 0 deletions src/at/vintagestory/modelcreator/Importer.java
Expand Up @@ -422,6 +422,11 @@ else if (obj.has("comment") && obj.get("comment").isJsonPrimitive())
element.setTintIndex(obj.get("tintIndex").getAsInt());
}

if (obj.has("renderPass") && obj.get("renderPass").isJsonPrimitive())
{
element.setRenderPass(obj.get("renderPass").getAsInt());
}

if (obj.has("unwrapMode") && obj.get("unwrapMode").isJsonPrimitive()) {
element.setUnwrapMode(obj.get("unwrapMode").getAsInt());
}
Expand Down
1 change: 0 additions & 1 deletion src/at/vintagestory/modelcreator/Project.java
Expand Up @@ -5,7 +5,6 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import javax.swing.ImageIcon;
Expand Down
4 changes: 2 additions & 2 deletions src/at/vintagestory/modelcreator/gui/CreditsDialog.java
Expand Up @@ -30,7 +30,7 @@ public static void show(JFrame parent)
JLabel message = new JLabel();
message.setText("<html>All praise for this program should go to MrCrayFish for making this awesome and simply to use tool "
+ "originally for Minecraft. He open sourced it and so Tyron took the freedom to adjust it to his needs for Vintage Story. "
+ "If you like this program, show some love to MrCrayFish! &lt;3</html>");
+ "If you like this program, show some love to MrCrayFish! &lt;3<br><br>Some of the features added by tyron:<br>- Animations & Keyframe Editor, Gif Animation Exporter<br>- Undo/Redo capability<br>- More Streamlined loading&saving system<br>- Drag&Drop loading of models and textures<br>- Texture autoreload<br>- Entity Texture mode with box-uv-auto-unwrap<br>- UV Map exporter<br>- Attachment point editor</html>");
leftPanel.add(message, BorderLayout.CENTER);

container.add(leftPanel, BorderLayout.CENTER);
Expand Down Expand Up @@ -79,7 +79,7 @@ public void actionPerformed(ActionEvent arg0)
JDialog dialog = new JDialog(parent, "Credits", false);
// dialog.setLayout(new BorderLayout());
dialog.setResizable(false);
dialog.setPreferredSize(new Dimension(500, 290));
dialog.setPreferredSize(new Dimension(500, 390));
dialog.add(container);
dialog.pack();
dialog.setLocationRelativeTo(null);
Expand Down
4 changes: 2 additions & 2 deletions src/at/vintagestory/modelcreator/gui/right/RightTopPanel.java
Expand Up @@ -38,7 +38,7 @@ public RightTopPanel(ModelCreator creator)
{
this.creator = creator;
setLayout(layout = new SpringLayout());
setPreferredSize(new Dimension(215, 950));
setPreferredSize(new Dimension(215, 1050));
initComponents();
setLayoutConstaints();
}
Expand Down Expand Up @@ -107,7 +107,7 @@ public void keyReleased(KeyEvent e)
tabbedPane.add("Keyframe", rightKeyFramesPanel = new RightKeyFramesPanel());
tabbedPane.add("P", new AttachmentPointsPanel());

tabbedPane.setPreferredSize(new Dimension(205, 650));
tabbedPane.setPreferredSize(new Dimension(205, 750));
tabbedPane.setTabPlacement(JTabbedPane.TOP);

tabbedPane.addChangeListener(c ->
Expand Down
Expand Up @@ -2,17 +2,25 @@

import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;

import javax.swing.BorderFactory;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JTextField;

import at.vintagestory.modelcreator.ModelCreator;
import at.vintagestory.modelcreator.Start;
import at.vintagestory.modelcreator.gui.ComponentUtil;
import at.vintagestory.modelcreator.interfaces.IElementManager;
import at.vintagestory.modelcreator.interfaces.IValueUpdater;
import at.vintagestory.modelcreator.model.Element;
import at.vintagestory.modelcreator.util.Parser;

public class ElementPropertiesPanel extends JPanel implements IValueUpdater
{
Expand All @@ -21,13 +29,17 @@ public class ElementPropertiesPanel extends JPanel implements IValueUpdater
private IElementManager manager;

private JRadioButton btnShade;

JTextField tintIndexField;
private JComboBox<String> renderPassList;


public ElementPropertiesPanel(IElementManager manager)
{
this.manager = manager;
setLayout(new GridLayout(1, 2));
setLayout(new GridLayout(3, 2));
setBorder(BorderFactory.createTitledBorder(Start.Border, "<html><b>Element Properties</b></html>"));
setPreferredSize(new Dimension(200, 50));
setPreferredSize(new Dimension(200, 100));
setAlignmentX(JPanel.LEFT_ALIGNMENT);
initComponents();
addComponents();
Expand All @@ -38,14 +50,52 @@ public void initComponents()
btnShade = ComponentUtil.createRadioButton("Shade", "<html>Determines if shadows should be rendered<br>Default: On</html>");
btnShade.addActionListener(e ->
{
Element elem2 = manager.getCurrentElement();
if (elem2 != null) elem2.setShade(btnShade.isSelected());
});

tintIndexField = new JTextField();
tintIndexField.setToolTipText("0 for no tint, 1 = for climate foliage tint, 2 = for climate water tint");
tintIndexField.setPreferredSize(new Dimension(200, 25));

tintIndexField.addKeyListener(new KeyAdapter()
{
@Override
public void keyReleased(KeyEvent e)
{
Element elem = manager.getCurrentElement();
if (elem != null) {
elem.setTintIndex(Parser.parseInt(tintIndexField.getText(), 0));
}
ModelCreator.DidModify();
}
});

renderPassList = new JComboBox<String>();
renderPassList.setToolTipText("Default is Opaque. For foliage you might want to use OpaqueNoCull.");
DefaultComboBoxModel<String> model = renderPassList();
renderPassList.setModel(model);
renderPassList.setPreferredSize(new Dimension(200, 25));

renderPassList.addActionListener(e -> {
Element elem = manager.getCurrentElement();
if (elem != null) elem.setShade(btnShade.isSelected());
if (elem != null) {
elem.setRenderPass(renderPassList.getSelectedIndex());
}
ModelCreator.DidModify();
});
}

public void addComponents()
{
add(btnShade);
add(new JLabel());

add(new JLabel("Tint index"));
add(tintIndexField);

add(new JLabel("Render pass"));
add(renderPassList);
}

@Override
Expand All @@ -56,11 +106,37 @@ public void updateValues(JComponent byGuiElem)
{
btnShade.setEnabled(true);
btnShade.setSelected(cube.isShaded());
tintIndexField.setEnabled(true);
renderPassList.setEnabled(true);

tintIndexField.setText(cube.getTintIndex() + "");
renderPassList.setSelectedIndex(cube.getRenderPass());
}
else
{
btnShade.setEnabled(false);
btnShade.setSelected(false);
renderPassList.setEnabled(false);

tintIndexField.setEnabled(false);
tintIndexField.setText("");
}
}


private DefaultComboBoxModel<String> renderPassList()
{
DefaultComboBoxModel<String> model = new DefaultComboBoxModel<String>();

model.addElement("<html><b>Opaque</b></html>");
model.addElement("<html><b>OpaqueNoCull</b></html>");
model.addElement("<html><b>BlendNoCull</b></html>");
model.addElement("<html><b>Transparent</b></html>");
model.addElement("<html><b>Liquid</b></html>");
model.addElement("<html><b>TopSoil</b></html>");
model.addElement("<html><b>Meta</b></html>");

return model;
}

}

This file was deleted.

13 changes: 13 additions & 0 deletions src/at/vintagestory/modelcreator/model/Element.java
Expand Up @@ -74,6 +74,7 @@ public class Element implements IDrawable
// Extra Variables
protected boolean shade = true;
private int tintIndex = 0;
private int renderPass = 0;

// Rotation Point Indicator
protected Sphere sphere = new Sphere();
Expand Down Expand Up @@ -934,6 +935,17 @@ public void setTintIndex(int tintIndex)
this.tintIndex = tintIndex;
}


public int getRenderPass()
{
return renderPass;
}

public void setRenderPass(int pass)
{
this.renderPass = pass;
}


public Element clone() {
Element cloned = new Element();
Expand Down Expand Up @@ -969,6 +981,7 @@ public Element clone() {
cloned.rescale = rescale;
cloned.shade = shade;
cloned.tintIndex = tintIndex;
cloned.renderPass = renderPass;
cloned.sphere = sphere;
cloned.texUStart = texUStart;
cloned.texVStart = texVStart;
Expand Down
2 changes: 0 additions & 2 deletions src/at/vintagestory/modelcreator/model/Face.java
Expand Up @@ -8,9 +8,7 @@

import org.lwjgl.BufferUtils;
import org.lwjgl.opengl.GL11;
import org.lwjgl.opengl.GL12;
import org.lwjgl.opengl.GL13;
import org.lwjgl.opengl.GL14;
import org.newdawn.slick.Color;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureImpl;
Expand Down
17 changes: 17 additions & 0 deletions src/at/vintagestory/modelcreator/util/Parser.java
Expand Up @@ -31,4 +31,21 @@ public static double parseDouble(String text, double def)
}
return value;
}



public static int parseInt(String text, int def)
{
int value;
try
{
text = text.replace(',', '.');
value = Integer.parseInt(text);
}
catch (NumberFormatException e)
{
value = def;
}
return value;
}
}

0 comments on commit 6dae65f

Please sign in to comment.