diff --git a/src/include/ui.h b/src/include/ui.h index 7e3aa1ee1..fb3591bed 100644 --- a/src/include/ui.h +++ b/src/include/ui.h @@ -198,25 +198,8 @@ typedef struct _ui_ { int IconH; /// icon H position int TextX; /// text X position int TextY; /// text Y position - } Resources[MaxCosts]; /// Icon+Text of all resources - - 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 + } Resources[MaxCosts+2]; /// Icon+Text of all resources + /// +2 for food and score // Info panel GraphicConfig InfoPanel; /// Info panel background diff --git a/src/include/upgrade_structs.h b/src/include/upgrade_structs.h index 3428a0f12..d875d07f4 100644 --- a/src/include/upgrade_structs.h +++ b/src/include/upgrade_structs.h @@ -62,6 +62,9 @@ enum _costs_ { MaxCosts /// how many different costs }; +#define FoodCost MaxCosts +#define ScoreCost MaxCosts+1 + /** ** Speed factor for harvesting resources */ diff --git a/src/ui/mainscr.cpp b/src/ui/mainscr.cpp index 599097558..f2da5375c 100644 --- a/src/ui/mainscr.cpp +++ b/src/ui/mainscr.cpp @@ -611,24 +611,26 @@ global void DrawResources(void) ,v>99999 ? SmallFont : GameFont,v); } } - VideoDrawSub(TheUI.FoodIcon.Graphic,0 - ,TheUI.FoodIconRow*TheUI.FoodIconH - ,TheUI.FoodIconW,TheUI.FoodIconH - ,TheUI.FoodIconX,TheUI.FoodIconY); + VideoDrawSub(TheUI.Resources[FoodCost].Icon.Graphic,0 + ,TheUI.Resources[FoodCost].IconRow*TheUI.Resources[FoodCost].IconH + ,TheUI.Resources[FoodCost].IconW,TheUI.Resources[FoodCost].IconH + ,TheUI.Resources[FoodCost].IconX,TheUI.Resources[FoodCost].IconY); sprintf(tmp,"%d/%d",ThisPlayer->NumFoodUnits,ThisPlayer->Food); if( ThisPlayer->Food<ThisPlayer->NumFoodUnits ) { - VideoDrawReverseText(TheUI.FoodTextX,TheUI.FoodTextY,GameFont,tmp); + VideoDrawReverseText(TheUI.Resources[FoodCost].TextX + ,TheUI.Resources[FoodCost].TextY,GameFont,tmp); } else { - VideoDrawText(TheUI.FoodTextX,TheUI.FoodTextY,GameFont,tmp); + VideoDrawText(TheUI.Resources[FoodCost].TextX + ,TheUI.Resources[FoodCost].TextY,GameFont,tmp); } - VideoDrawSub(TheUI.ScoreIcon.Graphic,0 - ,TheUI.ScoreIconRow*TheUI.ScoreIconH - ,TheUI.ScoreIconW,TheUI.ScoreIconH - ,TheUI.ScoreIconX,TheUI.ScoreIconY); + VideoDrawSub(TheUI.Resources[ScoreCost].Icon.Graphic,0 + ,TheUI.Resources[ScoreCost].IconRow*TheUI.Resources[ScoreCost].IconH + ,TheUI.Resources[ScoreCost].IconW,TheUI.Resources[ScoreCost].IconH + ,TheUI.Resources[ScoreCost].IconX,TheUI.Resources[ScoreCost].IconY); v=ThisPlayer->Score; - VideoDrawNumber(TheUI.ScoreTextX - ,TheUI.ScoreTextY+(v>99999)*3 + VideoDrawNumber(TheUI.Resources[ScoreCost].TextX + ,TheUI.Resources[ScoreCost].TextY+(v>99999)*3 ,v>99999 ? SmallFont : GameFont,v); } } @@ -1028,9 +1030,9 @@ global void DrawCosts(void) if( CostsFood ) { // FIXME: hardcoded image!!! - VideoDrawSub(TheUI.FoodIcon.Graphic - ,0,TheUI.FoodIconRow*TheUI.FoodIconH - ,TheUI.FoodIconW,TheUI.FoodIconH + VideoDrawSub(TheUI.Resources[FoodCost].Icon.Graphic + ,0,TheUI.Resources[FoodCost].IconRow*TheUI.Resources[FoodCost].IconH + ,TheUI.Resources[FoodCost].IconW,TheUI.Resources[FoodCost].IconH ,x,TheUI.StatusLineY+1); VideoDrawNumber(x+15,TheUI.StatusLineY+2,GameFont,CostsFood); x+=45; diff --git a/src/ui/script_ui.cpp b/src/ui/script_ui.cpp index 578d16fe8..790d599aa 100644 --- a/src/ui/script_ui.cpp +++ b/src/ui/script_ui.cpp @@ -673,172 +673,71 @@ local SCM CclDefineUI(SCM list) // // Parse icons // - for( i=1; i<MaxCosts; ++i ) { - // icon - temp=gh_car(list); + value=gh_car(list); + list=gh_cdr(list); + if( gh_eq_p(value,gh_symbol2scm("resources")) ) { + SCM sublist; + + sublist=gh_car(list); list=gh_cdr(list); + while( !gh_null_p(sublist) ) { + SCM slist; + int res; + char* name; - if( gh_null_p(temp) ) { - free(ui->Resources[i].Icon.File); - ui->Resources[i].Icon.File=NULL; - ui->Resources[i].Icon.Graphic=NULL; - ui->Resources[i].IconRow=0; - ui->Resources[i].IconX=0; - ui->Resources[i].IconY=0; - ui->Resources[i].IconW=0; - ui->Resources[i].IconH=0; - ui->Resources[i].TextX=0; - ui->Resources[i].TextY=0; - continue; + value=gh_car(sublist); + sublist=gh_cdr(sublist); + name=gh_scm2newstr(value,NULL); + for( res=0; res<MaxCosts; ++res ) { + if( !strcmp(name,DefaultResourceNames[res]) ) { + break; + } + } + if( res==MaxCosts ) { + if( !strcmp(name,"food") ) { + res=FoodCost; + } 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 temp=gh_car(list); list=gh_cdr(list); diff --git a/src/ui/ui.cpp b/src/ui/ui.cpp index 163b5589e..91ad5b09b 100644 --- a/src/ui/ui.cpp +++ b/src/ui/ui.cpp @@ -10,7 +10,8 @@ // /**@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 // it under the terms of the GNU General Public License as published @@ -200,17 +201,17 @@ global void LoadUserInterface(void) } // FIXME: reuse same graphics? - if( TheUI.FoodIcon.File ) { - TheUI.FoodIcon.Graphic=LoadGraphic(TheUI.FoodIcon.File); + if( TheUI.Resources[FoodCost].Icon.File ) { + TheUI.Resources[FoodCost].Icon.Graphic=LoadGraphic(TheUI.Resources[FoodCost].Icon.File); #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 } // FIXME: reuse same graphics? - if( TheUI.ScoreIcon.File ) { - TheUI.ScoreIcon.Graphic=LoadGraphic(TheUI.ScoreIcon.File); + if( TheUI.Resources[ScoreCost].Icon.File ) { + TheUI.Resources[ScoreCost].Icon.Graphic=LoadGraphic(TheUI.Resources[ScoreCost].Icon.File); #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 } @@ -299,26 +300,22 @@ local void OldSaveUi(FILE* file,const UI* ui) fprintf(file," (list \"%s\" %d %d)\n", ui->Resource.File,ui->ResourceX,ui->ResourceY); - for( i=1; i<MaxCosts; ++i ) { - fprintf(file," ; Resource %s\n",DefaultResourceNames[i]); - fprintf(file," (list \"%s\" %d\n %d %d %d %d %d %d)\n", + fprintf(file," 'resources (list"); + for( i=1; i<MaxCosts+2; ++i ) { + 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].IconX,ui->Resources[i].IconY, ui->Resources[i].IconW,ui->Resources[i].IconH, ui->Resources[i].TextX,ui->Resources[i].TextY); } - fprintf(file," ; Food\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,")\n"); fprintf(file," ; Info panel\n"); fprintf(file," (list \"%s\" %d %d %d %d)\n", @@ -586,12 +583,12 @@ global void CleanUserInterface(void) } VideoSaveFree(TheUI.Resource.Graphic); - for( i=0; i<MaxCosts; ++i ) { + for( i=0; i<MaxCosts+2; ++i ) { 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.ButtonPanel.Graphic); VideoSaveFree(TheUI.MenuButton.Graphic);