gdx-studio

#libgdx#java#desktop

git clone https://git.pyrossh.dev/gdx-studio

An IDE for creating Games using libgdx and Java supported on all platforms Android, iOS, Desktop


src/gdxstudio/panel/SceneEffectPanel.java
a9b2a64 1
package gdxstudio.panel;
a9b2a64 2
a9b2a64 3
import java.awt.Component;
a62d533 4
import javax.swing.DefaultCellEditor;
a62d533 5
import javax.swing.JComboBox;
a9b2a64 6
import javax.swing.JTable;
a9b2a64 7
a9b2a64 8
import scene2d.Asset;
a9b2a64 9
import scene2d.Effect;
a9b2a64 10
import scene2d.EffectType;
a9b2a64 11
import scene2d.InterpolationType;
a9b2a64 12
import scene2d.Scene;
a62d533 13
a62d533 14
public class SceneEffectPanel extends BaseTable {
a62d533 15
	private static final long serialVersionUID = 1L;
a62d533 16
	
a62d533 17
	static JComboBox<String> bgComboBox = createComboBox();
a62d533 18
	static JComboBox<String> musicComboBox = createComboBox();
a62d533 19
	static JComboBox<String> transitionComboBox = createComboBox();
a62d533 20
	static JComboBox<String> interpolationComboBox = createComboBox();
a62d533 21
	
a62d533 22
	public SceneEffectPanel(){
a9b2a64 23
		super("Properties", null, new SceneEffectRenderer());
a62d533 24
		editors.add(new DefaultCellEditor(bgComboBox));
a62d533 25
		editors.add(new DefaultCellEditor(musicComboBox));
a62d533 26
		editors.add(new DefaultCellEditor(transitionComboBox));
a9b2a64 27
		editors.add(createFloatSpinner("Duration"));
a62d533 28
		editors.add(new DefaultCellEditor(interpolationComboBox));
a9b2a64 29
		for(EffectType effect: EffectType.values())
a9b2a64 30
			transitionComboBox.addItem(effect.toString());
a62d533 31
		for(InterpolationType interpolation: InterpolationType.values())
a62d533 32
			interpolationComboBox.addItem(interpolation.toString());
a62d533 33
	}
a62d533 34
	
a62d533 35
	@Override
a62d533 36
	public void clear(String... names){
a62d533 37
		super.clear("Background", "Music", "Transition", "Duration", "Interpolation");
a62d533 38
	}
a62d533 39
	
a62d533 40
	@Override
a62d533 41
	public void update(String... values){
a9b2a64 42
		Scene scene = Scene.getCurrentScene();
7c84877 43
		super.update("Background", scene.sceneBackground, "Music", scene.sceneMusic,
7c84877 44
				"Transition", scene.sceneTransition, "Duration", ""+scene.sceneDuration,
7c84877 45
				"Interpolation", scene.sceneInterpolationType.toString());
a62d533 46
		bgComboBox.removeAllItems();
a62d533 47
		musicComboBox.removeAllItems();
a62d533 48
		bgComboBox.addItem("None");
a62d533 49
		musicComboBox.addItem("None");
a62d533 50
		for(String tex: Asset.texMap.keys())
a62d533 51
			bgComboBox.addItem(tex);
a62d533 52
		for(String tex: Asset.musicMap.keys())
a62d533 53
			musicComboBox.addItem(tex);
a62d533 54
	}
a62d533 55
	
a62d533 56
	@Override
a62d533 57
	public void setProperty(String key, String value){
a62d533 58
		if(key.isEmpty() || value.isEmpty())
a62d533 59
			return ;
a9b2a64 60
		Scene scene = Scene.getCurrentScene();
a62d533 61
		switch(key){
a62d533 62
			case "Background": 
7c84877 63
				scene.sceneBackground = value;
7c84877 64
				if(!scene.sceneBackground.equals("None"))
a9b2a64 65
					Scene.getCurrentScene().setBackground(scene.sceneBackground);
a62d533 66
				else
a9b2a64 67
					Scene.getCurrentScene().removeBackground();
a62d533 68
				break;
a62d533 69
			case "Music": 
7c84877 70
				scene.sceneMusic = value;
7c84877 71
				if(!scene.sceneMusic.equals("None"))
7c84877 72
					Asset.musicPlay(scene.sceneMusic);
a62d533 73
				break;
a62d533 74
			case "Transition": 
7c84877 75
				scene.sceneTransition = value;
7c84877 76
				break;
a62d533 77
			case "Duration": 
7c84877 78
				scene.sceneDuration = Float.parseFloat(value);
a62d533 79
				break;
a62d533 80
			case "Interpolation":
7c84877 81
				scene.sceneInterpolationType = InterpolationType.valueOf(value);
a62d533 82
				break;
a62d533 83
		}
a9b2a64 84
		Effect.createEffect(Scene.getRoot(), EffectType.valueOf(scene.sceneTransition), 1f,
a9b2a64 85
				scene.sceneDuration, scene.sceneInterpolationType);
a9b2a64 86
		Scene.isDirty = true;
a62d533 87
	}
a9b2a64 88
}
a9b2a64 89
a9b2a64 90
class SceneEffectRenderer extends BaseRenderer {
a9b2a64 91
	private static final long serialVersionUID = 1L;
a9b2a64 92
a9b2a64 93
	@Override
a9b2a64 94
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
a9b2a64 95
        setBorder(noFocusBorder);
a9b2a64 96
        if(column == 0)
a9b2a64 97
        	return new HeaderLabel(value.toString());
a9b2a64 98
        else {
a9b2a64 99
        	if(row == 3){
a9b2a64 100
        		if(!value.toString().isEmpty())
a9b2a64 101
        			spinnerFloat.setValue(Float.parseFloat(value.toString()));
a9b2a64 102
        		else
a9b2a64 103
        			spinnerFloat.setValue(new Float(0.0));
a9b2a64 104
        		return spinnerFloat;
a9b2a64 105
            }
a9b2a64 106
        }
a9b2a64 107
        return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
a9b2a64 108
    }
a62d533 109
}