Rev 136 | Rev 153 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 136 | Rev 140 | ||
---|---|---|---|
Line 68... | Line 68... | ||
68 | swprintf_s (connected_comment, WCHAR_SIZEOF (connected_comment), format_string, options.network.server_address); |
68 | swprintf_s (connected_comment, WCHAR_SIZEOF (connected_comment), format_string, options.network.server_address); |
69 | 69 | ||
70 | // completely reset the whole GUI structure so as to NULL out all pointers |
70 | // completely reset the whole GUI structure so as to NULL out all pointers |
71 | memset (&scene->gui, 0, sizeof (scene->gui)); |
71 | memset (&scene->gui, 0, sizeof (scene->gui)); |
72 | 72 | ||
73 | // set the buttons locations |
73 | // set the buttons and text locations |
74 |
|
74 | Scene_SetupButton (&scene->gui.llarrow, 0.3f, 0.5f, 2.0f, 4.0f, llarrow_spriteindex, L""); |
- | 75 | Scene_SetupButton (&scene->gui.larrow, 2.3f, 0.5f, 2.0f, 4.0f, larrow_spriteindex, L""); |
|
- | 76 | Scene_SetupButton (&scene->gui.rarrow, 4.3f, 0.5f, 2.0f, 4.0f, rarrow_spriteindex, L""); |
|
75 |
|
77 | Scene_SetupButton (&scene->gui.rrarrow, 6.3f, 0.5f, 2.0f, 4.0f, rrarrow_spriteindex, L""); |
76 |
|
78 | Scene_SetupButton (&scene->gui.newgamebutton, 20.0f, 65.0f, 20.0f, 26.0f, newgamebutton_spriteindex, L"\n\n\n\n\n\n\n%s", LOCALIZE (L"NewGame")); |
77 |
|
79 | Scene_SetupButton (&scene->gui.opengamebutton, 60.0f, 65.0f, 20.0f, 26.0f, opengamebutton_spriteindex, L"\n\n\n\n\n\n\n%s", LOCALIZE (L"OpenGame")); |
78 |
|
80 | Scene_SetupButton (&scene->gui.chatbutton, 1.0f, 10.0f, 10.0f, 13.0f, chatbutton_spriteindex, L""); |
79 |
|
81 | Scene_SetupButton (&scene->gui.gamesbutton, 1.0f, 35.0f, 10.0f, 13.0f, gamesbutton_spriteindex, L""); |
80 |
|
82 | Scene_SetupButton (&scene->gui.peoplebutton, 1.0f, 60.0f, 10.0f, 13.0f, peoplebutton_spriteindex, L""); |
- | 83 | ||
- | 84 | Scene_SetupTextArea (&scene->gui.arrow_text, 4.3f, 5.0f, 0, ALIGN_CENTER, ALIGN_TOP, ALIGN_CENTER, arrow_fontindex); |
|
- | 85 | Scene_SetupTextArea (&scene->gui.comment_text, 50.0f, 0.5f, 80.0f, ALIGN_CENTER, ALIGN_TOP, ALIGN_LEFT, chat_fontindex); |
|
- | 86 | Scene_SetupTextArea (&scene->gui.central_text, 50.0f, 40.0f, 0, ALIGN_CENTER, ALIGN_CENTER, ALIGN_CENTER, centermsg_fontindex); |
|
- | 87 | Scene_SetupTextArea (&scene->gui.history_text, 100.0f, 50.0f, 0, ALIGN_RIGHT, ALIGN_BOTTOM, ALIGN_LEFT, chat_fontindex); |
|
- | 88 | Scene_SetupTextArea (&scene->gui.clock_text, 99.0f, 66.6f, 0, ALIGN_RIGHT, ALIGN_CENTER, ALIGN_RIGHT, players_fontindex); |
|
- | 89 | Scene_SetupTextArea (&scene->gui.turn_text, 99.0f, 100.0f, 0, ALIGN_RIGHT, ALIGN_BOTTOM, ALIGN_RIGHT, players_fontindex); |
|
81 | 90 | ||
82 | // remember to update the scene |
91 | // remember to update the scene |
83 | scene->update = true; |
92 | scene->update = true; |
84 | 93 | ||
85 | return; // finished |
94 | return; // finished |
Line 979... | Line 988... | ||
979 | //////////////////////////////////////////////////////////////////////////////////////////////// |
988 | //////////////////////////////////////////////////////////////////////////////////////////////// |
980 | // now draw the move comment text |
989 | // now draw the move comment text |
981 | 990 | ||
982 | // does the move we are viewing have a comment ? if so, copy it, else leave it clear. Also if we're online, display a help text |
991 | // does the move we are viewing have a comment ? if so, copy it, else leave it clear. Also if we're online, display a help text |
983 | if ((currentmove->comment != NULL) && (currentmove->comment[0] != 0)) |
992 | if ((currentmove->comment != NULL) && (currentmove->comment[0] != 0)) |
984 |
|
993 | Scene_UpdateText (&scene->gui.comment_text, RGBA_TO_RGBACOLOR (255, 255, 255, 191), DURATION_INFINITE, false, currentmove->comment); |
985 | else if ((network_player != NULL) && network_player->is_logged_in && !network_player->is_in_game) |
994 | else if ((network_player != NULL) && network_player->is_logged_in && !network_player->is_in_game) |
986 |
|
995 | Scene_UpdateText (&scene->gui.comment_text, RGBA_TO_RGBACOLOR (255, 255, 255, 191), DURATION_INFINITE, false, connected_comment); |
987 | else if (RGBACOLOR_ALPHA (scene->gui.comment_text.color) >= 128) // HACK: don't clear if a dimmed hint text is already here |
996 | else if (RGBACOLOR_ALPHA (scene->gui.comment_text.color) >= 128) // HACK: don't clear if a dimmed hint text is already here |
988 | scene->gui.comment_text.is_displayed = false; // else clear comment text |
997 | scene->gui.comment_text.is_displayed = false; // else clear comment text |
989 | 998 | ||
990 | //////////////////////////////////////////////////////////////////////////////////////////////// |
999 | //////////////////////////////////////////////////////////////////////////////////////////////// |
991 | // now draw the game clock |
1000 | // now draw the game clock |
Line 1002... | Line 1011... | ||
1002 | seconds = (int) (current_time - stoppage_time - board->lastmove_time); // total seconds first, take pauses in account |
1011 | seconds = (int) (current_time - stoppage_time - board->lastmove_time); // total seconds first, take pauses in account |
1003 | 1012 | ||
1004 | minutes = seconds / 60; // minutes |
1013 | minutes = seconds / 60; // minutes |
1005 | seconds -= 60 * minutes; // remaining seconds |
1014 | seconds -= 60 * minutes; // remaining seconds |
1006 | 1015 | ||
1007 |
|
1016 | Scene_UpdateText (&scene->gui.clock_text, RGBACOLOR_SETALPHA (options.clock_color, 0x7f), DURATION_INFINITE, false, L"%02d:%02d ", minutes, seconds); // note: last space is alt+255 |
1008 | } |
1017 | } |
1009 | else |
1018 | else |
1010 | scene->gui.clock_text.is_displayed = false; |
1019 | scene->gui.clock_text.is_displayed = false; |
1011 | 1020 | ||
1012 | //////////////////////////////////////////////////////////////////////////////////////////////// |
1021 | //////////////////////////////////////////////////////////////////////////////////////////////// |
Line 1015... | Line 1024... | ||
1015 | // do we want to print the player's turn AND has the game not ended yet ? if so, copy it, else leave it clear |
1024 | // do we want to print the player's turn AND has the game not ended yet ? if so, copy it, else leave it clear |
1016 | if (options.want_turn && (board->game_state == STATE_PLAYING)) |
1025 | if (options.want_turn && (board->game_state == STATE_PLAYING)) |
1017 | { |
1026 | { |
1018 | if (Board_ColorToMove (board) == COLOR_BLACK) |
1027 | if (Board_ColorToMove (board) == COLOR_BLACK) |
1019 | { |
1028 | { |
1020 | if ( |
1029 | if (scene->gui.turn_text.color != 0x000000C0) |
1021 |
|
1030 | Scene_UpdateText (&scene->gui.turn_text, 0x000000C0, DURATION_INFINITE, true, LOCALIZE (L"BlackMoves")); |
1022 | } |
1031 | } |
1023 | else |
1032 | else |
1024 | { |
1033 | { |
1025 | if ( |
1034 | if (scene->gui.turn_text.color != 0xFFFFFF80) |
1026 |
|
1035 | Scene_UpdateText (&scene->gui.turn_text, 0xFFFFFF80, DURATION_INFINITE, true, LOCALIZE (L"WhiteMoves")); |
1027 | } |
1036 | } |
1028 | } |
1037 | } |
1029 | else |
1038 | else |
1030 | scene->gui.turn_text.is_displayed = false; |
1039 | scene->gui.turn_text.is_displayed = false; |
1031 | 1040 | ||
Line 1057... | Line 1066... | ||
1057 | if (move_index % 2 == 0) |
1066 | if (move_index % 2 == 0) |
1058 | wcscat_s (history_text, historytext_size, L"\n"); |
1067 | wcscat_s (history_text, historytext_size, L"\n"); |
1059 | } |
1068 | } |
1060 | 1069 | ||
1061 | // add 50% alpha to game history color and transmit it to 3D engine |
1070 | // add 50% alpha to game history color and transmit it to 3D engine |
1062 |
|
1071 | Scene_UpdateText (&scene->gui.history_text, RGBACOLOR_SETALPHA (options.history_color, 0x7f), DURATION_INFINITE, false, history_text); |
1063 | SAFE_free ((void **) &history_text); |
1072 | SAFE_free ((void **) &history_text); |
1064 | } |
1073 | } |
1065 | else |
1074 | else |
1066 | scene->gui.history_text.is_displayed = false; // if we don't need to display the game history, free the buffer |
1075 | scene->gui.history_text.is_displayed = false; // if we don't need to display the game history, free the buffer |
1067 | 1076 | ||
Line 1091... | Line 1100... | ||
1091 | // is the current player a computer AND are we playing a game right now |
1100 | // is the current player a computer AND are we playing a game right now |
1092 | // AND has the computer been thinking for more than 5 seconds AND is there no "thinking" text yet ? |
1101 | // AND has the computer been thinking for more than 5 seconds AND is there no "thinking" text yet ? |
1093 | if ((board->players[Board_ColorToMove (board)].type == PLAYER_COMPUTER) && (board->game_state == STATE_PLAYING) |
1102 | if ((board->players[Board_ColorToMove (board)].type == PLAYER_COMPUTER) && (board->game_state == STATE_PLAYING) |
1094 | && (board->lastmove_time + 5.0f < current_time) && !scene->gui.central_text.is_displayed) |
1103 | && (board->lastmove_time + 5.0f < current_time) && !scene->gui.central_text.is_displayed) |
1095 | { |
1104 | { |
1096 | Scene_SetText (&the_scene.gui.central_text, 50.0f, 40.0f, -1, ALIGN_CENTER, ALIGN_CENTER, ALIGN_CENTER, centermsg_fontindex, RGBA_TO_RGBACOLOR (255, 255, 255, 191), |
- | |
1097 |
|
1105 | Scene_UpdateText (&scene->gui.central_text, RGBA_TO_RGBACOLOR (255, 255, 255, 191), DURATION_INFINITE, true, LOCALIZE (L"Thinking")); // if so, display the "thinking" phrase in the middle of the screen |
1098 |
|
1106 | scene->gui.want_spinwheel = true; // start spinning wheel |
1099 | } |
1107 | } |
1100 | 1108 | ||
1101 | // is there a network player AND is our socket gone AWOL ? |
1109 | // is there a network player AND is our socket gone AWOL ? |
1102 | else if ((network_player != NULL) && (network_player->our_socket == INVALID_SOCKET)) |
1110 | else if ((network_player != NULL) && (network_player->our_socket == INVALID_SOCKET)) |
1103 | { |
1111 | { |
1104 | // is there nothing in the center of the screen yet ? |
1112 | // is there nothing in the center of the screen yet ? |
1105 | if (! |
1113 | if (!scene->gui.central_text.is_displayed) |
1106 | Scene_SetText (&the_scene.gui.central_text, 50.0f, 50.0f, -1, ALIGN_CENTER, ALIGN_CENTER, ALIGN_CENTER, centermsg_fontindex, RGBA_TO_RGBACOLOR (255, 255, 255, 191), |
- | |
1107 |
|
1114 | Scene_UpdateText (&scene->gui.central_text, RGBA_TO_RGBACOLOR (255, 255, 255, 191), DURATION_INFINITE, true, L"\n\n\n\n\n%s", LOCALIZE (L"Error_ConnectionToChessServerLost")); // display "error" in the middle of the screen |
1108 |
|
1115 | scene->overlay_spriteindex = sepia_spriteindex; // display sepia filter if no connection |
1109 | } |
1116 | } |
1110 | 1117 | ||
1111 | // is the game paused ? |
1118 | // is the game paused ? |
1112 | if (is_paused) |
1119 | if (is_paused) |
1113 | Scene_SetText (&the_scene.gui.central_text, 50.0f, 50.0f, -1, ALIGN_CENTER, ALIGN_CENTER, ALIGN_CENTER, centermsg_fontindex, RGBA_TO_RGBACOLOR (255, 255, 255, 255), |
- | |
1114 |
|
1120 | Scene_UpdateText (&scene->gui.central_text, RGBA_TO_RGBACOLOR (255, 255, 255, 255), 1.0f, false, L"\n\n\n\n\n%s", LOCALIZE (L"Paused")); // if so, display the "paused" phrase in the middle of the screen |
1115 | 1121 | ||
1116 | return; // finished, scene is updated |
1122 | return; // finished, scene is updated |
1117 | } |
1123 | } |
1118 | 1124 | ||
1119 | 1125 | ||
Line 1142... | Line 1148... | ||
1142 | 1148 | ||
1143 | re.color = RGBACOLOR_SETALPHA (color_rgbx, 0xC0); // copy reply color and force a slightly transparent alpha |
1149 | re.color = RGBACOLOR_SETALPHA (color_rgbx, 0xC0); // copy reply color and force a slightly transparent alpha |
1144 | re.arrival_time = current_time; // save CC reply arrival time |
1150 | re.arrival_time = current_time; // save CC reply arrival time |
1145 | 1151 | ||
1146 | // reallocate CC history array to hold now one reply more |
1152 | // reallocate CC history array to hold now one reply more |
1147 |
|
1153 | scene->gui.cchistory = (ccreply_t *) SAFE_realloc (scene->gui.cchistory, scene->gui.cchistory_count, scene->gui.cchistory_count + 1, sizeof (ccreply_t), false); |
1148 | memcpy (& |
1154 | memcpy (&scene->gui.cchistory[scene->gui.cchistory_count], &re, sizeof (ccreply_t)); |
1149 |
|
1155 | scene->gui.cchistory_count++; // CC history holds now one reply more |
1150 | 1156 | ||
1151 | return; // finished, announcement text is set |
1157 | return; // finished, announcement text is set |
1152 | } |
1158 | } |
1153 | 1159 | ||
1154 | 1160 | ||
Line 1175... | Line 1181... | ||
1175 | wcscpy_s (re.channelname, WCHAR_SIZEOF (re.channelname), LOCALIZE (L"ImportantMessage")); |
1181 | wcscpy_s (re.channelname, WCHAR_SIZEOF (re.channelname), LOCALIZE (L"ImportantMessage")); |
1176 | re.color = RGBA_TO_RGBACOLOR (192, 0, 0, 0xE0); // fair red, a bit more opaque than normal messages |
1182 | re.color = RGBA_TO_RGBACOLOR (192, 0, 0, 0xE0); // fair red, a bit more opaque than normal messages |
1177 | re.arrival_time = current_time; // save announcement arrival time |
1183 | re.arrival_time = current_time; // save announcement arrival time |
1178 | 1184 | ||
1179 | // reallocate CC history array to hold now one reply more |
1185 | // reallocate CC history array to hold now one reply more |
1180 |
|
1186 | scene->gui.cchistory = (ccreply_t *) SAFE_realloc (scene->gui.cchistory, scene->gui.cchistory_count, scene->gui.cchistory_count + 1, sizeof (ccreply_t), false); |
1181 | memcpy (& |
1187 | memcpy (&scene->gui.cchistory[scene->gui.cchistory_count], &re, sizeof (ccreply_t)); |
1182 |
|
1188 | scene->gui.cchistory_count++; // CC history holds now one reply more |
1183 | 1189 | ||
1184 | return; // finished, announcement text is set |
1190 | return; // finished, announcement text is set |
1185 | } |
1191 | } |
1186 | 1192 | ||
1187 | 1193 | ||
1188 | void |
1194 | void Scene_SetupButton (guibutton_t *button, float left_percent, float top_percent, float width_percent, float height_percent, int sprite_index, wchar_t *fmt, ...) |
1189 | { |
1195 | { |
1190 | // helper function to set up a GUI button |
1196 | // helper function to set up a GUI button. WARNING: -1 and NULL in parameter values means "no change"! |
1191 | 1197 | ||
1192 | va_list argptr; |
1198 | va_list argptr; |
1193 | 1199 | ||
1194 | button->left = |
1200 | if (left_percent != -1) button->left = left_percent; |
1195 | button->top = |
1201 | if (top_percent != -1) button->top = top_percent; |
1196 | button->width = |
1202 | if (width_percent != -1) button->width = width_percent; |
1197 | button->height = |
1203 | if (height_percent != -1) button->height = height_percent; |
1198 | button->sprite_index = sprite_index; |
1204 | if (sprite_index != -1) button->sprite_index = sprite_index; |
1199 | 1205 | ||
1200 | // concatenate all the arguments in one string |
1206 | // concatenate all the arguments in one string |
1201 | if (fmt != NULL) |
1207 | if (fmt != NULL) |
1202 | { |
1208 | { |
1203 | va_start (argptr, fmt); |
1209 | va_start (argptr, fmt); |
1204 | _vsnwprintf_s (button->text, WCHAR_SIZEOF (button->text), _TRUNCATE, fmt, argptr); |
1210 | _vsnwprintf_s (button->text, WCHAR_SIZEOF (button->text), _TRUNCATE, fmt, argptr); |
1205 | va_end (argptr); |
1211 | va_end (argptr); |
1206 | } |
1212 | } |
1207 | else |
1213 | else if (fmt[0] == 0) |
1208 | button->text[0] = 0; // (unless no text is specified for this button) |
1214 | button->text[0] = 0; // (unless no text is specified for this button) |
1209 | 1215 | ||
1210 | return; // finished, button is set |
1216 | return; // finished, button is set |
1211 | } |
1217 | } |
1212 | 1218 | ||
1213 | 1219 | ||
1214 | void |
1220 | void Scene_SetupTextArea (guitext_t *text, float xpos_percent, float ypos_percent, float maxwidth_percent, int horizontal_align, int vertical_align, int text_align, int font_index) |
1215 | { |
1221 | { |
- | 1222 | // helper function to set some text on display. WARNING: -1 in parameter values means "no change"! |
|
- | 1223 | ||
- | 1224 | if (xpos_percent != -1) text->xpos_percent = xpos_percent; // save text's X position, in percents from left to right |
|
- | 1225 | if (ypos_percent != -1) text->ypos_percent = ypos_percent; // save text's Y position, in percents from top to bottom |
|
- | 1226 | if (maxwidth_percent != -1) text->maxwidth_percent = maxwidth_percent; // save text's max width before word wrapping |
|
- | 1227 | if (horizontal_align != -1) text->horizontal_align = horizontal_align; // save text's horizontal alignment regarding the X position |
|
- | 1228 | if (vertical_align != -1) text->vertical_align = vertical_align; // save text's vertical alignment regarding the Y position |
|
- | 1229 | if (text_align != -1) text->text_align = text_align; // save text's horizontal alignment inside the bounding rectangle |
|
- | 1230 | if (font_index != -1) text->font_index = font_index; // save the index of the font with which to display this text |
|
- | 1231 | ||
- | 1232 | return; // finished, text area is setup |
|
- | 1233 | } |
|
- | 1234 | ||
- | 1235 | ||
- | 1236 | void Scene_UpdateText (guitext_t *text, unsigned long color_rgba, float duration, bool want_fade, wchar_t *fmt, ...) |
|
- | 1237 | { |
|
1216 | // helper function to |
1238 | // helper function to update some text on display |
1217 | 1239 | ||
1218 | static wchar_t message[4096]; |
1240 | static wchar_t message[4096]; |
1219 | va_list argptr; |
1241 | va_list argptr; |
1220 | int length; |
1242 | int length; |
1221 | 1243 | ||
1222 | // concatenate all the arguments in one string |
- | |
1223 | va_start (argptr, fmt); |
- | |
1224 | _vsnwprintf_s (message, WCHAR_SIZEOF (message), _TRUNCATE, fmt, argptr); |
- | |
1225 | va_end (argptr); |
- | |
1226 | - | ||
1227 | text->xpos_percent = xpos_percent; // save text's X position, in percents from left to right |
- | |
1228 | text->ypos_percent = ypos_percent; // save text's Y position, in percents from top to bottom |
- | |
1229 | text->maxwidth_percent = maxwidth_percent; // save text's max width before word wrapping |
- | |
1230 | text->horizontal_align = horizontal_align; // save text's horizontal alignment regarding the X position |
- | |
1231 | text->vertical_align = vertical_align; // save text's vertical alignment regarding the Y position |
- | |
1232 | text->text_align = text_align; // save text's horizontal alignment inside the bounding rectangle |
- | |
1233 | text->font_index = font_index; // save the index of the font with which to display this text |
- | |
1234 | text->color = color_rgba; // text's color, in RGBA |
1244 | text->color = color_rgba; // text's color, in RGBA |
- | 1245 | ||
- | 1246 | // concatenate all the arguments in one string |
|
- | 1247 | if (fmt != NULL) |
|
- | 1248 | { |
|
- | 1249 | va_start (argptr, fmt); |
|
- | 1250 | _vsnwprintf_s (message, WCHAR_SIZEOF (message), _TRUNCATE, fmt, argptr); |
|
- | 1251 | va_end (argptr); |
|
- | 1252 | } |
|
1235 | 1253 | ||
1236 | // now put the text in place |
1254 | // now put the text in place |
1237 | length = wcslen (message) + 1; // include null terminator |
1255 | length = wcslen (message) + 1; // include null terminator |
1238 | text->buffer = (wchar_t *) SAFE_realloc (text->buffer, text->buffer_size, length, sizeof (wchar_t), false); |
1256 | text->buffer = (wchar_t *) SAFE_realloc (text->buffer, text->buffer_size, length, sizeof (wchar_t), false); |
1239 | wcscpy_s (text->buffer, length, message); // copy message text |
1257 | wcscpy_s (text->buffer, length, message); // copy message text |
Line 1244... | Line 1262... | ||
1244 | text->want_fade = want_fade; // remember if text needs to be faded in and out |
1262 | text->want_fade = want_fade; // remember if text needs to be faded in and out |
1245 | 1263 | ||
1246 | // mark this text for display |
1264 | // mark this text for display |
1247 | text->is_displayed = true; |
1265 | text->is_displayed = true; |
1248 | 1266 | ||
1249 | return; // finished, text is |
1267 | return; // finished, text is updated |
1250 | } |
1268 | } |
1251 | 1269 | ||
1252 | 1270 | ||
1253 | static void Scene_AddPart (scene_t *scene, int part_type, int part_color, float pos_x, float pos_y, float pos_z, float turn_yaw, float pitch) |
1271 | static void Scene_AddPart (scene_t *scene, int part_type, int part_color, float pos_x, float pos_y, float pos_z, float turn_yaw, float pitch) |
1254 | { |
1272 | { |