void draw_dialogue(char* tab) { GRRLIB_ttfFont *myFont = GRRLIB_LoadTTF(fontCodec_ttf, fontCodec_ttf_size); //char tab[200] = texte; // 90 caracteres max (3 lignes) char ligne1[31]; char ligne2[31]; char ligne3[31]; char ligne4[31]; // recherche des espaces pour éviter de couper un mot en 2 // et division du dialogue sur 3 lignes int i; int j=0; int k=0; int l=0; int m=0; int z=0; while(tab[z]!='\0') z++; // n= nombre total de caracteres for(i=z; i<199; i++) tab[i]=' '; tab[199]='\n'; for(i=0; i<30; i++) // LIGNE 1 { if(tab[i]==' ') j=i; // recup du dernier espace pour savoir où couper } for(i=0; i<j; i++) // on crée la ligne 1 ligne1[i]=tab[i]; ligne1[j]='\0'; for(i=j+1; i<j+31; i++) // REBELOTE LIGNE 2 { if(tab[i]==' ') k=i; } for(i=0; i<(k-j); i++) ligne2[i]=tab[j+1+i]; // j+1 car on saute l'espace ligne2[k-j]='\0'; for(i=k+1; i<k+31; i++) // REBELOTE LIGNE 3 { if(tab[i]==' ') l=i; } for(i=0; i<(l-k); i++) ligne3[i]=tab[k+1+i]; // k+1 car on saute l'espace ligne3[l-k]='\0'; for(i=k+1; i<l+31; i++) // REBELOTE LIGNE 4 { if(tab[i]==' ') m=i; } for(i=0; i<(m-l); i++) ligne4[i]=tab[l+1+i]; // k+1 car on saute l'espace ligne4[m-l]='\0'; GRRLIB_PrintfTTF(75, 265, myFont , ligne1, 28 , CLR_WHITE); GRRLIB_PrintfTTF(75, 295, myFont , ligne2, 28 , CLR_WHITE); GRRLIB_PrintfTTF(75, 325, myFont , ligne3, 28 , CLR_WHITE); GRRLIB_PrintfTTF(75, 355, myFont , ligne4, 28 , CLR_WHITE); GRRLIB_FreeTTF(myFont); }
void cui_board_display(cui_board *board, GRRLIB_texImg* tex_pieces, GRRLIB_texImg* tex_tile, GRRLIB_ttfFont* font, int cursor_x, int cursor_y){ unsigned int i; unsigned int x=0, y=0; int offset_x = 140; int offset_y = 80; for(i=0;i<8;i++){ char board_alpha[2] = {i + 'A'}; GRRLIB_PrintfTTF (i*40+offset_x+20, offset_y + 8*40 + 16/2, font, board_alpha, 16, 0xFFFFFFFF); } for (i = 0; i < CUI_TILE_NB; i++) { u32 tile_color; if(x == cursor_x && y == cursor_y){ tile_color = 0x223388FF; }else tile_color = board->tile[i].color; GRRLIB_DrawImg(x*40+offset_x, y*40+offset_y, tex_tile, 0, 1, 1, tile_color); if ((i & 7) == 7){ char board_num[2]; snprintf(board_num, 2, "%d", 8-y); GRRLIB_PrintfTTF (offset_x - 20, y*40+offset_y + 16/2, font, board_num, 16, 0xFFFFFFFF); y++; x=0; }else{ x++; } } x=y=0; offset_x++; offset_y = 11; for (i = 0; i < CUI_TILE_NB; i++) { if (board->piece[i] != CUI_EMPTY){ u32 piece_color = (board->color[i] == CUI_WHITE ? board->piece_color1 : board->piece_color2); GRRLIB_DrawPart(x*40+offset_x, y*40+offset_y, board->piece[i]*40, 0, 40, 100, tex_pieces, 0, 1, 1, piece_color); } if ((i & 7) == 7){ y++; x=0; }else x++; } }
void GRRTerminal::printAll() { int pos = 0; vector<string>::const_iterator cii; GRRLIB_2dMode(); for (cii = lines.begin(); cii < lines.end(); cii++) { GRRLIB_PrintfTTF(_x, _y + (_size * 1.1) * pos++, _font, (*cii).c_str(), _size, _color); } }
cui_menu menu_home(cui_game* p_game) { cui_menu next_state = CUI_MENU_MAIN; bool done=false; GRRLIB_ttfFont* font = GRRLIB_LoadTTF(font_ttf, font_ttf_size); UI_button button_loader; UI_InitBtn(&button_loader, 200, 200, "Loader"); button_loader.img = GRRLIB_LoadTexture(button_png); button_loader.font = font; UI_button button_menu; UI_InitBtn(&button_menu, 400, 200, "Wii menu"); button_menu.img = GRRLIB_LoadTexture(button_png); button_menu.font = font; while(!done) { GRRLIB_FillScreen(0x000000FF); GRRLIB_PrintfTTF (15, 0, font, "HOME Menu", 96, 0xFFFFFFFF); GRRLIB_Line(0, 100, 640, 100, 0xFFFFFFFF); UI_DrawBtn(&button_loader); UI_DrawBtn(&button_menu); cui_cursor_display(p_game->cursor); cui_game_update_cursor(p_game->cursor); u32 pressed = WPAD_ButtonsDown(0); UI_UpdateBtn(&button_loader, p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, pressed & WPAD_BUTTON_A); UI_UpdateBtn(&button_menu, p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, pressed & WPAD_BUTTON_A); if ( pressed & WPAD_BUTTON_HOME ){ done = true; } if(button_loader.click){ done=true; next_state=CUI_MENU_EXIT; } if(button_menu.click){ SYS_ResetSystem(SYS_RETURNTOMENU, 0, 0); } GRRLIB_Render(); } GRRLIB_FreeTexture(button_loader.img); GRRLIB_FreeTexture(button_menu.img); free(button_loader.text); free(button_menu.text); return next_state; }
void Game::run(const string& initialLevel) { this->changeLevel(initialLevel); int frameCount = 0; char framePerSecond[32] = ""; while (!this->levels.empty()) { WPAD_ScanPads(); Level* level = this->levels.top(); level->nextStep(); level->render(); if (this->debugDrawEnabled) level->world->DrawDebugData(); if (this->console.isEnabled()) this->console.render(); // Render FPS GRRLIB_PrintfTTF(570, 32, this->font, framePerSecond, 16, GRRLIB_RED); GRRLIB_Render(); // Render the frame buffer to the screen // If level is finished, resume the previous one if (level->isFinished()) { Console::log(LOG_INFO, "Game::run() - resume previous level"); this->levels.pop(); delete level; if (this->levels.top()) this->levels.top()->loadGraphics(); } // WPAD_ButtonsDown tells us which buttons were pressed in this loop // this is a "one shot" state which will not fire again until the button has been released u32 pressed = WPAD_ButtonsDown(WPAD_CHAN_0); // We return to the launcher application via exit if (pressed & WPAD_BUTTON_HOME) return; if (pressed & WPAD_BUTTON_PLUS) this->console.enable(!this->console.isEnabled()); if (pressed & WPAD_BUTTON_MINUS) this->debugDrawEnabled = !this->debugDrawEnabled; // Count FPS frameCount++; if (this->fpsTimer.isExpired()) { sprintf(framePerSecond, "%2d FPS", frameCount); frameCount = 0; } } }
void GRRTerminal::addLine(string s) { lines.push_back(s); GRRLIB_2dMode(); GRRLIB_PrintfTTF(_x, _y + (_size * 1.1) * _lastline++, _font, s.c_str(), _size, _color); }
int main(int argc, char **argv) { SYS_SetResetCallback(WiiResetPressed); SYS_SetPowerCallback(WiiPowerPressed); usleep(250*1000); GRRLIB_Init(); GRRLIB_ttfFont *font = GRRLIB_LoadTTF(verdana_ttf, verdana_ttf_size); WPAD_Init(); USB_Initialize(); USB_DeviceChangeNotifyAsync(USB_CLASS_HID, change_notify_cb, NULL); int dev_id = get_device_id(); int fd = open_device(dev_id); struct ds4_input data; memset(&data, 0, sizeof(data)); fetch_data(fd, &data); random_leds(fd); int screenW = rmode->fbWidth, screenH = rmode->efbHeight; float pos_x = screenW/2, pos_y = screenH/2; while (run) { WPAD_ScanPads(); u32 pressed = WPAD_ButtonsDown(0); if (pressed & WPAD_BUTTON_B) { dev_id = get_device_id(); fd = open_device(dev_id); } if (pressed & WPAD_BUTTON_A) { random_leds(fd); } GRRLIB_FillScreen(0x0); GRRLIB_PrintfTTF(15, 15, font, "ds4wii by xerpi | L1: center | R1: random color", 15, 0xFFFFFFFF); u32 color = (r<<24)|(g<<16)|(b<<8)|0xFF; GRRLIB_Circle(pos_x, pos_y, 15, color, 0); GRRLIB_Circle(pos_x, pos_y, 14, color, 0); memset(&data, 0, sizeof(data)); fetch_data(fd, &data); if (data.L1) {pos_x = screenW/2, pos_y = screenH/2;} if (data.R1) {random_leds(fd);} //1920x940 if (data.finger1active) { GRRLIB_Circle((screenW/1920.0f)*data.finger1X, (screenH/940.0f)*data.finger1Y, 10, 0x00FF00FF, 1); } if (data.finger2active) { GRRLIB_Circle((screenW/1920.0f)*data.finger2X, (screenH/940.0f)*data.finger2Y, 10, 0x0000FFFF, 1); } /*char buf1[256]; sprintf(buf1, "aX: %8hi aY: %8hi aZ: %8hi", data.accelX, data.accelY, data.accelZ); char buf2[256]; sprintf(buf2, "gyroX: %8hi gyroY: %8hi gyroZ: %8hi", data.gyroX, data.gyroY, data.gyroZ); GRRLIB_PrintfTTF(15, 30, font, buf1, 14, 0xFFFFFFFF); GRRLIB_PrintfTTF(15, 45, font, buf2, 14, 0xFFFFFFFF); */ #define THRESHOLD 50.0f if (fabs(data.accelX) > THRESHOLD) pos_y -= data.accelX/55.0f; if (fabs(data.accelY) > THRESHOLD) pos_x -= data.accelY/55.0f; if (pressed & WPAD_BUTTON_HOME) run = 0; GRRLIB_Render(); } USB_CloseDevice(&fd); USB_Deinitialize(); GRRLIB_FreeTTF (font); GRRLIB_Exit(); exit(0); return 0; }
cui_menu menu_play(cui_game* p_game) { cui_menu next_state = CUI_MENU_MAIN; bool done=false; GRRLIB_texImg *tex_pieces = GRRLIB_LoadTexture(chess_classic_png); GRRLIB_texImg *tex_tile = GRRLIB_LoadTexture(keyboard_key_png); GRRLIB_ttfFont* font = GRRLIB_LoadTTF(font_ttf, font_ttf_size); bool is_debug = false; char coords[5]; char calculated_coords[5]; strcpy(coords, "d2d20"); strcpy(calculated_coords, "d2d20"); while(!done){ WPAD_IR(0, &ir); WPAD_ScanPads(); u32 pressed = WPAD_ButtonsDown(0); u32 released = WPAD_ButtonsUp(0); if(egg_check_s1_code(pressed, released)){ is_debug = true; p_game->board->tile_color1 = 0xc66300FF; p_game->board->tile_color2 = 0x632100FF; p_game->board->piece_color1 = 0x4242CCFF; p_game->board->piece_color2 = 0x444411FF; cui_board_init(p_game->board); if(voice) AESND_PlayVoice(voice, VOICE_STEREO8, warp, warp_size, VOICE_FREQ32KHZ, 1, false); } if ( pressed & WPAD_BUTTON_HOME ){ if(!p_game->is_mute)AESND_Pause(true); if(menu_home(p_game) == CUI_MENU_EXIT){done=true;next_state=CUI_MENU_EXIT;} if(!p_game->is_mute)AESND_Pause(false); } if ( pressed & WPAD_BUTTON_MINUS){ switch(menu_option(p_game)){ case CUI_MENU_OPTION_GFX:menu_option_gfx(p_game);break; case CUI_MENU_OPTION_SND:menu_option_snd(p_game);break; default:break; } } int index_offset_x = (p_game->cursor->hotspot_x - 40 / 2)/ 40 - 140 / 40; int index_offset_y = p_game->cursor->hotspot_y / 40 - 80 / 40; if (pressed & WPAD_BUTTON_B) { p_game->cursor->is_grabbing = true; if(index_offset_x >= 0 && index_offset_x < 8 && index_offset_y >= 0 && index_offset_y < 8){ coords[0] = 'a' + index_offset_x; coords[1] = '8' - index_offset_y; } } else if(released & WPAD_BUTTON_B){ p_game->cursor->is_grabbing = false; if(index_offset_x >= 0 && index_offset_x < 8 && index_offset_y >= 0 && index_offset_y < 8){ coords[2] = 'a' + index_offset_x; coords[3] = '8' - index_offset_y; coords[4] = 0; if(voice) AESND_PlayVoice(voice, VOICE_STEREO16, move_pcm, move_pcm_size, VOICE_FREQ48KHZ, 1, false); if(calculate_coords(coords, calculated_coords, p_game->engine)){ cui_board_read_core(p_game->board, p_game->engine); } } } cui_cursor_update(p_game->cursor, ir.x, ir.y, ir.angle); if(p_game->tex_wallpaper)GRRLIB_DrawImg(0, -50, p_game->tex_wallpaper, 1, 1, 1, 0XFFFFFFFF); cui_board_display(p_game->board, tex_pieces, tex_tile, font, index_offset_x, index_offset_y); cui_cursor_display(p_game->cursor); if(is_debug){ GRRLIB_PrintfTTF (20, 00, font, coords, 16, 0x424242FF); GRRLIB_PrintfTTF2 (20, 20, font, 16, 0xFFFFFFFF, "x:%.2f y:%.2f", ir.x, ir.y); GRRLIB_PrintfTTF2 (20, 40, font, 16, 0xFFFFFFFF, "x:%.2f y:%.2f", ir.x/40, ir.y/40); GRRLIB_PrintfTTF2 (20, 60, font, 16, 0xFFFFFFFF, "x:%d y:%d", index_offset_x, index_offset_y); GRRLIB_PrintfTTF (20, 80, font, p_game->cursor->is_grabbing?"GRAB":"POINT", 16, 0xFFFFFFFF); GRRLIB_Rectangle(p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, 4, 4, 0xFF4242FF, 1); } GRRLIB_Render(); } GRRLIB_FreeTexture(tex_pieces); GRRLIB_FreeTexture(tex_tile); GRRLIB_FreeTTF(font); return next_state; }
cui_menu menu_main(cui_game* p_game) { cui_menu next_state = CUI_MENU_MAIN; bool done=false; GRRLIB_ttfFont* font = GRRLIB_LoadTTF(font_ttf, font_ttf_size); GRRLIB_texImg *tex_pieces = GRRLIB_LoadTexture(chess_classic_png); GRRLIB_texImg *tex_tile = GRRLIB_LoadTexture(keyboard_key_png); GRRLIB_texImg *tex_btn = GRRLIB_LoadTexture(button_png); UI_button button_newgame; UI_InitBtn(&button_newgame, 280, 120, "New game"); button_newgame.img = tex_btn; button_newgame.font = font; UI_button button_options; UI_InitBtn(&button_options, 280, 200, "Options"); button_options.img = tex_btn; button_options.font = font; UI_button button_credit; UI_InitBtn(&button_credit, 280, 280, "credit"); button_credit.img = tex_btn; button_credit.font = font; while(!done){ cui_game_update_cursor(p_game->cursor); u32 pressed = WPAD_ButtonsDown(0); GRRLIB_PrintfTTF (5, 5, font, "ChessUI", 96, 0x424242FF); UI_UpdateBtn(&button_newgame, p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, pressed & WPAD_BUTTON_A); UI_UpdateBtn(&button_options, p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, pressed & WPAD_BUTTON_A); UI_UpdateBtn(&button_credit, p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, pressed & WPAD_BUTTON_A); if(button_newgame.click){ done=true; next_state=CUI_MENU_PLAY; } if(button_options.click){ done=true; next_state=CUI_MENU_OPTION; } if(button_credit.click){ done=true; next_state=CUI_MENU_CREDITS; } if ( pressed & WPAD_BUTTON_HOME ){ if(!p_game->is_mute)AESND_Pause(true); if(menu_home(p_game) == CUI_MENU_EXIT){done=true;next_state=CUI_MENU_EXIT;} if(!p_game->is_mute)AESND_Pause(false); } if ( pressed & WPAD_BUTTON_A ){ if(voice) AESND_PlayVoice(voice, VOICE_STEREO16, button_click_pcm, button_click_pcm_size, VOICE_FREQ48KHZ, 1, false); } cui_board_demo(p_game->board, tex_pieces, tex_tile, font); UI_DrawBtn(&button_newgame); UI_DrawBtn(&button_options); UI_DrawBtn(&button_credit); cui_cursor_display(p_game->cursor); GRRLIB_Render(); } GRRLIB_FreeTTF(font); GRRLIB_FreeTexture(tex_btn); free(button_newgame.text); free(button_options.text); free(button_credit.text); return next_state; }
enum e_cui_menu menu_option_gfx(cui_game* p_game) { cui_menu next_state = CUI_MENU_MAIN; bool done=false; u32 option_tile_color_1 = p_game->board->tile_color1; u32 option_tile_color_2 = p_game->board->tile_color2; u32 option_piece_color_1 = p_game->board->piece_color1; u32 option_piece_color_2 = p_game->board->piece_color2; GRRLIB_texImg *tex_tile = GRRLIB_LoadTexture(keyboard_key_png); GRRLIB_texImg *tex_pieces = GRRLIB_LoadTexture(chess_classic_png); GRRLIB_texImg *tex_up = GRRLIB_LoadTexture(scrollbar_arrowup_png); GRRLIB_texImg *tex_down = GRRLIB_LoadTexture(scrollbar_arrowdown_png); GRRLIB_ttfFont* font = GRRLIB_LoadTTF(font_ttf, font_ttf_size); int i,j; UI_button button_color[4][8]; //tile 1, tile 2, piece 1, piece 2 | R-+, G-+, B-+, A-+, for(i=0;i<4;i++){ for(j=0;j<8;j++){ UI_InitBtn(&button_color[i][j], 120 + j*64, 64 + i*80, NULL); button_color[i][j].img = j%2==0?tex_down:tex_up; } } UI_button button_return; UI_InitBtn(&button_return, 500, 400, "apply"); button_return.img = GRRLIB_LoadTexture(button_png); button_return.font = font; UI_button button_cancel; UI_InitBtn(&button_cancel, 350, 400, "cancel"); button_cancel.img = GRRLIB_LoadTexture(button_png); button_cancel.font = font; while(!done){ cui_game_update_cursor(p_game->cursor); u32 pressed = WPAD_ButtonsDown(0); u32* color_to_modify=NULL; u32 mask; for(i=0;i<4;i++){ for(j=0;j<8;j++){ UI_UpdateBtn(&button_color[i][j], p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, pressed & WPAD_BUTTON_A); if(button_color[i][j].click){ switch(i){ case 0:color_to_modify = &option_tile_color_1;break; case 1:color_to_modify = &option_tile_color_2;break; case 2:color_to_modify = &option_piece_color_1;break; case 3:color_to_modify = &option_piece_color_2;break; } if(j==0 || j==1)mask=0x06000000; if(j==2 || j==3)mask=0x00060000; if(j==4 || j==5)mask=0x00000600; if(j==6 || j==7)mask=0x00000006; *color_to_modify+=j%2==0?-mask:mask; } } } UI_UpdateBtn(&button_cancel, p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, pressed & WPAD_BUTTON_A); UI_UpdateBtn(&button_return, p_game->cursor->hotspot_x, p_game->cursor->hotspot_y, pressed & WPAD_BUTTON_A); if(button_return.click){ if((option_tile_color_1 != p_game->board->tile_color1) || (option_tile_color_2 != p_game->board->tile_color2)){ p_game->board->tile_color1 = option_tile_color_1; p_game->board->tile_color2 = option_tile_color_2; cui_board_init(p_game->board); } if(option_tile_color_1 != p_game->board->piece_color1)p_game->board->piece_color1=option_piece_color_1; if(option_tile_color_2 != p_game->board->piece_color2)p_game->board->piece_color2=option_piece_color_2; done=true; next_state=CUI_MENU_MAIN; } if(button_cancel.click){ done=true; next_state=CUI_MENU_MAIN; } if ( pressed & WPAD_BUTTON_HOME ){ if(!p_game->is_mute)AESND_Pause(true); if(menu_home(p_game) == CUI_MENU_EXIT){done=true;next_state=CUI_MENU_EXIT;} if(!p_game->is_mute)AESND_Pause(false); } GRRLIB_DrawImg(380, 80+140, tex_tile, 0, 2, 2, option_tile_color_1); GRRLIB_DrawImg(380, 180+140, tex_tile, 0, 2, 2, option_tile_color_2); GRRLIB_DrawImg(380+80, 80+140, tex_tile, 0, 2, 2, option_tile_color_2); GRRLIB_DrawImg(380+80, 180+140, tex_tile, 0, 2, 2, option_tile_color_1); GRRLIB_DrawImg(380+160, 80+140, tex_tile, 0, 2, 2, option_tile_color_1); GRRLIB_DrawImg(380+160, 180+140, tex_tile, 0, 2, 2, option_tile_color_2); GRRLIB_DrawImg(380, 80, tex_pieces, 0, 2, 2, option_piece_color_2); GRRLIB_DrawImg(380, 180, tex_pieces, 0, 2, 2, option_piece_color_1); GRRLIB_PrintfTTF (145, 0, font, "RED GREEN BLUE ALPHA", 20, 0xFFFFFFFF); GRRLIB_PrintfTTF (15, 40, font, "Tiles color #1", 20, 0xFFFFFFFF); GRRLIB_PrintfTTF (15, 40+80, font, "Tiles color #2", 20, 0xFFFFFFFF); GRRLIB_PrintfTTF (15, 40+80*2, font, "Pieces color #1", 20, 0xFFFFFFFF); GRRLIB_PrintfTTF (15, 40+80*3, font, "Pieces color #2", 20, 0xFFFFFFFF); for(i=0;i<4;i++){ for(j=0;j<8;j++){ UI_DrawBtn(&button_color[i][j]); } } UI_DrawBtn(&button_return); UI_DrawBtn(&button_cancel); GRRLIB_Line(235, 25, 235, 350, 0xFFFFFFFF); GRRLIB_Line(235+64*2, 25, 235+64*2, 350, 0xFFFFFFFF); GRRLIB_Line(235+64*4, 25, 235+64*4, 350, 0xFFFFFFFF); GRRLIB_Line(235+64*6, 25, 235+64*6, 350, 0xFFFFFFFF); cui_cursor_display(p_game->cursor); GRRLIB_Render(); } GRRLIB_FreeTexture(tex_tile); GRRLIB_FreeTexture(tex_pieces); GRRLIB_FreeTexture(tex_up); GRRLIB_FreeTexture(tex_down); GRRLIB_FreeTTF(font); free(button_return.text); free(button_cancel.text); return next_state; }