Skip to content

Commit a040da7

Browse files
committed
Group Animations [Base System]
1 parent bbe77e9 commit a040da7

File tree

12 files changed

+246
-15
lines changed

12 files changed

+246
-15
lines changed

keys.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"toggle_polygon_marker": 64,
1616
"toggle_polygon_count": 65,
1717
"toggle_lighting": 66,
18+
"toggle_animations": 67,
1819
"toggle_gametest": 68,
1920
"take_screenshot": 88,
2021
"toggle_editor_0": 2,

src/net/fexcraft/app/fmt/ui/Element.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public boolean select(){
7272
UserInterface.SELECTED = this; return true;
7373
}
7474

75+
public boolean deselect(){
76+
if(UserInterface.SELECTED == this) UserInterface.SELECTED = null; return true;
77+
}
78+
7579
public boolean isHovered(){
7680
return hovered;
7781
}

src/net/fexcraft/app/fmt/ui/editor/ContainerButton.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,25 @@ public ContainerButton(Element root, String id, int width, int height, int x, in
1515
super(root, id, width, height, x, y);
1616
this.setIcon("icons/editors/minimized", height - 2);
1717
this.setTexPosSize("ui/background_light", 0, 0, 64, 64);
18+
if(rowsizes != null){
19+
this.initRowData(rowsizes); this.addSubElements(); this.initHeight();
20+
}
21+
this.setExpanded(false); this.setBackgroundless(true);
22+
}
23+
24+
protected void initRowData(int[] rowsizes){
1825
this.rowsizes = rowsizes; rowheight = new int[rowsizes.length];
19-
int[] rowpass = new int[rowsizes.length]; this.addSubElements();
26+
}
27+
28+
protected void initHeight(){
29+
int[] rowpass = new int[rowsizes.length];
2030
elementheight = height + 2;
2131
for(Element elm : elements){
2232
if(rowpass[elm.row] < elm.height) rowpass[elm.row] = elm.height;
2333
}
2434
for(int i = 0; i < rowheight.length; i++){
2535
rowheight[i] = elementheight; elementheight += rowpass[i] + 4;
2636
}
27-
this.setExpanded(false); this.setBackgroundless(true);
2837
}
2938

3039
public abstract void addSubElements();

src/net/fexcraft/app/fmt/ui/editor/ModelGroupEditor.java

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@
66
import net.fexcraft.app.fmt.FMTB;
77
import net.fexcraft.app.fmt.ui.UserInterface;
88
import net.fexcraft.app.fmt.ui.general.Button;
9+
import net.fexcraft.app.fmt.ui.general.DialogBox;
910
import net.fexcraft.app.fmt.ui.general.NFC.AfterTask;
1011
import net.fexcraft.app.fmt.ui.general.NFC.ChooserMode;
1112
import net.fexcraft.app.fmt.ui.general.TextField;
13+
import net.fexcraft.app.fmt.utils.Animator;
14+
import net.fexcraft.app.fmt.utils.Animator.Animation;
1215
import net.fexcraft.app.fmt.utils.TextureManager;
1316
import net.fexcraft.app.fmt.utils.TextureUpdate;
1417
import net.fexcraft.app.fmt.wrappers.GroupCompound;
@@ -19,15 +22,15 @@
1922
public class ModelGroupEditor extends Editor {
2023

2124
private static final int[] accepted_texsiz = new int[]{ 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096 };//, 8192 };
22-
private ContainerButton group, model;
25+
private ContainerButton group, model, animations;
2326

2427
public ModelGroupEditor(){
2528
super("model_group_editor");
2629
}
2730

2831
@Override
2932
protected ContainerButton[] setupSubElements(){
30-
group = new ContainerButton(this, "group", 300, 28, 4, y, new int[]{ 1, 3, 1, 1, 1, 3, 1, 1 }){
33+
group = new ContainerButton(this, "group", 300, 28, 4, y, new int[]{ 1, 3, 1, 1, 1, 3, 1, 1, 1, 1 }){
3134
@Override
3235
public void addSubElements(){
3336
this.elements.add(new Button(this, "text0", 290, 20, 0, 0, RGB.WHITE).setText("Group Preview Color/Overlay", false).setRowCol(0, 0));
@@ -106,6 +109,39 @@ public void run(){
106109
}, ChooserMode.PNG); return true;
107110
}
108111
}.setText("null", true).setRowCol(7, 0));
112+
//
113+
this.elements.add(new Button(this, "text3", 290, 20, 0, 0, RGB.WHITE).setText("Add Animator", false).setRowCol(8, 0));
114+
this.elements.add(new TextField(this, "group_animator", 0, 0, 0){
115+
@Override
116+
protected boolean processButtonClick(int x, int y, boolean left){
117+
if(FMTB.MODEL.getSelected().isEmpty()) return true;
118+
if(!left){
119+
FMTB.showDialogbox(this.getText(), "test", null, DialogBox.NOTHING, null);
120+
this.setText("", true);
121+
return true;
122+
}
123+
else return super.processButtonClick(x, y, left);
124+
}
125+
@Override
126+
public void updateTextField(){
127+
this.deselect(); if(FMTB.MODEL.getSelected().isEmpty()) return;
128+
Animation anim = Animator.get(this.getTextValue());
129+
if(anim == null){
130+
FMTB.showDialogbox("Animation not found!", "ok", null, DialogBox.NOTHING, null);
131+
return;
132+
} anim.copy();
133+
ArrayList<TurboList> lists = FMTB.MODEL.getDirectlySelectedGroups();
134+
AfterTask task = new AfterTask(){
135+
@Override
136+
public void run(){
137+
for(TurboList list : lists){
138+
list.animations.add(anim.copy());
139+
} FMTB.MODEL.updateFields();
140+
}
141+
}; task.settings = anim.settings;
142+
UserInterface.SETTINGSBOX.show("Animator Settings", task);
143+
}
144+
}.setText("null", true).setRowCol(9, 0));
109145
}
110146
};
111147
group.setText("Group Settings", false);
@@ -159,7 +195,37 @@ public void run(){
159195
}
160196
};
161197
model.setText("Model Settings", false);
162-
return new ContainerButton[]{ model, group };
198+
animations = new ContainerButton(this, "animations", 300, 28, 4, y, null){
199+
@Override
200+
public void addSubElements(){
201+
this.elements.clear(); TurboList list = FMTB.MODEL.getFirstSelectedGroup();
202+
int[] rows = new int[list == null ? 1 : list.animations.size() + 1];
203+
for(int i = 0; i < rows.length; i++) rows[i] = 1; this.initRowData(rows);
204+
if(list == null){ return; }
205+
for(int i = 0; i < rows.length - 1; i++){ int j = i;
206+
this.elements.add(new TextField(this, "group_animation_" + i, 0, 0, 0) {
207+
@Override
208+
protected boolean processButtonClick(int x, int y, boolean left){
209+
if(left){
210+
Animation anim = list.animations.get(j); this.deselect();
211+
FMTB.MODEL.updateFields(); if(anim == null) return true;
212+
AfterTask task = new AfterTask(){
213+
@Override public void run(){ FMTB.MODEL.updateFields(); }
214+
}; task.settings = anim.settings; UserInterface.SETTINGSBOX.reset();
215+
UserInterface.SETTINGSBOX.show("[" + anim.id + "] Settings", task);
216+
}
217+
else{
218+
list.animations.remove(j); this.deselect(); FMTB.MODEL.updateFields();
219+
}
220+
return true;
221+
}
222+
}.setText("[" + i + "] " + list.animations.get(i).id, true).setRowCol(i + 1, 0));
223+
}
224+
this.initHeight(); return;
225+
}
226+
};
227+
animations.setText("Group Animations", false);
228+
return new ContainerButton[]{ model, group, animations };
163229
}
164230

165231
protected boolean updateRGB(Boolean apply, int j){

src/net/fexcraft/app/fmt/ui/general/SettingsBox.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class SettingsBox extends Element implements Dialog {
2424
private String alttext = "FMT Settings";
2525
private ArrayList<Setting> settings = new ArrayList<>();
2626
//
27-
private Button Confirm;
27+
private Button Confirm, Cancel;
2828
private AfterTask task;
2929

3030
public SettingsBox(){
@@ -33,18 +33,22 @@ public SettingsBox(){
3333
TextureManager.loadTexture("ui/settingsbox", null);
3434
this.setTexPosSize("ui/settingsbox", 0, 0, 512, 256);
3535
//
36-
this.elements.add(Confirm = new Button(this, "confirm", 120, 20, 0, 0, new RGB(255, 255, 0)){
37-
@Override protected boolean processButtonClick(int x, int y, boolean left){
38-
task.run(); reset(); return true;
39-
}
36+
this.elements.add(Confirm = new Button(this, "confirm", 100, 20, 0, 0, new RGB(255, 255, 0)){
37+
@Override protected boolean processButtonClick(int x, int y, boolean left){ task.run(); reset(); return true; }
4038
}.setText("Confirm", true));
39+
this.elements.add(Cancel = new Button(this, "cancel", 100, 20, 0, 0, new RGB(255, 255, 0)){
40+
@Override protected boolean processButtonClick(int x, int y, boolean left){ reset(); return true; }
41+
}.setText("Cancel", true));
4142
}
4243

4344
@Override
4445
public void renderSelf(int rw, int rh) {
4546
x = (rw / 2) - (width / 2); y = (rh / 2) - (height / 2); this.renderSelfQuad();
4647
FontRenderer.drawText(alttext + " [Page: " + (page + 1) + "/" + (settings.size() / perpage + 1) + "]", this.x + 12, this.y + 12, 1);
47-
if(Confirm.isVisible()){ Confirm.x = x + width - Confirm.width - 12; Confirm.y = y + 12; }
48+
if(Confirm.isVisible()){
49+
Confirm.x = x + width - Confirm.width - 12; Confirm.y = y + 12;
50+
Cancel.x = x + width - Confirm.width - 14 - Cancel.width; Cancel.y = y + 12;
51+
}
4852
for(int i = 0; i < perpage; i++){
4953
int j = (page * perpage) + i; if(j >= settings.size()) break; Setting setting = settings.get(j);
5054
FontRenderer.drawText("[" + j + "] " + setting.getId(), this.x + 12, this.y + 40 + (i * 30), 1);
@@ -59,7 +63,7 @@ public boolean onScrollWheel(int wheel){
5963
}
6064

6165
private void updateFields(){
62-
this.elements.removeIf(pre -> !pre.id.equals("confirm"));
66+
this.elements.removeIf(pre -> !(pre.id.equals("confirm") || pre.id.equals("cancel")));
6367
for(int i = 0; i < perpage; i++){
6468
int j = (page * perpage) + i; if(j >= settings.size()) break;
6569
Setting setting = settings.get(j);
@@ -129,7 +133,8 @@ public boolean visible(){
129133

130134
public void show(Object... objects){
131135
if(objects != null && objects.length >= 2){
132-
this.alttext = (String)objects[0]; this.task = (AfterTask)objects[1]; Confirm.setVisible(true);
136+
this.alttext = (String)objects[0]; this.task = (AfterTask)objects[1];
137+
Confirm.setVisible(true); Cancel.setVisible(true);
133138
this.settings.addAll(task.settings);
134139
}
135140
else{
@@ -142,7 +147,7 @@ public void show(Object... objects){
142147
@Override
143148
public void reset(){
144149
this.visible = false; this.elements.removeIf(pre -> !pre.id.equals("confirm"));
145-
this.Confirm.setVisible(false); this.settings.clear();
150+
this.Confirm.setVisible(false); this.Cancel.setVisible(false); this.settings.clear();
146151
}
147152

148153
}

src/net/fexcraft/app/fmt/ui/general/TextField.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,11 @@ public int getIntegerValue(){
190190
public boolean isSelected(){
191191
return selected;
192192
}
193+
194+
@Override
195+
public boolean deselect(){
196+
super.deselect(); this.selected = false; return true;
197+
}
193198

194199
public TextField setColor(String string, RGB rgb){
195200
switch(string){
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package net.fexcraft.app.fmt.utils;
2+
3+
import java.util.Arrays;
4+
import java.util.HashSet;
5+
import java.util.List;
6+
import java.util.Set;
7+
import net.fexcraft.app.fmt.utils.Settings.Setting;
8+
import net.fexcraft.app.fmt.utils.Settings.Type;
9+
import net.fexcraft.app.fmt.wrappers.PolygonWrapper;
10+
import net.fexcraft.app.fmt.wrappers.TurboList;
11+
12+
public class Animator {
13+
14+
public static final HashSet<Animation> nani = new HashSet<>();
15+
static {
16+
nani.add(new Rotator("rotator", new Setting(Type.FLOAT, "x", 0f), new Setting(Type.FLOAT, "y", 0f), new Setting(Type.FLOAT, "z", 0f)));
17+
}
18+
19+
public static abstract class Animation {
20+
21+
public final String id;
22+
public final List<Setting> settings;
23+
24+
public Animation(String id, Setting... settings){
25+
this.id = id; this.settings = Arrays.asList(settings);
26+
}
27+
28+
public abstract void pre(TurboList list);
29+
public abstract void post(TurboList list);
30+
protected abstract Animation COPY(String id, Setting[] settings);
31+
32+
public Animation copy(){
33+
Setting[] settings = new Setting[this.settings.size()];
34+
for(int i = 0; i < settings.length; i++) settings[i] = this.settings.get(i).copy();
35+
return this.COPY(id, settings);
36+
}
37+
38+
}
39+
40+
public static Set<Animation> get(){
41+
return nani;
42+
}
43+
44+
public static Animation get(String string){
45+
for(Animation ani : nani) if(ani.id.equals(string)) return ani; return null;
46+
}
47+
48+
public static class Rotator extends Animation {
49+
50+
private Setting x, y, z;
51+
52+
public Rotator(String id, Setting... settings){
53+
super(id, settings); x = settings[0]; y = settings[1]; z = settings[2];
54+
}
55+
56+
@Override
57+
public void pre(TurboList list){
58+
for(PolygonWrapper wrap : list){
59+
wrap.addPosRot(false, x.getValue(), y.getValue(), z.getValue());
60+
}
61+
}
62+
63+
@Override
64+
public void post(TurboList list){
65+
//
66+
}
67+
68+
@Override
69+
protected Animation COPY(String id, Setting[] settings){
70+
return new Rotator(id, settings);
71+
}
72+
73+
}
74+
75+
}

src/net/fexcraft/app/fmt/utils/KeyCompound.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ public boolean process(){
5959
keys.add(new KeyFunction("toggle_lighting", Keyboard.KEY_F8, true){
6060
@Override public boolean process(){ Settings.toggleLighting(); return true; }
6161
});
62+
keys.add(new KeyFunction("toggle_animations", Keyboard.KEY_F9, true){
63+
@Override public boolean process(){ Settings.toggleAnimations(); return true; }
64+
});
6265
//
6366
keys.add(new KeyFunction("toggle_gametest", Keyboard.KEY_F10, true){
6467
@Override public boolean process(){ FMTB.GAMETEST = !FMTB.GAMETEST; return true; }

src/net/fexcraft/app/fmt/utils/Settings.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
import com.google.gson.JsonPrimitive;
1010

1111
import net.fexcraft.app.fmt.FMTB;
12+
import net.fexcraft.app.fmt.wrappers.PolygonWrapper;
13+
import net.fexcraft.app.fmt.wrappers.TurboList;
1214
import net.fexcraft.lib.common.json.JsonUtil;
1315
import net.fexcraft.lib.common.math.RGB;
1416
import net.fexcraft.lib.common.math.Time;
@@ -22,7 +24,7 @@ public class Settings {
2224
static{ background_color.alpha = 0.2f; }
2325
public static float[] light0_position = new float[]{ 0, 1, 0, 0 };
2426
private static String language = "default";*/
25-
private static Setting floor, lines, demo, cube, polygon_marker, polygon_count, lighting, cullface;
27+
private static Setting floor, lines, demo, cube, polygon_marker, polygon_count, lighting, cullface, animate;
2628

2729
public static boolean floor(){ return floor.getValue(); }
2830

@@ -40,6 +42,8 @@ public class Settings {
4042

4143
public static boolean cullface(){ return cullface.getValue(); }
4244

45+
public static boolean animate(){ return animate.getValue(); }
46+
4347
//
4448

4549
public static boolean toggleFloor(){
@@ -83,6 +87,15 @@ public static float[] getLight0Position(){
8387
return SETTINGS.get("light0_position").getValue();
8488
}
8589

90+
public static boolean toggleAnimations(){
91+
boolean bool = animate.toggle();
92+
if(!bool){
93+
for(TurboList list : FMTB.MODEL.getCompound().values())
94+
for(PolygonWrapper wrapper : list) wrapper.resetPosRot();
95+
}
96+
return bool;
97+
}
98+
8699
//
87100

88101
public static SettingsMap DEFAULTS = new SettingsMap(), SETTINGS = new SettingsMap();
@@ -99,6 +112,7 @@ public static float[] getLight0Position(){
99112
DEFAULTS.add(new Setting(Type.FLOAT_ARRAY, "light0_position", new float[]{ 0, 1, 0, 0 }));
100113
DEFAULTS.add(new Setting(Type.STRING, "language_code", "default"));
101114
DEFAULTS.add(new Setting(Type.BOOLEAN, "cullface", true));
115+
DEFAULTS.add(new Setting(Type.BOOLEAN, "animate", false));
102116
}
103117

104118
public static void load(){
@@ -127,6 +141,7 @@ public static void load(){
127141
polygon_count = SETTINGS.get("polygon_count");
128142
lighting = SETTINGS.get("lighting");
129143
cullface = SETTINGS.get("cullface");
144+
animate = SETTINGS.get("animate");
130145
}
131146

132147
public static void save(){
@@ -328,6 +343,10 @@ public JsonElement save(){
328343
public boolean getBooleanValue(){
329344
if(this.getType().isBoolean()) return (boolean)value; return false;
330345
}
346+
347+
public Setting copy(){
348+
return new Setting(type, id, value);
349+
}
331350

332351
}
333352

0 commit comments

Comments
 (0)