Compare commits
15 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
a984333c3a | ||
|
4a1f1b7545 | ||
|
af7b39d8e9 | ||
|
a0acd16008 | ||
|
330ed1ab9b | ||
|
7e852ff05f | ||
|
6e1b0e3f69 | ||
|
411780b120 | ||
|
5359b93738 | ||
|
f9aae94bbc | ||
|
5c57a57e9a | ||
|
468b6dc327 | ||
|
69942ad17b | ||
|
3c74a808f3 | ||
|
8327fcfd19 |
@ -0,0 +1,83 @@
|
|||||||
|
package ru.windcorp.progressia.client.graphics.gui;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
|
||||||
|
import glm.mat._4.Mat4;
|
||||||
|
import glm.vec._2.i.Vec2i;
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
import ru.windcorp.progressia.client.graphics.backend.InputTracker;
|
||||||
|
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
||||||
|
import ru.windcorp.progressia.client.graphics.font.Font;
|
||||||
|
import ru.windcorp.progressia.client.graphics.Colors;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.event.FocusEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.event.HoverEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
||||||
|
import ru.windcorp.progressia.client.graphics.input.bus.InputListener;
|
||||||
|
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
||||||
|
|
||||||
|
public class Button extends Interactable {
|
||||||
|
|
||||||
|
public <T extends InputEvent> Button(String name, Label textLabel, Consumer<Button> onClick) {//, InputListener<T> onClick, Class<? extends T> onClickClass) {
|
||||||
|
super(name, textLabel);
|
||||||
|
setPreferredSize(107,34);
|
||||||
|
//Button inButton = (Button) setFocusable(true);
|
||||||
|
|
||||||
|
addListener((Class<KeyEvent>) KeyEvent.class, (InputListener<KeyEvent>) e -> {if ((e.isLeftMouseButton() && containsCursor()) || (e.getKey()==GLFW.GLFW_KEY_ENTER && isFocused()) )
|
||||||
|
{
|
||||||
|
isClicked = e.isPress();
|
||||||
|
if (!isDisabled())
|
||||||
|
{
|
||||||
|
onClick.accept(this);
|
||||||
|
takeFocus();
|
||||||
|
}
|
||||||
|
requestReassembly();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void assembleSelf(RenderTarget target) {
|
||||||
|
//Border
|
||||||
|
if (isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX(), getY(), getWidth(), getHeight(), 0xFFE5E5E5);
|
||||||
|
}
|
||||||
|
else if (isClicked() || isHovered() || isFocused())
|
||||||
|
{
|
||||||
|
target.fill(getX(), getY(), getWidth(), getHeight(), 0xFF37A2E6);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
target.fill(getX(), getY(), getWidth(), getHeight(), 0xFFCBCBD0);
|
||||||
|
}
|
||||||
|
//Inside area
|
||||||
|
if (!isClicked() && isHovered() && !isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX()+2, getY()+2, getWidth()-4, getHeight()-4, 0xFFC3E4F7);
|
||||||
|
}
|
||||||
|
else if (!isClicked() || isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX()+2, getY()+2, getWidth()-4, getHeight()-4, Colors.WHITE);
|
||||||
|
}
|
||||||
|
Font tempFont = new Font().withColor(Colors.BLACK);
|
||||||
|
if (isDisabled())
|
||||||
|
{
|
||||||
|
tempFont = tempFont.withColor(Colors.GRAY_A);
|
||||||
|
}
|
||||||
|
else if (isClicked())
|
||||||
|
{
|
||||||
|
tempFont = tempFont.withColor(Colors.WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
target.pushTransform(new Mat4().identity().translate( getX()+.5f*getWidth()-.5f*label.getPreferredSize().x, getY(), 0));
|
||||||
|
label = new Label(label.getName(), tempFont, label.getContentSupplier());
|
||||||
|
label.assembleSelf(target);
|
||||||
|
target.popTransform();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,117 @@
|
|||||||
|
package ru.windcorp.progressia.client.graphics.gui;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
|
||||||
|
import glm.mat._4.Mat4;
|
||||||
|
import glm.vec._2.i.Vec2i;
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
import ru.windcorp.progressia.client.graphics.backend.InputTracker;
|
||||||
|
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
||||||
|
import ru.windcorp.progressia.client.graphics.font.Font;
|
||||||
|
import ru.windcorp.progressia.client.graphics.Colors;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.event.FocusEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.event.HoverEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
||||||
|
import ru.windcorp.progressia.client.graphics.input.bus.InputListener;
|
||||||
|
import ru.windcorp.progressia.client.graphics.input.InputEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
||||||
|
|
||||||
|
public class Checkbox extends Interactable {
|
||||||
|
|
||||||
|
private boolean isActive;
|
||||||
|
|
||||||
|
public <T extends InputEvent> Checkbox(String name, Label textLabel, Consumer<Checkbox> onSet, Consumer<Checkbox> onReset) {//, InputListener<T> onClick, Class<? extends T> onClickClass) {
|
||||||
|
super(name, textLabel);
|
||||||
|
setPreferredSize(44 + textLabel.getPreferredSize().x,textLabel.getPreferredSize().y);
|
||||||
|
//Checkbox inCheck = (Checkbox) setFocusable(true);
|
||||||
|
|
||||||
|
addListener((Class<KeyEvent>) KeyEvent.class, (InputListener<KeyEvent>) e -> {if (e.isLeftMouseButton() && containsCursor()|| (e.getKey()==GLFW.GLFW_KEY_ENTER && isFocused()))
|
||||||
|
{
|
||||||
|
isClicked = e.isPress();
|
||||||
|
if (!isDisabled())
|
||||||
|
{
|
||||||
|
if (!isClicked && !isActive)
|
||||||
|
{
|
||||||
|
onSet.accept(this);
|
||||||
|
isActive = !isActive;
|
||||||
|
}
|
||||||
|
else if (!isClicked && isActive)
|
||||||
|
{
|
||||||
|
onReset.accept(this);
|
||||||
|
isActive = !isActive;
|
||||||
|
}
|
||||||
|
else if (isClicked)
|
||||||
|
{
|
||||||
|
takeFocus();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
requestReassembly();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;});
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isActive()
|
||||||
|
{
|
||||||
|
return isActive;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void assembleSelf(RenderTarget target) {
|
||||||
|
//Border
|
||||||
|
if (isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX()+label.getPreferredSize().x, getY(), getWidth()-label.getPreferredSize().x, getHeight(), 0xFFE5E5E5);
|
||||||
|
}
|
||||||
|
else if (isClicked() || isHovered() || isFocused())
|
||||||
|
{
|
||||||
|
target.fill(getX()+label.getPreferredSize().x, getY(), getWidth()-label.getPreferredSize().x, getHeight(), 0xFF37A2E6); // blue
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
target.fill(getX()+label.getPreferredSize().x, getY(), getWidth()-label.getPreferredSize().x, getHeight(), 0xFFCBCBD0);
|
||||||
|
}
|
||||||
|
//Inside area
|
||||||
|
if (!isClicked() && isHovered() && !isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX()+2+label.getPreferredSize().x, getY()+2, getWidth()-label.getPreferredSize().x-4, getHeight()-4, 0xFFC3E4F7); // light blue
|
||||||
|
}
|
||||||
|
else if (!isClicked() || isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX()+2+label.getPreferredSize().x, getY()+2, getWidth()-label.getPreferredSize().x-4, getHeight()-4, Colors.WHITE);
|
||||||
|
}
|
||||||
|
if (isActive() && !isClicked())
|
||||||
|
{
|
||||||
|
if (isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX()+getWidth()-getHeight()+4, getY()+4, getHeight()-8, getHeight()-8, 0xFFB3D7EF);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
target.fill(getX()+getWidth()-getHeight()+4, getY()+4, getHeight()-8, getHeight()-8, 0xFF37A2E6); // blue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (!isClicked())
|
||||||
|
{
|
||||||
|
if (isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX()+label.getPreferredSize().x+4, getY()+4, getHeight()-8, getHeight()-8, 0xFFE5E5E5);
|
||||||
|
}
|
||||||
|
else if (isFocused() || isHovered())
|
||||||
|
{
|
||||||
|
target.fill(getX()+label.getPreferredSize().x+4, getY()+4, getHeight()-8, getHeight()-8, 0xFF37A2E6); // blue
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
target.fill(getX()+label.getPreferredSize().x+4, getY()+4, getHeight()-8, getHeight()-8, 0xFFCBCBD0);
|
||||||
|
}
|
||||||
|
target.fill(getX()+label.getPreferredSize().x+6, getY()+6, getHeight()-12, getHeight()-12, Colors.WHITE);
|
||||||
|
}
|
||||||
|
target.pushTransform(new Mat4().identity().translate( getX(), getY(), 0));
|
||||||
|
label.assembleSelf(target);
|
||||||
|
target.popTransform();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,62 @@
|
|||||||
|
package ru.windcorp.progressia.client.graphics.gui;
|
||||||
|
|
||||||
|
import com.google.common.eventbus.Subscribe;
|
||||||
|
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.event.FocusEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.event.HoverEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
||||||
|
import glm.vec._2.i.Vec2i;
|
||||||
|
|
||||||
|
public class Interactable extends Component {
|
||||||
|
|
||||||
|
private Vec2i currentSize;
|
||||||
|
protected boolean isDisabled;
|
||||||
|
protected boolean isClicked;
|
||||||
|
protected Label label;
|
||||||
|
|
||||||
|
public Interactable(String name, Label textLabel)
|
||||||
|
{
|
||||||
|
super(name);
|
||||||
|
label = textLabel;
|
||||||
|
addChild(textLabel);
|
||||||
|
|
||||||
|
addListener(new Object() {
|
||||||
|
@Subscribe
|
||||||
|
public void onHoverChanged(HoverEvent e) {
|
||||||
|
requestReassembly();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
addListener(new Object() {
|
||||||
|
@Subscribe
|
||||||
|
public void onFocusChanged(FocusEvent e) {
|
||||||
|
//inButton.setText(new Label("dummy",new Font().withColor(Colors.BLACK),e.getNewState() ? "Is Focused" : "Isn't focused"));
|
||||||
|
requestReassembly();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isClicked()
|
||||||
|
{
|
||||||
|
return isClicked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisable(boolean isDisabled)
|
||||||
|
{
|
||||||
|
this.isDisabled = isDisabled;
|
||||||
|
setFocusable(isDisabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDisabled()
|
||||||
|
{
|
||||||
|
return isDisabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setText(Label newText)
|
||||||
|
{
|
||||||
|
removeChild(label);
|
||||||
|
label = newText;
|
||||||
|
addChild(label);
|
||||||
|
requestReassembly();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
package ru.windcorp.progressia.client.graphics.gui;
|
||||||
|
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
import org.lwjgl.glfw.GLFW;
|
||||||
|
|
||||||
|
import glm.mat._4.Mat4;
|
||||||
|
import glm.vec._2.i.Vec2i;
|
||||||
|
import ru.windcorp.progressia.client.graphics.Colors;
|
||||||
|
import ru.windcorp.progressia.client.graphics.flat.RenderTarget;
|
||||||
|
import ru.windcorp.progressia.client.graphics.input.KeyEvent;
|
||||||
|
import ru.windcorp.progressia.client.graphics.input.bus.InputListener;
|
||||||
|
|
||||||
|
public class RadioButton extends Interactable {
|
||||||
|
private RadioManager manager;
|
||||||
|
private boolean isSelected;
|
||||||
|
|
||||||
|
public RadioButton(String name, Label textLabel, Consumer<RadioButton> onSelect, RadioManager myManager)
|
||||||
|
{
|
||||||
|
super(name, textLabel);
|
||||||
|
setPreferredSize(textLabel.getPreferredSize().x+23,textLabel.getPreferredSize().y);
|
||||||
|
manager = myManager;
|
||||||
|
manager.addOption(this);
|
||||||
|
|
||||||
|
addListener((Class<KeyEvent>) KeyEvent.class, (InputListener<KeyEvent>) e -> {if ((e.isLeftMouseButton() && containsCursor()) || (e.getKey()==GLFW.GLFW_KEY_ENTER && isFocused()) )
|
||||||
|
{
|
||||||
|
isClicked = e.isPress();
|
||||||
|
if (!isDisabled() && !isClicked)
|
||||||
|
{
|
||||||
|
onSelect.accept(this);
|
||||||
|
manager.selectSelf(this);
|
||||||
|
}
|
||||||
|
requestReassembly();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;});
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSelected()
|
||||||
|
{
|
||||||
|
return isSelected;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelected(boolean selected)
|
||||||
|
{
|
||||||
|
isSelected = selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void assembleSelf(RenderTarget target) {
|
||||||
|
if (isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX()+getWidth()-getHeight(), getY(), getHeight(), getHeight(), 0xFFE5E5E5);
|
||||||
|
}
|
||||||
|
else if (isClicked() || isHovered() || isFocused())
|
||||||
|
{
|
||||||
|
target.fill(getX()+getWidth()-getHeight(), getY(), getHeight(), getHeight(), 0xFF37A2E6);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
target.fill(getX()+getWidth()-getHeight(), getY(), getHeight(), getHeight(), 0xFFCBCBD0);
|
||||||
|
}
|
||||||
|
//Inside area
|
||||||
|
if (!isClicked() && isHovered() && !isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX()+getWidth()-getHeight()+2, getY()+2, getHeight()-4, getHeight()-4, 0xFFC3E4F7);
|
||||||
|
}
|
||||||
|
else if (!isClicked() || isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX()+getWidth()-getHeight()+2, getY()+2, getHeight()-4, getHeight()-4, Colors.WHITE);
|
||||||
|
}
|
||||||
|
if (isSelected())
|
||||||
|
{
|
||||||
|
if (!isDisabled())
|
||||||
|
{
|
||||||
|
target.fill(getX()+getWidth()-getHeight()+4, getY()+4, getHeight()-8, getHeight()-8, 0xFF37A2E6);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
target.fill(getX()+getWidth()-getHeight()+4, getY()+4, getHeight()-8, getHeight()-8, 0xFFC3E4F7);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
target.pushTransform(new Mat4().identity().translate( getX(), getY(), 0));
|
||||||
|
label.assembleSelf(target);
|
||||||
|
target.popTransform();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
package ru.windcorp.progressia.client.graphics.gui;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.concurrent.CopyOnWriteArrayList;
|
||||||
|
|
||||||
|
public class RadioManager {
|
||||||
|
private List<RadioButton> options;
|
||||||
|
private int selectedOption;
|
||||||
|
|
||||||
|
public RadioManager()
|
||||||
|
{
|
||||||
|
options = Collections.synchronizedList(new CopyOnWriteArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addOption(RadioButton option)
|
||||||
|
{
|
||||||
|
options.add(option);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSelected()
|
||||||
|
{
|
||||||
|
return selectedOption;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void selectSelf(RadioButton option)
|
||||||
|
{
|
||||||
|
if (!options.contains(option))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
options.get(selectedOption).setSelected(false);
|
||||||
|
selectedOption = options.indexOf(option);
|
||||||
|
option.takeFocus();
|
||||||
|
option.setSelected(true);
|
||||||
|
}
|
||||||
|
}
|
@ -26,10 +26,15 @@ import ru.windcorp.progressia.client.graphics.Colors;
|
|||||||
import ru.windcorp.progressia.client.graphics.backend.GraphicsBackend;
|
import ru.windcorp.progressia.client.graphics.backend.GraphicsBackend;
|
||||||
import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface;
|
import ru.windcorp.progressia.client.graphics.backend.GraphicsInterface;
|
||||||
import ru.windcorp.progressia.client.graphics.font.Font;
|
import ru.windcorp.progressia.client.graphics.font.Font;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.Button;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.Checkbox;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.DynamicLabel;
|
import ru.windcorp.progressia.client.graphics.gui.DynamicLabel;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.GUILayer;
|
import ru.windcorp.progressia.client.graphics.gui.GUILayer;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.Button;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.Label;
|
import ru.windcorp.progressia.client.graphics.gui.Label;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.Panel;
|
import ru.windcorp.progressia.client.graphics.gui.Panel;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.RadioButton;
|
||||||
|
import ru.windcorp.progressia.client.graphics.gui.RadioManager;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutAlign;
|
||||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical;
|
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical;
|
||||||
import ru.windcorp.progressia.client.localization.Localizer;
|
import ru.windcorp.progressia.client.localization.Localizer;
|
||||||
@ -57,6 +62,54 @@ public class LayerTestGUI extends GUILayer {
|
|||||||
|
|
||||||
TestPlayerControls tpc = TestPlayerControls.getInstance();
|
TestPlayerControls tpc = TestPlayerControls.getInstance();
|
||||||
|
|
||||||
|
Button disableButton = new Button("TestButton",
|
||||||
|
new Label("TestButtonLabel", new Font().withColor(Colors.BLACK), "I'm in TestGUI"),
|
||||||
|
b -> {b.setDisable(!b.isDisabled());}
|
||||||
|
);
|
||||||
|
|
||||||
|
panel.addChild(disableButton);
|
||||||
|
|
||||||
|
panel.addChild(
|
||||||
|
new Button(
|
||||||
|
"TestButton2",
|
||||||
|
new Label("TestButtonLabel2", new Font().withColor(Colors.BLACK), "I enable the above button"),
|
||||||
|
b -> {disableButton.setDisable(false);}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
panel.addChild(
|
||||||
|
new Checkbox(
|
||||||
|
"Checkbox1",
|
||||||
|
new Label("CheckboxLabel", font,"Reset"),
|
||||||
|
c -> {c.setText(
|
||||||
|
new Label("CheckboxLabel", font, "Set")
|
||||||
|
);},
|
||||||
|
c -> {c.setText(
|
||||||
|
new Label("CheckboxLabel", font, "Reset")
|
||||||
|
);}
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
RadioManager manager = new RadioManager();
|
||||||
|
|
||||||
|
panel.addChild(
|
||||||
|
new RadioButton(
|
||||||
|
"Radio1,1",
|
||||||
|
new Label("RadioLabel1,1",font,"Option 1"),
|
||||||
|
rb -> {},
|
||||||
|
manager
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
panel.addChild(
|
||||||
|
new RadioButton(
|
||||||
|
"Radio1,2",
|
||||||
|
new Label("RadioLabel1,2",font,"Option 2"),
|
||||||
|
rb -> {},
|
||||||
|
manager
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
panel.addChild(
|
panel.addChild(
|
||||||
new Label(
|
new Label(
|
||||||
"IsFlyingDisplay",
|
"IsFlyingDisplay",
|
||||||
@ -261,12 +314,126 @@ public class LayerTestGUI extends GUILayer {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class Counter {
|
||||||
|
|
||||||
|
private int DISPLAY_INERTIA = 200;
|
||||||
|
private long AVERAGE_TIME = 10000;
|
||||||
|
private long first_time;
|
||||||
|
|
||||||
|
private final long[] values;
|
||||||
|
private int size;
|
||||||
|
private int head;
|
||||||
|
|
||||||
|
private long lastUpdate;
|
||||||
|
|
||||||
|
public Counter(long averageTime, int maxTPS)
|
||||||
|
{
|
||||||
|
DISPLAY_INERTIA = (int) averageTime*maxTPS/1000;
|
||||||
|
AVERAGE_TIME = averageTime;
|
||||||
|
first_time = -1;
|
||||||
|
values = new long[DISPLAY_INERTIA];
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add(long value) {
|
||||||
|
if (first_time==-1)
|
||||||
|
{
|
||||||
|
first_time=System.currentTimeMillis();
|
||||||
|
}
|
||||||
|
if (size == values.length) {
|
||||||
|
values[head] = value;
|
||||||
|
head++;
|
||||||
|
if (head == values.length)
|
||||||
|
head = 0;
|
||||||
|
} else {
|
||||||
|
values[size] = value;
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double average() {
|
||||||
|
double count=0;
|
||||||
|
long ctime = System.currentTimeMillis();
|
||||||
|
for (int i=0;i<size;i++)
|
||||||
|
{
|
||||||
|
if ((ctime-values[i])<AVERAGE_TIME)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ((ctime-first_time)<AVERAGE_TIME)
|
||||||
|
{
|
||||||
|
if ((ctime-first_time)<10)
|
||||||
|
{
|
||||||
|
return 20.0;
|
||||||
|
}
|
||||||
|
return count/(ctime-first_time)*1000;
|
||||||
|
}
|
||||||
|
return count/AVERAGE_TIME*1000;
|
||||||
|
}
|
||||||
|
|
||||||
|
public double update() {
|
||||||
|
long now = (long) (GraphicsInterface.getTime() / .05);
|
||||||
|
if (lastUpdate != now) {
|
||||||
|
lastUpdate = now;
|
||||||
|
add(System.currentTimeMillis());
|
||||||
|
}
|
||||||
|
|
||||||
|
return average();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class Queue {
|
||||||
|
|
||||||
|
private static final int DISPLAY_INERTIA = 32;
|
||||||
|
private static final double UPDATE_INTERVAL = Units.get(50.0, "ms");
|
||||||
|
|
||||||
|
private final double[] values = new double[DISPLAY_INERTIA];
|
||||||
|
private int size;
|
||||||
|
private int head;
|
||||||
|
|
||||||
|
private long lastUpdate;
|
||||||
|
|
||||||
|
public void add(double value) {
|
||||||
|
if (size == values.length) {
|
||||||
|
values[head] = value;
|
||||||
|
head++;
|
||||||
|
if (head == values.length)
|
||||||
|
head = 0;
|
||||||
|
} else {
|
||||||
|
values[size] = value;
|
||||||
|
size++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double average() {
|
||||||
|
if (size == values.length && head!=0) {
|
||||||
|
return (values[head-1]-values[head])/DISPLAY_INERTIA*20;
|
||||||
|
} else if (head==0) {
|
||||||
|
return (values[size-1]-values[0])/DISPLAY_INERTIA*20;
|
||||||
|
} else {
|
||||||
|
return values[head-1]/size*20;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public double update(double value) {
|
||||||
|
long now = (long) (GraphicsInterface.getTime() / UPDATE_INTERVAL);
|
||||||
|
if (lastUpdate != now) {
|
||||||
|
lastUpdate = now;
|
||||||
|
add(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return average();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private static final Averager FPS_RECORD = new Averager();
|
private static final Averager FPS_RECORD = new Averager();
|
||||||
private static final Averager TPS_RECORD = new Averager();
|
private static final Queue TPS_RECORD = new Queue();
|
||||||
|
|
||||||
private static final Supplier<CharSequence> TPS_STRING = DynamicStrings.builder()
|
private static final Supplier<CharSequence> TPS_STRING = DynamicStrings.builder()
|
||||||
.addDyn(new MutableStringLocalized("LayerTestGUI.TPSDisplay"))
|
.addDyn(new MutableStringLocalized("LayerTestGUI.TPSDisplay"))
|
||||||
.addDyn(() -> TPS_RECORD.update(ServerState.getInstance().getTPS()), 5, 1)
|
.addDyn(() -> TPS_RECORD.update(ServerState.getInstance().getUptimeTicks()), 5, 1)
|
||||||
.buildSupplier();
|
.buildSupplier();
|
||||||
|
|
||||||
private static final Supplier<CharSequence> POS_STRING = DynamicStrings.builder()
|
private static final Supplier<CharSequence> POS_STRING = DynamicStrings.builder()
|
||||||
|
BIN
src/main/resources/assets/textures/all_buttons.png
Normal file
BIN
src/main/resources/assets/textures/all_buttons.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 94 KiB |
Reference in New Issue
Block a user