What I am making is an editable digit. Right now you can not click on digits in our to manually edit them. So my plan is to make a panel to lay on top of another panel. The new panel is only a button. Put a text in front of that. When the button is pressed inkey is used to edit the string of the text. When we tell that panel to go bye bye it takes the panel and text with it.
Beside the pointer issue, and possible it is the same issue, is that this will only work once. If I try to make more than one of these it will crash when the button is pressed. However if there is just one it works fine. However for the editor I am working on I will probably need 1000.
Here is all the main code
//////////////////////////////
// this creates the button panel and text to lay on top of it allowing for editable text
//////////////////////////////
PANEL* create_foxpan(var pos_x,var pos_y,PANEL* mother_panel,BMAP* click_bmap,var* loc_display_var)
{
//////////////////////////////
// we create the panel and give it a button so it can adjust the string and display var
//////////////////////////////
fox_pan = pan_create("",mother_panel.layer + 1);
//////////////////////////////
// we set our position to our mother panel
//////////////////////////////
fox_pan.pos_x = mother_panel.pos_x + pos_x;
fox_pan.pos_y = mother_panel.pos_y + pos_y;
//////////////////////////////
// our bmap is our button
//////////////////////////////
pan_setbutton(fox_pan,0,0,
0,0,click_bmap,click_bmap,click_bmap,NULL,adjust_string,NULL,NULL);
//////////////////////////////
// we create the text and set it's string to that of the var we will display
//////////////////////////////
fox_text = txt_create(1,mother_panel.layer + 2);//1 higher than the butotn panel
str_cpy((fox_text.pstring)[0], "123");
str_for_num((fox_text.pstring)[0],*loc_display_var);
//////////////////////////////
// we set our position to our mother panel
//////////////////////////////
fox_text.pos_x = mother_panel.pos_x + pos_x;
fox_text.pos_y = mother_panel.pos_y + pos_y;
//////////////////////////////
// we record pointers to the panel
//////////////////////////////
fox_pan.skill_x = handle(mother_panel);//loc_display_var;//handle(loc_display_var); //handle(mother_panel);////loc_display_var;
fox_pan.skill_y = handle(fox_text);
//////////////////////////////
// we record pointers to the text
//////////////////////////////
fox_text.skill_x = handle(mother_panel);
fox_text.skill_y = loc_display_var;
//////////////////////////////
// we make the panel and the text visible
//////////////////////////////
set(fox_pan,SHOW);
set(fox_text,SHOW);
//////////////////////////////
// we return our panel pointer
//////////////////////////////
return(fox_pan);
}
//////////////////////////////
// this funciton is called when the button for the fox pan is pushed letting us know we want to change the string and thus the display number
//////////////////////////////
void adjust_string(var button_number,PANEL* panel_pointer)
{
//////////////////////////////
// we declare a string so we can use it to hold the old string
//////////////////////////////
STRING* old_string = "#3";
//////////////////////////////
// we get the pointer for the text we were using
//////////////////////////////
TEXT* temp_text = ptr_for_handle(panel_pointer.skill_y);
//////////////////////////////
// we copy the old string in case we need to put it back
//////////////////////////////
str_cpy(old_string,(temp_text.pstring)[0]);
//////////////////////////////
// we also check to see how we ended the key
//////////////////////////////
var key = inkey((temp_text.pstring)[0]); // wait until [enter] pressed
//////////////////////////////
// we get the var for the number
//////////////////////////////
var new_number = str_to_num((temp_text.pstring)[0]); // vpi == 3.142
//////////////////////////////
// we make sure we entered a number and not a letter
//////////////////////////////
if(new_number == 0)
{
//////////////////////////////
// we copy the original string back to this one
//////////////////////////////
str_cpy((temp_text.pstring)[0],old_string);
//////////////////////////////
// get it right!
//////////////////////////////
printf("must be a number");
}
else
{
//////////////////////////////
// we changed our number so now we need to update or display number
//////////////////////////////
var* loc_temp = temp_text.skill_y;
*loc_temp = new_number;
}
}
//////////////////////////////
// this function checks to see if the var has changed, and if it has we alter the string in the text to match it
//////////////////////////////
void monitor_for_var_change(TEXT** loc_text, var* loc_display_var)
{
//////////////////////////////
// we get the old value of the var
//////////////////////////////
var old_var = *loc_display_var;
// while(ptr_for_handle(handle(loc_text)) != NULL) //while(loc_text == NULL) //while(1)
while(loc_text)
{
//////////////////////////////
// this is for when we are done with the text
//////////////////////////////
if(loc_text.skill_x == 0)
{
sys_exit("");
return;
}
//////////////////////////////
// if our old var was changed then we update the string in the editble text for the fox pan
//////////////////////////////
if(old_var != *loc_display_var)
{
old_var = *loc_display_var;
str_for_num(*(loc_text.pstring)[0],*loc_display_var);
}
wait(1);
}
sys_exit("");
}
void destory_foxpan(PANEL* fox_pan)
{
TEXT* mytext;
mytext = ptr_for_handle(fox_pan.skill_y);
mytext.skill_x = 0;
wait(1);
//////////////////////////////
// we remove the text
//////////////////////////////
ptr_remove(mytext);
mytext = NULL;
//////////////////////////////
// we remove the panel
//////////////////////////////
ptr_remove(fox_pan);
}
Here is how I start up the foxx pans
temp_pan_0 = create_foxpan(0,0, mother_pan_show_0, button_to_push_bmap, display_number_0);
temp_text_0 = ptr_for_handle(temp_pan_0.skill_y);
monitor_for_var_change(ptr_for_handle(temp_pan_0.skill_y), display_number_0);
Here is how I destory the fox_pans
while(1)
{
if(key_y)
{
destory_foxpan(temp_pan_0);
// return;
while(key_y)wait(1);
}
}
I was planning on making this a user contribution so posting the code is cool.