Skip to content

Commit

Permalink
Improved Animations, Shift Input & Cubic Markers
Browse files Browse the repository at this point in the history
  • Loading branch information
Fexcraft committed Jun 5, 2019
1 parent 9251fd1 commit 3fa3b96
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 37 deletions.
15 changes: 7 additions & 8 deletions src/net/fexcraft/app/fmt/ui/editor/ModelGroupEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public void run(){
protected boolean processButtonClick(int x, int y, boolean left){
if(FMTB.MODEL.getSelected().isEmpty()) return true;
if(!left){
FMTB.showDialogbox(this.getText(), "test", null, DialogBox.NOTHING, null);
FMTB.showDialogbox(this.getText(), "ok", null, DialogBox.NOTHING, null);
this.setText("", true);
return true;
}
Expand All @@ -129,16 +129,16 @@ public void updateTextField(){
if(anim == null){
FMTB.showDialogbox("Animation not found!", "ok", null, DialogBox.NOTHING, null);
return;
} anim.copy();
} final Animation ani = anim.copy();
ArrayList<TurboList> lists = FMTB.MODEL.getDirectlySelectedGroups();
AfterTask task = new AfterTask(){
@Override
public void run(){
for(TurboList list : lists){
list.animations.add(anim.copy());
list.animations.add(ani);
} FMTB.MODEL.updateFields();
}
}; task.settings = anim.settings;
}; task.settings = ani.settings;
UserInterface.SETTINGSBOX.show("Animator Settings", task);
}
}.setText("null", true).setRowCol(9, 0));
Expand Down Expand Up @@ -207,11 +207,10 @@ public void addSubElements(){
@Override
protected boolean processButtonClick(int x, int y, boolean left){
if(left){
Animation anim = list.animations.get(j); this.deselect();
FMTB.MODEL.updateFields(); if(anim == null) return true;
Animation anim = list.animations.get(j); this.deselect(); if(anim == null) return true;
AfterTask task = new AfterTask(){
@Override public void run(){ FMTB.MODEL.updateFields(); }
}; task.settings = anim.settings; UserInterface.SETTINGSBOX.reset();
@Override public void run(){ anim.onSettingsUpdate(); FMTB.MODEL.updateFields(); }
}; task.settings = anim.settings; FMTB.MODEL.updateFields();
UserInterface.SETTINGSBOX.show("[" + anim.id + "] Settings", task);
}
else{
Expand Down
4 changes: 2 additions & 2 deletions src/net/fexcraft/app/fmt/ui/general/SettingsBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ public void show(Object... objects){

@Override
public void reset(){
this.visible = false; this.elements.removeIf(pre -> !pre.id.equals("confirm"));
this.Confirm.setVisible(false); this.Cancel.setVisible(false); this.settings.clear();
this.visible = false; this.elements.removeIf(pre -> !(pre.id.equals("confirm") || pre.id.equals("cancel")));
this.Confirm.setVisible(false); this.Cancel.setVisible(false); this.settings.clear(); this.updateFields();
}

}
126 changes: 110 additions & 16 deletions src/net/fexcraft/app/fmt/utils/Animator.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import net.fexcraft.app.fmt.utils.Settings.Setting;
import net.fexcraft.app.fmt.utils.Settings.Type;
import net.fexcraft.app.fmt.wrappers.PolygonWrapper;
Expand All @@ -13,11 +14,15 @@ public class Animator {

public static final HashSet<Animation> nani = new HashSet<>();
static {
nani.add(new Rotator("rotator", new Setting(Type.FLOAT, "x", 0f), new Setting(Type.FLOAT, "y", 0f), new Setting(Type.FLOAT, "z", 0f)));
nani.add(new Rotator("rotator", new Setting(Type.FLOAT, "x", 0f), new Setting(Type.FLOAT, "y", 0f), new Setting(Type.FLOAT, "z", 0f),
new Setting(Type.FLOAT, "x_min", -360f), new Setting(Type.FLOAT, "y_min", -360f), new Setting(Type.FLOAT, "z_min", -360f),
new Setting(Type.FLOAT, "x_max", 360f), new Setting(Type.FLOAT, "y_max", 360f), new Setting(Type.FLOAT, "z_max", 360f),
new Setting(Type.BOOLEAN, "loop", true), new Setting(Type.BOOLEAN, "opposite_on_end", false)));
nani.add(new Translator("translator", new Setting(Type.FLOAT, "x", 0f), new Setting(Type.FLOAT, "y", 0f), new Setting(Type.FLOAT, "z", 0f),
new Setting(Type.FLOAT, "x_min",-1f), new Setting(Type.FLOAT, "y_min", -1f), new Setting(Type.FLOAT, "z_min", -1f),
new Setting(Type.FLOAT, "x_max", 1f), new Setting(Type.FLOAT, "y_max", 1f), new Setting(Type.FLOAT, "z_max", 1f),
new Setting(Type.BOOLEAN, "loop", true)));
new Setting(Type.BOOLEAN, "loop", true), new Setting(Type.BOOLEAN, "opposite_on_end", false)));
//nani.add(new Transparency("glass", new Setting(Type.RGB, "color", RGB.BLUE)));
}

public static abstract class Animation {
Expand All @@ -32,6 +37,7 @@ public Animation(String id, Setting... settings){
public abstract void pre(TurboList list);
public abstract void post(TurboList list);
protected abstract Animation COPY(String id, Setting[] settings);
public void onSettingsUpdate(){}

public Animation copy(){
Setting[] settings = new Setting[this.settings.size()];
Expand All @@ -43,6 +49,10 @@ public Setting get(String id, Setting[] list){
for(Setting setting : list) if(setting.getId().equals(id)) return setting; return null;
}

public Setting get(String id, Iterable<Setting> list){
for(Setting setting : list) if(setting.getId().equals(id)) return setting; return null;
}

}

public static Set<Animation> get(){
Expand All @@ -55,22 +65,53 @@ public static Animation get(String string){

public static class Rotator extends Animation {

private Setting x, y, z;
private Setting x, y, z, x_max, y_max, z_max, x_min, y_min, z_min, loop, ooe;
private int xdir = 1, ydir = 1, zdir = 1; private float xpass, ypass, zpass;

public Rotator(String id, Setting... settings){
super(id, settings); x = get("x", settings); y = get("y", settings); z = get("z", settings);
x_min = get("x_min", settings); y_min = get("y_min", settings); z_min = get("z_min", settings);
x_max = get("x_max", settings); y_max = get("y_max", settings); z_max = get("z_max", settings);
loop = get("loop", settings); ooe = get("opposite_on_end", settings);
}

@Override
public void pre(TurboList list){
for(PolygonWrapper wrap : list){
wrap.addPosRot(false, x.getValue(), y.getValue(), z.getValue());
xpass += xdir * x.getFloatValue(); ypass += ydir * y.getFloatValue(); zpass += zdir * z.getFloatValue();
//
if(xpass > x_max.getFloatValue()){
xpass = x_max.getFloatValue(); if(ooe.getBooleanValue()) xdir = -xdir;
if(loop.getBooleanValue()) xpass = x_min.getFloatValue();
}
if(xpass < x_min.getFloatValue()){
xpass = x_min.getFloatValue(); if(ooe.getBooleanValue()) xdir = -xdir;
if(loop.getBooleanValue()) xpass = x_max.getFloatValue();
}
//
if(ypass > y_max.getFloatValue()){
ypass = y_max.getFloatValue(); if(ooe.getBooleanValue()) ydir = -ydir;
if(loop.getBooleanValue()) ypass = y_min.getFloatValue();
}
if(ypass < y_min.getFloatValue()){
ypass = y_min.getFloatValue(); if(ooe.getBooleanValue()) ydir = -ydir;
if(loop.getBooleanValue()) ypass = y_max.getFloatValue();
}
//
if(zpass > z_max.getFloatValue()){
zpass = z_max.getFloatValue(); if(ooe.getBooleanValue()) zdir = -zdir;
if(loop.getBooleanValue()) zpass = z_min.getFloatValue();
}
if(zpass < z_min.getFloatValue()){
zpass = z_min.getFloatValue(); if(ooe.getBooleanValue()) zdir = -zdir;
if(loop.getBooleanValue()) zpass = z_max.getFloatValue();
}
//
for(PolygonWrapper wrap : list){ wrap.addPosRot(false, xpass, ypass, zpass); }
}

@Override
public void post(TurboList list){
//
for(PolygonWrapper wrap : list){ wrap.addPosRot(false, -xpass, -ypass, -zpass); }
}

@Override
Expand All @@ -82,29 +123,46 @@ protected Animation COPY(String id, Setting[] settings){

public static class Translator extends Animation {

private Setting x, y, z, x_max, y_max, z_max, x_min, y_min, z_min, loop;
private Setting x, y, z, x_max, y_max, z_max, x_min, y_min, z_min, loop, ooe;
private int xdir = 1, ydir = 1, zdir = 1; private float xpass, ypass, zpass;

public Translator(String id, Setting... settings){
super(id, settings);
x = get("x", settings); y = get("y", settings); z = get("z", settings);
super(id, settings); x = get("x", settings); y = get("y", settings); z = get("z", settings);
x_min = get("x_min", settings); y_min = get("y_min", settings); z_min = get("z_min", settings);
x_max = get("x_max", settings); y_max = get("y_max", settings); z_max = get("z_max", settings);
loop = get("loop", settings);
loop = get("loop", settings); ooe = get("opposite_on_end", settings);
}

@Override
public void pre(TurboList list){
xpass += xdir * x.getFloatValue(); ypass += ydir * y.getFloatValue(); zpass += zdir * z.getFloatValue();
//
if(xpass > x_max.getFloatValue()){ xpass = x_max.getFloatValue(); if(loop.getBooleanValue()) xdir = -xdir; }
if(xpass < x_min.getFloatValue()){ xpass = x_min.getFloatValue(); if(loop.getBooleanValue()) xdir = -xdir; }
if(xpass > x_max.getFloatValue()){
xpass = x_max.getFloatValue(); if(ooe.getBooleanValue()) xdir = -xdir;
if(loop.getBooleanValue()) xpass = x_min.getFloatValue();
}
if(xpass < x_min.getFloatValue()){
xpass = x_min.getFloatValue(); if(ooe.getBooleanValue()) xdir = -xdir;
if(loop.getBooleanValue()) xpass = x_max.getFloatValue();
}
//
if(ypass > y_max.getFloatValue()){ ypass = y_max.getFloatValue(); if(loop.getBooleanValue()) ydir = -ydir; }
if(ypass < y_min.getFloatValue()){ ypass = y_min.getFloatValue(); if(loop.getBooleanValue()) ydir = -ydir; }
if(ypass > y_max.getFloatValue()){
ypass = y_max.getFloatValue(); if(ooe.getBooleanValue()) ydir = -ydir;
if(loop.getBooleanValue()) ypass = y_min.getFloatValue();
}
if(ypass < y_min.getFloatValue()){
ypass = y_min.getFloatValue(); if(ooe.getBooleanValue()) ydir = -ydir;
if(loop.getBooleanValue()) ypass = y_max.getFloatValue();
}
//
if(zpass > z_max.getFloatValue()){ zpass = z_max.getFloatValue(); if(loop.getBooleanValue()) zdir = -zdir; }
if(zpass < z_min.getFloatValue()){ zpass = z_min.getFloatValue(); if(loop.getBooleanValue()) zdir = -zdir; }
if(zpass > z_max.getFloatValue()){
zpass = z_max.getFloatValue(); if(ooe.getBooleanValue()) zdir = -zdir;
if(loop.getBooleanValue()) zpass = z_min.getFloatValue();
}
if(zpass < z_min.getFloatValue()){
zpass = z_min.getFloatValue(); if(ooe.getBooleanValue()) zdir = -zdir;
if(loop.getBooleanValue()) zpass = z_max.getFloatValue();
}
//
for(PolygonWrapper wrap : list){ wrap.addPosRot(true, xpass, ypass, zpass); }
}
Expand All @@ -120,5 +178,41 @@ protected Animation COPY(String id, Setting[] settings){
}

}

/*public static class Transparency extends Animation {
private RGB color;
public Transparency(String id, Setting... settings){
super(id, settings); this.onSettingsUpdate();
}
@Override
public void pre(TurboList list){
GL11.glPushMatrix();
GL11.glDepthMask(false);
GL11.glEnable(GL11.GL_ALPHA_TEST);
color.glColorApply();
}
@Override
public void post(TurboList list){
RGB.glColorReset();
GL11.glDisable(GL11.GL_ALPHA_TEST);
GL11.glDepthMask(true);
GL11.glPopMatrix();
}
@Override
protected Animation COPY(String id, Setting[] settings){
return new Transparency(id, settings);
}
@Override
public void onSettingsUpdate(){
color = get("color", settings).getValue(); color.alpha = 0.2f;
}
}*/

}
18 changes: 16 additions & 2 deletions src/net/fexcraft/app/fmt/utils/GGR.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,17 @@ private void acceptInputKeyboard(){
}

private String getKeyName(int i){
return GGR.isShiftDown() ? Keyboard.getKeyName(i) : Keyboard.getKeyName(i).toLowerCase();
return GGR.isShiftDown() ? i < 12 ? getSpecialChar(i) : Keyboard.getKeyName(i) : Keyboard.getKeyName(i).toLowerCase();
}

private String getSpecialChar(int i){
switch(i){
case 2: return "!"; case 3: return "@";
case 4: return "#"; case 5: return "$";
case 6: return "%"; case 7: return "^";
case 8: return "&"; case 9: return "*";
case 10: return "("; case 11: return ")";
} return Keyboard.getKeyName(i);
}

private boolean clickedL, clickedR, panning;
Expand Down Expand Up @@ -213,7 +223,11 @@ else if(panning){
}

public static boolean isShiftDown(){
return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
return Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_FUNCTION);
}

public static boolean iControlDown(){
return Keyboard.isKeyDown(Keyboard.KEY_LCONTROL) || Keyboard.isKeyDown(Keyboard.KEY_RCONTROL);
}

}
8 changes: 4 additions & 4 deletions src/net/fexcraft/app/fmt/utils/HelperCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public static final GroupCompound load(File file, ExImPorter exim, Map<String, S
if(exim.isInternal()){
GroupCompound compound = ((InternalPorter)exim).importModel(file, settings);
if(!compound.name.startsWith("import/")){ compound.name = "import/" + compound.name; }
LOADED.add(compound); return compound;
LOADED.add(compound); compound.deselectAll(); return compound;
}
else{
try{
Invocable inv = (Invocable)((ExternalPorter)exim).eval();
String result = (String)inv.invokeFunction("importModel", file);
GroupCompound compound = SaveLoad.getModel(file, JsonUtil.getObjectFromString(result), false);
if(!compound.name.startsWith("import/")){ compound.name = "import/" + compound.name; }
LOADED.add(compound); return compound;
LOADED.add(compound); compound.deselectAll(); return compound;
}
catch(FileNotFoundException | ScriptException | NoSuchMethodException e){
e.printStackTrace(); return null;
Expand Down Expand Up @@ -81,7 +81,7 @@ public static GroupCompound loadFMTB(File file){
FMTB.showDialogbox("Errors occured\nwhile parsing save file", "ok", null, DialogBox.NOTHING, null);
}
if(compound != null){ LOADED.add(compound); }
return compound;
compound.deselectAll(); return compound;
}

public static GroupCompound loadFrame(File file){
Expand Down Expand Up @@ -126,7 +126,7 @@ public static GroupCompound loadFrame(File file){
FMTB.showDialogbox("Errors occured\nwhile creating frame.", "ok", null, DialogBox.NOTHING, null);
}
if(compound != null){ LOADED.add(compound); }
return compound;
compound.deselectAll(); return compound;
}

}
1 change: 1 addition & 0 deletions src/net/fexcraft/app/fmt/utils/SaveLoad.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ public static GroupCompound getModel(File from, JsonObject obj, boolean ggr){
for(JsonElement elm : arr){
JsonObject animjsn = elm.getAsJsonObject();
Animation anim = Animator.get(animjsn.get("id").getAsString());
if(anim == null) continue; anim = anim.copy();
JsonArray settin = animjsn.get("settings").getAsJsonArray();
for(JsonElement elm0 : settin){
JsonObject sett = elm0.getAsJsonObject();
Expand Down
8 changes: 7 additions & 1 deletion src/net/fexcraft/app/fmt/utils/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.google.gson.JsonPrimitive;

import net.fexcraft.app.fmt.FMTB;
import net.fexcraft.app.fmt.wrappers.GroupCompound;
import net.fexcraft.app.fmt.wrappers.PolygonWrapper;
import net.fexcraft.app.fmt.wrappers.TurboList;
import net.fexcraft.lib.common.json.JsonUtil;
Expand Down Expand Up @@ -92,6 +93,11 @@ public static boolean toggleAnimations(){
if(!bool){
for(TurboList list : FMTB.MODEL.getCompound().values())
for(PolygonWrapper wrapper : list) wrapper.resetPosRot();
for(GroupCompound compound : HelperCollector.LOADED){
for(TurboList list : compound.getCompound().values()){
for(PolygonWrapper wrapper : list) wrapper.resetPosRot();
}
}
}
return bool;
}
Expand Down Expand Up @@ -349,7 +355,7 @@ public float getFloatValue(){
}

public Setting copy(){
return new Setting(type, id, value);
return new Setting(type.name(), id, save());
}

}
Expand Down
4 changes: 4 additions & 0 deletions src/net/fexcraft/app/fmt/wrappers/GroupCompound.java
Original file line number Diff line number Diff line change
Expand Up @@ -627,4 +627,8 @@ public PolygonWrapper getLastSelected(){
public int tx(TurboList list){ return list == null || list.getGroupTexture() == null ? textureSizeX : list.textureX; }
public int ty(TurboList list){ return list == null || list.getGroupTexture() == null ? textureSizeY : list.textureY; }

public void deselectAll(){
for(TurboList list : compound.values()){ list.selected = false; for(PolygonWrapper wrapper : list) wrapper.selected = false; }
}

}
4 changes: 1 addition & 3 deletions src/net/fexcraft/app/fmt/wrappers/PolygonWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public abstract class PolygonWrapper {

protected static final ModelRendererTurbo rotmarker = new ModelRendererTurbo(null, 0, 0, 16, 16).addSphere(0, 0, 0, 0.5f, 8, 8, 0, 0).setTextured(false).setColor(Settings.getSelectedColor());
protected static final ModelRendererTurbo rotmarker = new ModelRendererTurbo(null, 0, 0, 16, 16).addBox(-.25f, -.25f, -.25f, .5f, .5f, .5f).setTextured(false).setColor(Settings.getSelectedColor());
private static final ModelRendererTurbo something = new ModelRendererTurbo(null, 0, 0, 16, 16).setTextured(false);
//
public Vec3f pos = new Vec3f(), off = new Vec3f(), rot = new Vec3f();
Expand Down Expand Up @@ -49,10 +49,8 @@ public void renderLines(boolean rotXb, boolean rotYb, boolean rotZb){
//if(Settings.lines()) (selected ? sellines : lines).render();
GL11.glDisable(GL11.GL_TEXTURE_2D);
if((selected || turbolist.selected) && Settings.polygonMarker()){
if(Settings.cullface()) GL11.glDisable(GL11.GL_CULL_FACE);
rotmarker.setRotationPoint(lines.rotationPointX, lines.rotationPointY, lines.rotationPointZ);
rotmarker.render();
if(Settings.cullface()) GL11.glEnable(GL11.GL_CULL_FACE);
}
if(Settings.lines()){
if(selected || turbolist.selected){
Expand Down
Loading

0 comments on commit 3fa3b96

Please sign in to comment.