diff --git a/src/game/ui/Window.hx b/src/game/ui/Window.hx index 6013821..5960332 100644 --- a/src/game/ui/Window.hx +++ b/src/game/ui/Window.hx @@ -87,6 +87,11 @@ class Window extends dn.Process { return v; } + public function setAlign(h:WindowAlign, ?v:WindowAlign) { + horizontalAlign = h; + verticalAlign = v!=null ? v : h; + } + public function isActive() { return !destroyed && ( !isModal || isLatestModal() ); } @@ -206,6 +211,23 @@ class Window extends dn.Process { } } + + public function addSpacer(pixels=4) { + var f = new h2d.Flow(content); + f.minWidth = f.minHeight = pixels; + } + + public function addTitle(str:String) { + new ui.component.Text( str.toUpperCase(), Col.coldGray(0.5), content ); + addSpacer(); + } + + public function addText(str:String, col:Col=Black) { + new ui.component.Text( str, col, content ); + } + + + override function update() { super.update(); if( canBeClosedManually && isModal && ca.isPressed(MenuCancel) ) diff --git a/src/game/ui/component/Title.hx b/src/game/ui/component/Text.hx similarity index 62% rename from src/game/ui/component/Title.hx rename to src/game/ui/component/Text.hx index 7003a0d..fa787aa 100644 --- a/src/game/ui/component/Title.hx +++ b/src/game/ui/component/Text.hx @@ -1,7 +1,7 @@ package ui.component; -class Title extends ui.UiComponent { - public function new(label:String, col:dn.Col=ColdLightGray, ?p) { +class Text extends ui.UiComponent { + public function new(label:String, col:dn.Col=Black, ?p) { super(p); paddingTop = 4; diff --git a/src/game/ui/win/DebugWindow.hx b/src/game/ui/win/DebugWindow.hx new file mode 100644 index 0000000..182c6c4 --- /dev/null +++ b/src/game/ui/win/DebugWindow.hx @@ -0,0 +1,36 @@ +package ui.win; + +class DebugWindow extends ui.Window { + public var updateCooldownS = 0.0; + + public function new(?renderCb:DebugWindow->Void) { + super(false); + + if( renderCb!=null ) + this.renderCb = renderCb; + + content.backgroundTile = Col.white().toTile(1,1, 0.5); + content.padding = 4; + content.horizontalSpacing = 4; + content.verticalSpacing = 0; + content.layout = Vertical; + setAlign(End,Start); + } + + public dynamic function renderCb(thisWin:DebugWindow) {} + + override function onResize() { + super.onResize(); + switch verticalAlign { + case Start,End: content.maxHeight = Std.int( 0.4 * h()/Const.UI_SCALE ); + case Center: content.maxHeight = Std.int( 0.8 * h()/Const.UI_SCALE ); + case Fill: content.maxHeight = Std.int( h()/Const.UI_SCALE ); + } + } + + override function update() { + super.update(); + if( updateCooldownS<=0 || !cd.hasSetS("updateLock",updateCooldownS) ) + renderCb(this); + } +} \ No newline at end of file diff --git a/src/game/ui/win/SimpleMenu.hx b/src/game/ui/win/SimpleMenu.hx index 1e92964..00cc9b3 100644 --- a/src/game/ui/win/SimpleMenu.hx +++ b/src/game/ui/win/SimpleMenu.hx @@ -31,15 +31,6 @@ class SimpleMenu extends ui.Window { } } - public function addSpacer() { - var f = new h2d.Flow(content); - f.minWidth = f.minHeight = 4; - } - - public function addTitle(str:String) { - new ui.component.Title( str, Col.coldGray(0.6), content ); - } - public function addButton(label:String, ?tile:h2d.Tile, autoClose=true, cb:Void->Void) { var bt = new ui.component.Button(label, tile, content); bt.minWidth = content.colWidth;