Skip to content

Commit

Permalink
Added DebugWindow
Browse files Browse the repository at this point in the history
  • Loading branch information
deepnight committed Apr 30, 2024
1 parent f16d5e1 commit e7965be
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 11 deletions.
22 changes: 22 additions & 0 deletions src/game/ui/Window.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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() );
}
Expand Down Expand Up @@ -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) )
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
36 changes: 36 additions & 0 deletions src/game/ui/win/DebugWindow.hx
Original file line number Diff line number Diff line change
@@ -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);
}
}
9 changes: 0 additions & 9 deletions src/game/ui/win/SimpleMenu.hx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit e7965be

Please sign in to comment.