bool CScreenButtons::ContextMenu(int iButton, const ScreenPoint & sp, HWND hwnd) { CMenu mmMenu; mmMenu.Init(); Data::Actions::iterator it; Data::Actions::iterator begin = m_data->actions.begin(); Data::Actions::iterator end = m_data->actions.end(); for (it = begin; it != end; ++it) mmMenu.CreateItem(it->label.c_str(), it->command); DWORD dwRes = mmMenu.Popup(sp.x, sp.y, hwnd); it = std::find(begin, end, dwRes); if (it != end) { m_data->buttons[iButton] = *it; Save(); return true; } return false; }
int main(int argc, char** argv) { #ifdef _DEBUG // Visual Studio CRT memory leak detection // very useful, makes me sleep better :) _CrtSetDbgFlag( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF ); #endif fprintf(stderr, "%s version %i.%i\n", LYNX_TITLE, LYNX_MAJOR, LYNX_MINOR); srand((unsigned int)time(NULL)); float dt; uint32_t time, oldtime; uint32_t fpstimer, fpscounter=0; // Load config file if(!CLynx::cfg.AddFile( "game.cfg" )) fprintf(stderr, "Failed to open config file.\n"); // bad, but not critical // Game Modules // Startup SDL OpenGL window if(!initSDLvideo(SCREEN_WIDTH, SCREEN_HEIGHT, BPP, FULLSCREEN)) { assert(0); return -1; } // init menu menu_engine_callback_t callback; memset(&callback, 0, sizeof(callback)); callback.menu_func_host = menu_func_host; callback.menu_func_join = menu_func_join; callback.menu_func_quit = menu_func_quit; if(!g_menu.Init(SCREEN_WIDTH, SCREEN_HEIGHT, callback)) { fprintf(stderr, "Failed to load menu\n"); return -1; } // Draw the menu once, before we continue g_menu.DisplayLoadingScreen(); g_menu.DrawDefaultBackground(); g_menu.Update(0.0f, 0); SDL_GL_SwapBuffers(); // Ok, now we have something on the screen, now we can load the rest SDL_WM_SetCaption(WINDOW_TITLE, NULL); SDL_ShowCursor(SDL_DISABLE); SDL_WM_GrabInput(SDL_GRAB_ON); // we want key repeat. CLynxSys::GetKeyState remembers // if a key has been pressed by the user or by auto repeat. if(SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL) != 0) fprintf(stderr, "Failed to set key repeat\n"); // Init sound mixer initSDLMixer(); // we don't care, if it won't init. No sound for you. // Now we are finished with loading, activate the main menu g_menu.DisplayMain(); g_run = 1; oldtime = fpstimer = CLynxSys::GetTicks(); while(g_run) { time = CLynxSys::GetTicks(); dt = 0.001f * (float)(time-oldtime); if(dt > 0.150f) { fprintf(stderr, "Warning: Frame time too large: %f\n", dt); dt = 0.150f; } oldtime = time; fpscounter++; if(time - fpstimer > 1000.0f) { char title[128]; sprintf(title, "Lynx (FPS: %i)", (int)fpscounter); SDL_WM_SetCaption(title, NULL); fpscounter = 0; fpstimer = time; } // Update Server if(g_worldsv) { g_worldsv->Update(dt, time); g_svgame->Update(dt, time); g_server->Update(dt, time); } // Update Client if(g_worldcl) { g_mixer->Update(dt, time); if(g_client->IsInGame()) g_worldcl->Update(dt, time); g_client->Update(dt, time); g_renderer->Update(dt, time); if(!g_client->IsRunning()) { fprintf(stderr, "Disconnected\n"); g_menu.DisplayError("Disconnected from server"); g_menu.MakeVisible(); shutdown(&g_worldsv, &g_server, &g_svgame, &g_worldcl, &g_renderer, &g_mixer, &g_clgame, &g_client); } } else { // We have no gameplay background, let's clear the // menu screen. Otherwise the game itself is our // background - neat! g_menu.DrawDefaultBackground(); // but since we are not in a game, we don't need > 100 fps SDL_Delay(30); } // Update Menu g_menu.Update(dt, time); // Draw GL buffer SDL_GL_SwapBuffers(); // Limit to 100 fps // so my notebook fan is quiet :-) const float dtrest = 1.0f/100.0f - dt; if(dtrest > 0.0f) SDL_Delay((uint32_t)(dtrest * 1000.0f)); // Handle system events handleSDLevents(); } shutdownSDLMixer(); shutdown(&g_worldsv, &g_server, &g_svgame, &g_worldcl, &g_renderer, &g_mixer, &g_clgame, &g_client); return 0; }