void Main_PrepareKeyboard(int latrus) { SDL_Rect rc; rc.x = rc.y = 0; rc.w = KEYBOARD_WIDTH; rc.h = KEYBOARD_HEIGHT; SDL_FillRect(g_Keyboard, &rc, SDL_MapRGB(g_Keyboard->format, 0,0,0)); Uint32 colorbk = SDL_MapRGB(g_Keyboard->format, 64, 120, 64); for (int i = 0; i < m_nKeyboardKeysCount; i++) { int x = m_arrKeyboardKeys[i].x / 2; int y = m_arrKeyboardKeys[i].y / 2; int w = m_arrKeyboardKeys[i].w / 2; int h = m_arrKeyboardKeys[i].h / 2; rc.x = x + 1; rc.y = y + 1; rc.w = w - 2; rc.h = h - 2; SDL_FillRect(g_Keyboard, &rc, colorbk); } for (int i = 0; i < m_nKeyboardKeysCount; i++) { int x = m_arrKeyboardKeys[i].x / 2; int y = m_arrKeyboardKeys[i].y / 2; int w = m_arrKeyboardKeys[i].w / 2; int h = m_arrKeyboardKeys[i].h / 2; const char* label = latrus ? m_arrKeyboardKeys[i].label : m_arrKeyboardKeys[i].labelru; if (m_arrKeyboardKeys[i].label != NULL && (*label) != 0) { int len = strlen(label) * 8; Font_DrawText(x + w/2 - len/2, y + 4, label, g_Keyboard); } } }
void Main_Menu() { int exitMenu = FALSE; int currentItem = 0; int redrawScreen = TRUE; const int menuItemCount = sizeof(m_MainMenuItems) / sizeof(MenuItemStruct); const int menuLeft = 12; const int menuWidth = 8 * 16; char progname[50]; char buffer[32]; sprintf(progname, "BKBTL SDL version %d.%d " __DATE__ " ", VERSION_MAJOR, VERSION_MINOR); while (!exitMenu) { if (redrawScreen) { Main_DrawScreen(); // Draw menu background SDL_Rect rc; rc.x = menuLeft - 8; rc.y = 8 - 4; rc.w = 16 + menuWidth; rc.h = 8 + 12 * menuItemCount; SDL_FillRect(g_Screen, &rc, SDL_MapRGB(g_Screen->format, 32, 32, 192)); // Draw selected item background rc.x = menuLeft - 4; rc.y = 8 - 1 + currentItem * 12; rc.w = 8 + menuWidth; rc.h = 11 + 2; SDL_FillRect(g_Screen, &rc, SDL_MapRGB(g_Screen->format, 192, 32, 32)); // Draw menu items int y = 8; for (int i = 0; i < menuItemCount; i++) { Font_DrawText(menuLeft, y + 12 * i, m_MainMenuItems[i].text); } // Emulator name and version number Font_DrawText(menuLeft, SCREEN_HEIGHT - 12, progname); // Last FPS sprintf(buffer, "FPS: %d, Delay: %d", g_LastFps, g_LastDelay); Font_DrawText(menuLeft, SCREEN_HEIGHT - 24, buffer); SDL_Flip(g_Screen); redrawScreen = FALSE; } SDL_Event evt; while (SDL_PollEvent(&evt)) { redrawScreen = TRUE; if (evt.type == SDL_QUIT) { g_okQuit = exitMenu = TRUE; break; } if (evt.type == SDL_KEYDOWN || evt.type == SDL_JOYBUTTONDOWN) { KeyMappingStruct* mapping = FindKeyMapping(1, evt.key.keysym.sym, TRUE); if (mapping != NULL) { switch (mapping->resultcd) { case ID_EXIT: g_okQuit = exitMenu = TRUE; break; case ID_MENU: case ID_MENU_ESCAPE: exitMenu = TRUE; break; case ID_MENU_UP: if (currentItem > 0) currentItem--; else currentItem = menuItemCount - 1; break; case ID_MENU_DOWN: if (currentItem < menuItemCount - 1) currentItem++; else currentItem = 0; break; case ID_MENU_RIGHT: case ID_MENU_SELECT: if (Main_ExecuteMenuCommand(m_MainMenuItems[currentItem].command, TRUE)) exitMenu = TRUE; break; case ID_MENU_LEFT: if (Main_ExecuteMenuCommand(m_MainMenuItems[currentItem].command, FALSE)) exitMenu = TRUE; break; default: break; } } } } SDL_Delay(50); } }
// Show directory browser for *.BIN mask void Main_BrowseAndLoadBin() { // Get file list by mask char ** pfilenames = Common_FindFiles(g_AppDirectory, "*.bin"); int exitBrowser = FALSE; int currentItem = 0; int redrawScreen = TRUE; int menuItemCount = 0; const int menuLeft = 12; const int menuWidth = 8 * 32; const int menuHeight = 11 * 20; while (!exitBrowser) { if (redrawScreen) { Main_DrawScreen(); // Draw menu background SDL_Rect rc; rc.x = menuLeft - 8; rc.y = 8 - 4; rc.w = 12 + menuWidth; rc.h = 8 + menuHeight; SDL_FillRect(g_Screen, &rc, SDL_MapRGB(g_Screen->format, 32, 32, 192)); // Draw selected item background rc.x = menuLeft - 4; rc.y = 8 - 1 + currentItem * 11; rc.w = 4 + menuWidth; rc.h = 11 + 2; SDL_FillRect(g_Screen, &rc, SDL_MapRGB(g_Screen->format, 192, 32, 32)); // Draw menu items char ** pitem = pfilenames; int y = 8; menuItemCount = 0; while (*pitem != NULL) { Font_DrawText(menuLeft, y, *pitem); pitem++; y += 11; menuItemCount++; } SDL_Flip(g_Screen); redrawScreen = FALSE; } SDL_Event evt; while (SDL_PollEvent(&evt)) { redrawScreen = TRUE; if (evt.type == SDL_QUIT) { g_okQuit = exitBrowser = TRUE; break; } if (evt.type == SDL_KEYDOWN) { switch (evt.key.keysym.sym) { case SDLK_PAUSE: // POWER UP button on Dingoo g_okQuit = exitBrowser = TRUE; break; case SDLK_TAB: // Left shoulder on Dingoo case SDLK_ESCAPE: // SELECT button on Dingoo exitBrowser = TRUE; break; case SDLK_UP: if (currentItem > 0) currentItem--; else currentItem = menuItemCount - 1; break; case SDLK_DOWN: if (currentItem < menuItemCount - 1) currentItem++; else currentItem = 0; break; case SDLK_LCTRL: // A button on Dingoo case SDLK_SPACE: // X button on Dingoo case SDLK_RETURN: // START button on Dingoo { char * filename = pfilenames[currentItem]; Main_LoadBin(filename); // Print "S1000" Emulator_KeyboardEvent(0123, TRUE); Emulator_KeyboardEvent(0123, FALSE); Emulator_KeyboardEvent(061, TRUE); Emulator_KeyboardEvent(061, FALSE); Emulator_KeyboardEvent(060, TRUE); Emulator_KeyboardEvent(060, FALSE); Emulator_KeyboardEvent(060, TRUE); Emulator_KeyboardEvent(060, FALSE); Emulator_KeyboardEvent(060, TRUE); Emulator_KeyboardEvent(060, FALSE); exitBrowser = TRUE; } break; default: break; } } } SDL_Delay(50); } Common_FindFiles_Cleanup(pfilenames); }
void ClientGame::Render() { glHint(GL_LINE_SMOOTH_HINT, GL_NICEST ); glHint(GL_POLYGON_SMOOTH_HINT, GL_NICEST ); glEnable(GL_LINE_SMOOTH); glEnable(GL_POLYGON_SMOOTH); if (m_gameState == GameState_MainMenu) { RenderMainMenu(); return; } if (m_gameState == GameState_WaitingForServer) { return; } glClearColor( 0.97f * 0.9f, 0.96f * 0.9f, 0.89f * 0.9f, 0.0f ); glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT ); glDisable(GL_TEXTURE_2D); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(m_mapX, m_mapX + m_xSize * m_mapScale, m_mapY + m_ySize * m_mapScale, m_mapY); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); const int outerBorder = 35; // Draw the background. glColor(0xFFFFFFFF); glBegin(GL_QUADS); glVertex2i(-outerBorder, -outerBorder); glVertex2i(m_xMapSize + outerBorder, -outerBorder); glVertex2i(m_xMapSize + outerBorder, m_yMapSize + outerBorder); glVertex2i(-outerBorder, m_yMapSize + outerBorder); glEnd(); // Outer thick border of the map glColor(0xFF7FD6F2); glLineWidth(2); glBegin(GL_LINE_LOOP); glVertex2i(-outerBorder, -outerBorder); glVertex2i(m_xMapSize + outerBorder, -outerBorder); glVertex2i(m_xMapSize + outerBorder, m_yMapSize + outerBorder); glVertex2i(-outerBorder, m_yMapSize + outerBorder); glEnd(); // Grid glColor(0xFF7FD6F2); glLineWidth(1); glBegin(GL_LINES); for (int x = 0; x < m_xMapSize / m_gridSpacing; ++x) { glVertex2i(x * m_gridSpacing, 0); glVertex2i(x * m_gridSpacing, m_yMapSize); } glVertex2i(m_xMapSize, 0); glVertex2i(m_xMapSize, m_yMapSize); for (int y = 0; y < m_yMapSize / m_gridSpacing; ++y) { glVertex2i(0, y * m_gridSpacing); glVertex2i(m_xMapSize, y * m_gridSpacing); } glVertex2i(0, m_yMapSize); glVertex2i(m_xMapSize, m_yMapSize); glEnd(); // Buildings. glEnable(GL_TEXTURE_2D); glColor(0xFFFFFFFF); for (int i = 0; i < m_map.GetNumStops(); ++i) { const Stop& stop = m_map.GetStop(i); Vec2 position = stop.point; const Texture* texture = NULL; switch (stop.structureType) { case StructureType_Bank: texture = &m_buildingBankTexture; break; case StructureType_Tower: texture = &m_buildingTowerTexture; break; case StructureType_Police: texture = &m_buildingPoliceTexture; break; } if (texture != NULL) { Render_DrawSprite(*texture, static_cast<int>(position.x) - texture->xSize / 2, static_cast<int>(position.y) - texture->ySize / 2); } } for (int i = 0; i < m_state.GetNumEntities(); ++i) { const Entity* entity = m_state.GetEntity(i); switch (entity->GetTypeId()) { case EntityTypeId_Building: { const BuildingEntity* building = static_cast<const BuildingEntity*>(entity); Vec2 position = m_map.GetStop(building->m_stop).point; if (building->m_raided) { Render_DrawSprite(m_buildingRaidedHouseTexture, static_cast<int>(position.x) - m_buildingRaidedHouseTexture.xSize / 2, static_cast<int>(position.y) - m_buildingHouseTexture.ySize / 2); } else { Render_DrawSprite(m_buildingHouseTexture, static_cast<int>(position.x) - m_buildingHouseTexture.xSize / 2, static_cast<int>(position.y) - m_buildingHouseTexture.ySize / 2); } } break; } } glDisable(GL_TEXTURE_2D); // Rails. glLineWidth(8.0f / m_mapScale); glBegin(GL_LINES); for (int i = 0; i < m_map.GetNumRails(); ++i) { const Rail& rail = m_map.GetRail(i); const Stop& stop1 = m_map.GetStop(rail.stop1); const Stop& stop2 = m_map.GetStop(rail.stop2); assert(rail.line >= 0); unsigned long color = m_map.GetLineColor(rail.line); // Draw the rails partially transparent to make the buldings more readable. color = (color & 0x00FFFFFF) | 0x90000000; glColor( color ); glVertex(stop1.point); glVertex(stop2.point); } glEnd(); // Stops. for (int i = 0; i < m_map.GetNumStops(); ++i) { const Stop& stop = m_map.GetStop(i); float inflate = 0.0f; if (i == m_hoverStop) { inflate = 5.0f; } if (stop.line == -1) { glColor( 0xFF000000 ); DrawCircle(stop.point, 8.0f + inflate); glColor( 0xFFFFFFFF ); DrawCircle(stop.point, 6.0f + inflate); } else { glColor( m_map.GetLineColor(stop.line) ); DrawCircle(stop.point, 8.0f + inflate); } } // Draw the legend of the grid. Font_BeginDrawing(m_font); glColor(0xFF7FD6F2); int fontHeight = Font_GetTextHeight(m_font); for (int x = 0; x < m_xMapSize / m_gridSpacing; ++x) { char buffer[32]; sprintf(buffer, "%d", x); int textWidth = Font_GetTextWidth(m_font, buffer); Font_DrawText(buffer, x * m_gridSpacing + m_gridSpacing / 2 - textWidth / 2, -outerBorder + 5); Font_DrawText(buffer, x * m_gridSpacing + m_gridSpacing / 2 - textWidth / 2, m_yMapSize + 5); } for (int y = 0; y < m_yMapSize / m_gridSpacing; ++y) { char buffer[32]; sprintf(buffer, "%c", 'A' + y); Font_DrawText(buffer, -outerBorder + 10, y * m_gridSpacing + m_gridSpacing / 2 - fontHeight / 2); Font_DrawText(buffer, m_xMapSize + 10, y * m_gridSpacing + m_gridSpacing / 2 - fontHeight / 2); } Font_EndDrawing(); glEnable(GL_TEXTURE_2D); // DL: How about blinking for showing selection? const float kBlinkDuration = 0.2f; const float kBlinkCycleDuration = 1.0f; float blinkT = fmodf(m_time, kBlinkCycleDuration); float blinkAlpha = 1.0f; if (blinkT < kBlinkDuration) { blinkAlpha = (cosf(2.0f*kPi*blinkT/kBlinkDuration)+1.0f)/2.0f; } unsigned long blinkColor = (static_cast<int>(blinkAlpha*255.0f) << 24) | 0xffffff; // Entities int index = 0; const AgentEntity* agent; while (m_state.GetNextEntityWithType(index, agent)) { if (m_selectedAgent == agent->GetId() && m_pathLength == 0) { glColor(blinkColor); } else { glColor(0xFFFFFFFF); } Vec2 position = GetAgentPosition(agent); if (agent->m_state == AgentEntity::State_Hacking) { Render_DrawSprite(m_agentHackingTexture, static_cast<int>(position.x) - m_agentHackingTexture.xSize / 2, static_cast<int>(position.y) - m_agentHackingTexture.ySize / 2); } else if (agent->m_state == AgentEntity::State_Stakeout) { Render_DrawSprite(m_agentStakeoutTexture, static_cast<int>(position.x) - m_agentStakeoutTexture.xSize / 2, static_cast<int>(position.y) - m_agentStakeoutTexture.ySize / 2); } else if (agent->m_intel != -1) { Render_DrawSprite(m_agentIntelTexture, static_cast<int>(position.x) - m_agentIntelTexture.xSize / 2, static_cast<int>(position.y) - m_agentIntelTexture.ySize / 2); } else { Render_DrawSprite(m_agentTexture, static_cast<int>(position.x) - m_agentTexture.xSize / 2, static_cast<int>(position.y) - m_agentTexture.ySize / 2); } } m_mapParticles.Draw(); // Draw the UI. glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluOrtho2D(0, m_xSize, m_ySize, 0); glDisable(GL_TEXTURE_2D); glColor(0xB0DBEDF7); glBegin(GL_QUADS); glVertex2i(0, m_ySize - yStatusBarSize); glVertex2i(m_xSize, m_ySize - yStatusBarSize); glVertex2i(m_xSize, m_ySize); glVertex2i(0, m_ySize); glEnd(); glColor(0xFF86DDEE); glLineWidth(1); glBegin(GL_LINE_LOOP); glVertex2i(0, m_ySize - yStatusBarSize); glVertex2i(m_xSize, m_ySize - yStatusBarSize); glVertex2i(m_xSize, m_ySize); glVertex2i(0, m_ySize); glEnd(); glEnable(GL_TEXTURE_2D); for (int i = 0; i < ButtonId_NumButtons; ++i) { if (m_button[i].enabled) { int xButton, yButton, xButtonSize, yButtonSize; GetButtonRect((ButtonId)i, xButton, yButton, xButtonSize, yButtonSize); if (m_button[i].toggled) { glColor(0xFFB0E8E1); } else { glColor(0xFFFFFFFF); } int buttonOffset = 0; int shadowOffset = 10; Render_DrawSprite( m_buttonShadowTexture, xButton + shadowOffset, yButton + shadowOffset ); if (m_activeButton == i && m_activeButtonDown) { buttonOffset = 5; } Render_DrawSprite( m_buttonTexture[i], xButton + buttonOffset, yButton + buttonOffset ); } } m_notificationLog.Draw(); const int maxPlayers = 32; const PlayerEntity* player[maxPlayers] = { NULL }; int numPlayers = m_state.GetEntitiesWithType(player, maxPlayers); // Show the players. const int playerBoxHeight = 150; glDisable(GL_TEXTURE_2D); glColor(0xB0DBEDF7); glLineWidth(1); glBegin(GL_QUADS); for (int i = 0; i < numPlayers; ++i) { int x = m_xSize - 300; int y = 10 + (playerBoxHeight + 15) * i; glVertex2i( x, y ); glVertex2i( m_xSize, y ); glVertex2i( m_xSize, y + playerBoxHeight ); glVertex2i( x, y + playerBoxHeight ); } glEnd(); glColor(0xFF86DDEE); glBegin(GL_LINE_LOOP); for (int i = 0; i < numPlayers; ++i) { int x = m_xSize - 300; int y = 10 + (playerBoxHeight + 15) * i; glVertex2i( x, y ); glVertex2i( m_xSize, y ); glVertex2i( m_xSize, y + playerBoxHeight ); glVertex2i( x, y + playerBoxHeight ); } glEnd(); glEnable(GL_TEXTURE_2D); glColor(0xFFFFFFFF); const int scaledAgentWidth = (m_agentTexture.xSize * fontHeight) / m_agentTexture.ySize; const int scaledHouseWidth = (m_buildingHouseTexture.xSize * fontHeight) / m_buildingHouseTexture.ySize; const int scaledIntelWidth = (m_intelTexture.xSize * fontHeight) / m_intelTexture.ySize; for (int i = 0; i < numPlayers; ++i) { Render_DrawSprite(m_playerPortraitTexture, m_xSize - 290, 20 + (playerBoxHeight + 15) * i); int offset = 0; if (player[i]->m_hackingBank) { Render_DrawSprite(m_playerBankHackedTexture, m_xSize - m_playerPortraitTexture.xSize - 60 + offset, 20 + (playerBoxHeight + 15) * i + 90 - m_playerBankHackedTexture.ySize); offset += m_playerBankHackedTexture.xSize; } if (player[i]->m_hackingTower) { Render_DrawSprite(m_playerCellHackedTexture, m_xSize - m_playerPortraitTexture.xSize - 60 + offset, 20 + (playerBoxHeight + 15) * i + 90 - m_playerCellHackedTexture.ySize); offset += m_playerCellHackedTexture.xSize; } if (player[i]->m_hackingPolice) { Render_DrawSprite(m_playerPoliceHackedTexture, m_xSize - m_playerPortraitTexture.xSize - 60 + offset, 20 + (playerBoxHeight + 15) * i + 90 - m_playerPoliceHackedTexture.ySize); offset += m_playerPoliceHackedTexture.xSize; } Render_DrawSprite(m_agentTexture, m_xSize - 280, playerBoxHeight - 25 +(playerBoxHeight + 15) * i, scaledAgentWidth, fontHeight); Render_DrawSprite(m_buildingHouseTexture, m_xSize - 180, playerBoxHeight - 25 +(playerBoxHeight + 15) * i, scaledHouseWidth, fontHeight); Render_DrawSprite(m_intelTexture, m_xSize - 80, playerBoxHeight - 25 +(playerBoxHeight + 15) * i, scaledIntelWidth, fontHeight); } Font_BeginDrawing(m_font); glColor(0xFF000000); for (int i = 0; i < numPlayers; ++i) { Font_DrawText(player[i]->m_name, m_xSize - m_playerPortraitTexture.xSize - 60, 20 + (playerBoxHeight + 15) * i); char buffer[32]; sprintf(buffer, "x%d", player[i]->m_numAgents); Font_DrawText(buffer, m_xSize - 280 + scaledAgentWidth + 5, playerBoxHeight - 25 + (playerBoxHeight + 15) * i); sprintf(buffer, "x%d", player[i]->m_numSafeHouses); Font_DrawText(buffer, m_xSize - 180 + scaledHouseWidth + 5, playerBoxHeight - 25 + (playerBoxHeight + 15) * i); sprintf(buffer, "x%d", player[i]->m_numIntels); Font_DrawText(buffer, m_xSize - 80 + scaledHouseWidth + 5, playerBoxHeight - 25 + (playerBoxHeight + 15) * i); } glColor(0xFF000000); Font_EndDrawing(); // Tool tip. const char* toolTip = NULL; if (m_hoverButton == ButtonId_Capture) { toolTip = "Search and capture any enemy agents\nat this location"; } else if (m_hoverButton == ButtonId_Stakeout) { toolTip = "Put the agent into stakeout mode\nso any enemy agents passing through\nthe stop will be detected"; } else if (m_hoverButton == ButtonId_Infiltrate) { toolTip = "Search and infiltrate enemy safe\nhouses at this location"; } else if (m_hoverButton == ButtonId_Hack) { toolTip = "Hack the building to gather\ninformation"; } else if (m_hoverButton == ButtonId_Intel) { toolTip = "Pickup/drop the intel"; } if (toolTip != NULL) { int xTipSize = 510; int yTipSize = 120; int xTip = 10; int yTip = m_ySize - yStatusBarSize - yTipSize - 10; glDisable(GL_TEXTURE_2D); glColor(0xB0DBEDF7); glLineWidth(1); glBegin(GL_QUADS); glVertex2i( xTip, yTip ); glVertex2i( xTip + xTipSize, yTip ); glVertex2i( xTip + xTipSize, yTip + yTipSize ); glVertex2i( xTip, yTip + yTipSize ); glEnd(); glColor(0xFF86DDEE); glBegin(GL_LINE_LOOP); glVertex2i( xTip, yTip ); glVertex2i( xTip + xTipSize, yTip ); glVertex2i( xTip + xTipSize, yTip + yTipSize ); glVertex2i( xTip, yTip + yTipSize ); glEnd(); glColor(0xFF000000); Font_BeginDrawing(m_font); Font_DrawText(toolTip, xTip + 10, yTip + 10); Font_EndDrawing(); } glEnable(GL_TEXTURE_2D); glColor(0xFFFFFFFF); for (int i = 0; i < numPlayers; ++i) { if (player[i]->m_eliminated) { Render_DrawSprite(m_playerEliminatedTexture, m_xSize - 250, 20 + (playerBoxHeight + 15) * i); } } m_screenParticles.Draw(); if (m_gameState == GameState_GameOver) { const int windowWidth = 200; const int widonwHeight = 100; glDisable(GL_TEXTURE_2D); glColor(0xB0DBEDF7); glLineWidth(1); glBegin(GL_QUADS); glVertex2i( (m_xSize - windowWidth) / 2, (m_ySize - widonwHeight) / 2 ); glVertex2i( (m_xSize + windowWidth) / 2, (m_ySize - widonwHeight) / 2 ); glVertex2i( (m_xSize + windowWidth) / 2, (m_ySize + widonwHeight) / 2 ); glVertex2i( (m_xSize - windowWidth) / 2, (m_ySize + widonwHeight) / 2 ); glEnd(); glColor(0xFF86DDEE); glBegin(GL_LINE_LOOP); glVertex2i( (m_xSize - windowWidth) / 2, (m_ySize - widonwHeight) / 2 ); glVertex2i( (m_xSize + windowWidth) / 2, (m_ySize - widonwHeight) / 2 ); glVertex2i( (m_xSize + windowWidth) / 2, (m_ySize + widonwHeight) / 2 ); glVertex2i( (m_xSize - windowWidth) / 2, (m_ySize + widonwHeight) / 2 ); glEnd(); glEnable(GL_TEXTURE_2D); Font_BeginDrawing(m_font); const char* text = m_isWinner ? "You WIN!" : "GAME OVER"; glColor(0xff000000); int textWidth = Font_GetTextWidth(m_font, text); Font_DrawText(text, (m_xSize - textWidth)/2, (m_ySize - fontHeight)/2); Font_EndDrawing(); } }