#include "supertux/textscroller.hpp"
#include "audio/sound_manager.hpp"
-#include "control/joystickkeyboardcontroller.hpp"
+#include "control/input_manager.hpp"
#include "lisp/parser.hpp"
#include "supertux/fadeout.hpp"
#include "supertux/info_box_line.hpp"
#include "supertux/globals.hpp"
-#include "supertux/mainloop.hpp"
+#include "supertux/screen_manager.hpp"
#include "supertux/resources.hpp"
#include "util/reader.hpp"
#include "video/drawing_context.hpp"
+#include <sstream>
+#include <stdexcept>
+
static const float DEFAULT_SPEED = 20;
static const float LEFT_BORDER = 50;
static const float SCROLL = 60;
lines = InfoBoxLine::split(text, SCREEN_WIDTH - 2*LEFT_BORDER);
// load background image
- background.reset(new Surface("images/background/" + background_file));
+ background = Surface::create("images/background/" + background_file);
scroll = 0;
fading = false;
TextScroller::~TextScroller()
{
- for(std::vector<InfoBoxLine*>::iterator i = lines.begin(); i != lines.end(); i++) delete *i;
+ for(std::vector<InfoBoxLine*>::iterator i = lines.begin(); i != lines.end(); ++i) delete *i;
}
void
TextScroller::setup()
{
- sound_manager->play_music(music);
+ SoundManager::current()->play_music(music);
}
void
TextScroller::update(float elapsed_time)
{
- if(g_main_controller->hold(Controller::UP)) {
+ Controller* controller = InputManager::current()->get_controller();
+ if(controller->hold(Controller::UP)) {
speed = -defaultspeed*5;
- } else if(g_main_controller->hold(Controller::DOWN)) {
+ } else if(controller->hold(Controller::DOWN)) {
speed = defaultspeed*5;
} else {
speed = defaultspeed;
}
- if(g_main_controller->pressed(Controller::JUMP)
- || g_main_controller->pressed(Controller::ACTION)
- || g_main_controller->pressed(Controller::MENU_SELECT))
+ if((controller->pressed(Controller::JUMP)
+ || controller->pressed(Controller::ACTION)
+ || controller->pressed(Controller::MENU_SELECT)
+ )&& !(controller->pressed(Controller::UP))) // prevent skipping if jump with up is enabled
scroll += SCROLL;
- if(g_main_controller->pressed(Controller::PAUSE_MENU)) {
- g_main_loop->exit_screen(new FadeOut(0.5));
+ if(controller->pressed(Controller::START) ||
+ controller->pressed(Controller::ESCAPE)) {
+ ScreenManager::current()->pop_screen(std::unique_ptr<ScreenFade>(new FadeOut(0.5)));
}
scroll += speed * elapsed_time;
{
context.draw_filled_rect(Vector(0, 0), Vector(SCREEN_WIDTH, SCREEN_HEIGHT),
Color(0.6f, 0.7f, 0.8f, 0.5f), 0);
- context.draw_surface(background.get(), Vector(SCREEN_WIDTH/2 - background->get_width()/2 , SCREEN_HEIGHT/2 - background->get_height()/2), 0);
+ context.draw_surface_part(background, Rectf(0, 0, background->get_width(), background->get_height()),
+ Rectf(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT), 0);
+
float y = SCREEN_HEIGHT - scroll;
for(size_t i = 0; i < lines.size(); i++) {
if (y + lines[i]->get_height() >= 0 && SCREEN_HEIGHT - y >= 0) {
- lines[i]->draw(context, Rect(LEFT_BORDER, y, SCREEN_WIDTH - 2*LEFT_BORDER, y), LAYER_GUI);
+ lines[i]->draw(context, Rectf(LEFT_BORDER, y, SCREEN_WIDTH - 2*LEFT_BORDER, y), LAYER_GUI);
}
y += lines[i]->get_height();
if(y < 0 && !fading ) {
fading = true;
- g_main_loop->exit_screen(new FadeOut(0.5));
+ ScreenManager::current()->pop_screen(std::unique_ptr<ScreenFade>(new FadeOut(0.5)));
}
}