Esempio n. 1
0
void TeamBox::ClearTeam()
{
  associated_team = NULL;
  ai_level = 0;

  NeedRedrawing();
}
Esempio n. 2
0
bool ScrollBox::SendKey(const SDL_keysym & key)
{
  if (!WidgetList::SendKey(key)) {
    int new_offset = offset;
    switch(key.sym)
    {
    case SDLK_PAGEUP:
      new_offset -= size.y;
      break;
    case SDLK_PAGEDOWN:
      new_offset += size.y;
      break;
    default:
      return false;
    }

    if (new_offset < 0)
      new_offset = 0;
    if (new_offset > GetMaxOffset())
      new_offset = GetMaxOffset();

    if (new_offset != offset) {
      offset = new_offset;
      Pack();
      NeedRedrawing();
    }
  }
  return true;
}
Esempio n. 3
0
void GameModeEditor::LoadGameMode()
{
  std::string mode = opt_game_mode->GetValue();
  Config::GetInstance()->SetGameMode(mode);
  GameMode * game_mode = GameMode::GetInstance();
  game_mode->Load();

  if (game_mode->allow_character_selection == GameMode::ALWAYS) {
    opt_allow_character_selection->SetChoice(0); // "always"
  } else if (game_mode->allow_character_selection == GameMode::BEFORE_FIRST_ACTION) {
    opt_allow_character_selection->SetChoice(1); // "before_action"
  } else if (game_mode->allow_character_selection == GameMode::NEVER) {
    opt_allow_character_selection->SetChoice(2); // "never"
  } else {
    ASSERT(false);
  }

  opt_duration_turn->SetValue(game_mode->duration_turn, true);
  opt_energy_ini->SetValue(game_mode->character.init_energy, true);
  opt_energy_max->SetValue(game_mode->character.max_energy, true);
  opt_time_before_death_mode->SetValue(game_mode->duration_before_death_mode, true);
  opt_damage_during_death_mode->SetValue(game_mode->damage_per_turn_during_death_mode, true);
  opt_gravity->SetValue((int)(game_mode->gravity), true);

  NeedRedrawing();

  if (!warned && mode == "blitz") {
    Question puppy_attention_span(Question::WARNING);
    puppy_attention_span.Set(_("The blitz mode does not reset the time between each team turn. "
                               "A team looses when it has no players left or its time has ran out."),
                             true, 0);
    puppy_attention_span.Ask();
    warned = true;
  }
}
Esempio n. 4
0
void TeamBox::ClearTeam()
{
  associated_team = NULL;
  ai_name = NO_AI_NAME;

  NeedRedrawing();
}
Esempio n. 5
0
void FileListBox::PopulateFileList(const std::string& path)
{
  new_path = path;
  if (path.compare(path.size()-1, sizeof(PATH_SEPARATOR), PATH_SEPARATOR))
    new_path += PATH_SEPARATOR;
  MSG_DEBUG("file", "Searching in %s\n", new_path.c_str());

  FolderSearch *f = OpenFolder(new_path);

  // Now that we have made use of new_path, it can be freed:
  // clearing the list is now possible
  Clear();

  if (f) {
    bool is_file = list_files;
    const char *name;

    while ((name = FolderSearchNext(f, is_file)) != NULL) {
      if (is_file) {
        // We have a file, check that it validates the list
        if (MatchFilter(name)) {
          std::string* filename = new std::string(new_path);
          *filename += name;
          MSG_DEBUG("file", "Adding file %s\n", name);
          AddLabelItem(false, ANSIToUTF8(new_path, name), filename, Font::FONT_MEDIUM);
        } else {
          MSG_DEBUG("file", "NOT adding file %s, invalid extension\n", name);
        }
      } else if (strcmp(name, ".")) {
        std::string* filename;
        if (!strcmp(name, "..")) {
          // Are we at the root?
          if (!strcmp(name, PATH_SEPARATOR))
            break;
          size_t pos = new_path.find_last_of(PATH_SEPARATOR, new_path.size()-2, sizeof(PATH_SEPARATOR));
          filename = new std::string(new_path.substr(0, pos+1));
        } else
          filename = new std::string(new_path);
        *filename += name;
        MSG_DEBUG("file", "Adding directory %s\n", name);
        AddLabelItem(false, std::string("[") + ANSIToUTF8(new_path, name) + "]", filename,
                     Font::FONT_MEDIUM, Font::FONT_NORMAL, c_yellow);
      } else
        MSG_DEBUG("file", "Rejecting %s\n", name);

      // Prepare again for searching files
      is_file = list_files;
    }

    CloseFolder(f);
    Pack();
    NeedRedrawing();
  } else {
    MSG_DEBUG("file", "Search failed?\n");
  }

  // Store last time to drop fast clicks
  last_time = SDL_GetTicks();
}
Esempio n. 6
0
void PictureWidget::SetNoSurface()
{
  NeedRedrawing();

  if (spr)
    delete spr;
  spr = NULL;
}
Esempio n. 7
0
void Label::SetText(const std::string & new_txt)
{
  NeedRedrawing();

  Text::SetText(new_txt);

  if (max_width) SetMaxWidth(size.x);
  size.y = GetHeight();
}
Esempio n. 8
0
void AbstractSpinButton::SetMaxValue(int max_value)
{
  if (m_max_value != max_value) {
    m_max_value = max_value;
    SetValue(m_value);
    NeedRedrawing();
  }
  ASSERT(m_min_value < m_max_value);
  ASSERT(m_step <= (m_max_value - m_min_value));
}
Esempio n. 9
0
void PictureWidget::SetSurface(const Surface & s, ScalingType type_)
{
  if (spr)
    delete spr;

  picture_size = s.GetSize();
  spr = new Sprite(s);
  type = type_;
  loaded = true;
  // Don't call immediately ApplyScaling(type) to save on rotozooms
  NeedRedrawing();
}
Esempio n. 10
0
void ComboBox::SetChoice(std::vector<std::string>::size_type index)
{
  std::string text;

  if (index >= m_choices.size ())
    return; /* index = 0; // loop back */

  m_index = index;

  txt_value_black->SetText(m_choices[m_index].second);
  txt_value_white->SetText(m_choices[m_index].second);

  RecreateTorus();
  NeedRedrawing();
}
Esempio n. 11
0
bool TextBox::SendKey(const SDL_keysym & key)
{
  bool used = true;

  NeedRedrawing();

  std::string new_txt = GetText();

  used = TextHandle(new_txt, cursor_pos, key);

  if (new_txt != GetText()) {
    BasicSetText(new_txt);
  }

  return used;
}
Esempio n. 12
0
void TeamBox::SetTeam(Team& _team, bool read_team_values)
{
  Team* old_team = associated_team;

  associated_team = &_team;

  if (_team.IsRemote()) {
    team_name->SetFont(dark_gray_color, Font::FONT_MEDIUM, Font::FONT_BOLD, false);

    // translators: this is the team listing and will expand in a context like "OOo team - Remote"
    team_name->SetText(Format(_("%s Team - Remote"), _team.GetName().c_str()));

    if (previous_custom_team) {
      previous_custom_team->SetVisible(false);
      next_custom_team->SetVisible(false);
    }
  } else {
    team_name->SetFont(primary_red_color, Font::FONT_MEDIUM, Font::FONT_BOLD, true);
    team_name->SetText(Format(_("%s Team"), _team.GetName().c_str()));

    if (previous_custom_team) {
      previous_custom_team->SetVisible(true);
      next_custom_team->SetVisible(true);
    }
  }
  UpdatePlayerType();
  team_logo->SetSurface(_team.GetFlag());

  // Update group
  SetGroup(_team.GetGroup());

  if (read_team_values) {
    player_name->SetText(_team.GetPlayerName());
    nb_characters->SetValue(_team.GetNbCharacters());
    for (uint i=0; i<4; i++) {
      if (ai_names[i] == _team.GetAIName()) {
        SetAILevel(i);
        break;
      }
    }
  } else if (old_team) {
    UpdateTeam(old_team->GetId());
  }
  previous_player_name = player_name->GetText();

  NeedRedrawing();
}
Esempio n. 13
0
Widget* ComboBox::ClickUp(const Point2i &mousePosition, uint button)
{
  NeedRedrawing();

  bool is_click = Mouse::IS_CLICK_BUTTON(button);
  if ( (is_click && mousePosition.x > (GetPositionX() + GetSizeX()/2))
       || button == SDL_BUTTON_WHEELUP ) {
    SetChoice(m_index + 1);
    return this;
  } else if ( (is_click && mousePosition.x <= (GetPositionX() + GetSizeX()/2))
              || button == SDL_BUTTON_WHEELDOWN ) {
    SetChoice(m_index - 1);
    return this;
  }

  return NULL;
}
Esempio n. 14
0
Widget * SpinButton::ClickUp(const Point2i & mousePosition,
                             uint button)
{
  NeedRedrawing();

  bool is_click = Mouse::IS_CLICK_BUTTON(button);
  if ((button == SDL_BUTTON_WHEELDOWN && Contains(mousePosition)) ||
      (is_click && m_minus->Contains(mousePosition))){
    DecValue();
    return this;
  } else if ((button == SDL_BUTTON_WHEELUP && Contains(mousePosition)) ||
             (is_click && m_plus->Contains(mousePosition))){
    IncValue();
    return this;
  }
  return NULL;
}
Esempio n. 15
0
void MultiTabs::SelectTab(uint current)
{
  ASSERT(!tabs.empty());

  if (current >= tabs.size())
    return;

  if (current_tab != current) {
    current_tab = current;

    // update first_tab to be sure that current tab will be visible
    if (current_tab < first_tab)
      first_tab = current_tab;
    else if (current_tab+1 > first_tab + nb_visible_tabs)
      first_tab = current_tab - nb_visible_tabs + 1;

    NeedRedrawing();
  }
}
Esempio n. 16
0
void AbstractSpinButton::SetValue(int value, 
                                  bool force)
{
  int old_value = m_value;

  if (!force) {
    m_value = InRange_Long(value, m_min_value, m_max_value);
  } else {
    m_value = value;
    if (value > m_max_value) {
      m_max_value = value;
    } else if (value < m_min_value) {
      m_min_value = value;
    }
  }

  if (old_value != m_value) {
    ValueHasChanged();
    NeedRedrawing();
  }
}
Esempio n. 17
0
void TeamScrollBox::SetNbTeams(uint nb)
{
  // Reset the list and readd the widget
  count = 0;
  vbox->Empty();

  for (uint i = 0; count < nb; i++) {
    ASSERT(i < teams.size());

    // It is easy to have hole in the selection
    // with network game
    if (teams[i]->GetTeam()) {
      AddWidget(teams[i]);
      count++;
    }
  }
  ASSERT(count == nb);

  Pack();
  NeedRedrawing();
}
Esempio n. 18
0
Widget * TextBox::ClickUp(const Point2i & mousePosition,
                          uint button)
{
  NeedRedrawing();

  if (button == SDL_BUTTON_MIDDLE) {
    std::string new_txt = GetText();
    bool        used    = RetrieveBuffer(new_txt, cursor_pos);

    if (new_txt != GetText())
      BasicSetText(new_txt);
    return used ? this : NULL;
  } else if (button == SDL_BUTTON_LEFT) {
    const std::string      cur_txt = GetText();
    const Font*            font    = Font::GetInstance(GetFontSize(), GetFontStyle());
    std::string            txt     = "";
    std::string::size_type pos     = 0;

    cursor_pos = 0;
    while (pos <= cur_txt.size() &&
           this->position.x + font->GetWidth(txt) < mousePosition.x+2) {
      cursor_pos = pos;
      while ((cur_txt[pos++] & 0xc0) == 0x80
             && pos < cur_txt.size()) { } // eat all UTF-8 characters
      txt = cur_txt.substr(0, pos);
    }

    Label::Draw(mousePosition);
    DrawCursor(position, cursor_pos);

    return this;
  }

  // Om nom nom
  return this;
}
Esempio n. 19
0
Widget * ScrollBox::ClickUp(const Point2i & mousePosition, uint button)
{
  ScrollMode old_mode = scroll_mode;
  start_drag_offset = NO_DRAG;
  scroll_mode = SCROLL_MODE_NONE;

  if (!vbox->GetFirstWidget()) {
    return NULL;
  }

  // Handle the click up as a widget click only if we weren't dragging
  // If we click up close to where we clicked down, it will however register
  // as a click and not a scrolling
  if (vbox->Contains(mousePosition) &&
      (start_drag_y==NO_DRAG || abs(start_drag_y-mousePosition.y)<2)) {
    Widget *w = vbox->ClickUp(mousePosition, button);

    if (w) {
      SetFocusOn(w);
      return w;
    }
    // The click was not handled, let's try using it for scrolling
  }

  if (HasScrollBar()) {
    bool is_click   = Mouse::IS_CLICK_BUTTON(button);
    int  max_offset = GetMaxOffset();
    int  new_offset = offset;

    // The event involves the scrollbar or its buttons
    if ((button == SDL_BUTTON_WHEELDOWN && Contains(mousePosition)) ||
        (is_click && m_down->Contains(mousePosition))) {

      // bottom button
      new_offset = offset+SCROLL_SPEED;
    } else if ((button == SDL_BUTTON_WHEELUP && Contains(mousePosition)) ||
               (is_click && m_up->Contains(mousePosition))) {

      // top button
      new_offset = offset-SCROLL_SPEED;
    } else if (is_click) {
      // Was it released after a drag operation?
      if (old_mode!=SCROLL_MODE_NONE /*&& start_drag_y != mousePosition.y*/)
        return this;
      const Rectanglei& scroll_track = GetScrollTrack();
      if (scroll_track.Contains(mousePosition)) {
        // Set this as new scroll thumb position
        int height = scroll_track.GetSizeY();
        new_offset = ((mousePosition.y - scroll_track.GetPositionY()) * (size.y+max_offset)
                      + (height/2)) / scroll_track.GetSizeY();
      }
    }

    // Clip new offset to correct value
    if (new_offset > max_offset)
      new_offset = max_offset;
    if (new_offset < 0)
      new_offset = 0;

    if (new_offset != offset) {
      offset = new_offset;
      Pack();
      NeedRedrawing();
    }

    return this;
  }

  return NULL;
}