Posted By: oldschoolj
How to: matching panels with images - 09/25/07 02:05
Well I'm not sure if this will be useful to anyone, but here we go.
Situation: Lets say you have a bunch of panels, such as in an inventory, or
abilities for a game, or in a RTS, the panels that let you build things.
Regardless, you probably want to have a nice pop-up image when you click them,
or mouse-over them. So you've made some custom bitmaps, that you want to showup
as a tooltip for each one of those icons, panels, etc. Here is an easy way to make the right image show up. This example is based on a maximum of 1,000
unique tooltips. I'm going to assume that you've already defined each of your panels, and have them all assigned dynamically to a pointer, which we will call
temp_panel. If thats not the case, and you are needing to have a solution for
moving icons around, I can post that too.
First we need to define our bitmap entities. In my case, its items that the hero can wear.
Code:
Make a temporary bmap enitity, which we will use to point to the right bmap.
Code:
We need a temporary panel entity as well, which will display all of our tooltips.
Code:
We have to have an array, which will store the handles for all of our tooltips.
Code:
Then we need to assign the arrays positions to the bitmaps. We can use a handle for that. You can name the bitmaps whatever you like, and also assign whatever
position in the array that you want, to that bmap. It does'nt matter:) The only
thing that IS important is that your array numbering matches your icon panel
numbering, as you will see further down. So it is important to use a naming
method ordering method.
Code:
Now for the function that does the work. my inventory panel is called
ui_inv_panel, and I've previously made this panel with its own image. I also want to make sure that all of the tooltips show up next to the panel no matter
how big or small they are. In my case it's on the left, and in line with the
bottom of the inventory. While I have the mouse-button pressed the tooltip will
showup, and then the panel will be removed after I let go. If you've made a
function for dragging the icon around, it won't interupt this display, and
there is no delay.
So we make a local variable, "d" in this case, and run a for loop, untill it
reaches 1000. Because we've already had temp_panel pointing to the icon panels,
we can take that as an argument, and the for loop will run untill that pointer
matches the panel we are touching. Then, we take the temporary bmap we made,
and make it point to the proper image. We create the panel with that image, put
it in the right spot, and keep it around as long as we have the mouse clicked.
After that, we remove it, because we don't need it anymore
Code:
Well, I'm still learning about this stuff, and am very new to programming, so if
others out there have had a hard time in this situation, I hope that this will speed you along:)
PS. I'm aware that i don't need to type "0000" because I probably could put just 0, but I'm am somewhat of a OCD, so it makes me feel better, lol.
Jesse
Situation: Lets say you have a bunch of panels, such as in an inventory, or
abilities for a game, or in a RTS, the panels that let you build things.
Regardless, you probably want to have a nice pop-up image when you click them,
or mouse-over them. So you've made some custom bitmaps, that you want to showup
as a tooltip for each one of those icons, panels, etc. Here is an easy way to make the right image show up. This example is based on a maximum of 1,000
unique tooltips. I'm going to assume that you've already defined each of your panels, and have them all assigned dynamically to a pointer, which we will call
temp_panel. If thats not the case, and you are needing to have a solution for
moving icons around, I can post that too.
First we need to define our bitmap entities. In my case, its items that the hero can wear.
Code:
BMAP* item_desc_0000 ="item_desc_0000.tga";//item_sword_00001 icon panel, all other weapons are item_icon_0002-0099
BMAP* item_desc_0100 ="item_desc_0100.tga";//item_shield_00001 icon panel, all other shields are item_icon_0101-0149
BMAP* item_desc_0150 ="item_desc_0150.tga";//item_belt_00001 icon panel, all other belts are item_icon[0150]-0199
BMAP* item_desc_0200 ="item_desc_0200.tga";//slim_cap_00001 icon panel, all other head items are item_icon_0201-0249
BMAP* item_desc_0250 ="item_desc_0250.tga";//slim_chest_00001 icon panel, all other chest items are item_icon_0251-0299
BMAP* item_desc_0300 ="item_desc_0300.tga";//slim_lboot_00001 icon panel, all other Lboots are item_icon_0301-0349
BMAP* item_desc_0350 ="item_desc_0350.tga";//slim_rboot_00001 icon panel, all other Rboots are item_icon_0351-0399
BMAP* item_desc_0400 ="item_desc_0400.tga";//slim_lshoulder_00001 icon panel, all other Lshoulders are item_icon_0401-0449
BMAP* item_desc_0450 ="item_desc_0450.tga";//slim_rshoulder_00001 icon panel, all other Rshoulders are item_icon_0450-0499
BMAP* item_desc_0550 ="item_desc_0550.tga";//slim_wrist_00001 icon panel, all other wrists are item_icon_0551-0600
Make a temporary bmap enitity, which we will use to point to the right bmap.
Code:
BMAP* item_desc_temp; //temp bmap pointer
We need a temporary panel entity as well, which will display all of our tooltips.
Code:
PANEL* ui_item_desc_pan; //temp panel pointer
We have to have an array, which will store the handles for all of our tooltips.
Code:
var item_desc_array[1000]; //will point to the bmap needed for item description
Then we need to assign the arrays positions to the bitmaps. We can use a handle for that. You can name the bitmaps whatever you like, and also assign whatever
position in the array that you want, to that bmap. It does'nt matter:) The only
thing that IS important is that your array numbering matches your icon panel
numbering, as you will see further down. So it is important to use a naming
method ordering method.
Code:
item_desc_array[0000]=handle(item_desc_0000);
item_desc_array[0100]=handle(item_desc_0100);
item_desc_array[0150]=handle(item_desc_0150);
item_desc_array[0200]=handle(item_desc_0200);
item_desc_array[0250]=handle(item_desc_0250);
item_desc_array[0300]=handle(item_desc_0300);
item_desc_array[0350]=handle(item_desc_0350);
item_desc_array[0400]=handle(item_desc_0400);
item_desc_array[0450]=handle(item_desc_0450);
item_desc_array[0550]=handle(item_desc_0550);
Now for the function that does the work. my inventory panel is called
ui_inv_panel, and I've previously made this panel with its own image. I also want to make sure that all of the tooltips show up next to the panel no matter
how big or small they are. In my case it's on the left, and in line with the
bottom of the inventory. While I have the mouse-button pressed the tooltip will
showup, and then the panel will be removed after I let go. If you've made a
function for dragging the icon around, it won't interupt this display, and
there is no delay.
So we make a local variable, "d" in this case, and run a for loop, untill it
reaches 1000. Because we've already had temp_panel pointing to the icon panels,
we can take that as an argument, and the for loop will run untill that pointer
matches the panel we are touching. Then, we take the temporary bmap we made,
and make it point to the proper image. We create the panel with that image, put
it in the right spot, and keep it around as long as we have the mouse clicked.
After that, we remove it, because we don't need it anymore

Code:
function ui_inv_show_desc()
{
var d;
for (d = 0000;d<999;d++)
{
if(temp_panel == item_icon[d])
{
item_desc_temp = ptr_for_handle(item_desc_array[d]);
}
}
ui_item_desc_pan = pan_create ("bmap = item_desc_temp;flags = VISIBLE;", 5);
ui_item_desc_pan.pos_x = ui_inv_panel.pos_x - bmap_width(item_desc_0000);
ui_item_desc_pan.pos_y = ui_inv_panel.pos_y + (bmap_height(ui_inv_bg) - bmap_height(item_desc_0000));
while (mouse_left == 1)
{
wait (1);
}
pan_remove (ui_item_desc_pan);
}
Well, I'm still learning about this stuff, and am very new to programming, so if
others out there have had a hard time in this situation, I hope that this will speed you along:)
PS. I'm aware that i don't need to type "0000" because I probably could put just 0, but I'm am somewhat of a OCD, so it makes me feel better, lol.
Jesse