Made resources more configurable

This commit is contained in:
jsalmon3 2003-05-08 18:47:40 +00:00
parent b17b94b954
commit ae8f67640c
5 changed files with 104 additions and 220 deletions

View file

@ -198,25 +198,8 @@ typedef struct _ui_ {
int IconH; /// icon H position int IconH; /// icon H position
int TextX; /// text X position int TextX; /// text X position
int TextY; /// text Y position int TextY; /// text Y position
} Resources[MaxCosts]; /// Icon+Text of all resources } Resources[MaxCosts+2]; /// Icon+Text of all resources
/// +2 for food and score
GraphicConfig FoodIcon; /// units icon image
int FoodIconRow; /// units icon image row (frame)
int FoodIconX; /// units icon X position
int FoodIconY; /// units icon Y position
int FoodIconW; /// units icon W position
int FoodIconH; /// units icon H position
int FoodTextX; /// units text X position
int FoodTextY; /// units text Y position
GraphicConfig ScoreIcon; /// score icon image
int ScoreIconRow; /// score icon image row (frame)
int ScoreIconX; /// score icon X position
int ScoreIconY; /// score icon Y position
int ScoreIconW; /// score icon W position
int ScoreIconH; /// score icon H position
int ScoreTextX; /// score text X position
int ScoreTextY; /// score text Y position
// Info panel // Info panel
GraphicConfig InfoPanel; /// Info panel background GraphicConfig InfoPanel; /// Info panel background

View file

@ -62,6 +62,9 @@ enum _costs_ {
MaxCosts /// how many different costs MaxCosts /// how many different costs
}; };
#define FoodCost MaxCosts
#define ScoreCost MaxCosts+1
/** /**
** Speed factor for harvesting resources ** Speed factor for harvesting resources
*/ */

View file

@ -611,24 +611,26 @@ global void DrawResources(void)
,v>99999 ? SmallFont : GameFont,v); ,v>99999 ? SmallFont : GameFont,v);
} }
} }
VideoDrawSub(TheUI.FoodIcon.Graphic,0 VideoDrawSub(TheUI.Resources[FoodCost].Icon.Graphic,0
,TheUI.FoodIconRow*TheUI.FoodIconH ,TheUI.Resources[FoodCost].IconRow*TheUI.Resources[FoodCost].IconH
,TheUI.FoodIconW,TheUI.FoodIconH ,TheUI.Resources[FoodCost].IconW,TheUI.Resources[FoodCost].IconH
,TheUI.FoodIconX,TheUI.FoodIconY); ,TheUI.Resources[FoodCost].IconX,TheUI.Resources[FoodCost].IconY);
sprintf(tmp,"%d/%d",ThisPlayer->NumFoodUnits,ThisPlayer->Food); sprintf(tmp,"%d/%d",ThisPlayer->NumFoodUnits,ThisPlayer->Food);
if( ThisPlayer->Food<ThisPlayer->NumFoodUnits ) { if( ThisPlayer->Food<ThisPlayer->NumFoodUnits ) {
VideoDrawReverseText(TheUI.FoodTextX,TheUI.FoodTextY,GameFont,tmp); VideoDrawReverseText(TheUI.Resources[FoodCost].TextX
,TheUI.Resources[FoodCost].TextY,GameFont,tmp);
} else { } else {
VideoDrawText(TheUI.FoodTextX,TheUI.FoodTextY,GameFont,tmp); VideoDrawText(TheUI.Resources[FoodCost].TextX
,TheUI.Resources[FoodCost].TextY,GameFont,tmp);
} }
VideoDrawSub(TheUI.ScoreIcon.Graphic,0 VideoDrawSub(TheUI.Resources[ScoreCost].Icon.Graphic,0
,TheUI.ScoreIconRow*TheUI.ScoreIconH ,TheUI.Resources[ScoreCost].IconRow*TheUI.Resources[ScoreCost].IconH
,TheUI.ScoreIconW,TheUI.ScoreIconH ,TheUI.Resources[ScoreCost].IconW,TheUI.Resources[ScoreCost].IconH
,TheUI.ScoreIconX,TheUI.ScoreIconY); ,TheUI.Resources[ScoreCost].IconX,TheUI.Resources[ScoreCost].IconY);
v=ThisPlayer->Score; v=ThisPlayer->Score;
VideoDrawNumber(TheUI.ScoreTextX VideoDrawNumber(TheUI.Resources[ScoreCost].TextX
,TheUI.ScoreTextY+(v>99999)*3 ,TheUI.Resources[ScoreCost].TextY+(v>99999)*3
,v>99999 ? SmallFont : GameFont,v); ,v>99999 ? SmallFont : GameFont,v);
} }
} }
@ -1028,9 +1030,9 @@ global void DrawCosts(void)
if( CostsFood ) { if( CostsFood ) {
// FIXME: hardcoded image!!! // FIXME: hardcoded image!!!
VideoDrawSub(TheUI.FoodIcon.Graphic VideoDrawSub(TheUI.Resources[FoodCost].Icon.Graphic
,0,TheUI.FoodIconRow*TheUI.FoodIconH ,0,TheUI.Resources[FoodCost].IconRow*TheUI.Resources[FoodCost].IconH
,TheUI.FoodIconW,TheUI.FoodIconH ,TheUI.Resources[FoodCost].IconW,TheUI.Resources[FoodCost].IconH
,x,TheUI.StatusLineY+1); ,x,TheUI.StatusLineY+1);
VideoDrawNumber(x+15,TheUI.StatusLineY+2,GameFont,CostsFood); VideoDrawNumber(x+15,TheUI.StatusLineY+2,GameFont,CostsFood);
x+=45; x+=45;

View file

@ -673,172 +673,71 @@ local SCM CclDefineUI(SCM list)
// //
// Parse icons // Parse icons
// //
for( i=1; i<MaxCosts; ++i ) { value=gh_car(list);
// icon list=gh_cdr(list);
temp=gh_car(list); if( gh_eq_p(value,gh_symbol2scm("resources")) ) {
SCM sublist;
sublist=gh_car(list);
list=gh_cdr(list); list=gh_cdr(list);
while( !gh_null_p(sublist) ) {
SCM slist;
int res;
char* name;
if( gh_null_p(temp) ) { value=gh_car(sublist);
free(ui->Resources[i].Icon.File); sublist=gh_cdr(sublist);
ui->Resources[i].Icon.File=NULL; name=gh_scm2newstr(value,NULL);
ui->Resources[i].Icon.Graphic=NULL; for( res=0; res<MaxCosts; ++res ) {
ui->Resources[i].IconRow=0; if( !strcmp(name,DefaultResourceNames[res]) ) {
ui->Resources[i].IconX=0; break;
ui->Resources[i].IconY=0; }
ui->Resources[i].IconW=0; }
ui->Resources[i].IconH=0; if( res==MaxCosts ) {
ui->Resources[i].TextX=0; if( !strcmp(name,"food") ) {
ui->Resources[i].TextY=0; res=FoodCost;
continue; } else if( !strcmp(name,"score") ) {
res=ScoreCost;
} else {
errl("Resource not found",value);
}
}
free(name);
slist=gh_car(sublist);
sublist=gh_cdr(sublist);
while( !gh_null_p(slist) ) {
value=gh_car(slist);
slist=gh_cdr(slist);
if( gh_eq_p(value,gh_symbol2scm("pos")) ) {
value=gh_car(slist);
slist=gh_cdr(slist);
ui->Resources[res].IconX=gh_scm2int(gh_car(value));
ui->Resources[res].IconY=gh_scm2int(gh_car(gh_cdr(value)));
} else if( gh_eq_p(value,gh_symbol2scm("file")) ) {
value=gh_car(slist);
slist=gh_cdr(slist);
ui->Resources[res].Icon.File=gh_scm2newstr(value,NULL);
} else if( gh_eq_p(value,gh_symbol2scm("row")) ) {
value=gh_car(slist);
slist=gh_cdr(slist);
ui->Resources[res].IconRow=gh_scm2int(value);
} else if( gh_eq_p(value,gh_symbol2scm("size")) ) {
value=gh_car(slist);
slist=gh_cdr(slist);
ui->Resources[res].IconW=gh_scm2int(gh_car(value));
ui->Resources[res].IconH=gh_scm2int(gh_car(gh_cdr(value)));
} else if( gh_eq_p(value,gh_symbol2scm("text-pos")) ) {
value=gh_car(slist);
slist=gh_cdr(slist);
ui->Resources[res].TextX=gh_scm2int(gh_car(value));
ui->Resources[res].TextY=gh_scm2int(gh_car(gh_cdr(value)));
} else {
errl("Unsupported tag",value);
}
}
} }
if( !gh_list_p(temp) ) {
fprintf(stderr,"list expected\n");
return SCM_UNSPECIFIED;
}
value=gh_car(temp);
temp=gh_cdr(temp);
str=gh_scm2newstr(value,NULL);
free(ui->Resources[i].Icon.File);
ui->Resources[i].Icon.File=str;
value=gh_car(temp);
temp=gh_cdr(temp);
x=gh_scm2int(value);
ui->Resources[i].IconRow=x;
value=gh_car(temp);
temp=gh_cdr(temp);
x=gh_scm2int(value);
ui->Resources[i].IconX=x;
value=gh_car(temp);
temp=gh_cdr(temp);
y=gh_scm2int(value);
ui->Resources[i].IconY=y;
value=gh_car(temp);
temp=gh_cdr(temp);
x=gh_scm2int(value);
ui->Resources[i].IconW=x;
value=gh_car(temp);
temp=gh_cdr(temp);
y=gh_scm2int(value);
ui->Resources[i].IconH=y;
value=gh_car(temp);
temp=gh_cdr(temp);
x=gh_scm2int(value);
ui->Resources[i].TextX=x;
value=gh_car(temp);
temp=gh_cdr(temp);
y=gh_scm2int(value);
ui->Resources[i].TextY=y;
} }
// Food icon
temp=gh_car(list);
list=gh_cdr(list);
if( !gh_list_p(temp) ) {
fprintf(stderr,"list expected\n");
return SCM_UNSPECIFIED;
}
value=gh_car(temp);
temp=gh_cdr(temp);
str=gh_scm2newstr(value,NULL);
free(ui->FoodIcon.File);
ui->FoodIcon.File=str;
value=gh_car(temp);
temp=gh_cdr(temp);
i=gh_scm2int(value);
ui->FoodIconRow=i;
value=gh_car(temp);
temp=gh_cdr(temp);
x=gh_scm2int(value);
ui->FoodIconX=x;
value=gh_car(temp);
temp=gh_cdr(temp);
y=gh_scm2int(value);
ui->FoodIconY=y;
value=gh_car(temp);
temp=gh_cdr(temp);
x=gh_scm2int(value);
ui->FoodIconW=x;
value=gh_car(temp);
temp=gh_cdr(temp);
y=gh_scm2int(value);
ui->FoodIconH=y;
value=gh_car(temp);
temp=gh_cdr(temp);
x=gh_scm2int(value);
ui->FoodTextX=x;
value=gh_car(temp);
temp=gh_cdr(temp);
y=gh_scm2int(value);
ui->FoodTextY=y;
// Score icon
temp=gh_car(list);
list=gh_cdr(list);
if( !gh_list_p(temp) ) {
fprintf(stderr,"list expected\n");
return SCM_UNSPECIFIED;
}
value=gh_car(temp);
temp=gh_cdr(temp);
str=gh_scm2newstr(value,NULL);
free(ui->ScoreIcon.File);
ui->ScoreIcon.File=str;
value=gh_car(temp);
temp=gh_cdr(temp);
i=gh_scm2int(value);
ui->ScoreIconRow=i;
value=gh_car(temp);
temp=gh_cdr(temp);
x=gh_scm2int(value);
ui->ScoreIconX=x;
value=gh_car(temp);
temp=gh_cdr(temp);
y=gh_scm2int(value);
ui->ScoreIconY=y;
value=gh_car(temp);
temp=gh_cdr(temp);
x=gh_scm2int(value);
ui->ScoreIconW=x;
value=gh_car(temp);
temp=gh_cdr(temp);
y=gh_scm2int(value);
ui->ScoreIconH=y;
value=gh_car(temp);
temp=gh_cdr(temp);
x=gh_scm2int(value);
ui->ScoreTextX=x;
value=gh_car(temp);
temp=gh_cdr(temp);
y=gh_scm2int(value);
ui->ScoreTextY=y;
// InfoPanel // InfoPanel
temp=gh_car(list); temp=gh_car(list);
list=gh_cdr(list); list=gh_cdr(list);

View file

@ -10,7 +10,8 @@
// //
/**@name ui.c - The user interface globals. */ /**@name ui.c - The user interface globals. */
// //
// (c) Copyright 1999-2003 by Lutz Sammer and Andreas Arens // (c) Copyright 1999-2003 by Lutz Sammer, Andreas Arens, and
// Jimmy Salmon
// //
// FreeCraft is free software; you can redistribute it and/or modify // FreeCraft is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published // it under the terms of the GNU General Public License as published
@ -200,17 +201,17 @@ global void LoadUserInterface(void)
} }
// FIXME: reuse same graphics? // FIXME: reuse same graphics?
if( TheUI.FoodIcon.File ) { if( TheUI.Resources[FoodCost].Icon.File ) {
TheUI.FoodIcon.Graphic=LoadGraphic(TheUI.FoodIcon.File); TheUI.Resources[FoodCost].Icon.Graphic=LoadGraphic(TheUI.Resources[FoodCost].Icon.File);
#ifdef USE_OPENGL #ifdef USE_OPENGL
MakeTexture(TheUI.FoodIcon.Graphic,TheUI.FoodIcon.Graphic->Width,TheUI.FoodIcon.Graphic->Height); MakeTexture(TheUI.Resources[FoodCost].Icon.Graphic,TheUI.Resources[FoodCost].Icon.Graphic->Width,TheUI.Resources[FoodCost].Icon.Graphic->Height);
#endif #endif
} }
// FIXME: reuse same graphics? // FIXME: reuse same graphics?
if( TheUI.ScoreIcon.File ) { if( TheUI.Resources[ScoreCost].Icon.File ) {
TheUI.ScoreIcon.Graphic=LoadGraphic(TheUI.ScoreIcon.File); TheUI.Resources[ScoreCost].Icon.Graphic=LoadGraphic(TheUI.Resources[ScoreCost].Icon.File);
#ifdef USE_OPENGL #ifdef USE_OPENGL
MakeTexture(TheUI.ScoreIcon.Graphic,TheUI.ScoreIcon.Graphic->Width,TheUI.ScoreIcon.Graphic->Height); MakeTexture(TheUI.Resources[ScoreCost].Icon.Graphic,TheUI.Resources[ScoreCost].Icon.Graphic->Width,TheUI.Resources[ScoreCost].Icon.Graphic->Height);
#endif #endif
} }
@ -299,26 +300,22 @@ local void OldSaveUi(FILE* file,const UI* ui)
fprintf(file," (list \"%s\" %d %d)\n", fprintf(file," (list \"%s\" %d %d)\n",
ui->Resource.File,ui->ResourceX,ui->ResourceY); ui->Resource.File,ui->ResourceX,ui->ResourceY);
for( i=1; i<MaxCosts; ++i ) { fprintf(file," 'resources (list");
fprintf(file," ; Resource %s\n",DefaultResourceNames[i]); for( i=1; i<MaxCosts+2; ++i ) {
fprintf(file," (list \"%s\" %d\n %d %d %d %d %d %d)\n", if( !ui->Resources[i].Icon.File ) {
continue;
}
fprintf(file,"\n '%s",
i<MaxCosts ? DefaultResourceNames[i] :
i==FoodCost ? "food" : "score");
fprintf(file," (list 'file \"%s\" 'row %d\n"
" 'pos '(%d %d) 'size '(%d %d) 'text-pos '(%d %d))",
ui->Resources[i].Icon.File,ui->Resources[i].IconRow, ui->Resources[i].Icon.File,ui->Resources[i].IconRow,
ui->Resources[i].IconX,ui->Resources[i].IconY, ui->Resources[i].IconX,ui->Resources[i].IconY,
ui->Resources[i].IconW,ui->Resources[i].IconH, ui->Resources[i].IconW,ui->Resources[i].IconH,
ui->Resources[i].TextX,ui->Resources[i].TextY); ui->Resources[i].TextX,ui->Resources[i].TextY);
} }
fprintf(file," ; Food\n"); fprintf(file,")\n");
fprintf(file," (list \"%s\" %d\n %d %d %d %d %d %d)\n",
ui->FoodIcon.File,ui->FoodIconRow,
ui->FoodIconX,ui->FoodIconY,
ui->FoodIconW,ui->FoodIconH,
ui->FoodTextX,ui->FoodTextY);
fprintf(file," ; Score\n");
fprintf(file," (list \"%s\" %d\n %d %d %d %d %d %d)\n",
ui->ScoreIcon.File,ui->ScoreIconRow,
ui->ScoreIconX,ui->ScoreIconY,
ui->ScoreIconW,ui->ScoreIconH,
ui->ScoreTextX,ui->ScoreTextY);
fprintf(file," ; Info panel\n"); fprintf(file," ; Info panel\n");
fprintf(file," (list \"%s\" %d %d %d %d)\n", fprintf(file," (list \"%s\" %d %d %d %d)\n",
@ -586,12 +583,12 @@ global void CleanUserInterface(void)
} }
VideoSaveFree(TheUI.Resource.Graphic); VideoSaveFree(TheUI.Resource.Graphic);
for( i=0; i<MaxCosts; ++i ) { for( i=0; i<MaxCosts+2; ++i ) {
VideoSaveFree(TheUI.Resources[i].Icon.Graphic); VideoSaveFree(TheUI.Resources[i].Icon.Graphic);
free(TheUI.Resources[i].Icon.File);
TheUI.Resources[i].Icon.File=NULL;
} }
VideoSaveFree(TheUI.FoodIcon.Graphic);
VideoSaveFree(TheUI.ScoreIcon.Graphic);
VideoSaveFree(TheUI.InfoPanel.Graphic); VideoSaveFree(TheUI.InfoPanel.Graphic);
VideoSaveFree(TheUI.ButtonPanel.Graphic); VideoSaveFree(TheUI.ButtonPanel.Graphic);
VideoSaveFree(TheUI.MenuButton.Graphic); VideoSaveFree(TheUI.MenuButton.Graphic);