Skip to content

Commit

Permalink
Merge branch 'menuRework'
Browse files Browse the repository at this point in the history
  • Loading branch information
deepnight committed May 6, 2024
2 parents e7965be + 02473e9 commit fb96c26
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 16 deletions.
20 changes: 18 additions & 2 deletions src/game/ui/UiComponent.hx
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,13 @@ class UiComponent extends h2d.Flow {
function onUse() {}
public dynamic function onUseCb() {}

public dynamic function onFocus() {
@:allow(ui.UiGroupController)
function onFocus() {
filter = new dn.heaps.filter.Invert();
}
public dynamic function onBlur() {

@:allow(ui.UiGroupController)
function onBlur() {
filter = null;
}

Expand Down Expand Up @@ -73,6 +76,19 @@ class UiComponent extends h2d.Flow {
inline function get_globalCenterY() return ( globalTop + globalBottom ) * 0.5;


public function getRelativeX(relativeTo:h2d.Object) {
_tmpPt.set();
localToGlobal(_tmpPt);
relativeTo.globalToLocal(_tmpPt);
return _tmpPt.x;
}

public function getRelativeY(relativeTo:h2d.Object) {
_tmpPt.set();
localToGlobal(_tmpPt);
relativeTo.globalToLocal(_tmpPt);
return _tmpPt.y;
}

public inline function globalAngTo(to:UiComponent) {
return Math.atan2(to.globalCenterY-globalCenterY, to.globalCenterX-globalCenterX);
Expand Down
8 changes: 7 additions & 1 deletion src/game/ui/UiGroupController.hx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum abstract GroupDir(Int) {
class UiGroupController extends dn.Process {
var uid : Int;
var ca : ControllerAccess<GameAction>;
var currentComp : Null<UiComponent>;
public var currentComp(default,null) : Null<UiComponent>;

var components : Array<UiComponent> = [];

Expand Down Expand Up @@ -316,6 +316,12 @@ class UiGroupController extends dn.Process {
currentComp = null;
}

public function clearAllRegisteredComponents() {
currentComp = null;
components = [];
invalidateConnections();
}

function focusClosestComponentFromGlobalCoord(x:Float, y:Float) {
var best = Lib.findBestInArray(components, e->{
return -M.dist(x, y, e.globalCenterX, e.globalCenterY);
Expand Down
26 changes: 13 additions & 13 deletions src/game/ui/Window.hx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ enum WindowAlign {
class Window extends dn.Process {
public static var ALL : Array<Window> = [];

var uiWid(get,never) : Int; inline function get_uiWid() return M.ceil( w()/Const.UI_SCALE );
var uiHei(get,never) : Int; inline function get_uiHei() return M.ceil( h()/Const.UI_SCALE );

public var content: h2d.Flow;

var ca : ControllerAccess<GameAction>;
Expand Down Expand Up @@ -170,35 +173,32 @@ class Window extends dn.Process {

root.setScale(Const.UI_SCALE);

var wid = M.ceil( w()/Const.UI_SCALE );
var hei = M.ceil( h()/Const.UI_SCALE );

// Horizontal
if( horizontalAlign==Fill )
content.minWidth = content.maxWidth = wid;
content.minWidth = content.maxWidth = uiWid;

switch horizontalAlign {
case Start: content.x = 0;
case End: content.x = wid-content.outerWidth;
case Center: content.x = Std.int( wid*0.5 - content.outerWidth*0.5 + getModalIndex()*8 );
case Fill: content.x = 0; content.minWidth = content.maxWidth = wid;
case End: content.x = uiWid-content.outerWidth;
case Center: content.x = Std.int( uiWid*0.5 - content.outerWidth*0.5 + getModalIndex()*8 );
case Fill: content.x = 0; content.minWidth = content.maxWidth = uiWid;
}

// Vertical
if( verticalAlign==Fill )
content.minHeight = content.maxHeight = hei;
content.minHeight = content.maxHeight = uiHei;

switch verticalAlign {
case Start: content.y = 0;
case End: content.y = hei-content.outerHeight;
case Center: content.y = Std.int( hei*0.5 - content.outerHeight*0.5 + getModalIndex()*4 );
case Fill: content.y = 0; content.minHeight = content.maxHeight = hei;
case End: content.y = uiHei-content.outerHeight;
case Center: content.y = Std.int( uiHei*0.5 - content.outerHeight*0.5 + getModalIndex()*4 );
case Fill: content.y = 0; content.minHeight = content.maxHeight = uiHei;
}

// Mask
if( mask!=null ) {
mask.minWidth = wid;
mask.minHeight = hei;
mask.minWidth = uiWid;
mask.minHeight = uiHei;
}
}

Expand Down
26 changes: 26 additions & 0 deletions src/game/ui/component/ControlsHelp.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package ui.component;

class ControlsHelp extends ui.UiComponent {
public function new(?p) {
super(p);

layout = Horizontal;
horizontalSpacing = 16;
}


public function addControl(a:GameAction, label:String, col:Col=White) {
var f = new h2d.Flow(this);
f.layout = Horizontal;
f.verticalAlign = Middle;

var icon = App.ME.controller.getFirstBindindIconFor(a, "agnostic", f);
f.addSpacing(4);

var tf = new h2d.Text(Assets.fontPixel, f);
f.getProperties(tf).offsetY = -2;
tf.textColor = col;
tf.text = txt;
}

}

0 comments on commit fb96c26

Please sign in to comment.