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
00042 item->minWidth = 320;
00043 item->minHeight = 240;
00044
00045 item->input = TeamSelInput;
00046 item->update = TeamSelUpdate;
00047 item->active = TRUE;
00048 item->expandHeight = TRUE;
00049
00050 dInfo.luw = dInfo.luh = 6;
00051 dInfo.lw = dInfo.pw / dInfo.luw;
00052 dInfo.lh = dInfo.ph / dInfo.luh;
00053
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
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
00072 menuSettings->team = 0;
00073
00074 colorVals[COLOR_BLUE] = menuSettings->deselColor[TEAM_BLUE];
00075 }
00076
00077 void TeamSelUninit(MenuItem *item) {
00078 int loop;
00079 Player *p = players;
00080
00081 RemoveRenderItem(&(menuSettings->teams[0].tank));
00082 RemoveRenderItem(&(menuSettings->teams[1].tank));
00083
00084 colorVals[COLOR_RED] = menuSettings->selColor[TEAM_RED];
00085 colorVals[COLOR_BLUE] = menuSettings->selColor[TEAM_BLUE];
00086
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];
00098 Player *p = players;
00099
00100
00101 if (!item->isPlaced) {
00102
00103 item->isPlaced = TRUE;
00104
00105
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
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
00117 PlaceRenderItem(&(menuSettings->teams[0].tank));
00118 PlaceRenderItem(&(menuSettings->teams[1].tank));
00119
00120 PlaceRenderItem(&(textItems[TEXTITEM_CHOSETEAM]));
00121 }
00122
00123 top[0] = top[1] = menuSettings->teams[0].tank.loc.y +
00124 menuSettings->teams[0].tank.loc.h;
00125
00126 max = item->region.y + item->region.h + 6;
00127
00128 for (loop = MAX_PLAYERS; loop > 0; loop--, p++) {
00129
00130 if (!(p->flags & PLAYER_ACTIVE)) continue;
00131
00132 if (placeRemaining[p->team] && p->labelName.enableDraw &&
00133 (top[p->team] >= (max - p->labelName.loc.h))) {
00134
00135 ClearRenderItem(&(p->labelName));
00136 }
00137
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
00142 p->labelName.loc.y = top[TEAM_RED];
00143
00144 top[TEAM_RED] += p->labelName.loc.h + 2;
00145
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
00151 p->labelName.loc.y = top[TEAM_BLUE];
00152
00153 top[TEAM_BLUE] += p->labelName.loc.h + 2;
00154
00155 p->labelName.loc.x = menuSettings->teams[TEAM_BLUE].tank.loc.x;
00156 }
00157
00158 placeRemaining[p->team] = TRUE;
00159
00160 PlaceRenderItem(&(p->labelName));
00161 }
00162
00163 }
00164 return 0;
00165 }
00166
00167 int TeamSelInput(MenuItem *item, Uint8 *ec, rtsa_char keyval) {
00168
00169 if ((ec[EC_ROTLEFT] == 1) && menuSettings->team) {
00170
00171 ec[EC_ROTLEFT]++;
00172
00173 menuSettings->team = 0;
00174
00175 colorVals[COLOR_RED] = menuSettings->selColor[TEAM_RED];
00176
00177 colorVals[COLOR_BLUE] = menuSettings->deselColor[TEAM_BLUE];
00178
00179 goto TeamSelInput_redraw;
00180 }
00181
00182 else if ((ec[EC_ROTRIGHT] == 1) && !menuSettings->team) {
00183
00184 ec[EC_ROTRIGHT]++;
00185
00186 menuSettings->team++;
00187
00188 colorVals[COLOR_RED] = menuSettings->deselColor[TEAM_RED];
00189
00190 colorVals[COLOR_BLUE] = menuSettings->selColor[TEAM_BLUE];
00191
00192 TeamSelInput_redraw:
00193 PlaceRenderItem(&(menuSettings->teams[0].tank));
00194 PlaceRenderItem(&(menuSettings->teams[1].tank));
00195 }
00196
00197 else if ((ec[EC_FIRE] == 1) && ((networkState == NETSTATE_SERVER)
00198 || (networkState == NETSTATE_CLIENT))) {
00199
00200 return STATE_PLAY;
00201 }
00202 return 0;
00203 }
00204