Skip to content

Commit

Permalink
🔨 Implemented User Interface Beta!
Browse files Browse the repository at this point in the history
Change log v1.5
## New Features
- User Interface
- Text
- TextInput

Vector2
- Added a new methods Add()
- Added a new methods Subtract()
- Added a new methods Divide()
- Added a new methods Multiply()
  • Loading branch information
jabo-bernardo authored Apr 13, 2020
1 parent 1eefd72 commit b089fd1
Show file tree
Hide file tree
Showing 22 changed files with 479 additions and 6 deletions.
Binary file modified bin/dev/jabo/kree/Input.class
Binary file not shown.
Binary file modified bin/dev/jabo/kree/Scene.class
Binary file not shown.
Binary file modified bin/dev/jabo/kree/SceneManager.class
Binary file not shown.
Binary file modified bin/dev/jabo/kree/Transform.class
Binary file not shown.
Binary file modified bin/dev/jabo/kree/Vector2.class
Binary file not shown.
Binary file modified bin/dev/jabo/kree/gameTest/MyScene.class
Binary file not shown.
Binary file added bin/dev/jabo/kree/ui/Constraint.class
Binary file not shown.
Binary file added bin/dev/jabo/kree/ui/ProgressBar.class
Binary file not shown.
Binary file added bin/dev/jabo/kree/ui/Text.class
Binary file not shown.
Binary file added bin/dev/jabo/kree/ui/TextInput.class
Binary file not shown.
Binary file added bin/dev/jabo/kree/ui/UserInterface.class
Binary file not shown.
10 changes: 10 additions & 0 deletions src/dev/jabo/kree/Input.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,25 @@ public class Input implements KeyListener, MouseMotionListener, MouseListener {
public static boolean leftMouseDown;
public static boolean middleMouseDown;
public static boolean rightMouseDown;


public static boolean keyPressed = false;
public static char lastKey;


static int limiter;
@Override
public void keyPressed(KeyEvent arg0) {
keys[arg0.getKeyCode()] = true;
lastKey = (char) arg0.getKeyCode();
keyPressed = true;
}

@Override
public void keyReleased(KeyEvent arg0) {
keys[arg0.getKeyCode()] = false;
keyPressed = false;

}

@Override
Expand Down
3 changes: 3 additions & 0 deletions src/dev/jabo/kree/Scene.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@

import java.awt.Graphics;

import dev.jabo.kree.ui.UserInterface;

public abstract class Scene {

protected Game game;

public GameObject[] gameObjects = new GameObject[0];
public UserInterface[] userInterfaces = new UserInterface[0];

public Scene(Game game) {
this.game = game;
Expand Down
8 changes: 8 additions & 0 deletions src/dev/jabo/kree/SceneManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.awt.Graphics;

import dev.jabo.kree.ui.UserInterface;

public class SceneManager {

public static Scene activeScene;
Expand All @@ -21,6 +23,9 @@ public static void Update() {
for(GameObject obj : activeScene.gameObjects) {
obj.Update();
}
for(UserInterface obj : activeScene.userInterfaces) {
obj.Update();
}
}
}

Expand All @@ -30,6 +35,9 @@ public static void Render(Graphics g) {
for(GameObject obj : activeScene.gameObjects) {
obj.Render(g);
}
for(UserInterface obj : activeScene.userInterfaces) {
obj.Render(g);
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/dev/jabo/kree/Transform.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public Transform() {
}

public void Translate(Vector2 position) {
Vector2.Add(this.position, position);
this.position.Add(position);
}

}
21 changes: 18 additions & 3 deletions src/dev/jabo/kree/Vector2.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,24 @@ static int Distance(Vector2 v1, Vector2 v2) {
);
}

static void Add(Vector2 v1, Vector2 v2) {
v1.x += v2.x;
v1.y += v2.y;
public void Add(Vector2 vector) {
this.x += vector.x;
this.y += vector.y;
}

public void Subtract(Vector2 vector) {
this.x -= vector.x;
this.y -= vector.y;
}

public void Divide(Vector2 vector) {
this.x /= vector.x;
this.y /= vector.y;
}

public void Multiply(Vector2 vector) {
this.x *= vector.x;
this.y *= vector.y;
}

public void MoveTowards(Vector2 to, float speed) {
Expand Down
27 changes: 25 additions & 2 deletions src/dev/jabo/kree/gameTest/MyScene.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
package dev.jabo.kree.gameTest;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

import dev.jabo.kree.Game;
import dev.jabo.kree.Input;
import dev.jabo.kree.Scene;
import dev.jabo.kree.Vector2;
import dev.jabo.kree.ui.ProgressBar;
import dev.jabo.kree.ui.Text;
import dev.jabo.kree.ui.TextInput;

public class MyScene extends Scene {


Text myText = new Text(this, "Health: 32", new Vector2(100, 128), 128);
TextInput myTextInput = new TextInput(this, new Vector2(25, 25), new Vector2(128, 64));
ProgressBar myBar = new ProgressBar(this);

public MyScene(Game game) {
super(game);
Expand All @@ -18,15 +27,29 @@ public MyScene(Game game) {
public void Initialize() {



myTextInput.SetFont(new Font("Arial", Font.BOLD, 24));
myText.SetColor(new Color(255, 100, 100));



}

@Override
public void Update() {
myText.SetText(myTextInput.GetValue());

if(Input.leftMouseDown) {
myBar.Add(0.5f);
}

if(Input.rightMouseDown) {
myBar.Subtract(0.5f);
}
}

@Override
public void Render(Graphics g) {


}

Expand Down
9 changes: 9 additions & 0 deletions src/dev/jabo/kree/ui/Constraint.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.jabo.kree.ui;

public class Constraint {

public Constraint() {

}

}
114 changes: 114 additions & 0 deletions src/dev/jabo/kree/ui/ProgressBar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package dev.jabo.kree.ui;

import java.awt.Color;
import java.awt.Graphics;

import dev.jabo.kree.Scene;
import dev.jabo.kree.Vector2;

public class ProgressBar extends UserInterface {

private Vector2 position = new Vector2(0, 0);
private Vector2 scale = new Vector2(128, 32);

private float value = 100, maxValue = 150;

private Color backgroundColor = new Color(25, 25, 25);
private Color foregroundColor = new Color(255, 125, 25);

private int padding = 4;

public ProgressBar(Scene parentScene) {



AddToScene(parentScene);
}

public ProgressBar(Scene parentScene, Vector2 position) {

this.position = position;

AddToScene(parentScene);
}

public ProgressBar(Scene parentScene, Vector2 position, Vector2 scale) {

this.position = position;
this.scale = scale;

AddToScene(parentScene);
}

@Override
public void Update() {
if(value > maxValue) {
value = maxValue;
}
if(value <= 0) {
value = 0;
}
}

@Override
public void Render(Graphics g) {

g.setColor(backgroundColor);
g.fillRect(position.x, position.y, scale.x, scale.y);
g.setColor(foregroundColor);
g.fillRect(position.x + padding, position.y + padding, (int) ((value / maxValue) * (scale.x - (padding * 2))), scale.y - (padding * 2));
}

// Misc
public void Add(float value) {
this.value += value;
}

public void Subtract(float value) {
this.value -= value;
}

// Setters
public void SetValue(float value) {
this.value = value;
}

public void SetMaxValue(float maxValue) {
this.maxValue = maxValue;
}

public void SetColor(Color foregroundColor, Color backgroundColor) {
this.foregroundColor = foregroundColor;
this.backgroundColor = backgroundColor;
}

public void SetPosition(Vector2 position) {
this.position = position;
}

public void SetScale(Vector2 scale) {
this.scale = scale;
}

public void SetPadding(int padding) {
this.padding = padding;
}

// Getters
public float GetValue() {
return value;
}

public float GetMaxValue() {
return maxValue;
}

public Vector2 GetPosition() {
return position;
}

public Vector2 GetScale() {
return scale;
}

}
109 changes: 109 additions & 0 deletions src/dev/jabo/kree/ui/Text.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package dev.jabo.kree.ui;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;

import dev.jabo.kree.Scene;
import dev.jabo.kree.Vector2;

public class Text extends UserInterface {

private String text;

private Font font = new Font("Times New Roman", Font.PLAIN, 14);

private int width = 0;
private int height = 0;

private boolean showBorder = false;

private Color color = Color.black;

public Text(Scene parentScene, String text, Vector2 position, int width) {
this.position = position;
this.text = text;

this.width = width;

AddToScene(parentScene);
}

@Override
public void Update() {



}

@Override
public void Render(Graphics g) {
if(showBorder) {
g.drawRect(position.x, position.y, width, height);
}

g.setFont(this.font);
g.setColor(color);
drawTextLineByLine(g);
}

public void drawTextLineByLine(Graphics g) {

this.height = 0;

String[] s = text.split(" ");

int line = 1;
int col = 0;

String last = "";
boolean endl = false;

int curWidth = 0;

for(String str : s) {
int width = g.getFontMetrics(font).stringWidth(last);
curWidth += width + (col * 2);
if(curWidth > this.width) {
endl = true;
}
if(endl) {
line++;
endl = false;
curWidth = 0;
col = 0;
last = "";
}
last = str;
g.drawString(str, this.position.x + (curWidth), this.position.y + font.getSize() * line);
col++;
this.height = font.getSize() * line;
}

}

public void SetColor(Color color) {
this.color = color;
}

public void ShowBorder() {
showBorder = true;
}

public void HideBorder() {
showBorder = false;
}

public void SetFont(Font font) {
this.font = font;
}

public void SetText(String text) {
this.text = text;
}

public String GetText() {
return text;
}

}
Loading

0 comments on commit b089fd1

Please sign in to comment.