PDA

View Full Version : GUI



ShadowDust
12-29-2008, 05:02 AM
how can i make a GUI that moves with the screen?

Seth
12-29-2008, 08:37 AM
You can attach an entity to the camera itself, instead of another entity:


this:SetAttach(C_ENTITY_CAMERA, Vector2(0,0)); //attach to camera, will be at the upper left.

You may want to do:

this:SetAlignment(C_ORIGIN_TOP_LEFT, Vector2(0,0)); //align by top left point

and

this:SetPersistent(false); //don't save with the map

as well. Check the RPG or Dink example's script\gui\interface.lua as an example.

sirlich
10-16-2009, 03:28 PM
I guess I'm not understanding the syntax behind "GetType()" I've edited the setup_constants.lua to add C_TYPE_GUI = 100;

Now since my gui/inventory project relies on left mouse clicks for player movement AND I've incorporated buttons on my gui interface (see image)... I need to ignore the movement clicks when the mouse clicks on the gui buttons...

After creating the button entity and adding the button image in the interface script, I've placed 'this:SetType(C_TYPE_GUI);' to assign its type. Now trying to ignore this type in the mouse movement, apparently I'm not getting it right.

I've tried:
if (this:GetType() != "100") then
if (this:GetType() != 100) then
if (this:GetType() != "C_TYPE_GUI") then

Help with syntax please?

Edit: fixed another way:

if (ent:Data():Get("ObjType") != "gui") then
Still not sure why GetType didn't work though.

sirlich
10-17-2009, 01:45 PM
Also, if I would like to have a second, but separate entity (with it's own controls and attached entities) as part of my gui, would I need to create a separate interface.lua file (interface2.lua) and would the interface_utils.lua file need to reflect another "g_interfaceID", say _G.g_interfaceID2? Thinking yes but just need confirmation.

Another Problem:


m_Inventory = this:CreateEntity(this:GetMap(), Vector2(0,0), "gui/inventory.lua");
this:AddImageToMapCache("~/inventory_40.png");
this:SetType(C_TYPE_GUI);
m_Inventory:RunFunction("Setup", "Button", "inventory", 10, 20, C_ORIGIN_TOP_LEFT);
m_Inventory:SetAttach(this:GetID(), Vector2(380,-400)); m_Inventory:SetName("Inventory");
m_Inventory:Data():SetIfNull("ObjType",'gui');
m_Inventory:Data():SetIfNull("Name", 'Inventory');
m_Inventory:SetLockedScale(true);

m_bInventory = this:CreateEntity(this:GetMap(), Vector2(0,0), "gui/bgui_inventory.lua");
this:AddImageToMapCache("~/button_inv.png");
this:SetType(C_TYPE_GUI);
m_bInventory:RunFunction("Setup", "Button", "button_inv", 10, 20, C_ORIGIN_TOP_LEFT);
m_bInventory:SetAttach(this:GetID(), Vector2(365,45)); m_bInventory:SetName("Button_Inv");
m_bInventory:Data():SetIfNull("ObjType",'gui');
m_bInventory:Data():SetIfNull("Name", 'Inventory');
m_bInventory:SetLockedScale(true);

m_bInventory works yet m_inventory entity produces an error:

Unable to find resourceID 4224115185 (extra info not available)
Error, entity 6654 () is unable to find image with hash 4224115185 to use.
...even when the entity scripts are identical

I had the image originally in a map directory and imported into a map Palette, though without thinking it would affect the map, I moved the image to the script directory to make it easier on coding the gui interface. After this error occurred, I went back to the map in the editor and noticed the same error (Unable to find resourceID ...) recurring dozens of times. So I did a "Rebuild World Navigation Cache" and when that didn't clear the error, just cleared the map. That fixed the error in the editor but not when running the game. A bug perhaps?

sirlich
10-17-2009, 03:19 PM
...
I've tried:
if (this:GetType() != "100") then
if (this:GetType() != 100) then
if (this:GetType() != "C_TYPE_GUI") then

Help with syntax please?

Edit: fixed another way:

if (ent:Data():Get("ObjType") != "gui") then
Still not sure why GetType didn't work though.

Edit again: thinking it didn't work because of "this" instead of using "m_Inventory"... That's got to be the hardest part of coding: knowing when to use "this"...

Still not sure about the "100" or 100 or "C_TYPE_GUI" though will probably be easy to figure out now.

As for the previous post, worked around it (so far, I think) by putting this in the interface.lua:

m_Inventory:RunFunction("Setup", false);
m_Inventory:SetName("Inventory");
m_Inventory:Data():SetIfNull("ObjType",'gui');
m_Inventory:Data():SetIfNull("Name", 'Inventory');
m_Inventory:SetLockedScale(true);
and the following in the entity setup function:

this:SetPersistent(false);

this:SetImage("~/inventory_40.png", nil);
this:SetLayerByName("GUI 1");
this:SetAlignment(C_ORIGIN_TOP_LEFT, Vector2(400,150));
this:SetAttach(C_ENTITY_CAMERA, Vector2(400,150));

Seth
10-20-2009, 06:06 AM
Sorry for the slow reply, looks like you got most of it going, couple of notes:

1. think of "this:" as a way to say "GetTheEntityThatRanThisScript:", so, just like GetPlayer, it returns an Entity.

2. GetType() uses a number

3. Images that are put in map directories are handled a special way, it doesn't matter which map directory they are in, any map can find them and use them

But, images in the script directory don't work that way and can't be used as tiles unless an entity specifically loads them and knows the path. (or uses the ~/ thing for "my dir" like you did)

So I suspect you are getting the "Unable to find resourceID 4224115185 (extra info not available)" because there is still a tilepic or two someplace that uses those images laying around.

You should probably use the Tile Edit Floating palette->Utilities->Remove tiles with missing graphics option, this should kill them all for you. (Zoom out on the map in question first, it only works on what you can see)