- le_current_level->cleanup();
- if(le_current_level->load(le_level_subset->name.c_str(), levelnb) != 0)
- {
- le_current_level->load(le_level_subset->name.c_str(), le_level);
- }
- else
- {
- le_level = levelnb;
- }
-
- le_set_defaults();
-
- le_current_level->load_gfx();
-
- le_world.activate_bad_guys();
-}
-
-void le_quit(void)
-{
- /*if(level_changed == true)
- if(askforsaving() == CANCEL)
- return;*/ //FIXME
-
- SDL_EnableKeyRepeat(0, 0); // disables key repeating
-
- delete le_selection;
- delete leveleditor_menu;
- delete subset_load_menu;
- delete subset_new_menu;
- delete subset_settings_menu;
- delete level_settings_menu;
- delete select_tilegroup_menu;
- delete select_objects_menu;
- delete le_save_level_bt;
- delete le_exit_bt;
- delete le_test_level_bt;
- delete le_next_level_bt;
- delete le_previous_level_bt;
- delete le_move_right_bt;
- delete le_move_left_bt;
- delete le_rubber_bt;
- delete le_select_mode_one_bt;
- delete le_select_mode_two_bt;
- delete le_settings_bt;
- delete le_tilegroup_bt;
- delete le_objects_bt;
- delete le_tilemap_panel;
-
- delete le_current_level;
- le_current_level = 0;
- delete le_level_subset;
- le_level_subset = 0;
-
- for(ButtonPanelMap::iterator i = tilegroups_map.begin();
- i != tilegroups_map.end(); ++i)
- {
- delete i->second;
- }
- for(ButtonPanelMap::iterator i = objects_map.begin();
- i != objects_map.end(); ++i)
- {
- delete i->second;
- }
-}
-
-void le_drawminimap()
-{
- if(le_current_level == NULL)
- return;
-
- int mini_tile_width;
- if(screen->w - 64 > le_current_level->width * 4)
- mini_tile_width = 4;
- else if(screen->w - 64 > le_current_level->width * 2)
- mini_tile_width = 2;
- else
- mini_tile_width = 1;
- int left_offset = (screen->w - 64 - le_current_level->width*mini_tile_width) / 2;
-
- for (int y = 0; y < 15; ++y)
- for (int x = 0; x < le_current_level->width; ++x)
- {
-
- Tile::draw_stretched(left_offset + mini_tile_width*x, y * 4, mini_tile_width , 4, le_current_level->bg_tiles[y][x]);
-
- Tile::draw_stretched(left_offset + mini_tile_width*x, y * 4, mini_tile_width , 4, le_current_level->ia_tiles[y][x]);
-
- Tile::draw_stretched(left_offset + mini_tile_width*x, y * 4, mini_tile_width , 4, le_current_level->fg_tiles[y][x]);
-
- }
-
- fillrect(left_offset, 0, le_current_level->width*mini_tile_width, 15*4, 200, 200, 200, 128);
-
- fillrect(left_offset + (pos_x/32)*mini_tile_width, 0, 19*mini_tile_width, 2, 200, 200, 200, 200);
- fillrect(left_offset + (pos_x/32)*mini_tile_width, 0, 2, 15*4, 200, 200, 200, 200);
- fillrect(left_offset + (pos_x/32)*mini_tile_width + 19*mini_tile_width - 2, 0, 2, 15*4, 200, 200, 200, 200);
- fillrect(left_offset + (pos_x/32)*mini_tile_width, 15*4-2, 19*mini_tile_width, 2, 200, 200, 200, 200);
-
-}
-
-void le_drawinterface()
-{
- int x,y;
- char str[80];
-
- if(le_current_level != NULL)
- {
- /* draw a grid (if selected) */
- if(le_show_grid)
- {
- for(x = 0; x < 19; x++)
- fillrect(x*32 - ((int)pos_x % 32), 0, 1, screen->h, 225, 225, 225,255);
- for(y = 0; y < 15; y++)
- fillrect(0, y*32, screen->w - 32, 1, 225, 225, 225,255);
- }
- }
-
- if(show_minimap && use_gl) // use_gl because the minimap isn't shown correctly in software mode. Any idea? FIXME Possible reasons: SDL_SoftStretch is a hack itsself || an alpha blitting issue SDL can't handle in software mode
- le_drawminimap();
-
- if(le_selection_mode == CURSOR)
- if(le_current.IsTile())
- le_selection->draw( cursor_x - pos_x, cursor_y);
- else
- le_selection->draw( cursor_x, cursor_y);
- else if(le_selection_mode == SQUARE)
- {
- int w, h;
- le_highlight_selection();
- /* draw current selection */
- w = selection.x2 - selection.x1;
- h = selection.y2 - selection.y1;
- fillrect(selection.x1 - pos_x, selection.y1, w, SELECT_W, SELECT_CLR);
- fillrect(selection.x1 - pos_x + w, selection.y1, SELECT_W, h, SELECT_CLR);
- fillrect(selection.x1 - pos_x, selection.y1 + h, w, SELECT_W, SELECT_CLR);
- fillrect(selection.x1 - pos_x, selection.y1, SELECT_W, h, SELECT_CLR);
- }
-
-
- /* draw button bar */
- fillrect(screen->w - 64, 0, 64, screen->h, 50, 50, 50,255);
-
- if(le_current.IsTile())
- {
- Tile::draw(19 * 32, 14 * 32, le_current.tile);
- if(TileManager::instance()->get(le_current.tile)->editor_images.size() > 0)
- TileManager::instance()->get(le_current.tile)->editor_images[0]->draw( 19 * 32, 14 * 32);
- }
- if(le_current.IsObject())
- {
- le_current.obj->draw_on_screen(19 * 32, 14 * 32);
- le_current.obj->draw_on_screen(cursor_x,cursor_y);
- }
-
- if(le_current_level != NULL)
- {
- le_save_level_bt->draw();
- le_exit_bt->draw();
- le_test_level_bt->draw();
- le_next_level_bt->draw();
- le_previous_level_bt->draw();
- le_rubber_bt->draw();
- if(le_selection_mode == SQUARE)
- le_select_mode_one_bt->draw();
- else if(le_selection_mode == CURSOR)
- le_select_mode_two_bt->draw();
- le_settings_bt->draw();
- le_move_right_bt->draw();
- le_move_left_bt->draw();
- le_tilegroup_bt->draw();
- le_objects_bt->draw();
- if(!cur_tilegroup.empty())
- tilegroups_map[cur_tilegroup]->draw();
- else if(!cur_objects.empty())
- {
- objects_map[cur_objects]->draw();
- }
-
- le_tilemap_panel->draw();
-
- sprintf(str, "%d/%d", le_level,le_level_subset->levels);
- white_text->drawf(str, -10, 16, A_RIGHT, A_TOP, 0);
-
- white_small_text->draw("F1 for Help", 10, 430, 1);
- }
- else
- {
- if(!Menu::current())
- white_small_text->draw("No Level Subset loaded - Press ESC and choose one in the menu", 10, 430, 1);
- else
- white_small_text->draw("No Level Subset loaded", 10, 430, 1);
- }
-
-}
-
-void le_drawlevel()
-{
- unsigned int y,x,i,s;
- Uint8 a;
-
- /* Draw the real background */
- if(le_current_level->bkgd_image[0] != '\0')
- {
- s = (int)((float)pos_x * ((float)le_current_level->bkgd_speed/60.)) % screen->w;
- le_current_level->img_bkgd->draw_part(s,0,0,0,
- le_current_level->img_bkgd->w - s - 32, le_current_level->img_bkgd->h);
- le_current_level->img_bkgd->draw_part(0,0,screen->w - s - 32 ,0,s,
- le_current_level->img_bkgd->h);
- }
- else
- {
- drawgradient(le_current_level->bkgd_top, le_current_level->bkgd_bottom);
- }
-
- if(le_current.IsTile())
- {
- Tile::draw(cursor_x-pos_x, cursor_y,le_current.tile,128);
- if(!TileManager::instance()->get(le_current.tile)->images.empty())
- fillrect(cursor_x-pos_x,cursor_y,TileManager::instance()->get(le_current.tile)->images[0]->w,TileManager::instance()->get(le_current.tile)->images[0]->h,50,50,50,50);
- }
- if(le_current.IsObject())
- {
- le_current.obj->move_to(cursor_x, cursor_y);
- }
-
- /* clearscreen(current_level.bkgd_red, current_level.bkgd_green, current_level.bkgd_blue); */
-
- for (y = 0; y < 15; ++y)
- for (x = 0; x < 20; ++x)
- {
-
- if(active_tm == TM_BG)
- a = 255;
- else
- a = 128;
-
- Tile::draw(32*x - fmodf(pos_x, 32), y * 32, le_current_level->bg_tiles[y][x + (int)(pos_x / 32)],a);
-
- if(active_tm == TM_IA)
- a = 255;
- else
- a = 128;
-
- Tile::draw(32*x - fmodf(pos_x, 32), y * 32, le_current_level->ia_tiles[y][x + (int)(pos_x / 32)],a);
-
- if(active_tm == TM_FG)
- a = 255;
- else
- a = 128;
-
- Tile::draw(32*x - fmodf(pos_x, 32), y * 32, le_current_level->fg_tiles[y][x + (int)(pos_x / 32)],a);
-
- /* draw whats inside stuff when cursor is selecting those */
- /* (draw them all the time - is this the right behaviour?) */
- if(TileManager::instance()->get(le_current_level->ia_tiles[y][x + (int)(pos_x / 32)])->editor_images.size() > 0)
- TileManager::instance()->get(le_current_level->ia_tiles[y][x + (int)(pos_x / 32)])->editor_images[0]->draw( x * 32 - ((int)pos_x % 32), y*32);
-
- }
-
- /* Draw the Bad guys: */
- for (i = 0; i < le_world.bad_guys.size(); ++i)
- {
- /* to support frames: img_bsod_left[(frame / 5) % 4] */
-
- scroll_x = pos_x;
- le_world.bad_guys[i].draw();
- }
-
-
- /* Draw the player: */
- /* for now, the position is fixed at (100, 240) */
- largetux.walk_right->draw( 100 - pos_x, 240);
-}
-
-void le_checkevents()
-{
- SDLKey key;
- SDLMod keymod;
- Button* pbutton;
- int x,y;
-
- keymod = SDL_GetModState();
-
- while(SDL_PollEvent(&event))
- {
- if (Menu::current())
- {
- Menu::current()->event(event);
- }
- else
- {
- mouse_cursor->set_state(MC_NORMAL);
-
- /* testing SDL_KEYDOWN, SDL_KEYUP and SDL_QUIT events*/
- if(event.type == SDL_KEYDOWN
- || ((event.type == SDL_MOUSEBUTTONDOWN || SDL_MOUSEMOTION)
- && (event.motion.x > 0
- && event.motion.x < screen->w - 64 &&
- event.motion.y > 0 && event.motion.y < screen->h)))
- {
- switch(event.type)
- {
- case SDL_KEYDOWN: // key pressed
- key = event.key.keysym.sym;
- switch(key)
- {
- case SDLK_ESCAPE:
- Menu::set_current(leveleditor_menu);
- case SDLK_LEFT:
- if(fire == DOWN)
- cursor_x -= KEY_CURSOR_SPEED;
- else
- cursor_x -= KEY_CURSOR_FASTSPEED;
-
- if(cursor_x < pos_x + MOUSE_LEFT_MARGIN)
- pos_x = cursor_x - MOUSE_LEFT_MARGIN;
-
- break;
- case SDLK_RIGHT:
- if(fire == DOWN)
- cursor_x += KEY_CURSOR_SPEED;
- else
- cursor_x += KEY_CURSOR_FASTSPEED;
-
- if(cursor_x > pos_x + MOUSE_RIGHT_MARGIN-32)
- pos_x = cursor_x - MOUSE_RIGHT_MARGIN+32;
-
- break;
- case SDLK_UP:
- if(fire == DOWN)
- cursor_y -= KEY_CURSOR_SPEED;
- else
- cursor_y -= KEY_CURSOR_FASTSPEED;
-
- if(cursor_y < 0)
- cursor_y = 0;
- break;
- case SDLK_DOWN:
- if(fire == DOWN)
- cursor_y += KEY_CURSOR_SPEED;
- else
- cursor_y += KEY_CURSOR_FASTSPEED;
-
- if(cursor_y > screen->h-32)
- cursor_y = screen->h-32;
- break;
- case SDLK_LCTRL:
- fire =UP;
- break;
- case SDLK_F1:
- le_showhelp();
- break;
- case SDLK_HOME:
- cursor_x = 0;
- pos_x = cursor_x;
- break;
- case SDLK_END:
- cursor_x = (le_current_level->width * 32) - 32;
- pos_x = cursor_x;
- break;
- case SDLK_F9:
- le_show_grid = !le_show_grid;
- break;
- default:
- break;
- }
- break;
- case SDL_KEYUP: /* key released */
- switch(event.key.keysym.sym)
- {
- case SDLK_LCTRL:
- fire = DOWN;
- break;
- default:
- break;
- }
- break;
- case SDL_MOUSEBUTTONDOWN:
- if(event.button.button == SDL_BUTTON_LEFT)
- {
- le_mouse_pressed[LEFT] = true;
-
- selection.x1 = event.motion.x + pos_x;
- selection.y1 = event.motion.y;
- selection.x2 = event.motion.x + pos_x;
- selection.y2 = event.motion.y;
- }
- else if(event.button.button == SDL_BUTTON_RIGHT)
- {
- le_mouse_pressed[RIGHT] = true;
- }
- break;
- case SDL_MOUSEBUTTONUP:
- if(event.button.button == SDL_BUTTON_LEFT)
- {
- le_mouse_pressed[LEFT] = false;
- le_mouse_clicked[LEFT] = true;
- }
- else if(event.button.button == SDL_BUTTON_RIGHT)
- {
- le_mouse_pressed[RIGHT] = false;
- le_mouse_clicked[RIGHT] = true;
- }
- break;
- case SDL_MOUSEMOTION:
-
- if(!Menu::current())
- {
- x = event.motion.x;
- y = event.motion.y;
-
- if(le_current.IsTile())
- {
- cursor_x = ((int)(pos_x + x) / 32) * 32;
- cursor_y = ((int) y / 32) * 32;
- }
- else
- {
- cursor_x = x;
- cursor_y = y;
- }
-
- if(le_mouse_pressed[LEFT])
- {
- selection.x2 = x + pos_x;
- selection.y2 = y;
- }
-
- if(le_mouse_pressed[RIGHT])
- {
- pos_x += -1 * event.motion.xrel;
- }
- }
- break;
- case SDL_QUIT: // window closed
- done = 1;
- break;
- default:
- break;
- }
- }
- }