PDA

View Full Version : Some Gui problems


coreys
09-08-2007, 06:16 AM
Well, I'm setting up an Inventory on Maloria, and there's obviously an area there with the slots for the item icons. It's a 4x6 grid, basically, and there' up/down page buttons. So I have this function to show the items for the page:

function loadPage() {
this.itemssize = clientr.items.size()-((this.page-1)*24);
temp.base = {218, 53};
temp.i = 1;
with (Inv) {
for (h=0; h<6; h++) {
for (w=0; w<4; w++) {
with (new GuiShowImgCtrl("ItemIcon_" @ temp.i)) {
resize(temp.base[0]+(32*w),temp.base[1]+(32*h),32,32);
image = "block.png";
Inv.addControl(this);
}
player.chat = h;
if (temp.i <= this.itemssize)
temp.i++;
else
break;
}
}
}
}
But, for whatever reason, when it gets the point where it's setting player.chat to h, h equals 5...that means it seems to be waiting until the end of the first for loop before going on the the next for loop. o.0

Help. :<

Inverness
09-08-2007, 06:26 AM
h and w should both be temp variables.

And use the F2 window (echo) rather than player.chat. Because most likely all the loops are being completed so fast player.chat only shows the last result.

coreys
09-08-2007, 06:29 AM
Okay, I did change them to that, but I also figured out why that's happening. It has to do with the chat system on Maloria, so there's nothing wrong with the for loops. However, the icons are showing in...odd places.
Here's what I have now:

function loadPage() {
for (a=1; a<25; a++) {
makevar("ItemIcon_" @ a).destroy();
}
this.itemssize = clientr.items.size()-((this.page-1)*24);
temp.base = {218, 53};
temp.i = 1;
temp.height = temp.width = 0;
for (temp.height=0; temp.height<6; temp.height++) {
for (temp.width=0; temp.width<4; temp.width++) {
with (new GuiShowImgCtrl("ItemIcon_" @ temp.i)) {
resize(temp.base[0]+(32*temp.width),temp.base[1]+(32*temp.height),32,32);
image = "block.png";
Inv.addControl(this);
}
if (temp.i < this.itemssize)
temp.i++;
else
break;
}
}
}
There's an icon in the top left corner and the the bottom left corner. o.0

zokemon
09-08-2007, 07:11 AM
Okay, I did change them to that, but I also figured out why that's happening. It has to do with the chat system on Maloria, so there's nothing wrong with the for loops. However, the icons are showing in...odd places.
Here's what I have now:

function loadPage() {
for (a=1; a<25; a++) {
makevar("ItemIcon_" @ a).destroy();
}
this.itemssize = clientr.items.size()-((this.page-1)*24);
temp.base = {218, 53};
temp.i = 1;
temp.height = temp.width = 0;
for (temp.height=0; temp.height<6; temp.height++) {
for (temp.width=0; temp.width<4; temp.width++) {
with (new GuiShowImgCtrl("ItemIcon_" @ temp.i)) {
resize(temp.base[0]+(32*temp.width),temp.base[1]+(32*temp.height),32,32);
image = "block.png";
Inv.addControl(this);
}
if (temp.i < this.itemssize)
temp.i++;
else
break;
}
}
}
There's an icon in the top left corner and the the bottom left corner. o.0

Huh? How would the chat system be doing it?

coreys
09-08-2007, 05:01 PM
Huh? How would the chat system be doing it?

Oh, no it's just that the chat is setting so fast that your chat system doesn't actually show until the number 5.

Chompy
09-08-2007, 05:49 PM
The icon coords, are you taking them into consideration from the inventory itself?
Like before the loop get the x and y of the inventory object etc..

coreys
09-08-2007, 06:01 PM
The loop is determining the coordinates though o.0

Googi
09-08-2007, 08:01 PM
The icon coords, are you taking them into consideration from the inventory itself?
Like before the loop get the x and y of the inventory object etc..

I think that's what temp.base is for.

Chompy
09-08-2007, 10:18 PM
Hmm, then my guess is, you're not giving them a coordinate in the Inventory control? I'm not used to use the inventory itself as an gui control.. I just use an image and then a for() loop and place them on the image itself..

and I use another method for placing them (Thanks Contiga for that one :p)

x = x + (offsetx*index§iconshorizontal);
y = y + (offsety*int(index/iconsvertical));


for example for 6x6 icons I do:

this.ix = inventory.x;
this.iy = inventory.y;
for(temp.i = 0; i < 36; i ++) {
new GuiBitmapButtonCtrl("button_" @ i) {
x = thiso.ix + 13.5 + (33*(i§6));
y = thiso.iy + 165 + (33*int(i/6));

this.image = "bomb.png";

normalbitmap = this.image;
mouseoverbitmap = this.image;
pressedbitmap = this.image;

width = 32;
height = 32;

thiso.catchevent(this, "onMouseDown", "onItemPressed");
}
}


PS: In the scripts I had to write § instead of o/o (percent symbol), stupid bad request **** =/

coreys
09-08-2007, 10:39 PM
Thanks Chompy...well now I'm having problems with dragging the icon around. Here's what I have:

function loadPage() {
for (a=1; a<25; a++) {
makevar("ItemIcon_" @ a).destroy();
}
this.itemssize = clientr.items.size()-((this.page-1)*24);
temp.base = {218+Inv.x, 53+Inv.y};
for (temp.i=0; temp.i<this.itemssize; temp.i++) {
new GuiShowImgCtrl("ItemIcon_" @ temp.i) {
x = temp.base[0] + (32*(temp.i%4));
y = temp.base[1] + (32*int(temp.i/6));
image = "bcalarmclock.png";
this.origin = {this.x, this.y};
thiso.catchevent(this.name, "onMouseDown", "linkItem");
thiso.catchevent(this.name, "onRightMouseDown", "onItemRightClicked");
thiso.catchevent(this.name, "onMouseUp", "unlinkItem");
thiso.catchevent(this.name, "onMouseDragged", "moveItem");
InventoryGUI.addControl(this);
}
}
}
function linkItem(iname) {
makevar(iname).zoom = 1.2;
makevar(iname).width = makevar(iname).width*1.2;
makevar(iname).height = makevar(iname).height*1.2;
this.linkeditem = makevar(iname);
}
function unlinkItem() {
if (this.linkeditem != NULL) {
for (i=0; i<this.slots.size(); i++) {
if (this.linkeditem.x in |this.slots[i][0]+Inv.x, this.slots[i][2]+Inv.x| && this.linkeditem.y in |this.slots[i][1]+Inv.y, this.slots[i][3]+Inv.y|) {
if (this.slots[i][5] == NULL) equipItem(this.slots[i][4], this.linkeditem.name);
else {
unequipItem(this.slots[i][4], this.slots[i][5]);
equipItem(this.slots[i][4], this.linkeditem.name);
}
this.slots[i][5] = this.linkeditem.name;
}
}
with (this.linkeditem) {
zoom = 1;
extent = {32,32};
position = this.origin;
}
this.linkeditem = NULL;
}
}
function moveItem() {
if (this.linkeditem != NULL)
this.linkeditem.position = {params[2], params[3]};
}
Which works, except...for some reason I can't drag the icon to the left. o.0 Which is kind of a problem, because the main reason I'm doing this is to drag it to the equip slots, which is to the left of the icons.

By the way, Chompy, where the hell have you been? You haven't been on Maloria in forever. D:

Chompy
09-08-2007, 11:04 PM
By the way, Chompy, where the hell have you been? You haven't been on Maloria in forever. D:

Internet problems...
I'm switching to a faster modem tomorrow, because our current one just plainly sucks.. I think my current modem is run by teletubies =/

zokemon
09-09-2007, 01:53 AM
Oh, no it's just that the chat is setting so fast that your chat system doesn't actually show until the number 5.

That's not the chat system, normal chat is just like that o_o. Everything in Graal only updates every 0.05 seconds you know.

coreys
09-09-2007, 02:32 AM
That's not the chat system, normal chat is just like that o_o. Everything in Graal only updates every 0.05 seconds you know.

That's what I meant, jerk ;(

And Zeo, you said you fixed it when you were on RC, but you didn't D:

Googi
09-09-2007, 05:31 AM
this.linkeditem.position = {params[2], params[3]};

I'm not sure where the values for the params[] array are supposed to be coming from here...

Chompy
09-09-2007, 03:14 PM
And Zeo, you said you fixed it when you were on RC, but you didn't D:

I fixed the dragging..
It worked for me atleast xD

coreys
09-09-2007, 04:03 PM
I'm not sure where the values for the params[] array are supposed to be coming from here...

From the event the catchevent() is catching. It worked.

And Chompy wtf, it works the same as before for me...I already tried exactly what you did, which was use mousescreenx and mousescreeny and it didn't change anything...D:

Googi
09-09-2007, 11:26 PM
From the event the catchevent() is catching. It worked.

But I thought the params[] array for onMouseDragged should only have three values - the modifier key, mousex and mousey.

coreys
09-10-2007, 02:50 PM
But I thought the params[] array for onMouseDragged should only have three values - the modifier key, mousex and mousey.

But, because I used catchevent(), the first param is the control name
Anyways, I signed back on and it suddenly works, so wtf o.o

coreys
09-27-2007, 02:13 AM
Hmm, then my guess is, you're not giving them a coordinate in the Inventory control? I'm not used to use the inventory itself as an gui control.. I just use an image and then a for() loop and place them on the image itself..

and I use another method for placing them (Thanks Contiga for that one :p)

x = x + (offsetx*index§iconshorizontal);
y = y + (offsety*int(index/iconsvertical));


for example for 6x6 icons I do:

this.ix = inventory.x;
this.iy = inventory.y;
for(temp.i = 0; i < 36; i ++) {
new GuiBitmapButtonCtrl("button_" @ i) {
x = thiso.ix + 13.5 + (33*(i§6));
y = thiso.iy + 165 + (33*int(i/6));

this.image = "bomb.png";

normalbitmap = this.image;
mouseoverbitmap = this.image;
pressedbitmap = this.image;

width = 32;
height = 32;

thiso.catchevent(this, "onMouseDown", "onItemPressed");
}
}


PS: In the scripts I had to write § instead of o/o (percent symbol), stupid bad request **** =/

Sorry to revive this thread, but...that actually doesn't work, Chompy. =/
It works only for an even grid (like your 6x6 example)
So i changed the y to:

y = temp.base[1] + (32*int(roundTo((temp.id/6),1.1)));
roundTo() being Zero's roundTo() function.

public function roundTo(val, place) {
return int(val/place + 0.5)*place;
}
But, that only works for TWO lines...(on a 4x6 grid)...so now I can't figure out how to do it.