Skip to content

Commit

Permalink
cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
newk5 committed Oct 10, 2021
1 parent 80b5149 commit f23227c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 146 deletions.
4 changes: 4 additions & 0 deletions script/debug.nut
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
return "[ "+str+" ]";
}

function printVectorScreen(v, pref="") {
Console.Print(pref+"VectorScreen{ X="+v.X+", Y="+v.Y+" }");
}

function showDebugUI() {

UI.showDebugInfo=true;
Expand Down
173 changes: 31 additions & 142 deletions script/decui/UI/UI.nut
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,9 @@ class DecUI {
e.Position.Y = e.Position.Y + s.down;
}
}
}
}
}

}

function Cursor(status) {
Expand Down Expand Up @@ -1028,6 +1029,7 @@ class DecUI {
index = this.listsNumeration.labels
};
this.listsNumeration.labels++;
b.shiftPos();
this.postConstruct(b);

if (o.rawin("bindTo")){
Expand All @@ -1037,7 +1039,7 @@ class DecUI {
if (b.getParent() == null){
b.metadata["posBeforeMove"] <- VectorScreen(b.Position.X,b.Position.Y);
}
b.shiftPos();

this.apply3DProps(o,b);
debug(b);

Expand Down Expand Up @@ -1169,69 +1171,30 @@ class DecUI {
this.listsNumeration.canvas++;

if (o.rawin("children") && o.children != null){
foreach (i, c in o.children) {
if (c.rawin("className")){
local className = c.className;

if (className == "Combobox"){
b.add(UI.Canvas(c.id), false);
} else{
local t= typeof c;
local el = t == "instance" ? UI.Canvas(c.id) : c ;
local comp = ["TabView", "Grid", "DataTable"]
local processChildren = comp.find(className) == null;

b.attachChild(el, processChildren);
}

}else {
b.add(c, false);

}
foreach (i, child in o.children) {
b.add(child, false);
/*
.add() already postions, aligns and moves the child, however,
at that point the child has already gone through those stages
once when it was created, and at that point the parent didn't exist yet
which means all of those stages were done with values relative to the player resolution
so we must reset the position and go through these same stages once again
*/
child.rePosition();
}
}


if (o.rawin("children") && o.children != null){
foreach (i, c in o.children) {
if (!c.rawin("className")) {
if (c.metadata.rawin("posBeforeMove")){
c.Position = c.metadata.posBeforeMove;
if (c.metadata.rawin("movedPos")){
c.metadata.movedPos.clear();
}
}
c.realign();
c.shiftPos();
}else {
local ccanvas = c.getCanvas();
if (ccanvas.metadata.rawin("posBeforeMove")){
ccanvas.Position = ccanvas.metadata.posBeforeMove;
if (ccanvas.metadata.rawin("movedPos")){
ccanvas.metadata.movedPos.clear();
}
}
ccanvas.realign();
ccanvas.shiftPos();
}
}
}
if (b.getParent() == null){
b.metadata["posBeforeMove"] <- VectorScreen(b.Position.X,b.Position.Y);
}
b.shiftPos();


if (b.autoResize){
if (b.autoResize){
b.realign();
b.resetMoves();
b.shiftPos();
}

if (o.rawin("border") ){
this.applyBorder(o.border, b);
}
this.apply3DProps(o,b);
this.apply3DProps(o,b);
this.postConstruct(b);
debug(b);
return b;
Expand Down Expand Up @@ -1388,7 +1351,7 @@ class DecUI {
local s = o.rawin("file") ? GUISprite(o.file, o.rawin("Position") ? o.Position : VectorScreen(0,0 )) : GUISprite();
local b = this.applyElementProps(s, o);

b.metadata.list = "sprites";
b.metadata.list = "sprites";
b.metadata.index = this.listsNumeration.sprites;
if (o.rawin("file")){
b.SetTexture(o.file);
Expand All @@ -1399,58 +1362,16 @@ class DecUI {
this.listsNumeration.sprites++;

if (o.rawin("children") && o.children != null){
foreach (i, c in o.children) {
if (c.rawin("className")){
local className = c.className;

if (className == "Combobox"){
b.add(UI.Canvas(c.id), false);
} else{
local t= typeof c;
b.attachChild(t == "instance" ? UI.Canvas(c.id) : c );
}

}else {
b.add(c, false);

}
foreach (i, child in o.children) {
b.add(child, false);
child.rePosition();
}
}

if (o.rawin("children") && o.children != null){
foreach (i, c in o.children) {
if (!c.rawin("className")) {
if (c.metadata.rawin("posBeforeMove")){
c.Position = c.metadata.posBeforeMove;
if (c.metadata.rawin("movedPos")){
c.metadata.movedPos.clear();
}
}
c.realign();
c.shiftPos();
}else {
local ccanvas = c.getCanvas();
if (ccanvas.metadata.rawin("posBeforeMove")){
ccanvas.Position = ccanvas.metadata.posBeforeMove;
if (ccanvas.metadata.rawin("movedPos")){
ccanvas.metadata.movedPos.clear();
}
}
ccanvas.realign();
ccanvas.shiftPos();
}
}
}else{
if (b.getParent() == null){
b.metadata["posBeforeMove"] <- VectorScreen(b.Position.X,b.Position.Y);
}
b.shiftPos();
}

if (b.autoResize){
b.realign();
b.resetMoves();
b.shiftPos();
b.realign();
b.resetMoves();
b.shiftPos();
}
if (o.rawin("border") ){
this.applyBorder(o.border, b);
Expand All @@ -1472,51 +1393,19 @@ class DecUI {

lists[names.find("windows")].push(b);
idsMetadata[this.cleanID(o.id)] <- { list = b.metadata.list, index = this.listsNumeration.windows };
this.listsNumeration.windows++;
this.listsNumeration.windows++;
if (o.rawin("children") && o.children != null){
foreach (i, c in o.children) {

b.add(c, false);


foreach (i, child in o.children) {
b.add(child, false);
child.rePosition();
}
}

if (o.rawin("children") && o.children != null){
foreach (i, c in o.children) {
if (!c.rawin("className")) {
if (c.metadata.rawin("posBeforeMove")){
c.Position = c.metadata.posBeforeMove;
if (c.metadata.rawin("movedPos")){
c.metadata.movedPos.clear();
}
}
c.realign();
c.shiftPos();
} else {
local ccanvas = c.getCanvas();
if (ccanvas.metadata.rawin("posBeforeMove")){
ccanvas.Position = ccanvas.metadata.posBeforeMove;
if (ccanvas.metadata.rawin("movedPos")){
ccanvas.metadata.movedPos.clear();
}
}
ccanvas.realign();
ccanvas.shiftPos();

}
}
}else{
if (b.getParent() == null){
b.metadata["posBeforeMove"] <- VectorScreen(b.Position.X,b.Position.Y);
}
b.shiftPos();
}

if (b.autoResize){
b.realign();
b.resetMoves();
b.shiftPos();
b.realign();
b.resetMoves();
b.shiftPos();
}


Expand Down
4 changes: 4 additions & 0 deletions script/decui/components/DecUIComponent.nut
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ class DecUIComponent {
UI.Canvas(this.id).show(restoreAlpha);
}

function rePosition() {
getCanvas().rePosition();
}

function hide() {
UI.Canvas(this.id).hide();
}
Expand Down
20 changes: 16 additions & 4 deletions script/decui/extensions.nut
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,9 @@ foreach(i,e in elements ) {
childElement.metadata["parentID"] <- this.id;

childElement.parents = list;
if (ct == "instance"){ //attach the parents list to the instance canvas aswell
childElement.getCanvas().parents = list;
}


this.AddChild(ct =="instance" ? childElement.getCanvas(): childElement);
Expand Down Expand Up @@ -695,14 +698,23 @@ foreach(i,e in elements ) {

//add(e)
e.rawnewmember("add", function(child, processChildren = true) {

this.attachChild(child, processChildren);



}, null, false);


//rePosition()
e.rawnewmember("rePosition", function() {
local hasMove = this.rawin("move") && this.move != null;
local hasAlign = this.rawin("align") && this.align != null;
if (hasAlign || hasMove){
this.resetPosition();
this.realign();
this.resetMoves();
this.shiftPos();
}

}, null, false);

//shift()
e.rawnewmember("shiftPos", function() {
this.UI.shift(this);
Expand Down

0 comments on commit f23227c

Please sign in to comment.