Skip to content

Commit

Permalink
Input changer
Browse files Browse the repository at this point in the history
  • Loading branch information
macbury committed Apr 9, 2015
1 parent 94dbbb5 commit 17aab3d
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 67 deletions.
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ project(":desktop") {
compile "com.badlogicgames.gdx:gdx-bullet-platform:$gdxVersion:natives-desktop"
compile files("${rootDir}/libs/task-dialog-1.3.5.jar")
compile files("${rootDir}/libs/swing-bits-0.5.0.jar")
compile files("${rootDir}/libs/ColorPicker.jar")
compile files("${rootDir}/libs/miglayout-3.7.2.jar")

}
Expand Down
7 changes: 6 additions & 1 deletion core/assets/shaders/helpers/fog.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
vec4 fog(vec4 inColot, vec4 fogColor, vec4 eyePosition, vec4 fragmentPosition) {
vec3 flen = eyePosition.xyz - fragmentPosition.xyz;
float fog = dot(flen, flen) * eyePosition.w;
fog = clamp(fog, 0.0, 1.0);
//if (fragmentPosition.y <= 3f) {
// fog = 1f;
//} else {
fog = clamp(fog, 0.0, 1.0);
// }

return mix(inColot, fogColor, fog);
}
2 changes: 1 addition & 1 deletion core/assets/shaders/terrain.vert.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void main() {
v_uvMul = a_textureFullCoords.zw - v_uvStart;

vec3 lightDiffuse = directionalLightDiffuse(u_mainLight, v_normal);
v_lightDiffuse = u_ambientLight * vec4(lightDiffuse, 1f);
v_lightDiffuse = u_ambientLight + vec4(lightDiffuse, 1f);
v_textCoord = a_texCoord0;
v_position = u_worldTransform * a_position;
v_position = applyWind(u_time, u_windDirection, waviness, v_position, u_mapSize, u_windDisplacementTexture);
Expand Down
2 changes: 1 addition & 1 deletion core/src/macbury/forge/level/LevelEnv.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public LevelEnv() {
mainLight = new DirectionalLight();
mainLight.set(1f, 1f, 1f,-1, -1, 0.5f);

ambientLight = Color.WHITE;
ambientLight = Color.GRAY;
}

}
21 changes: 21 additions & 0 deletions editor/src/icons/Utils.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
package icons;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Color;

import javax.swing.*;
/**
* Created by macbury on 10.11.14.
*/
public class Utils {
private static final String TAG = "utils";

public static ImageIcon getIcon(String name) {
try {
return new ImageIcon(Utils.class.getResource("./"+name+".png"));
Expand All @@ -12,4 +17,20 @@ public static ImageIcon getIcon(String name) {
return null;
}
}

public static java.awt.Color fromLibgdx(Color c) {
float [] hsbvals = java.awt.Color.RGBtoHSB((int)(255*c.r), (int)(255*c.g), (int)(255*c.b), null);
return java.awt.Color.getHSBColor(hsbvals[0],hsbvals[1],hsbvals[2]);
}

public static Color fromAwt(java.awt.Color tempColor) {
return new com.badlogic.gdx.graphics.Color(((float)tempColor.getRed())/255f,((float)tempColor.getGreen())/255f,((float)tempColor.getBlue())/255f,1f);
}

public static String rgbToString(float r, float g, float b) {
String rs = Integer.toHexString((int)(r * 256));
String gs = Integer.toHexString((int)(g * 256));
String bs = Integer.toHexString((int)(b * 256));
return rs + gs + bs;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,6 @@ public void onNewMap(ProjectController controller, EditorScreen screen) {
changeManager = screen.changeManager;

changeManager.addListener(this);

this.binder = new DefaultBeanBinder(new EditorScreenBeanInfo.EditorScreenBean(screen), inspectorSheetPanel, new EditorScreenBeanInfo());
this.binder.setListener(this);

}

@Override
Expand All @@ -63,17 +59,24 @@ public void onProjectStructureChange(ProjectController controller) {
public void onMapSaved(ProjectController projectController, EditorScreen editorScreen) {

}

/*
@Override
public void onPropertyChange(DefaultBeanBinder binder, PropertyChangeEvent event, Object object) {
this.pause = PropertyChangeable.class.isInstance(changeManager.getCurrent());
if (!pause) {
if (com.badlogic.gdx.graphics.Color.class.isInstance(event.getNewValue())) {
PropertyChangeable propertyChangeable = new PropertyChangeable(object, event);
changeManager.addChangeable(propertyChangeable).apply();
Gdx.app.log(TAG, "Color change: "+ event.getNewValue() + " from " + event.getOldValue() + " for " + object.toString());
} else {
this.pause = PropertyChangeable.class.isInstance(changeManager.getCurrent());
if (!pause) {
PropertyChangeable propertyChangeable = new PropertyChangeable(object, event);
changeManager.addChangeable(propertyChangeable).apply();
}
pause = false;
Gdx.app.log(TAG, "Property change: "+ event.getNewValue() + " from " + event.getOldValue() + " for " + object.toString());
}
pause = false;
Gdx.app.log(TAG, "Property change: "+ event.getNewValue() + " from " + event.getOldValue() + " for " + object.toString());
}
}*/

@Override
public void onChangeManagerChange(ChangeManager changeManager) {
Expand All @@ -82,13 +85,24 @@ public void onChangeManagerChange(ChangeManager changeManager) {

@Override
public void onToolPaneUnSelected(SelectionSystem system) {

if (binder != null) {
binder.unbind();
}
this.binder = null;
}

@Override
public void onToolPaneSelected(ToolsController.ToolControllerListener selectedToolController, SelectionSystem system) {
if (selectedToolController == this)
if (selectedToolController == this) {
this.binder = new DefaultBeanBinder(new EditorScreenBeanInfo.EditorScreenBean(screen), inspectorSheetPanel, new EditorScreenBeanInfo());
this.binder.setListener(this);
inspectorSheetPanel.updateUI();
}
}

@Override
public void onPropertyChange(DefaultBeanBinder binder, PropertyChangeEvent event, Object object) {
PropertyChangeable propertyChangeable = new PropertyChangeable(object, event);
propertyChangeable.apply();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,14 @@
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JColorChooser;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.*;

import com.badlogic.gdx.graphics.Color;
import com.bric.swing.ColorPicker;
import com.l2fprod.common.beans.editor.AbstractPropertyEditor;
import com.l2fprod.common.swing.renderer.ColorCellRenderer;
import icons.Utils;
import macbury.forge.editor.windows.MainWindow;


/**
Expand All @@ -35,14 +30,14 @@ protected class ColorEditorComponent extends JPanel {

private static final long serialVersionUID = 411604969565728959L;

private ColorCellRenderer label = null;
private JLabel label = null;
private JButton button = null;

public ColorEditorComponent() {

setLayout(new BoxLayout(this, BoxLayout.X_AXIS));

label = new ColorCellRenderer();
label = new JLabel();
label.setBorder(BorderFactory.createEmptyBorder(0, 2, 0, 0));
label.setAlignmentX(JTextField.LEFT_ALIGNMENT);
label.setBackground(UIManager.getColor("Table.selectionBackground"));
Expand Down Expand Up @@ -72,34 +67,6 @@ public void actionPerformed(ActionEvent e) {
}
});

label.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
selectColor();
}

@Override
public void mousePressed(MouseEvent e) {

}

@Override
public void mouseReleased(MouseEvent e) {

}

@Override
public void mouseEntered(MouseEvent e) {

}

@Override
public void mouseExited(MouseEvent e) {

}
});


JPanel left = new JPanel();
left.setLayout(new BorderLayout(0, 0));
left.add(label);
Expand All @@ -111,12 +78,12 @@ public void mouseExited(MouseEvent e) {
right.setPreferredSize(new Dimension(size.width, 25));
right.setAlignmentX(JPanel.RIGHT_ALIGNMENT);

add(left, BorderLayout.WEST);
add(right, BorderLayout.CENTER);
add(left, BorderLayout.CENTER);
add(right, BorderLayout.EAST);
}

public void setColor(Color color) {
label.setValue(new java.awt.Color(color.toIntBits()));
label.setText(color.toString());
ColorEditor.this.color = color;
}
}
Expand All @@ -139,18 +106,15 @@ public void setValue(Object value) {
}

protected void selectColor() {
java.awt.Color oldColor = new java.awt.Color(color.toIntBits());
String title = "Select color";
java.awt.Color selectedColor = JColorChooser.showDialog(editor, title, oldColor);
java.awt.Color selectedColor = ColorPicker.showDialog(MainWindow.current, Utils.fromLibgdx(color));

if (selectedColor != null) {
Color newColor = Utils.fromAwt(selectedColor);

selectedColor.toString();
Color newColor = new Color(selectedColor.getRed());
colorEditor.setColor(newColor);

//colorEditor.setColor(newColor);
firePropertyChange(color, newColor);

//firePropertyChange(oldColor, newColor);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public EditorScreenBeanInfo() {
tilesetProperty.setDisplayName("Title");
tilesetProperty.setShortDescription("Map title for editor");

ExtendedPropertyDescriptor fogProperty = addProperty("fogColor").setCategory(CATEGORY_LEVEL);
fogProperty.setDisplayName("Fog & sky color");
fogProperty.setShortDescription("Color of the fog and sky");

ExtendedPropertyDescriptor ambientLightColorProperty = addProperty("ambientLight").setCategory(CATEGORY_LIGHTING);
ambientLightColorProperty.setDisplayName("Ambient Light Color");
ambientLightColorProperty.setShortDescription("color for ambient light");
Expand All @@ -39,6 +43,14 @@ public EditorScreenBean(EditorScreen screen) {
this.screen = screen;
}

public Color getFogColor() {
return screen.level.env.skyColor;
}

public void setFogColor(Color newColor) {
screen.level.env.skyColor.set(newColor);
}

public String getTitle() {
return screen.level.state.getName();
}
Expand All @@ -52,15 +64,15 @@ public Color getSunLightColor() {
}

public void setSunLightColor(Color hexColor) {

screen.level.env.mainLight.color.set(hexColor);
}

public Color getAmbientLight() {
return screen.level.env.ambientLight;
}

public void setAmbientLight(Color hexColor) {

screen.level.env.ambientLight.set(hexColor);
}

public String getWindSpeed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void apply() {
}

public static class BrushType implements Disposable{
public static final int MAX_SIZE = 20;
public static final int MAX_SIZE = 60;
private final String name;
private ImageIcon imageIcon;
private Pixmap basePixmap;
Expand Down

0 comments on commit 17aab3d

Please sign in to comment.