1 registered members (TipmyPip),
18,619
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
A problem regarding text fonts(Solved)
#314931
03/12/10 06:47
03/12/10 06:47
|
Joined: Mar 2009
Posts: 88
Walori
OP
Junior Member
|
OP
Junior Member
Joined: Mar 2009
Posts: 88
|
G'day today I have a cosmetic problem for you guru's out there. The situation is as it follows: (Link to the image:http://img291.imageshack.us/img291/9704/problempic.jpg) I've done two functions (see below for sources) which handle Quest interface, and more the part of text handling. First I load quests from separate file to the memory and initialize the txts and panels from this function. I copy texts to the newly created txts and assign a font to the txt. So far so good (look the picture; the text below the panel is the text copied to the memory) Now when I press F3 in this case I open my nicely done questbook. Panels load ok, They get aligned and painted as I want but the texts use the original font from Acknex engine. (See picture; The last quest on the panel and compate it to the text foreground). Now this wouldn't be such a problem if I didn't want to use WWRAP, but I do.Note that I'm copying from struct array (QUEST*quest[200] to the function array QUEST*q[20],see source) TLDR (And the question): What happens to the font when I copy it to the function pointer from memory where font works? And why if I try to add font later to the book txts they disappear? SOURCES:
Defined:
FONT* ArialB = "Arial#18";
FONT* ArialN = "Arial#14";
typedef struct
{
Quest*quest[200];
}MODULE;
Questbook:
function INIT_CHR_QUESTBOOK(MODULE*mod, CHR*chr)
{
var i;
var a;
var b;
int open = 0;
var x_pos = 0;
var y_pos = 40;
int f3_clear = 1;
QUEST*q[20];
for(i=0;i<20;i++)
{
q[i] = NULL;
}
PANEL* qb_bg=
{
pos_x = 0;
pos_y = 0;
size_x = 0;
size_y = 0;
//bmap = NULL;
green = 0;
blue = 120;
red = 0;
layer = 100;
flags = VISIBLE | LIGHT | TRANSLUCENT;
}
TEXT* q_title =
{
strings = 1;
font = "Arial#16";
layer = 105;
}
TEXT* q_desc =
{
strings = 1;
font = "Arial#14";
layer = 105;
}
PANEL* q_pan=
{
pos_x = 0;
pos_y = 0;
size_x = 0;
size_y = 0;
layer = 100;
}
PANEL*clicked_panel = NULL;
QUEST*clicked_quest = NULL;
//Just to keep on tracks of inventories
INVENTORY* inv = new(INVENTORY);
inv->id = 2;
inv->open = 0;
chr->inventory[2] = inv;
while(chr != NULL && mod != NULL)
{
//This is to check if there are new quests
//Note that q[20] is only a pointer to quests in the player, we won't mod anything on that array
for(i=0;i<20;i++)
{
for(a=0;a<20;a++)
{
if(q[a] == chr->quest[i])
{
break;
}
//if we didn't break,we have a new quest
for(b=0;b<20;b++)
{
if(q[b] == NULL)
{
q[b] = chr->quest[i];
//q[b]->description_txt->font ="Arial#16";
//chr->quest[i]->title_pan->pos_x =
break;
}
}
}
}
for(i=0;i<20;i++)
{
if(q[i] != NULL)
{
q[i]->description_txt->font = ArialN;
}
}
if(key_f3 && f3_clear && open == 0)
{
set(qb_bg,VISIBLE);
qb_bg.pos_x = 0;
qb_bg.pos_y = 0;
qb_bg.size_x = 240;
qb_bg.size_y = screen_size.y;
for(i=0;i<20;i++)
{
if(chr->quest[i] != NULL)
{
//We leave 100 pixels for each quest
if(y_pos < screen_size.y - 100)
{
chr->quest[i]->title_txt->pos_x = x_pos;
chr->quest[i]->title_txt->pos_y = y_pos;
chr->quest[i]->title_txt->size_x = qb_bg->size_x - 2*x_pos;
chr->quest[i]->title_txt->size_y = 20;
chr->quest[i]->title_txt->flags = VISIBLE | WWRAP;
chr->quest[i]->description_txt-> pos_x = x_pos;
chr->quest[i]->description_txt->pos_y = y_pos+23;
chr->quest[i]->description_txt->size_x = qb_bg->size_x - 2*x_pos;
test_var3 = chr->quest[i]->description_txt->size_x;
chr->quest[i]->description_txt->size_y = 70;
chr->quest[i]->description_txt->flags = VISIBLE | WWRAP;
layer_sort(chr->quest[i]->description_txt, 200);
chr->quest[i]->title_pan->pos_x = x_pos;
chr->quest[i]->title_pan->pos_y = y_pos;
chr->quest[i]->title_pan->size_x = qb_bg->size_x - 2*x_pos;
chr->quest[i]->title_pan->size_y = 20;
chr->quest[i]->title_pan->red = 250;
chr->quest[i]->title_pan->green = 250;
chr->quest[i]->title_pan->blue = 0;
chr->quest[i]->title_pan->flags = VISIBLE | LIGHT;
chr->quest[i]->description_pan->pos_x = x_pos;
chr->quest[i]->description_pan->pos_y = y_pos+21;
chr->quest[i]->description_pan->size_x = qb_bg->size_x - 2*x_pos;
chr->quest[i]->description_pan->size_y = 70;
chr->quest[i]->description_pan->flags = VISIBLE | LIGHT;
y_pos +=100;
}
}
}
f3_clear = 0;
open = 1;
}
if(!key_f3) f3_clear = 1;
if(open == 1 && f3_clear == 1 && !key_f3)
{
if(mouse_left)
if(mouse_panel)
{
for(i=0;i<20;i++)
{
if(chr->quest[i] != NULL)
{
if(chr->quest[i]->description_pan == mouse_panel)
{
clicked_panel = mouse_panel;
clicked_quest = chr->quest[i];
str_cpy((q_title->pstring)[0],(clicked_quest->title_txt->pstring)[0]);
str_cpy((q_desc->pstring)[0],(clicked_quest->description_txt->pstring)[0]);
break;
}
}
}
}
if(clicked_quest != NULL)
{
if(q_pan.size_y < 400)
{
q_pan.flags = VISIBLE | LIGHT;
q_pan.pos_y = 100;
q_pan.pos_x = qb_bg.size_x;
q_pan.size_x = 250;
q_pan.red = 250;
q_title.pos_x = qb_bg->size_x;
q_title.pos_y = q_pan.pos_y+3;
q_desc.pos_y = q_title.pos_y+20;
q_desc.pos_x = qb_bg->size_x;
q_pan.size_y +=160*time_step;
}
else
{
q_desc.flags = VISIBLE;
q_title.flags = VISIBLE;
str_cpy((q_title->pstring)[0],(clicked_quest->title_txt->pstring)[0]);
str_cpy((q_desc->pstring)[0],(clicked_quest->description_txt->pstring)[0]);
}
}
}
if(key_f3 && f3_clear == 1 && open == 1)
{
str_cpy((q_title->pstring)[0],"");
str_cpy((q_desc->pstring)[0],"");
q_desc.flags = NULL;
q_title.flags = NULL;
q_pan.flags = NULL;
reset(qb_bg,VISIBLE);
for(i=0;i<20;i++)
{
if(chr->quest[i] != NULL)
{
chr->quest[i]->title_txt->flags = NULL;
chr->quest[i]->description_txt->flags = NULL;
chr->quest[i]->description_pan->flags = NULL;
chr->quest[i]->title_pan->flags = NULL;
}
}
y_pos = 40;
q_pan.size_y = 0;
open = 0;
f3_clear = 0;
}
wait(5);
}
}
Loading to the struct array
function INIT_MODULE_QUEST(MODULE*mod, STRING* file_path)
{
var i;
var fhandle;
var var_temp;
var a = 0;
var count = 0;
STRING* temp_str="";
fhandle = file_open_read(file_path);
file_str_readto(fhandle,temp_str,"~",4000);
file_str_readto(fhandle,temp_str,"~",4000);
file_str_readto(fhandle,temp_str,"~",4000);
str_cpy(temp_str,"");
while(1)
{
QUEST* q = new(QUEST);
q->title_txt = txt_create(1,0);
q->description_txt = txt_create(1,0);
q->id = file_var_read(fhandle);
if(q->id == 0)
{
ptr_remove((q->title_txt.pstring)[0]);
ptr_remove(q->title_txt);
ptr_remove((q->description_txt.pstring)[0]);
ptr_remove(q->description_txt);
free(q);
break;
}
q->description_txt->font = ArialN;
q->title_txt->font = ArialB;
file_str_readto(fhandle,(q->title_txt->pstring)[0],"~",4000);
file_str_readto(fhandle,(q->description_txt->pstring)[0],"~",4000);
q->required_quest = file_var_read(fhandle);
q->completed = 0;
q->required_gossipP = file_var_read(fhandle);
q->required_gold = file_var_read(fhandle);
q->quest_giver = file_var_read(fhandle);
q->quest_receiver = file_var_read(fhandle);
q->quest_objective = file_var_read(fhandle);
q->quest_doer = file_var_read(fhandle);
for(i=0;i<4;i++)
{
q->received_item[i] = file_var_read(fhandle);
}
//THIS IS PRE POSITION FOR DEBUG MSG
for(i=0;i<3;i++)
{
OBJECTIVE* obj = new(OBJECTIVE);
obj->item_1 = 0;
obj->npc_1 = 0;
obj->complete = 0;
obj->item_c_1 = file_var_read(fhandle);
obj->npc_c_1 = file_var_read(fhandle);
obj->required_item = file_var_read(fhandle);
obj->required_npc = file_var_read(fhandle);
q->obj[a] = obj;
a++;
}
a = 0;
mod->quest[q->id] = q;
wait(1);
}
ptr_remove(temp_str);
file_close(fhandle);
return 1;
}
(Sorry for huges post, this has just bugged me for a while and would really like to get on with it Yours Walori
Last edited by Walori; 03/15/10 11:02.
|
|
|
Re: A problem regarding text fonts
[Re: MMike]
#315392
03/15/10 06:54
03/15/10 06:54
|
Joined: Mar 2009
Posts: 88
Walori
OP
Junior Member
|
OP
Junior Member
Joined: Mar 2009
Posts: 88
|
Quest does work as much it should at this point ( leaving this out)
The font define was only for testing to see if it's something wrong with those I had defined straight to the objects. Result is still the same.
regards walori
EDIT: All works now, appearently I had given questbook structure an invalid pointer which I created upon quest giving, it's a mystery though why engine didn't throw an error message for invalid pointer
Last edited by Walori; 03/15/10 11:03.
|
|
|
|