Add support for windows positions
This commit is contained in:
@@ -5,6 +5,17 @@ import com.bartlomiejpluta.base.api.game.gui.component.Component;
|
|||||||
|
|
||||||
public abstract class BaseWindow extends BaseWidget implements Window {
|
public abstract class BaseWindow extends BaseWidget implements Window {
|
||||||
protected Component content;
|
protected Component content;
|
||||||
|
protected WindowPosition windowPosition;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public WindowPosition getWindowPosition() {
|
||||||
|
return windowPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setWindowPosition(WindowPosition windowPosition) {
|
||||||
|
this.windowPosition = windowPosition;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected float getContentWidth() {
|
protected float getContentWidth() {
|
||||||
|
|||||||
@@ -73,16 +73,67 @@ public class DefaultWindowManager extends BaseWidget implements WindowManager {
|
|||||||
switch (displayMode) {
|
switch (displayMode) {
|
||||||
case DISPLAY_STACK -> {
|
case DISPLAY_STACK -> {
|
||||||
for (var window : windows) {
|
for (var window : windows) {
|
||||||
window.draw(screen, gui);
|
drawWindow(screen, window, gui);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case DISPLAY_TOP -> {
|
case DISPLAY_TOP -> {
|
||||||
var topWindow = windows.peekFirst();
|
var topWindow = windows.peekFirst();
|
||||||
if (topWindow != null) {
|
if (topWindow != null) {
|
||||||
topWindow.draw(screen, gui);
|
drawWindow(screen, topWindow, gui);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void drawWindow(Screen screen, Window window, GUI gui) {
|
||||||
|
switch (window.getWindowPosition()) {
|
||||||
|
case TOP -> window.setPosition(
|
||||||
|
(screen.getWidth() - window.getWidth()) / 2,
|
||||||
|
window.getMarginTop()
|
||||||
|
);
|
||||||
|
|
||||||
|
case TOP_RIGHT -> window.setPosition(
|
||||||
|
screen.getWidth() - window.getWidth() - window.getMarginRight(),
|
||||||
|
window.getMarginTop()
|
||||||
|
);
|
||||||
|
|
||||||
|
case RIGHT -> window.setPosition(
|
||||||
|
screen.getWidth() - window.getWidth() - window.getMarginRight(),
|
||||||
|
(screen.getHeight() - window.getHeight()) / 2
|
||||||
|
);
|
||||||
|
|
||||||
|
case BOTTOM_RIGHT -> window.setPosition(
|
||||||
|
screen.getWidth() - window.getWidth() - window.getMarginRight(),
|
||||||
|
screen.getHeight() - window.getHeight() - window.getMarginBottom()
|
||||||
|
);
|
||||||
|
|
||||||
|
case BOTTOM -> window.setPosition(
|
||||||
|
(screen.getWidth() - window.getWidth()) / 2,
|
||||||
|
screen.getHeight() - window.getHeight() - window.getMarginBottom()
|
||||||
|
);
|
||||||
|
|
||||||
|
case BOTTOM_LEFT -> window.setPosition(
|
||||||
|
window.getMarginLeft(),
|
||||||
|
screen.getHeight() - window.getHeight() - window.getMarginBottom()
|
||||||
|
);
|
||||||
|
|
||||||
|
case LEFT -> window.setPosition(
|
||||||
|
window.getMarginLeft(),
|
||||||
|
(screen.getHeight() - window.getHeight()) / 2
|
||||||
|
);
|
||||||
|
|
||||||
|
case TOP_LEFT -> window.setPosition(
|
||||||
|
window.getMarginLeft(),
|
||||||
|
window.getMarginTop()
|
||||||
|
);
|
||||||
|
|
||||||
|
case CENTER -> window.setPosition(
|
||||||
|
(screen.getWidth() - window.getWidth()) / 2,
|
||||||
|
(screen.getHeight() - window.getHeight()) / 2
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
window.draw(screen, gui);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,10 @@ package com.bartlomiejpluta.base.api.game.gui.window;
|
|||||||
import com.bartlomiejpluta.base.api.game.gui.base.Widget;
|
import com.bartlomiejpluta.base.api.game.gui.base.Widget;
|
||||||
|
|
||||||
public interface Window extends Widget {
|
public interface Window extends Widget {
|
||||||
|
WindowPosition getWindowPosition();
|
||||||
|
|
||||||
|
void setWindowPosition(WindowPosition windowPosition);
|
||||||
|
|
||||||
void onOpen(WindowManager manager);
|
void onOpen(WindowManager manager);
|
||||||
|
|
||||||
void onClose(WindowManager manager);
|
void onClose(WindowManager manager);
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package com.bartlomiejpluta.base.api.game.gui.window;
|
||||||
|
|
||||||
|
public enum WindowPosition {
|
||||||
|
TOP,
|
||||||
|
TOP_RIGHT,
|
||||||
|
RIGHT,
|
||||||
|
BOTTOM_RIGHT,
|
||||||
|
BOTTOM,
|
||||||
|
BOTTOM_LEFT,
|
||||||
|
LEFT,
|
||||||
|
TOP_LEFT,
|
||||||
|
CENTER
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user