Skip to content

Commit fb96c26

Browse files
committed
Merge branch 'menuRework'
2 parents e7965be + 02473e9 commit fb96c26

File tree

4 files changed

+64
-16
lines changed

4 files changed

+64
-16
lines changed

src/game/ui/UiComponent.hx

+18-2
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,13 @@ class UiComponent extends h2d.Flow {
3434
function onUse() {}
3535
public dynamic function onUseCb() {}
3636

37-
public dynamic function onFocus() {
37+
@:allow(ui.UiGroupController)
38+
function onFocus() {
3839
filter = new dn.heaps.filter.Invert();
3940
}
40-
public dynamic function onBlur() {
41+
42+
@:allow(ui.UiGroupController)
43+
function onBlur() {
4144
filter = null;
4245
}
4346

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

7578

79+
public function getRelativeX(relativeTo:h2d.Object) {
80+
_tmpPt.set();
81+
localToGlobal(_tmpPt);
82+
relativeTo.globalToLocal(_tmpPt);
83+
return _tmpPt.x;
84+
}
85+
86+
public function getRelativeY(relativeTo:h2d.Object) {
87+
_tmpPt.set();
88+
localToGlobal(_tmpPt);
89+
relativeTo.globalToLocal(_tmpPt);
90+
return _tmpPt.y;
91+
}
7692

7793
public inline function globalAngTo(to:UiComponent) {
7894
return Math.atan2(to.globalCenterY-globalCenterY, to.globalCenterX-globalCenterX);

src/game/ui/UiGroupController.hx

+7-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ enum abstract GroupDir(Int) {
2222
class UiGroupController extends dn.Process {
2323
var uid : Int;
2424
var ca : ControllerAccess<GameAction>;
25-
var currentComp : Null<UiComponent>;
25+
public var currentComp(default,null) : Null<UiComponent>;
2626

2727
var components : Array<UiComponent> = [];
2828

@@ -316,6 +316,12 @@ class UiGroupController extends dn.Process {
316316
currentComp = null;
317317
}
318318

319+
public function clearAllRegisteredComponents() {
320+
currentComp = null;
321+
components = [];
322+
invalidateConnections();
323+
}
324+
319325
function focusClosestComponentFromGlobalCoord(x:Float, y:Float) {
320326
var best = Lib.findBestInArray(components, e->{
321327
return -M.dist(x, y, e.globalCenterX, e.globalCenterY);

src/game/ui/Window.hx

+13-13
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ enum WindowAlign {
1010
class Window extends dn.Process {
1111
public static var ALL : Array<Window> = [];
1212

13+
var uiWid(get,never) : Int; inline function get_uiWid() return M.ceil( w()/Const.UI_SCALE );
14+
var uiHei(get,never) : Int; inline function get_uiHei() return M.ceil( h()/Const.UI_SCALE );
15+
1316
public var content: h2d.Flow;
1417

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

171174
root.setScale(Const.UI_SCALE);
172175

173-
var wid = M.ceil( w()/Const.UI_SCALE );
174-
var hei = M.ceil( h()/Const.UI_SCALE );
175-
176176
// Horizontal
177177
if( horizontalAlign==Fill )
178-
content.minWidth = content.maxWidth = wid;
178+
content.minWidth = content.maxWidth = uiWid;
179179

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

187187
// Vertical
188188
if( verticalAlign==Fill )
189-
content.minHeight = content.maxHeight = hei;
189+
content.minHeight = content.maxHeight = uiHei;
190190

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

198198
// Mask
199199
if( mask!=null ) {
200-
mask.minWidth = wid;
201-
mask.minHeight = hei;
200+
mask.minWidth = uiWid;
201+
mask.minHeight = uiHei;
202202
}
203203
}
204204

src/game/ui/component/ControlsHelp.hx

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package ui.component;
2+
3+
class ControlsHelp extends ui.UiComponent {
4+
public function new(?p) {
5+
super(p);
6+
7+
layout = Horizontal;
8+
horizontalSpacing = 16;
9+
}
10+
11+
12+
public function addControl(a:GameAction, label:String, col:Col=White) {
13+
var f = new h2d.Flow(this);
14+
f.layout = Horizontal;
15+
f.verticalAlign = Middle;
16+
17+
var icon = App.ME.controller.getFirstBindindIconFor(a, "agnostic", f);
18+
f.addSpacing(4);
19+
20+
var tf = new h2d.Text(Assets.fontPixel, f);
21+
f.getProperties(tf).offsetY = -2;
22+
tf.textColor = col;
23+
tf.text = txt;
24+
}
25+
26+
}

0 commit comments

Comments
 (0)