Made inventory windows draggable
This commit is contained in:
parent
9c85164ed1
commit
38021852d0
@ -17,6 +17,8 @@
|
||||
*/
|
||||
package ru.windcorp.progressia.client.graphics.world.hud;
|
||||
|
||||
import com.google.common.eventbus.Subscribe;
|
||||
|
||||
import glm.vec._2.Vec2;
|
||||
import glm.vec._4.Vec4;
|
||||
import ru.windcorp.progressia.client.graphics.Colors;
|
||||
@ -25,19 +27,23 @@ import ru.windcorp.progressia.client.graphics.font.Font;
|
||||
import ru.windcorp.progressia.client.graphics.font.Typeface;
|
||||
import ru.windcorp.progressia.client.graphics.gui.Button;
|
||||
import ru.windcorp.progressia.client.graphics.gui.Component;
|
||||
import ru.windcorp.progressia.client.graphics.gui.DragManager;
|
||||
import ru.windcorp.progressia.client.graphics.gui.Group;
|
||||
import ru.windcorp.progressia.client.graphics.gui.Label;
|
||||
import ru.windcorp.progressia.client.graphics.gui.Panel;
|
||||
import ru.windcorp.progressia.client.graphics.gui.event.DragEvent;
|
||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutBorderHorizontal;
|
||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutFill;
|
||||
import ru.windcorp.progressia.client.graphics.gui.layout.LayoutVertical;
|
||||
import ru.windcorp.progressia.client.localization.MutableString;
|
||||
import ru.windcorp.progressia.client.localization.MutableStringConcat;
|
||||
import ru.windcorp.progressia.client.localization.MutableStringLocalized;
|
||||
import ru.windcorp.progressia.client.world.item.inventory.InventoryComponent;
|
||||
|
||||
public class InventoryWindow extends Panel {
|
||||
|
||||
private static final String CLOSE_CHAR = "\u2715";
|
||||
private static final String HANDLE_CHAR = "\u2800";
|
||||
private static final Vec4 CLOSE_BUTTON_IDLE = Colors.toVector(0xFFBC1515);
|
||||
private static final Vec4 CLOSE_BUTTON_HOVER = Colors.toVector(0xFFFA6464);
|
||||
private static final Vec4 CLOSE_BUTTON_PRESSED = Colors.BLACK;
|
||||
@ -56,6 +62,17 @@ public class InventoryWindow extends Panel {
|
||||
titleBar.addChild(createLabel(component).setLayoutHint(LayoutBorderHorizontal.CENTER));
|
||||
titleBar.addChild(createCloseButton(component).setLayoutHint(LayoutBorderHorizontal.RIGHT));
|
||||
|
||||
new DragManager().install(titleBar);
|
||||
titleBar.addListener(new Object() {
|
||||
@Subscribe
|
||||
public void onWindowDragged(DragEvent e) {
|
||||
Vec2 change = new Vec2((float) e.getCurrentChangeX(), (float) e.getCurrentChangeY());
|
||||
change.div(getParent().getWidth(), getParent().getHeight());
|
||||
relativePosition.add(change);
|
||||
requestReassembly();
|
||||
}
|
||||
});
|
||||
|
||||
addChild(titleBar);
|
||||
|
||||
addChild(component);
|
||||
@ -63,7 +80,10 @@ public class InventoryWindow extends Panel {
|
||||
|
||||
private Label createLabel(InventoryComponent component) {
|
||||
String translationKey = "Inventory." + component.getInventory().getId() + ".Title";
|
||||
MutableString titleText = new MutableStringLocalized(translationKey);
|
||||
MutableString titleText = new MutableStringConcat(
|
||||
HANDLE_CHAR + " ",
|
||||
new MutableStringLocalized(translationKey)
|
||||
);
|
||||
Font titleFont = new Font().deriveBold().withColor(Colors.BLACK).withAlign(Typeface.ALIGN_LEFT);
|
||||
|
||||
return new Label(getName() + ".Title", titleFont, titleText);
|
||||
|
@ -39,9 +39,15 @@ public class WindowedLayout implements Layout {
|
||||
if (Float.isNaN(relPos.x) || Float.isNaN(relPos.y)) {
|
||||
relPos.x = 0.5f;
|
||||
relPos.y = 2 / 3.0f;
|
||||
}
|
||||
} else {
|
||||
float minPosX = 0;
|
||||
float minPosY = window.getHeight() / (float) c.getHeight();
|
||||
float maxPosX = 1;
|
||||
float maxPosY = 1;
|
||||
|
||||
relPos.clamp(0, 1);
|
||||
relPos.x = Glm.clamp(relPos.x, minPosX, maxPosX);
|
||||
relPos.y = Glm.clamp(relPos.y, minPosY, maxPosY);
|
||||
}
|
||||
|
||||
window.setPosition(
|
||||
(int) (relPos.x * c.getWidth() - window.getWidth() / 2.0f),
|
||||
|
Reference in New Issue
Block a user