Beispiel #1
0
void GSTitle::Draw2d()
{
  GSGui::Draw2d();

#ifdef SHOW_ENV_INFO
  // Draw env info, etc.
  static GuiText t;

  t.SetSize(Vec2f(1.0f, 0.1f));
  t.SetJust(GuiText::AMJU_JUST_LEFT);
  t.SetDrawBg(true);

  t.SetLocalPos(Vec2f(-1.0f, 0.8f));
  std::string s = "SaveDir: " + GetAppName();
  t.SetText(s);
  t.Draw();

  t.SetLocalPos(Vec2f(-1.0f, 0.7f));
  s = "Server: " + GetServer();
  t.SetText(s);
  t.Draw();

  t.SetLocalPos(Vec2f(-1.0f, 0.6f));
  s = "Env: " + GetEnv();
  t.SetText(s);
  t.Draw();
#endif
}
Beispiel #2
0
void Hud::UpdateScores()
{
  // Names of gui elements in hud gui text file
  const char* GUI_NAME[2][2] = 
  {
    { "p1-score-text", "p1-lives-text" },
    { "p2-score-text", "p2-lives-text" }
  };

  for (int i = 0; i < 2; i++)
  {
    PlayerNum pn = (PlayerNum)i;
    int score = TheScores::Instance()->GetScore(pn);
    GuiText* t = (GuiText*)m_gui->GetElementByName(GUI_NAME[i][0]);
    Assert(t);
    t->SetText(ToString(score));
    int lives = TheScores::Instance()->GetLives(pn); 
    t = (GuiText*)m_gui->GetElementByName(GUI_NAME[i][1]);
    Assert(t);
    t->SetText(ToString(lives));
  }

  int hiScore = TheScores::Instance()->GetHiScore();
  GuiText* t = (GuiText*)m_gui->GetElementByName("hi-score-text");
  Assert(t);
  t->SetText(ToString(hiScore));
  t = (GuiText*)m_gui->GetElementByName("hi-name-text");
  Assert(t);
  t->SetText(TheScores::Instance()->GetHiScoreName()); 
}
void BroadcastConsole::OnMsgRecv(const std::string& str)
{
  // Discard if same as last msg
  if (!m_texts.empty())
  {
    if (m_texts[0]->GetText() == str)
    {
      std::cout << "Discarding duplicate msg\n";
      return;
    }
  }

  GuiText* text = new GuiText;
  text->SetIsMulti(true);
  text->SetTextSize(1.0f); // TODO CONFIG
  text->SetSize(Vec2f(2.0f, 0.1f)); // assume single line
  text->SetText(str);
  text->SizeToText();
  text->SetFgCol(Colour(1, 1, 0, 1));

  m_texts.push_front(text);

  static const unsigned int NUM_LINES = ROConfig()->GetInt("chat-max-lines", 10);
  if (m_texts.size() > NUM_LINES) 
  {
    m_texts.pop_back();
  }
  ReposText();
}
void TrailCircle::Draw()
{
    static GuiImage* circleImg = 0;
    static GuiText text;

    if (!circleImg)
    {
        circleImg = new GuiImage;
        Texture* tex = (Texture*)TheResourceManager::Instance()->GetRes("circ1.png");
        tex->SetFilter(AmjuGL::AMJU_TEXTURE_NICE);
        circleImg->SetTexture(tex);
        float aspect = (float)Screen::X() / (float)Screen::Y();
        circleImg->SetSize(Vec2f(CIRCLE_SIZE, CIRCLE_SIZE * aspect));

        text.SetSize(Vec2f(0.1f, 0.1f));
    }

    const Colour BLACK(0, 0, 0, 1);
    const Colour WHITE(1, 1, 1, 1);
    const Colour RED(1, 0, 0, 1);

    circleImg->SetLocalPos(Vec2f(m_pos.x - CIRCLE_SIZE * 0.5f, m_pos.y + CIRCLE_SIZE * 0.5f));
    PushColour();
    MultColour(m_incorrect ? RED : (m_clicked ? BLACK : WHITE));
    circleImg->Draw();
    PopColour();

    // Draw number/letter
    text.SetSize(Vec2f(0.2f, 0.1f));
    text.SetJust(GuiText::AMJU_JUST_CENTRE);
    text.SetLocalPos(m_pos + Vec2f(-0.1f, 0.012f));
    text.SetText(m_str);
    text.SetFgCol(m_clicked || m_incorrect ? WHITE : BLACK);
    text.Draw();
}
Beispiel #5
0
void GSMain::Draw2d()
{
  AmjuGL::Viewport(0, 0, Screen::X(), Screen::Y());
  TheHud::Instance()->Draw();
  
  // Store scaled modelview matrix
  float mat[16];
  AmjuGL::GetMatrix(AmjuGL::AMJU_MODELVIEW_MATRIX, mat);

  // Split screen -- draw all screens
  int numVps = TheViewportManager::Instance()->GetNumViewports();
  for (int i = 0; i < numVps; i++)
  {
    AmjuGL::SetMatrixMode(AmjuGL::AMJU_MODELVIEW_MATRIX);
    AmjuGL::SetIdentity();
    // Restore scaled mv matrix
    AmjuGL::MultMatrix(mat);

    TheViewportManager::Instance()->GetViewport(i)->Draw2d();
  }
  m_gui->Draw(); // split screen line etc

  TheLurker::Instance()->Draw();

#ifdef GEKKO
  TheCursorManager::Instance()->Draw();
#endif

#ifdef SHOW_INFO
  // TODO Switch on/off
  if (true)
  {
    static GuiText t;
    t.SetFgCol(Colour(1, 1, 1, 1));
    t.SetBgCol(Colour(0, 0, 0, 1));
    t.SetDrawBg(true);
    t.SetFontSize(0.8f); // TODO CONFIG
    t.SetIsMulti(true);
    t.SetLocalPos(Vec2f(-1.0f, -0.8f));
    t.SetSize(Vec2f(1.0f, 0.2f));
    t.SetJust(GuiText::AMJU_JUST_LEFT);

    float playerX = Player::GetPlayer(AMJU_P1)->GetPos().x;

    static std::string old;
    std::string s = "Depth: " + ToString((int)GetCurrentDepth()) +
      " X: " + ToString((int)playerX) + 
      "\nNum Game Objects: " + 
      ToString((int)TheGame::Instance()->GetGameObjects()->size());

    if (old != s)
    {
      t.SetText(s);
    }
    old = s;
    t.Draw();
  }
#endif // SHOW_INFO
}
Beispiel #6
0
void GSGui::UpdateHeartCount()
{
  if (m_gui)
  {
    GuiText* text = (GuiText*)GetElementByName(m_gui, "score-num");
    if (text)
    {
      int h = 0;
      if (GetPlayerCount(SCORE_KEY, &h))
      {
        text->SetText(ToString(h));
      }
      else
      {
        text->SetText("");
      }
    }
  }
}
Beispiel #7
0
  virtual void Draw()
  {
    // Don't draw name of local player ?
    if (IsVisible() && m_player->GetId() != GetLocalPlayerId())
    {
      //Assert(m_player->GetAABB());
      //DrawAABB(*(m_player->GetAABB()));
 
      // Print name 
      // TODO Do all these in one go, to minimise state changes
      AmjuGL::PushAttrib(AmjuGL::AMJU_BLEND | AmjuGL::AMJU_DEPTH_READ);
      AmjuGL::Enable(AmjuGL::AMJU_BLEND);
      AmjuGL::Disable(AmjuGL::AMJU_DEPTH_READ);

      GuiText text;
      text.SetTextSize(5.0f); // TODO CONFIG
      text.SetText(m_player->GetName());
    
      static const float MAX_NAME_WIDTH = 4.0f; // minimise this to reduce overdraw - calc from text
      text.SetSize(Vec2f(MAX_NAME_WIDTH, 1.0f));
      text.SetJust(GuiText::AMJU_JUST_CENTRE);
      //text.SetInverse(true);
      //text.SetDrawBg(true);
      text.SetFgCol(Colour(1, 1, 1, 1));

      AmjuGL::PushMatrix();
    
      Matrix m;
      m.SetIdentity();

      // Reverse modelview rotation
      Matrix r;
      r.ModelView();
      m = TransposeRot(r);

      Vec3f tr(m_combined[12], m_combined[13], m_combined[14]);
      m.TranslateKeepRotation(tr);
      AmjuGL::MultMatrix(m);
      static const float SCALE_FACTOR = 20.0f;
      float x = MAX_NAME_WIDTH * SCALE_FACTOR * -0.5f;
      AmjuGL::Translate(x, 60.0f, 0); // TODO CONFIG
    
      AmjuGL::Scale(SCALE_FACTOR, SCALE_FACTOR, 10);  

      text.Draw();
      AmjuGL::PopMatrix();
      AmjuGL::PopAttrib();
    }
  }
Beispiel #8
0
void LurkMsg::Set(const std::string& str, const Colour& fgCol, const Colour& bgCol, LurkPos lp,
  CommandFunc onFinished)
{
  GuiText* text = new GuiText;
  if (lp == AMJU_CENTRE)
  {
    text->SetIsMulti(true);
  }
  text->SetTextSize(1.5f); // TODO CONFIG
  text->SetSize(Vec2f(1.6f, 0.1f)); // assume single line
  text->SetText(str);
  text->SizeToText();
  text->SetFgCol(fgCol);

  Set(text, fgCol, bgCol, lp, onFinished);
}
Beispiel #9
0
void GSYesNo::OnActive()
{
  GSGui::OnActive();

  m_gui = LoadGui("gui-yesno.txt");
  Assert(m_gui);

  GuiButton* yes = (GuiButton*)GetElementByName(m_gui, "yes-button");
  yes->SetCommand(Amju::OnYes);
  yes->SetHasFocus(true);
  yes->SetText(m_yesText);

  GuiButton* no = (GuiButton*)GetElementByName(m_gui, "no-button");
  no->SetCommand(Amju::OnNo);
  no->SetIsCancelButton(true); 
  no->SetText(m_noText);
  
  GuiText* q = (GuiText*)GetElementByName(m_gui, "question");
  q->SetText(m_question);
}
void GSFileUpdateCheck::OnDownloadedFile(const std::string& filename)
{
  // If we are no longer the current state, it doesn't matter
  if (TheGame::Instance()->GetState() != this)
  {
    return;
  }

  m_numFilesDownloaded++;
  if (m_numFilesDownloaded >= m_numFilesToWaitFor)
  {
    // Done! Update to new timestamp
    OnFinishedChecking(m_newtimestamp);

    if (m_gui)
    {
      GuiText* t = (GuiText*)GetElementByName(m_gui, "filename");
      t->SetText(filename);
    }
  }
}
Beispiel #11
0
void GSNetError::OnActive()
{
  GSGui::OnActive();

  m_gui = LoadGui("gui-error.txt");
  Assert(m_gui);

////  m_gui->GetElementByName("error-ok-button")->SetCommand(Amju::OnErrorOk);
////  m_gui->GetElementByName("error-quit-button")->SetCommand(Amju::OnErrorQuit);
  
  GuiButton* ok = (GuiButton*)GetElementByName(m_gui, "error-ok-button");
  ok->SetCommand(Amju::OnErrorOk);
  ok->SetHasFocus(true);

  GuiButton* quit = (GuiButton*)GetElementByName(m_gui, "error-quit-button");
  quit->SetCommand(Amju::OnErrorQuit);
  quit->SetIsCancelButton(true);


  GuiText* t = dynamic_cast<GuiText*>(m_gui->GetElementByName("error"));
  Assert(t);
  t->SetText(m_errorStr);
}
Beispiel #12
0
void GSTitle::OnActive()
{
  static bool first = true;
  if (first)
  {
    first = false;

    TheAvatarManager::Instance()->Load();

    // Set default keyboard layout
    KbSetLayout(KB_LAYOUT_REGULAR);

    TheGSOptions::Instance()->LoadFromConfig();
  }

  // Kill off any dummy player object
  TheGame::Instance()->ClearGameObjects();

#ifdef SHOW_FRAME_TIME
  Font* font = (Font*)TheResourceManager::Instance()->GetRes("font2d/arial-font.font");
  TheGame::Instance()->SetFrameTimeFont(font);
#endif

  GSGui::OnActive();

  if (!m_titleImage.OpenAndLoad("title-bgimage.txt"))
  {
std::cout << "Failed to load GUI title bg image!\n";
    Assert(0);
  }

  m_gui = LoadGui("gui-title.txt");
  Assert(m_gui);

  GuiButton* start = (GuiButton*)GetElementByName(m_gui, "start-button");
  start->SetCommand(Amju::OnStartButton);
  start->SetHasFocus(true); 

  GuiButton* options = (GuiButton*)GetElementByName(m_gui, "options-button");
  options->SetCommand(Amju::OnOptionsButton);

  GuiButton* quick = (GuiButton*)GetElementByName(m_gui, "quick-start-button");
  static PlayerInfoManager* pim = ThePlayerInfoManager::Instance();
  if (pim->GetNumPlayerNames() > 0)
  {
    quick->SetVisible(true);
    quick->SetCommand(Amju::OnQuickStartButton);
    quick->SetHasFocus(true);

    // Change button text to player name
    Strings names = pim->GetPlayerNames();
    Assert(!names.empty());
    pim->SetCurrentPlayer(names[0]);
    PlayerInfo* pi = pim->GetPI();
    Assert(pi);
    std::string playername = pi->PIGetString(PI_KEY("playername"));
    quick->SetText(playername);
  }
  else
  {
    quick->SetVisible(false);
  }

  GuiButton* quit = (GuiButton*)GetElementByName(m_gui, "quit-button");
  quit->SetCommand(Amju::OnQuitButton);
  quit->SetIsCancelButton(true);

#ifdef SHOW_VERSION
  GuiText* ver = (GuiText*)GetElementByName(m_gui, "version");
  std::string s = "v." + ToString(VersionMajor) + "." + ToString(VersionMinor);
#ifdef _DEBUG
  s += " DEBUG";
#endif
  ver->SetText(s);
#endif

  //CreateText("my game");

#ifdef PLAY_MUSIC
  TheSoundManager::Instance()->PlaySong(ROConfig()->GetValue("music-title", "Sound/hammers.it"));
#endif
}
Beispiel #13
0
void Hud::Draw()
{
  float dt = TheTimer::Instance()->GetDt();

  static const char* SCORE_NAME[3] = 
  {
    "p1-score-text", 
    "p2-score-text",
    "hi-score-text"
  };

  static const float origSize[3] = 
  {
    dynamic_cast<GuiText*>(m_gui->GetElementByName(SCORE_NAME[0]))->GetFontSize(),
    dynamic_cast<GuiText*>(m_gui->GetElementByName(SCORE_NAME[1]))->GetFontSize(),
    dynamic_cast<GuiText*>(m_gui->GetElementByName(SCORE_NAME[2]))->GetFontSize()
  };

  for (int i = 0; i < 3; i++)
  {
    if (s_scoreExpandTimer[i] > 0)
    {
      s_scoreExpandTimer[i] -= dt;
      if (s_scoreExpandTimer[i] < 0)
      {
        s_scoreExpandTimer[i] = 0;
      }
      GuiText* text = dynamic_cast<GuiText*>(m_gui->GetElementByName(SCORE_NAME[i]));
      Assert(text);
      static const float EXPAND_SCALE = ROConfig()->GetFloat("hud-expand-scale");
      text->SetFontSize(origSize[i] * (s_scoreExpandTimer[i] * EXPAND_SCALE + 1.0f));
      std::string s = text->GetText();
      text->SetText("");
      text->SetText(s); // force tri list rebuild
    }
  }

  if (s_lifeTimer > 0)
  {
    s_lifeTimer -= dt;
    if (s_lifeTimer < 0)
    {
      s_lifeTimer = 0;
    }
    static const char* GUI_NAME[4] = 
    {
      "heart-img1", 
      "p1-lives-text",
      "heart-img2", 
      "p2-lives-text"
    };
    float t = s_lifeTimer * 10;
    bool vis = (((int)t % 2) == 0);
    for (int i = 0; i < 4; i++)
    {
      GuiElement* elem = m_gui->GetElementByName(GUI_NAME[i]);
      Assert(elem);
      elem->SetVisible(vis);
    }
  } 

  m_gui->Draw();
}
Beispiel #14
0
void Hud::SetDepth(int depth)
{
  GuiText* t = (GuiText*)m_gui->GetElementByName("depth-num");
  Assert(t);
  t->SetText(ToString(depth));
}
Beispiel #15
0
void Game::RunOneLoop()
{
#ifdef SHOW_FRAME_TIME
    static std::string fps;
    static int framesThisSec = 0;
    framesThisSec++;
    static int elapsed = 0;
    float e = TheTimer::Instance()->GetElapsedTime(); 

    if ((int)e != elapsed)
    {
      elapsed = (int)e;
      fps = ToString(framesThisSec);
      framesThisSec = 0;
    }

#ifdef WIN32
    unsigned long start = GetTickCount();
#else
    // Get time taken to update/draw/flip, giving the 'real' FPS, not fixed to screen refresh rate
    timeval tbefore;
    gettimeofday(&tbefore, 0);
#endif

#endif //  SHOW_FRAME_TIME

  Update();

#ifdef SHOW_FRAME_TIME
#ifdef WIN32
    unsigned long mid = GetTickCount();
#else
    // Get time taken to update/draw/flip, giving the 'real' FPS, not fixed to screen refresh rate
    timeval mid;
    gettimeofday(&mid, 0);
#endif
#endif //  SHOW_FRAME_TIME

  Draw();

#ifdef SHOW_FRAME_TIME
  if (m_font)
  {
#ifdef WIN32
    unsigned long draw = GetTickCount() - mid;
    unsigned long update = mid - start;
    std::string s = "Draw: " + ToString((unsigned int)draw) + " update: " + ToString((unsigned int)update);

#else
    timeval tafter;
    gettimeofday(&tafter, 0);
    double draw = tafter.tv_sec - mid.tv_sec + (tafter.tv_usec - mid.tv_usec) * 1e-6;
    double update = mid.tv_sec - tbefore.tv_sec + (mid.tv_usec - tbefore.tv_usec) * 1e-6;
    int idraw = (int)(draw * 1000.0f);
    int iupdate = (int)(update * 1000.0f);
    std::string s = std::string("Draw: ") + 
      std::string((idraw < 10 ? "0" : "")) + ToString(idraw) +
      std::string("ms update: ") + std::string((iupdate < 10 ? "0" : "")) + 
      ToString(iupdate) + "ms";
#endif

    s += " fps: " + fps;

    // Display time per frame
    static GuiText t;
    t.SetFont(m_font);
    t.SetScaleX(0.7f);
    t.SetFgCol(Colour(1, 1, 1, 1));
    t.SetLocalPos(Vec2f(-1.0f, 1.0f));
    t.SetSize(Vec2f(2.0f, 0.1f));
    t.SetJust(GuiText::AMJU_JUST_LEFT);
    t.SetText(s);
    AmjuGL::PushAttrib(AmjuGL::AMJU_LIGHTING | AmjuGL::AMJU_TEXTURE_2D);
    AmjuGL::Disable(AmjuGL::AMJU_LIGHTING);
    AmjuGL::Enable(AmjuGL::AMJU_TEXTURE_2D);
    t.Draw(); 
    AmjuGL::PopAttrib();
  }
#endif //  SHOW_FRAME_TIME

  AmjuGL::Flip(); 
}
Beispiel #16
0
void Hud::SetLevel(int level)
{
  GuiText* t = (GuiText*)m_gui->GetElementByName("level-num");
  Assert(t);
  t->SetText(ToString(level));
}
Beispiel #17
0
void Ve1NameNode::Draw()
{
  // Print name 
  // TODO Do all these in one go, to minimise state changes
  AmjuGL::PushAttrib(AmjuGL::AMJU_BLEND | AmjuGL::AMJU_DEPTH_READ);
  AmjuGL::Enable(AmjuGL::AMJU_BLEND);
  AmjuGL::Disable(AmjuGL::AMJU_DEPTH_READ);

  GuiText text;
  text.SetTextSize(5.0f); // TODO CONFIG
  text.SetText(ToString(*m_obj));
    
  static const float MAX_NAME_WIDTH = 4.0f; // minimise this to reduce overdraw - calc from text
  text.SetSize(Vec2f(MAX_NAME_WIDTH, 1.0f));
  text.SetJust(GuiText::AMJU_JUST_CENTRE);
  //text.SetInverse(true);
  //text.SetDrawBg(true);

  AmjuGL::PushMatrix();
    
  Matrix m;
  m.SetIdentity();
  //Vec3f tr(m_local[12], m_local[13], m_local[14]);
  Vec3f tr(m_combined[12], m_combined[13], m_combined[14]);
  m.Translate(tr);
  AmjuGL::MultMatrix(m);
  static const float SCALE_FACTOR = 20.0f;
  float x = MAX_NAME_WIDTH * SCALE_FACTOR * -0.5f;
  AmjuGL::Translate(x, 60.0f, 0); // TODO CONFIG
    
  AmjuGL::Scale(SCALE_FACTOR, SCALE_FACTOR, 10);  

  text.Draw();
  AmjuGL::PopMatrix();
  AmjuGL::PopAttrib();

  /*
  AmjuGL::PushAttrib(
    AmjuGL::AMJU_TEXTURE_2D | AmjuGL:: AMJU_LIGHTING | AmjuGL::AMJU_BLEND | AmjuGL::AMJU_DEPTH_READ | AmjuGL::AMJU_DEPTH_WRITE);

  AmjuGL::Enable(AmjuGL::AMJU_TEXTURE_2D);
  AmjuGL::Disable(AmjuGL::AMJU_LIGHTING);
  AmjuGL::Enable(AmjuGL::AMJU_BLEND);
  AmjuGL::Disable(AmjuGL::AMJU_DEPTH_READ);
  AmjuGL::Disable(AmjuGL::AMJU_DEPTH_WRITE);

  AmjuGL::PushMatrix();
  AmjuGL::SetIdentity();

  AmjuGL::SetMatrixMode(AmjuGL::AMJU_PROJECTION_MATRIX);
  AmjuGL::PushMatrix();
  AmjuGL::SetIdentity();

  MultColour(Colour(0, 0, 1, 1));
  GuiText text;
  text.SetTextSize(0.5f);
  std::string s = "Object " + ToString(m_obj->GetId()) + " " + m_obj->GetTypeName();
  text.SetText(s);
  text.SizeToText();
  text.SetJust(GuiText::AMJU_JUST_LEFT);
  text.SetLocalPos(screenpos);
  text.Draw();


  AmjuGL::PopMatrix();
  AmjuGL::SetMatrixMode(AmjuGL::AMJU_MODELVIEW_MATRIX);
  AmjuGL::PopMatrix();

  AmjuGL::PopAttrib();
  */
}