Skip to content

Commit

Permalink
pop up
Browse files Browse the repository at this point in the history
  • Loading branch information
rpereira committed Jan 6, 2018
1 parent 8a2d7ce commit 4279d96
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,8 @@ public static final Color dialogPickColor() {
if (value == null) {
return (null);
}
System.out.println(value);
int colorInt = 0xFF000000 | Integer.parseInt(value.replace("#", ""), 16);
Color color = new Color(colorInt);
return (color);
}

// TODO : more tiny fd dialogs
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ public final void setName(Object value) {

/** add a value to the spinner */
public final Object remove(Object value) {
if (!this.values.remove(value)) {
return (false);
}
this.valuesNames.remove(value);
return (value);
return (this.remove(this.values.indexOf(value)));
}

public final Object remove(int index) {
Expand All @@ -103,8 +99,8 @@ public final Object remove(int index) {
}

/**
* sort the spinner, keep the selected object as selected (meaning sorting
* may changes picked index)
* sort the spinner, keep the selected object as selected (meaning sorting may
* changes picked index)
*/
public final void sort(Comparator<Object> comparator) {
Object picked = this.getPickedObject();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@

package com.grillecube.client.renderer.model.editor.gui;

import com.grillecube.client.renderer.gui.components.GuiButton;
import com.grillecube.client.renderer.gui.components.GuiLabel;
import com.grillecube.client.renderer.gui.components.GuiText;
import com.grillecube.client.renderer.gui.components.GuiWindow;
import com.grillecube.client.renderer.gui.components.parameters.GuiParameter;
import com.grillecube.client.renderer.gui.components.parameters.GuiTextParameterTextCenterBox;
import com.grillecube.client.renderer.gui.components.parameters.GuiTextParameterTextFillBox;
import com.grillecube.client.renderer.gui.event.GuiEventPress;
import com.grillecube.client.renderer.gui.event.GuiListener;
import com.grillecube.common.utils.Color;

public class GuiPopUp extends GuiWindow {

private final GuiLabel info;
private final GuiButton confirm;
private final GuiButton cancel;

/**
* the callback can be null, then no action is done on confirmed or cancelled
*/
public GuiPopUp(@SuppressWarnings("rawtypes") GuiPopUpCallback callback) {
super();

super.setBox(0.3f, 0.3f, 0.4f, 0.4f, 0.0f);

GuiParameter<GuiText> txtSize = new GuiTextParameterTextFillBox(0.75f);
GuiParameter<GuiText> txtCenter = new GuiTextParameterTextCenterBox();

float w = 0.2f;
float h = w / 1.6f;

this.info = new GuiLabel();
this.info.setBox(0.0f, 0.8f, 1.0f, h, 0.0f);
this.info.setFontColor(Color.WHITE);
this.info.addTextParameter(txtSize);
this.info.addTextParameter(txtCenter);
this.info.setText("Pop up");
this.addChild(info);

this.confirm = new GuiButton();
this.confirm.setText("Confirm");
this.confirm.addTextParameter(txtSize);
this.confirm.addTextParameter(txtCenter);
this.confirm.setBox(0.25f, 0.15f, w, h, 0.0f);
this.addChild(this.confirm);
this.confirm.addListener(new GuiListener<GuiEventPress<GuiButton>>() {
@SuppressWarnings("unchecked")
@Override
public void invoke(GuiEventPress<GuiButton> event) {
if (callback != null) {
callback.onConfirm(GuiPopUp.this);
}
close();
}
});

this.cancel = new GuiButton();
this.cancel.setText("Decline");
this.cancel.setBox(0.55f, 0.15f, w, h, 0.0f);
this.cancel.addTextParameter(txtSize);
this.cancel.addTextParameter(txtCenter);
this.cancel.addListener(new GuiListener<GuiEventPress<GuiButton>>() {
@SuppressWarnings("unchecked")
@Override
public void invoke(GuiEventPress<GuiButton> event) {
if (callback != null) {
callback.onCancel(GuiPopUp.this);
}
close();
}
});
this.addChild(this.cancel);
}

protected final GuiLabel getInfoText() {
return (this.info);
}

protected final GuiButton getConfirmButton() {
return (this.confirm);
}

protected final GuiButton getCancelButton() {
return (this.cancel);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.grillecube.client.renderer.model.editor.gui;

/** simple callback interface to play with 'GuiPopUp' class */
public interface GuiPopUpCallback<T extends GuiPopUp> {

/** callback if confirmed */
public void onConfirm(T popUp);

/** callback if cancel */
public void onCancel(T popUp);
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,22 @@

package com.grillecube.client.renderer.model.editor.gui;

import com.grillecube.client.renderer.gui.components.GuiButton;
import com.grillecube.client.renderer.gui.components.GuiLabel;
import com.grillecube.client.renderer.gui.components.GuiPrompt;
import com.grillecube.client.renderer.gui.components.GuiText;
import com.grillecube.client.renderer.gui.components.GuiWindow;
import com.grillecube.client.renderer.gui.components.parameters.GuiParameter;
import com.grillecube.client.renderer.gui.components.parameters.GuiTextParameterTextCenterBox;
import com.grillecube.client.renderer.gui.components.parameters.GuiTextParameterTextFillBox;
import com.grillecube.client.renderer.gui.event.GuiEventPress;
import com.grillecube.client.renderer.gui.event.GuiListener;
import com.grillecube.client.renderer.model.animation.Bone;
import com.grillecube.client.renderer.model.editor.mesher.EditableModel;
import com.grillecube.common.utils.Color;

public class GuiWindowNewBone extends GuiWindow {
public class GuiWindowNewBone extends GuiPopUp {

private final GuiLabel info;
private final GuiPrompt name;
private final GuiSpinnerEditor parent;
private final GuiButton confirm;
private final GuiButton cancel;
public final GuiPrompt name;
public final GuiSpinnerEditor parent;

public GuiWindowNewBone(EditableModel model) {
super();
public GuiWindowNewBone(EditableModel model, GuiPopUpCallback<GuiWindowNewBone> callback) {
super(callback);

super.setBox(0.3f, 0.3f, 0.4f, 0.4f, 0.0f);

Expand All @@ -34,13 +26,7 @@ public GuiWindowNewBone(EditableModel model) {
float w = 0.2f;
float h = w / 1.6f;

this.info = new GuiLabel();
this.info.setBox(0.0f, 0.8f, 1.0f, h, 0.0f);
this.info.setFontColor(Color.WHITE);
this.info.addTextParameter(txtSize);
this.info.addTextParameter(txtCenter);
this.info.setText("Please enter the name of the new bone and select it parent");
this.addChild(info);
super.getInfoText().setText("Please enter the name of the new bone and select it parent");

this.name = new GuiPrompt();
this.name.setHint("enter bone name");
Expand All @@ -58,34 +44,5 @@ public GuiWindowNewBone(EditableModel model) {
this.parent.setBox(0.4f, 0.45f, w, h, 0.0f);
this.parent.pick(0);
this.addChild(this.parent);

this.confirm = new GuiButton();
this.confirm.setText("Confirm");
this.confirm.addTextParameter(txtSize);
this.confirm.addTextParameter(txtCenter);
this.confirm.setBox(0.25f, 0.15f, w, h, 0.0f);
this.addChild(this.confirm);
this.confirm.addListener(new GuiListener<GuiEventPress<GuiButton>>() {
@Override
public void invoke(GuiEventPress<GuiButton> event) {
Bone bone = new Bone(model.getSkeleton(), name.getHeldText());
bone.setParent((String) parent.getPickedObject());
model.getSkeleton().addBone(bone);
close();
}
});

this.cancel = new GuiButton();
this.cancel.setText("Decline");
this.cancel.setBox(0.55f, 0.15f, w, h, 0.0f);
this.cancel.addTextParameter(txtSize);
this.cancel.addTextParameter(txtCenter);
this.cancel.addListener(new GuiListener<GuiEventPress<GuiButton>>() {
@Override
public void invoke(GuiEventPress<GuiButton> event) {
close();
}
});
this.addChild(this.cancel);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@
import com.grillecube.client.renderer.gui.event.GuiSpinnerEventPick;
import com.grillecube.client.renderer.model.ModelSkeleton;
import com.grillecube.client.renderer.model.animation.Bone;
import com.grillecube.client.renderer.model.editor.gui.GuiPopUpCallback;
import com.grillecube.client.renderer.model.editor.gui.GuiPromptEditor;
import com.grillecube.client.renderer.model.editor.gui.GuiSpinnerEditor;
import com.grillecube.client.renderer.model.editor.gui.GuiWindowNewBone;
import com.grillecube.client.renderer.model.editor.mesher.EditableModel;
import com.grillecube.common.maths.Matrix4f;
import com.grillecube.common.maths.Quaternion;
import com.grillecube.common.maths.Vector3f;
Expand Down Expand Up @@ -71,8 +73,23 @@ public void invoke(GuiEventClick<GuiButton> event) {
// (System.currentTimeMillis() % 10000) + "");
// getModelSkeleton().addBone(bone);
// refresh();
GuiWindowNewBone win = new GuiWindowNewBone(getSelectedModel());
win.open(getOldestParent());
new GuiWindowNewBone(getSelectedModel(), new GuiPopUpCallback<GuiWindowNewBone>() {

@Override
public void onConfirm(GuiWindowNewBone win) {
EditableModel model = getSelectedModel();
Bone bone = new Bone(model.getSkeleton(), win.name.getHeldText());
bone.setParent((String) win.parent.getPickedObject());
model.getSkeleton().addBone(bone);
bones.add(bone, bone.getName());
bones.pick(bones.count() - 1);
guiRenderer.toast("Bone added.");
}

@Override
public void onCancel(GuiWindowNewBone win) {
}
}).open(getOldestParent());
}
});

Expand All @@ -96,8 +113,10 @@ public void invoke(GuiSpinnerEventPick<GuiSpinner> event) {
this.removeBone.addListener(new GuiListener<GuiEventClick<GuiButton>>() {
@Override
public void invoke(GuiEventClick<GuiButton> event) {
getModelSkeleton().removeBone(getSelectedBone());
refresh();
Bone bone = getSelectedBone();
getModelSkeleton().removeBone(bone);
bones.remove(bone);
guiRenderer.toast("Bone removed.");
}
});
}
Expand Down
10 changes: 5 additions & 5 deletions VoxelEngine/src/com/grillecube/common/world/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public abstract class Entity extends PhysicObject {
private World world;

/** entity AI */
private final ArrayList<EntityAI> ais;
private final ArrayList<EntityAI<Entity>> ais;

/** entity forces */
private final ArrayList<Force<Entity>> forces;
Expand Down Expand Up @@ -106,8 +106,8 @@ public Entity(World world, float width, float height, float depth) {
this.sz = depth;

// aies
this.ais = new ArrayList<EntityAI>();
this.addAI(new EntityAIIdle(this));
this.ais = new ArrayList<EntityAI<Entity>>();
this.addAI(new EntityAIIdle<Entity>());

// default states
this.setState(Entity.STATE_VISIBLE);
Expand Down Expand Up @@ -146,8 +146,8 @@ private final void updateBoundingBox() {

private final void updateAI(double dt) {
for (int i = 0; i < this.ais.size(); i++) {
EntityAI ai = this.ais.get(i);
ai.update(dt);
EntityAI<Entity> ai = this.ais.get(i);
ai.update(this, dt);
}
}

Expand Down
29 changes: 12 additions & 17 deletions VoxelEngine/src/com/grillecube/common/world/entity/ai/EntityAI.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,29 @@

import com.grillecube.common.world.entity.Entity;

public abstract class EntityAI {

/** the entity for this ai */
private final Entity entity;
public abstract class EntityAI<T extends Entity> {

/** in seconds, accumulate times since last update */
private double accumulator;

/** time needed to accumulate before updating */
private double updateTime;

public EntityAI(Entity entity) {
this.entity = entity;
public EntityAI() {
this.accumulator = 0;
this.updateTime = Double.MAX_VALUE;
}

/** called on every entity's update */
public final void update(double dt) {
this.onUpdate(dt);
public final void update(T entity, double dt) {
this.onUpdate(entity, dt);
this.accumulator += dt;
int n = (int) (this.accumulator / this.updateTime);

if (n > 0) {
do {
--n;
this.onTimedUpdate();
this.onTimedUpdate(entity);
} while (n > 0);
this.accumulator -= n * this.updateTime;
}
Expand All @@ -36,15 +33,17 @@ public final void update(double dt) {
/**
* called on every entity's update
*
* @param entity
* the entity
* @param dt
*/
protected abstract void onUpdate(double dt);
protected abstract void onUpdate(T entity, double dt);

/**
* called until the time stored in {@link #accumulator} <
* {@link #updateTime} needed by the accumulator
* called until the time stored in {@link #accumulator} < {@link #updateTime}
* needed by the accumulator
*/
protected abstract void onTimedUpdate();
protected abstract void onTimedUpdate(T entity);

public final double getUpdateTime() {
return (this.updateTime);
Expand All @@ -58,8 +57,4 @@ public final void setUpdateTime(double time) {
public final double getAccumulator() {
return (this.accumulator);
}

public final Entity getEntity() {
return (this.entity);
}
}
Loading

0 comments on commit 4279d96

Please sign in to comment.