parent
0ca67870d6
commit
d8d800d2ad
Binary file not shown.
@ -0,0 +1,68 @@
|
||||
package com.trs.game.view;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.scenes.scene2d.utils.SpriteDrawable;
|
||||
|
||||
public class Button {
|
||||
int id;
|
||||
int xPos;
|
||||
int yPos;
|
||||
int width;
|
||||
int height;
|
||||
String text;
|
||||
Color buttonColor;
|
||||
Color textColor;
|
||||
|
||||
|
||||
public Button(int id, int xPos, int yPos, int width, int height, String text, Color buttonColor, Color textColor){
|
||||
this.id = id;
|
||||
this.xPos = xPos;
|
||||
this.yPos = yPos;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.text = text;
|
||||
this.buttonColor = buttonColor;
|
||||
this.textColor = textColor;
|
||||
}
|
||||
|
||||
public void render(SpriteBatch batch, ShapeRenderer renderer, BitmapFont font){
|
||||
if(batch.isDrawing())batch.end();
|
||||
if(renderer.isDrawing()) renderer.end();
|
||||
renderer.begin(ShapeRenderer.ShapeType.Filled);
|
||||
renderer.setColor(buttonColor);
|
||||
renderer.rect(xPos, yPos, width, height);
|
||||
renderer.end();
|
||||
batch.begin();
|
||||
font.setColor(textColor);
|
||||
font.draw(batch, text, ((xPos + width/2) - (getTextWidth(font,text)/2)), ((yPos + height/2) + (getTextHeight(font,text)/2)));
|
||||
batch.end();
|
||||
}
|
||||
|
||||
public void dispose(){
|
||||
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(int id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public float getTextWidth(BitmapFont font, String text){
|
||||
GlyphLayout glyphLayout = new GlyphLayout();
|
||||
glyphLayout.setText(font,text);
|
||||
return glyphLayout.width;
|
||||
}
|
||||
public float getTextHeight(BitmapFont font, String text){
|
||||
GlyphLayout glyphLayout = new GlyphLayout();
|
||||
glyphLayout.setText(font,text);
|
||||
return glyphLayout.height;
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,4 +1,35 @@
|
||||
package com.trs.game.view;
|
||||
|
||||
public interface Screen {
|
||||
import java.util.ArrayList;
|
||||
|
||||
public abstract class Screen {
|
||||
|
||||
public final int SCREEN_WIDTH;
|
||||
public final int SCREEN_HEIGHT;
|
||||
|
||||
int id;
|
||||
ArrayList<Button> buttons;
|
||||
|
||||
public Screen(int SCREEN_WIDTH, int SCREEN_HEIGHT){
|
||||
buttons = new ArrayList();
|
||||
this.SCREEN_WIDTH = SCREEN_WIDTH;
|
||||
this.SCREEN_HEIGHT =SCREEN_HEIGHT;
|
||||
}
|
||||
|
||||
abstract public void timer();
|
||||
abstract public void render();
|
||||
abstract public int touchDown(int x, int y);
|
||||
abstract public void dispose();
|
||||
|
||||
public int getId(){
|
||||
return id;
|
||||
}
|
||||
|
||||
public int getWidth() {
|
||||
return SCREEN_WIDTH;
|
||||
}
|
||||
|
||||
public int getHeight() {
|
||||
return SCREEN_HEIGHT;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in new issue