teamsel.c

Go to the documentation of this file.
00001 
00025 #include "teamsel.h"
00026 #include "color.h"
00027 #include "states.h"
00028 #include "tanksprite.h"
00029 #include "menustate.h"
00030 #include "net.h"
00031 #include <string.h>
00032 
00033 
00038 #define MIDDLE_MARGIN   64
00039 
00040 void TeamSelInit(MenuItem *item) {
00041     // setup the menu item fields
00042     item->minWidth = 320;
00043     item->minHeight = 240;
00044     //item->focus =
00045     item->input = TeamSelInput;
00046     item->update = TeamSelUpdate;
00047     item->active = TRUE;
00048     item->expandHeight = TRUE;
00049     // setup position of screen parts
00050     dInfo.luw = dInfo.luh = 6;
00051     dInfo.lw = dInfo.pw / dInfo.luw;
00052     dInfo.lh = dInfo.ph / dInfo.luh;
00053     // initalize two tanks
00054     menuSettings->teams[0].tank.renderer =
00055     menuSettings->teams[1].tank.renderer = DrawTank;
00056     menuSettings->teams[0].tank.loc.w = menuSettings->teams[0].tank.loc.h =
00057     menuSettings->teams[1].tank.loc.w = menuSettings->teams[1].tank.loc.h =
00058         dInfo.luw << 3;
00059     menuSettings->teams[0].rot = 4 << 8;
00060     menuSettings->teams[1].rot = 12 << 8;
00061     menuSettings->teams[1].team++;
00062     AddRenderItem(&(menuSettings->teams[0].tank), LAYER_TANKS);
00063     AddRenderItem(&(menuSettings->teams[1].tank), LAYER_TANKS);
00064     // set the colors
00065     menuSettings->selColor[TEAM_RED] = colorVals[COLOR_RED];
00066     menuSettings->selColor[TEAM_BLUE] = colorVals[COLOR_BLUE];
00067     menuSettings->deselColor[TEAM_RED] = ColorBlend(colorFmtInd[COLOR_RED],
00068     colorFmtInd[COLOR_REGBACK], 2, 3);  
00069     menuSettings->deselColor[TEAM_BLUE] = ColorBlend(colorFmtInd[COLOR_BLUE],
00070     colorFmtInd[COLOR_REGBACK], 2, 4);
00071     // set a condition that will cause tank zero to be selected
00072     menuSettings->team = 0;
00073     // set tank 1's deselected color
00074     colorVals[COLOR_BLUE] = menuSettings->deselColor[TEAM_BLUE];
00075 }
00076 
00077 void TeamSelUninit(MenuItem *item) {
00078     int loop;
00079     Player *p = players;
00080     // remove the tank render items used to denote the different teams
00081     RemoveRenderItem(&(menuSettings->teams[0].tank));
00082     RemoveRenderItem(&(menuSettings->teams[1].tank));
00083     // restore colors
00084     colorVals[COLOR_RED] = menuSettings->selColor[TEAM_RED];
00085     colorVals[COLOR_BLUE] = menuSettings->selColor[TEAM_BLUE];
00086     // clear all rendered names
00087     for (loop = MAX_PLAYERS; loop > 0; loop--, p++) {
00088         if ((p->flags & PLAYER_ACTIVE) && p->labelName.enableDraw) {
00089             ClearRenderItem(&(p->labelName));
00090         }
00091     }
00092 }
00093 
00094 int TeamSelUpdate(MenuItem *item) {
00095     Bool placeRemaining[TEAM_MAX] = { 0 };
00096     int loop, max;
00097     int top[TEAM_MAX];  // the top position for the next name of a teammember
00098     Player *p = players;
00099     // update the data with the latest information from the server
00100     // see if the visible components need to be moved
00101     if (!item->isPlaced) {
00102         // set the placed flag
00103         item->isPlaced = TRUE;
00104         // Move the components to the proper place.
00105         // Place the chose team prompt
00106         textItems[TEXTITEM_CHOSETEAM].loc.x = item->region.x +
00107         ((item->region.w - textItems[TEXTITEM_CHOSETEAM].loc.w) >> 1);
00108         textItems[TEXTITEM_CHOSETEAM].loc.y = item->region.y;
00109         // place two tanks
00110         menuSettings->teams[0].tank.loc.y = menuSettings->teams[1].tank.loc.y =
00111         item->region.y + textItems[TEXTITEM_CHOSETEAM].loc.h + 4;
00112         menuSettings->teams[1].tank.loc.x = (menuSettings->teams[0].tank.loc.x =
00113         item->region.x + (item->region.w >> 1) - (MIDDLE_MARGIN >> 1) -
00114         menuSettings->teams[0].tank.loc.w) + MIDDLE_MARGIN +
00115         menuSettings->teams[0].tank.loc.w;
00116         // make both tanks visible
00117         PlaceRenderItem(&(menuSettings->teams[0].tank));
00118         PlaceRenderItem(&(menuSettings->teams[1].tank));
00119         // make the chose team title visible
00120         PlaceRenderItem(&(textItems[TEXTITEM_CHOSETEAM]));
00121     }
00122     // get the top position
00123     top[0] = top[1] = menuSettings->teams[0].tank.loc.y +
00124     menuSettings->teams[0].tank.loc.h;
00125     // set the maximum height value for player names
00126     max = item->region.y + item->region.h + 6;
00127     // loop through the players
00128     for (loop = MAX_PLAYERS; loop > 0; loop--, p++) {
00129         // only work on active players
00130         if (!(p->flags & PLAYER_ACTIVE)) continue;
00131         // see if the player doesn't fit but was visible
00132         if (placeRemaining[p->team] && p->labelName.enableDraw &&
00133         (top[p->team] >= (max - p->labelName.loc.h))) {
00134             // clear the player's name from view
00135             ClearRenderItem(&(p->labelName));
00136         }
00137         // see if the player will fit and is not visible or needs to be moved
00138         else if ((!p->labelName.enableDraw || placeRemaining[p->team]) &&
00139         (top[p->team] < (max - p->labelName.loc.h))) {
00140             if (p->team == TEAM_RED) {
00141                 // set the vertical position
00142                 p->labelName.loc.y = top[TEAM_RED];
00143                 // advance the next position
00144                 top[TEAM_RED] += p->labelName.loc.h + 2;
00145                 // set the horizonal position -- right aligned
00146                 p->labelName.loc.x = menuSettings->teams[TEAM_RED].tank.loc.x +
00147                 menuSettings->teams[TEAM_RED].tank.loc.h - p->labelName.loc.h;
00148             }
00149             else {
00150                 // set the vertical position
00151                 p->labelName.loc.y = top[TEAM_BLUE];
00152                 // advance the next position
00153                 top[TEAM_BLUE] += p->labelName.loc.h + 2;
00154                 // set the horizonal position -- left aligned
00155                 p->labelName.loc.x = menuSettings->teams[TEAM_BLUE].tank.loc.x;
00156             }
00157             // render all others for this team
00158             placeRemaining[p->team] = TRUE;
00159             // place it
00160             PlaceRenderItem(&(p->labelName));
00161         }
00162         // some or all will still be in the same spot -- no need to render them
00163     }
00164     return 0;
00165 }
00166 
00167 int TeamSelInput(MenuItem *item, Uint8 *ec, rtsa_char keyval) {
00168     // check for left input when right team selected
00169     if ((ec[EC_ROTLEFT] == 1) && menuSettings->team) {
00170         // clear the input
00171         ec[EC_ROTLEFT]++;
00172         // chose the new team
00173         menuSettings->team = 0;
00174         // set tank 0's selected color
00175         colorVals[COLOR_RED] = menuSettings->selColor[TEAM_RED];
00176         // set tank 1's deselected color
00177         colorVals[COLOR_BLUE] = menuSettings->deselColor[TEAM_BLUE];
00178         // redraw both tanks
00179         goto TeamSelInput_redraw;
00180     }
00181     // check for right input when left team selected
00182     else if ((ec[EC_ROTRIGHT] == 1) && !menuSettings->team) {
00183         // clear the input
00184         ec[EC_ROTRIGHT]++;
00185         // chose the new team
00186         menuSettings->team++;
00187         // set tank 0's deselected color
00188         colorVals[COLOR_RED] = menuSettings->deselColor[TEAM_RED];
00189         // set tank 1's selected color
00190         colorVals[COLOR_BLUE] = menuSettings->selColor[TEAM_BLUE];
00191         // redraw both tanks
00192         TeamSelInput_redraw:
00193         PlaceRenderItem(&(menuSettings->teams[0].tank));
00194         PlaceRenderItem(&(menuSettings->teams[1].tank));
00195     }
00196     // check for selection input
00197     else if ((ec[EC_FIRE] == 1) && ((networkState == NETSTATE_SERVER)
00198     || (networkState == NETSTATE_CLIENT))) {
00199         // play!
00200         return STATE_PLAY;
00201     }
00202     return 0;
00203 }
00204 

Generated on Mon May 28 04:41:39 2007 for Retro Tank Super Attack by  doxygen 1.5.2