Example #1
0
    NextLevelDialog(GameControl* game)
        : Dialog("BRAVO!!!",Event::NOP,Event::MENU),
          m_game(game)
    {
        rightControl()->text("<--");
        char buf[32];
        const GameStats& stats = m_game->stats();
        int time = (stats.endTime - stats.startTime)/1000;
        int h = time/60/60;
        int m = time/60 - h*60;
        int s = time - m*60;

        Box *vbox = new VBox();
        vbox->add(new Spacer(),10,1);
        if (h > 0) {
            sprintf(buf,"time: %dh %dm %ds",m,h,s);
        } else if (m > 0) {
            int m = time/60/1000;
            sprintf(buf,"time: %dm %ds",m,s);
        } else {
            sprintf(buf,"time: %ds",s);
        }
        vbox->add(new Label(buf),20,0);
        sprintf(buf,"%d stroke%s",stats.strokeCount,stats.strokeCount==1?"":"s");
        vbox->add(new Label(buf),20,0);
        if (stats.pausedStrokes) {
            sprintf(buf,"     (%d while paused)",stats.pausedStrokes);
            vbox->add(new Label(buf),20,0);
        }
        sprintf(buf,"%d undo%s",stats.undoCount,stats.undoCount==1?"":"s");
        vbox->add(new Label(buf),20,0);
        vbox->add(new Spacer(),10,1);

        Box *hbox2 = new HBox();
        hbox2->add(new Spacer(),20,0);
        hbox2->add(new Button("review",Event(Event::REPLAY,game->m_level)),BUTTON_WIDTH,0);
        hbox2->add(new Spacer(),1,1);
        hbox2->add(new Button("again",Event::RESET),BUTTON_WIDTH,0);
        hbox2->add(new Spacer(),1,1);
        hbox2->add(new Button("next",Event::NEXT),BUTTON_WIDTH,0);
        hbox2->add(new Spacer(),20,0);
        vbox->add(hbox2,BUTTON_HEIGHT,0);

        vbox->add(new Spacer(),10,0);
        content()->add(vbox,0,0);
        m_targetPos = Vec2( 150, 70);
        sizeTo(Vec2(500,240));
    }
  bool onEvent( Event& ev )
  {
    switch (ev.code) {
    case Event::MENU:
      switch(ev.x) {
      case 1:
	content()->empty();	
	content()->add(new LevelSelector(m_game, m_chosenLevel));
	rightControl()->text("<--");
	rightControl()->event(Event::CANCEL);
	break;
      case 2:
	close();
	break;
      case 3: 
	content()->empty();
	content()->add(new HelpPage());
	rightControl()->text("<--");
	rightControl()->event(Event::CANCEL);
	break;
      }
      return true;
    case Event::SELECT:
      fprintf(stderr,"select level %d\n",ev.x);
      m_chosenLevel = ev.x;
      content()->empty();
      content()->add(new LevelLauncher(m_chosenLevel,NULL));
      rightControl()->text("<--");
      rightControl()->event(Event(Event::MENU,1));
      return true;
    case Event::CANCEL:
      content()->empty();
      content()->add(new FrontPage());
      rightControl()->text("X");
      rightControl()->event(Event::QUIT);
      return true;
    case Event::PLAY:
    case Event::REPLAY:
      close();
      break;
    default:
      break;
    }
    return Dialog::onEvent(ev);
  }