00001
00025 #include "debug.h"
00026
00027 #ifdef GAMEMOD
00028 #include "debug.scene.h"
00029 #include "debug.grid.h"
00030 #include "scene.h"
00031 #include "sdlengine.h"
00032 #include "menu.h"
00033 #include "interface.h"
00034 #include "dialogues.h"
00035 #include "lbaengine.h"
00036 #include "images.h"
00037 #include "redraw.h"
00038
00039 enum ButtonType
00040 {
00041 NO_ACTION,
00042 FREE_CAMERA,
00043 CHANGE_SCENE,
00044 SHOW_CELLING_GRID,
00045 SHOW_ZONES,
00046 SHOW_ZONE_CUBE,
00047 SHOW_ZONE_CAMERA,
00048 SHOW_ZONE_SCENARIC,
00049 SHOW_ZONE_CELLINGGRID,
00050 SHOW_ZONE_OBJECT,
00051 SHOW_ZONE_TEXT,
00052 SHOW_ZONE_LADDER
00053 };
00054
00055 enum WindowType
00056 {
00057 NO_MENU,
00058 FREE_CAMERA_INFO_MENU,
00059 CHANGE_SCENE_INFO_MENU,
00060 ZONES_MENU
00061 };
00062
00063 typedef struct DebugButtonStruct
00064 {
00065 int left;
00066 int top;
00067 int right;
00068 int bottom;
00069 char *text;
00070 int textLeft;
00071 int textTop;
00072 int isActive;
00073 int color;
00074 int activeColor;
00075 int submenu;
00076 int type;
00077 } DebugButtonStruct;
00078
00079 typedef struct DebugWindowStruct
00080 {
00081 int left;
00082 int top;
00083 int right;
00084 int bottom;
00085 int alpha;
00086 int isActive;
00087 int numLines;
00088 char *text[20];
00089 int numButtons;
00090 DebugButtonStruct debugButtons[50];
00091 } DebugWindowStruct;
00092
00093 DebugWindowStruct debugWindows[10];
00094 int numDebugWindows=0;
00095
00096
00097 void debug_fill_button(int X, int Y, int width, int height, char color)
00098 {
00099 int i, j;
00100 unsigned char *ptr;
00101 int offset;
00102
00103 ptr = frontVideoBuffer + screenLockupTable[Y] + X;
00104 offset = 640 - (width);
00105
00106 for (i = 0; i < height; i++)
00107 {
00108 for (j = 0; j < width; j++)
00109 {
00110 *(ptr++) = color;
00111 }
00112 ptr += offset;
00113 }
00114 }
00115
00116 void debug_draw_button(int left, int top, int right, int bottom, char *text, int textLeft, int textRight, int isActive, char color)
00117 {
00118 debug_fill_button(left+1,top+1,right-left-1,bottom-top-1,color);
00119 draw_button_box(left,top,right,bottom);
00120 ttf_draw_text(textLeft,textRight,text,0);
00121 copy_block_phys(left,top,right,bottom);
00122 }
00123
00124 void debug_draw_window_box(int left, int top, int right, int bottom, int alpha)
00125 {
00126 draw_transparent_box(left,top,right,bottom,alpha);
00127 draw_button_box(left,top,right,bottom);
00128
00129 }
00130
00131 void debug_draw_window_buttons(int w)
00132 {
00133 int b;
00134 for(b=0; b < debugWindows[w].numButtons; b++)
00135 {
00136 int left = debugWindows[w].debugButtons[b].left;
00137 int top = debugWindows[w].debugButtons[b].top;
00138 int right = debugWindows[w].debugButtons[b].right;
00139 int bottom = debugWindows[w].debugButtons[b].bottom;
00140 char *text = debugWindows[w].debugButtons[b].text;
00141 int textLeft = debugWindows[w].debugButtons[b].textLeft;
00142 int textTop = debugWindows[w].debugButtons[b].textTop;
00143 int isActive = debugWindows[w].debugButtons[b].isActive;
00144 char color = debugWindows[w].debugButtons[b].color;
00145 if(isActive>0)
00146 color = debugWindows[w].debugButtons[b].activeColor;
00147
00148 debug_draw_button(left,top,right,bottom,text,textLeft,textTop,isActive,color);
00149 }
00150 }
00151
00152 void debug_draw_window(int w)
00153 {
00154 int left = debugWindows[w].left;
00155 int top = debugWindows[w].top;
00156 int right = debugWindows[w].right;
00157 int bottom = debugWindows[w].bottom;
00158 int alpha = debugWindows[w].alpha;
00159
00160 debug_draw_window_box(left,top,right,bottom,alpha);
00161
00162 if(debugWindows[w].numLines>0)
00163 {
00164 int l;
00165 for(l=0; l < debugWindows[w].numLines; l++)
00166 {
00167 ttf_draw_text(left+10,top+l*20+5,debugWindows[w].text[l],0);
00168 }
00169 }
00170
00171 copy_block_phys(left,top,right,bottom);
00172
00173 debug_draw_window_buttons(w);
00174 }
00175
00176 int debug_type_use_menu(int type)
00177 {
00178 int w,b;
00179 for(w=0; w < numDebugWindows; w++)
00180 {
00181 if(debugWindows[w].isActive>0)
00182 {
00183 for(b=0; b < debugWindows[w].numButtons; b++)
00184 {
00185 if(debugWindows[w].debugButtons[b].type==type)
00186 {
00187 int submenu = debugWindows[w].debugButtons[b].submenu;
00188 if(submenu>0)
00189 debugWindows[submenu].isActive = !debugWindows[submenu].isActive;
00190 return submenu;
00191 }
00192 }
00193 }
00194 }
00195 return 0;
00196 }
00197
00198 void debug_reset_buttons_state()
00199 {
00200 int w,b;
00201 for(w=0; w < numDebugWindows; w++)
00202 {
00203 if(debugWindows[w].isActive>0)
00204 {
00205 for(b=0; b < debugWindows[w].numButtons; b++)
00206 {
00207 if(debugWindows[w].debugButtons[b].type<=-1)
00208 debugWindows[w].debugButtons[b].isActive = 0;
00209 }
00210 }
00211 }
00212 }
00213
00214 void debug_refresh_buttons(int type)
00215 {
00216 int w,b;
00217 for(w=0; w < numDebugWindows; w++)
00218 {
00219 if(debugWindows[w].isActive>0)
00220 {
00221 for(b=0; b < debugWindows[w].numButtons; b++)
00222 {
00223 if(debugWindows[w].debugButtons[b].type==type)
00224 {
00225 int left = debugWindows[w].debugButtons[b].left;
00226 int top = debugWindows[w].debugButtons[b].top;
00227 int right = debugWindows[w].debugButtons[b].right;
00228 int bottom = debugWindows[w].debugButtons[b].bottom;
00229 char *text = debugWindows[w].debugButtons[b].text;
00230 int textLeft = debugWindows[w].debugButtons[b].textLeft;
00231 int textTop = debugWindows[w].debugButtons[b].textTop;
00232 char color = debugWindows[w].debugButtons[b].color;
00233 int isActive = debugWindows[w].debugButtons[b].isActive = !debugWindows[w].debugButtons[b].isActive;
00234
00235 if(isActive>0)
00236 color = debugWindows[w].debugButtons[b].activeColor;
00237
00238 debug_draw_button(left,top,right,bottom,text,textLeft,textTop,isActive,color);
00239
00240 if(debugWindows[w].debugButtons[b].submenu && isActive>0)
00241 debug_draw_window(debugWindows[w].debugButtons[b].submenu);
00242 }
00243 }
00244 }
00245 }
00246 }
00247
00248 void debug_draw_windows()
00249 {
00250 int w;
00251 for(w=0; w < numDebugWindows; w++)
00252 {
00253 if(debugWindows[w].isActive>0)
00254 {
00255 debug_draw_window(w);
00256 }
00257 }
00258 }
00259
00260 void debug_reset_button(int type)
00261 {
00262 int w,b;
00263 for(w=0; w < numDebugWindows; w++)
00264 {
00265 if(debugWindows[w].isActive>0)
00266 {
00267 for(b=0; b < debugWindows[w].numButtons; b++)
00268 {
00269 if(debugWindows[w].debugButtons[b].type==type)
00270 {
00271 int submenu = debugWindows[w].debugButtons[b].submenu;
00272 debugWindows[w].debugButtons[b].isActive = 0;
00273 if(submenu>0)
00274 {
00275 debugWindows[submenu].debugButtons[b].isActive = !debugWindows[submenu].debugButtons[b].isActive;
00276 }
00277
00278 return;
00279 }
00280 }
00281 }
00282 }
00283 }
00284
00285 void debug_redraw_screen()
00286 {
00287 redraw_engine_actions(1);
00288 copy_screen(frontVideoBuffer,workVideoBuffer);
00289 debug_draw_windows();
00290 }
00291
00292 int debug_get_actions_state(int type)
00293 {
00294 int state=0;
00295 switch(type)
00296 {
00297 case FREE_CAMERA:
00298 state = useFreeCamera;
00299 break;
00300 case CHANGE_SCENE:
00301 state = canChangeScenes;
00302 break;
00303 case SHOW_ZONES:
00304 state = showingZones;
00305 break;
00306 case SHOW_ZONE_CUBE:
00307 case SHOW_ZONE_CAMERA:
00308 case SHOW_ZONE_SCENARIC:
00309 case SHOW_ZONE_CELLINGGRID:
00310 case SHOW_ZONE_OBJECT:
00311 case SHOW_ZONE_TEXT:
00312 case SHOW_ZONE_LADDER:
00313 state = typeZones;
00314 break;
00315 default:
00316 break;
00317 }
00318 return state;
00319 }
00320
00321 void debug_set_actions(int type)
00322 {
00323 switch(type)
00324 {
00325 case FREE_CAMERA:
00326 useFreeCamera = !useFreeCamera;
00327 break;
00328
00329 case CHANGE_SCENE:
00330 canChangeScenes = !canChangeScenes;
00331 break;
00332
00333 case SHOW_ZONES:
00334 showingZones = !showingZones;
00335 debug_reset_button(-1);
00336 debug_reset_button(-2);
00337 debug_redraw_screen();
00338 break;
00339 case SHOW_ZONE_CUBE:
00340 if(showingZones)
00341 {
00342 if(typeZones & 0x01)
00343 typeZones &= ~0x01;
00344 else
00345 typeZones |= 0x01;
00346 debug_redraw_screen();
00347 }
00348 break;
00349 case SHOW_ZONE_CAMERA:
00350 if(showingZones)
00351 {
00352 if(typeZones & 0x02)
00353 typeZones &= ~0x02;
00354 else
00355 typeZones |= 0x02;
00356 debug_redraw_screen();
00357 }
00358 break;
00359 case SHOW_ZONE_SCENARIC:
00360 if(showingZones)
00361 {
00362 if(typeZones & 0x04)
00363 typeZones &= ~0x04;
00364 else
00365 typeZones |= 0x04;
00366 debug_redraw_screen();
00367 }
00368 break;
00369 case SHOW_ZONE_CELLINGGRID:
00370 if(showingZones)
00371 {
00372 if(typeZones & 0x08)
00373 typeZones &= ~0x08;
00374 else
00375 typeZones |= 0x08;
00376 debug_redraw_screen();
00377 debug_redraw_screen();
00378 }
00379 break;
00380 case SHOW_ZONE_OBJECT:
00381 if(showingZones)
00382 {
00383 if(typeZones & 0x10)
00384 typeZones &= ~0x10;
00385 else
00386 typeZones |= 0x10;
00387 debug_redraw_screen();
00388 debug_redraw_screen();
00389 }
00390 break;
00391 case SHOW_ZONE_TEXT:
00392 if(showingZones)
00393 {
00394 if(typeZones & 0x20)
00395 typeZones &= ~0x20;
00396 else
00397 typeZones |= 0x20;
00398 debug_redraw_screen();
00399 }
00400 break;
00401 case SHOW_ZONE_LADDER:
00402 if(showingZones)
00403 {
00404 if(typeZones & 0x40)
00405 typeZones &= ~0x40;
00406 else
00407 typeZones |= 0x40;
00408 debug_redraw_screen();
00409 }
00410 break;
00411
00412
00413 case -1:
00414 debug_reset_button(-2);
00415 debug_redraw_screen();
00416 break;
00417 case -2:
00418 debug_reset_button(-1);
00419 debug_redraw_screen();
00420 break;
00421 default:
00422 break;
00423 }
00424 }
00425
00426 void debug_add_button(int window, int left, int top, int right, int bottom, char * text, int textLeft, int textTop, int isActive, int color, int activeColor, int submenu, int type)
00427 {
00428 int button = debugWindows[window].numButtons;
00429 debugWindows[window].debugButtons[button].left = left;
00430 debugWindows[window].debugButtons[button].top = top;
00431 debugWindows[window].debugButtons[button].right = right;
00432 debugWindows[window].debugButtons[button].bottom = bottom;
00433 debugWindows[window].debugButtons[button].text = text;
00434 debugWindows[window].debugButtons[button].textLeft = textLeft;
00435 debugWindows[window].debugButtons[button].textTop = textTop;
00436 debugWindows[window].debugButtons[button].isActive = debug_get_actions_state(type);
00437 debugWindows[window].debugButtons[button].color = color;
00438 debugWindows[window].debugButtons[button].activeColor = activeColor;
00439 debugWindows[window].debugButtons[button].submenu = submenu;
00440 debugWindows[window].debugButtons[button].type = type;
00441 debugWindows[window].numButtons++;
00442 }
00443
00444 void debug_add_window_text(int window, char *text)
00445 {
00446 int line = debugWindows[window].numLines;
00447 debugWindows[window].text[line] = text;
00448 debugWindows[window].numLines++;
00449 }
00450
00451 void debug_add_window(int left, int top, int right, int bottom, int alpha, int isActive)
00452 {
00453 debugWindows[numDebugWindows].left = left;
00454 debugWindows[numDebugWindows].top = top;
00455 debugWindows[numDebugWindows].right = right;
00456 debugWindows[numDebugWindows].bottom = bottom;
00457 debugWindows[numDebugWindows].alpha = alpha;
00458 debugWindows[numDebugWindows].numButtons = 0;
00459 debugWindows[numDebugWindows].isActive = isActive;
00460 numDebugWindows++;
00461 }
00462
00463 void debug_left_menu()
00464 {
00465
00466 debug_add_window(5,60,200,474,4,1);
00467 debug_add_button(0,5,55,160,75,"Use free camera",30,60,0,87,119,NO_MENU,FREE_CAMERA);
00468 debug_add_button(0,161,55,200,75,"info",171,60,0,87,119,FREE_CAMERA_INFO_MENU,-1);
00469 debug_add_button(0,5,76,160,96,"Change scenes",30,81,0,87,119,NO_MENU,CHANGE_SCENE);
00470 debug_add_button(0,161,76,200,96,"info",171,81,0,87,119,CHANGE_SCENE_INFO_MENU,-2);
00471 debug_add_button(0,5,97,200,117,"Show celling grids",30,102,0,87,119,NO_MENU,3);
00472 debug_add_button(0,5,118,200,138,"Show zones",30,123,0,87,119,ZONES_MENU,SHOW_ZONES);
00473
00474
00475
00476 debug_add_window(205,55,634,160,4,0);
00477 debug_add_window_text(FREE_CAMERA_INFO_MENU,"When enable, use the following keys to browse through the scenes:");
00478 debug_add_window_text(FREE_CAMERA_INFO_MENU," - S to go North");
00479 debug_add_window_text(FREE_CAMERA_INFO_MENU," - X to go South");
00480 debug_add_window_text(FREE_CAMERA_INFO_MENU," - Z to go West");
00481 debug_add_window_text(FREE_CAMERA_INFO_MENU," - C to go East");
00482
00483
00484 debug_add_window(205,55,634,137,4,0);
00485 debug_add_window_text(CHANGE_SCENE_INFO_MENU,"When enable, use the following keys to change to another scene:");
00486 debug_add_window_text(CHANGE_SCENE_INFO_MENU," - R to go Next Scene");
00487 debug_add_window_text(CHANGE_SCENE_INFO_MENU," - F to go Previous Scene");
00488
00489
00490 debug_add_window(205,55,634,97,4,0);
00491 debug_add_window_text(ZONES_MENU,"You can enable or disable each zone type:");
00492 debug_add_button(ZONES_MENU,205,118,350,138,"Cube Zones",215,123,1,87,119,0,SHOW_ZONE_CUBE);
00493 debug_add_button(ZONES_MENU,205,139,350,159,"Camera Zones",215,144,2,87,119,0,SHOW_ZONE_CAMERA);
00494 debug_add_button(ZONES_MENU,205,160,350,180,"Scenaric Zones",215,165,3,87,119,0,SHOW_ZONE_SCENARIC);
00495 debug_add_button(ZONES_MENU,205,181,350,201,"Celling Grid Zones",215,186,4,87,119,0,SHOW_ZONE_CELLINGGRID);
00496 debug_add_button(ZONES_MENU,205,202,350,222,"Object Zones",215,207,5,87,119,0,SHOW_ZONE_OBJECT);
00497 debug_add_button(ZONES_MENU,205,223,350,243,"Text Zones",215,228,6,87,119,0,SHOW_ZONE_TEXT);
00498 debug_add_button(ZONES_MENU,205,244,350,264,"Ladder Zones",215,249,7,87,119,0,SHOW_ZONE_LADDER);
00499 }
00500
00501 int debug_process_button(int X, int Y)
00502 {
00503 int i;
00504 int j;
00505
00506 for (i = 0; i < numDebugWindows; i++)
00507 {
00508 for (j = 0; j < debugWindows[i].numButtons; j++)
00509 {
00510 if(X > (debugWindows[i].debugButtons[j].left)
00511 && X < (debugWindows[i].debugButtons[j].right)
00512 && Y > (debugWindows[i].debugButtons[j].top)
00513 && Y < (debugWindows[i].debugButtons[j].bottom))
00514 {
00515 return (debugWindows[i].debugButtons[j].type);
00516 }
00517 }
00518 }
00519
00520 return 0;
00521 }
00522
00523 void debug_plasma_window(char *text, int color)
00524 {
00525 int textSize;
00526 process_plasma_effect(5, color);
00527 if (!(rand() % 5))
00528 {
00529 plasmaEffectPtr[rand() % 320 * 10 + 6400] = 255;
00530 }
00531 textSize = dialogue_text_size(text);
00532 display_dialogue_text((SCREEN_WIDTH/2)-(textSize/2),10,text);
00533 draw_button_box(5,5,634,50);
00534 copy_block_phys(5,5,634,50);
00535 }
00536
00537 void debug_process_window()
00538 {
00539 if(rightMouse)
00540 {
00541 int quit=0;
00542 char * text = "Game Debug Window";
00543 int color = 64;
00544 int colorIdx = 4;
00545 int count = 0;
00546 MouseStatusStruct mouseData;
00547 rightMouse = 0;
00548 leftMouse = 0;
00549
00550 copy_screen(frontVideoBuffer,workVideoBuffer);
00551
00552 debug_reset_buttons_state();
00553 if(numDebugWindows==0)
00554 debug_left_menu();
00555 debug_draw_windows();
00556
00557 do
00558 {
00559 read_keys();
00560 get_mouse_positions(&mouseData);
00561
00562 if(mouseData.left)
00563 {
00564 int type=0;
00565 if((type=debug_process_button(mouseData.X,mouseData.Y))!=NO_ACTION)
00566 {
00567 if(debug_type_use_menu(type))
00568 {
00569 copy_screen(workVideoBuffer,frontVideoBuffer);
00570 copy_block_phys(205,55,634,474);
00571 }
00572
00573 debug_refresh_buttons(type);
00574 debug_set_actions(type);
00575 }
00576 mouseData.left = 0;
00577 }
00578
00579
00580 if(count==256)
00581 {
00582 colorIdx++;
00583 count=0;
00584 }
00585 color=colorIdx*16;
00586 if(color>=240){
00587 color=64;
00588 colorIdx=4;
00589 }
00590 debug_plasma_window(text, color);
00591
00592
00593 if(mouseData.right)
00594 quit=1;
00595
00596 fps_cycles(25);
00597
00598 count++;
00599 }
00600 while(!quit);
00601 reqBgRedraw = 1;
00602 }
00603 }
00604
00605 void process_debug(short int pKey)
00606 {
00607 debug_process_window();
00608
00609 change_grid(pKey);
00610 change_grid_camera(pKey);
00611 if(needChangeScene==0);
00612 apply_celling_grid(pKey);
00613 }
00614
00615 #endif
00616