Skip to content

Commit

Permalink
Doubles are now editable within the inspector
Browse files Browse the repository at this point in the history
  • Loading branch information
Flafla2 committed Jan 23, 2014
1 parent 4468785 commit 44a3f86
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ public EditorObjectWizard(GuiEditor editor, EditorObject c, Vector2 pos, int wid
sec.textField.text = o+"";
sections.add(sec);
currentPos.y += sec.sectionHeight();
} else if(type == double.class)
{
GuiEditorInspectorSectionDouble sec = new GuiEditorInspectorSectionDouble(name,editor,currentPos,width);
if(o != null)
sec.textField.text = o+"";
sections.add(sec);
currentPos.y += sec.sectionHeight();
} else if(type == Vector2.class)
{
GuiEditorInspectorSectionVec2D sec = new GuiEditorInspectorSectionVec2D(name,editor,currentPos,width);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.remote.remote2d.editor.inspector;

import org.lwjgl.input.Keyboard;

import com.remote.remote2d.editor.GuiEditor;
import com.remote.remote2d.engine.Remote2D;
import com.remote.remote2d.engine.art.Fonts;
import com.remote.remote2d.engine.gui.GuiTextField;
import com.remote.remote2d.engine.gui.TextLimiter;
import com.remote.remote2d.engine.logic.Vector2;

public class GuiEditorInspectorSectionDouble extends GuiEditorInspectorSection {

GuiTextField textField;

public GuiEditorInspectorSectionDouble(String name, GuiEditor inspector, Vector2 pos, int width) {
super(name, inspector, pos, width);
textField = new GuiTextField(pos.add(new Vector2(10,20)), new Vector2(width-20,20), 20);
textField.limitToDigits = TextLimiter.LIMIT_TO_FLOAT;
}

@Override
public int sectionHeight() {
return 40;
}

@Override
public Object getData() {
if(textField.text.trim().equals(""))
return new Double(0);
return Double.parseDouble(textField.text);
}

@Override
public void initSection() {

}

@Override
public void tick(int i, int j, int k) {
textField.tick(i, j, k);
}

@Override
public void render(float interpolation) {
Fonts.get("Arial").drawString(renderName, pos.x, pos.y, 20, isComplete() ? 0xffffff : 0xff7777);
textField.render(interpolation);
}

@Override
public void setData(Object o) {
if(o instanceof Double)
{
textField.text = o+"";
}
}

@Override
public void deselect() {
textField.deselect();
}

@Override
public boolean isSelected() {
return textField.isSelected();
}

@Override
public boolean isComplete() {
return !textField.text.trim().equals("") && !textField.text.equals("-");
}

@Override
public boolean hasFieldBeenChanged() {
return textField.isSelected() && isComplete() && Remote2D.getIntegerKeyboardList().contains(Keyboard.KEY_RETURN);
}

}

0 comments on commit 44a3f86

Please sign in to comment.