예제 #1
0
void Scene::SendInput(IEvent &e)
{
	// this happens if mouse wasn't set by the sender.
	if(e.Mouse.x < -200000)
		e.Mouse = MouseInfo();

	if(!vpScreens.empty())
		vpScreens.back()->Input(e);
}
예제 #2
0
void TrackSelectionState::Update()
{
   m_continue_button.Update(MouseInfo(Mouse()));
   m_back_button.Update(MouseInfo(Mouse()));

   if (IsKeyPressed(KeyEscape) || m_back_button.hit)
   {
      if (m_state.midi_out) m_state.midi_out->Reset();
      m_state.track_properties = BuildTrackProperties();
      ChangeState(new TitleState(m_state));
      return;
   }

   if (IsKeyPressed(KeyEnter) || m_continue_button.hit)
   {

      if (m_state.midi_out) m_state.midi_out->Reset();
      m_state.track_properties = BuildTrackProperties();
      ChangeState(new PlayingState(m_state));

      return;
   }

   if (IsKeyPressed(KeyDown) || IsKeyPressed(KeyRight))
   {
      m_current_page++;
      if (m_current_page == m_page_count) m_current_page = 0;
   }

   if (IsKeyPressed(KeyUp) || IsKeyPressed(KeyLeft))
   {
      m_current_page--;
      if (m_current_page < 0) m_current_page += m_page_count;
   }

   m_tooltip = L"";

   if (m_back_button.hovering) m_tooltip = L"Click to return to the title screen.";
   if (m_continue_button.hovering) m_tooltip = L"Click to begin playing with these settings.";

   // Our delta milliseconds on the first frame after we seek down to the
   // first note is extra long because the seek takes a while.  By skipping
   // the "Play" that update, we don't have an artificially fast-forwarded
   // start.
   if (!m_first_update_after_seek)
   {
      PlayTrackPreview(static_cast<microseconds_t>(GetDeltaMilliseconds()) * 1000);
   }
   m_first_update_after_seek = false;

   // Do hit testing on each tile button on this page
   size_t start = m_current_page * m_tiles_per_page;
   size_t end = std::min( static_cast<size_t>((m_current_page+1) * m_tiles_per_page), m_track_tiles.size() );
   for (size_t i = start; i < end; ++i)
   {
      TrackTile &t = m_track_tiles[i];

      MouseInfo mouse = MouseInfo(Mouse());
      mouse.x -= t.GetX();
      mouse.y -= t.GetY();

      t.Update(mouse);

      if (t.ButtonLeft().hovering || t.ButtonRight().hovering)
      {
         switch (t.GetMode())
         {
         case Track::ModeNotPlayed: m_tooltip = L"Track won't be played or shown during the game."; break;
         case Track::ModePlayedAutomatically: m_tooltip = L"Track will be played automatically by the game."; break;
         case Track::ModePlayedButHidden: m_tooltip = L"Track will be played automatically by the game, but also hidden from view."; break;
         case Track::ModeYouPlay: m_tooltip = L"'You Play' means you want to play this track yourself."; break;
         }
      }

      if (t.ButtonPreview().hovering)
      {
         if (t.IsPreviewOn()) m_tooltip = L"Turn track preview off.";
         else m_tooltip = L"Preview how this track sounds.";
      }

      if (t.ButtonColor().hovering) m_tooltip = L"Pick a color for this track's notes.";

      if (t.HitPreviewButton())
      {
         if (m_state.midi_out) m_state.midi_out->Reset();

         if (t.IsPreviewOn())
         {
            // Turn off any other preview modes
            for (size_t j = 0; j < m_track_tiles.size(); ++j)
            {
               if (i == j) continue;
               m_track_tiles[j].TurnOffPreview();
            }

            const microseconds_t PreviewLeadIn  = 25000;
            const microseconds_t PreviewLeadOut = 25000;

            m_preview_on = true;
            m_preview_track_id = t.GetTrackId();
            m_state.midi->Reset(PreviewLeadIn, PreviewLeadOut);
            PlayTrackPreview(0);

            // Find the first note in this track so we can skip right to the good part.
            microseconds_t additional_time = -PreviewLeadIn;
            const MidiTrack &track = m_state.midi->Tracks()[m_preview_track_id];
            for (size_t i = 0; i < track.Events().size(); ++i)
            {
               const MidiEvent &ev = track.Events()[i];
               if (ev.Type() == MidiEventType_NoteOn && ev.NoteVelocity() > 0)
               {
                  additional_time += track.EventUsecs()[i] - m_state.midi->GetDeadAirStartOffsetMicroseconds() - 1;
                  break;
               }
            }

            PlayTrackPreview(additional_time);
            m_first_update_after_seek = true;
         }
         else
         {
            m_preview_on = false;
         }
      }
   }

   


}