Add a new "char_list" QTreeWidget that allows for categorizing characters (#399)
* initial commit * use a "category" value instead * add filtering and taken indicator * hide serverlist header * set the items to disabled in place of the [X] text Co-authored-by: stonedDiscord <10584181+stonedDiscord@users.noreply.github.com>
This commit is contained in:
		
							parent
							
								
									d8dd429c20
								
							
						
					
					
						commit
						d41ec17fe7
					
				@ -342,6 +342,9 @@ public:
 | 
			
		||||
  // Returns the showname from the ini of p_char
 | 
			
		||||
  QString get_showname(QString p_char);
 | 
			
		||||
 | 
			
		||||
  // Returns the category of this character
 | 
			
		||||
  QString get_category(QString p_char);
 | 
			
		||||
 | 
			
		||||
  // Returns the value of chat image from the specific p_char's ini file
 | 
			
		||||
  QString get_chat(QString p_char);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -715,6 +715,9 @@ private:
 | 
			
		||||
 | 
			
		||||
  AOImage *ui_char_select_background;
 | 
			
		||||
 | 
			
		||||
  // pretty list of characters
 | 
			
		||||
  QTreeWidget *ui_char_list;
 | 
			
		||||
 | 
			
		||||
  // abstract widget to hold char buttons
 | 
			
		||||
  QWidget *ui_char_buttons;
 | 
			
		||||
 | 
			
		||||
@ -908,6 +911,7 @@ private slots:
 | 
			
		||||
 | 
			
		||||
  void on_back_to_lobby_clicked();
 | 
			
		||||
 | 
			
		||||
  void on_char_list_double_clicked(QTreeWidgetItem *p_item, int column);
 | 
			
		||||
  void on_char_select_left_clicked();
 | 
			
		||||
  void on_char_select_right_clicked();
 | 
			
		||||
  void on_char_search_changed();
 | 
			
		||||
 | 
			
		||||
@ -11,6 +11,15 @@ void Courtroom::construct_char_select()
 | 
			
		||||
 | 
			
		||||
  ui_char_select_background = new AOImage(this, ao_app);
 | 
			
		||||
 | 
			
		||||
  ui_char_list = new QTreeWidget(ui_char_select_background);
 | 
			
		||||
  ui_char_list->setColumnCount(2);
 | 
			
		||||
  ui_char_list->setHeaderLabels({"Name", "ID"});
 | 
			
		||||
  ui_char_list->setHeaderHidden(true);
 | 
			
		||||
  ui_char_list->header()->setSectionResizeMode(QHeaderView::ResizeToContents);
 | 
			
		||||
  ui_char_list->hideColumn(1);
 | 
			
		||||
  ui_char_list->setDropIndicatorShown(true);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
  ui_char_buttons = new QWidget(ui_char_select_background);
 | 
			
		||||
 | 
			
		||||
  ui_selector = new AOImage(ui_char_select_background, ao_app);
 | 
			
		||||
@ -45,6 +54,10 @@ void Courtroom::construct_char_select()
 | 
			
		||||
  ui_char_passworded->setChecked(true);
 | 
			
		||||
 | 
			
		||||
  set_size_and_pos(ui_char_buttons, "char_buttons");
 | 
			
		||||
  set_size_and_pos(ui_char_list, "char_list");
 | 
			
		||||
 | 
			
		||||
  connect(ui_char_list, SIGNAL(itemDoubleClicked(QTreeWidgetItem *, int)),
 | 
			
		||||
          this, SLOT(on_char_list_double_clicked(QTreeWidgetItem *, int)));
 | 
			
		||||
 | 
			
		||||
  connect(ui_back_to_lobby, SIGNAL(clicked()), this,
 | 
			
		||||
          SLOT(on_back_to_lobby_clicked()));
 | 
			
		||||
@ -126,6 +139,20 @@ void Courtroom::set_char_select_page()
 | 
			
		||||
  put_button_in_place(current_char_page * max_chars_on_page, chars_on_page);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Courtroom::on_char_list_double_clicked(QTreeWidgetItem *p_item, int column)
 | 
			
		||||
{
 | 
			
		||||
  int cid = p_item->text(1).toInt();
 | 
			
		||||
  if (cid == -1 && !p_item->isExpanded()) {
 | 
			
		||||
    p_item->setExpanded(true);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  else if (cid == -1) {
 | 
			
		||||
    p_item->setExpanded(false);
 | 
			
		||||
    return;
 | 
			
		||||
  }
 | 
			
		||||
  char_clicked(cid);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void Courtroom::char_clicked(int n_char)
 | 
			
		||||
{
 | 
			
		||||
  if (n_char != -1)
 | 
			
		||||
@ -218,7 +245,32 @@ void Courtroom::character_loading_finished()
 | 
			
		||||
    char_button->set_image(char_list.at(n).name);
 | 
			
		||||
    char_button->setToolTip(char_list.at(n).name);
 | 
			
		||||
    ui_char_button_list.append(char_button);
 | 
			
		||||
 | 
			
		||||
    QString char_category = ao_app->get_category(char_list.at(n).name);
 | 
			
		||||
    QList<QTreeWidgetItem*> matching_list = ui_char_list->findItems(char_category, Qt::MatchFixedString, 0);
 | 
			
		||||
    // create the character tree item
 | 
			
		||||
    QTreeWidgetItem *treeItem = new QTreeWidgetItem();
 | 
			
		||||
    treeItem->setText(0, char_list.at(n).name);
 | 
			
		||||
    treeItem->setIcon(0, QIcon(ao_app->get_static_image_suffix(
 | 
			
		||||
      ao_app->get_character_path(char_list.at(n).name, "char_icon"))));
 | 
			
		||||
    treeItem->setData(1, Qt::DisplayRole, n);
 | 
			
		||||
    // category logic
 | 
			
		||||
    QTreeWidgetItem *category;
 | 
			
		||||
    if (char_category == "") // no category
 | 
			
		||||
      ui_char_list->addTopLevelItem(treeItem);
 | 
			
		||||
    else if (!matching_list.isEmpty()) { // our category already exists
 | 
			
		||||
      category = matching_list[0];
 | 
			
		||||
      category->addChild(treeItem);
 | 
			
		||||
    }
 | 
			
		||||
    else { // we need to make a new category
 | 
			
		||||
      category = new QTreeWidgetItem();
 | 
			
		||||
      category->setText(0, char_category);
 | 
			
		||||
      category->setData(1, Qt::DisplayRole, -1);
 | 
			
		||||
      category->setChildIndicatorPolicy(QTreeWidgetItem::DontShowIndicatorWhenChildless);
 | 
			
		||||
      ui_char_list->insertTopLevelItem(0, category);
 | 
			
		||||
      category->addChild(treeItem);
 | 
			
		||||
    }
 | 
			
		||||
      
 | 
			
		||||
    
 | 
			
		||||
    connect(char_button, &AOCharButton::clicked,
 | 
			
		||||
            [this, n]() { this->char_clicked(n); });
 | 
			
		||||
 | 
			
		||||
@ -241,7 +293,7 @@ void Courtroom::character_loading_finished()
 | 
			
		||||
              .arg(QString::number(ao_app->char_list_size)));
 | 
			
		||||
    }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  ui_char_list->expandAll();
 | 
			
		||||
  filter_character_list();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -250,24 +302,35 @@ void Courtroom::filter_character_list()
 | 
			
		||||
  ui_char_button_list_filtered.clear();
 | 
			
		||||
  for (int i = 0; i < char_list.size(); i++) {
 | 
			
		||||
    AOCharButton *current_char = ui_char_button_list.at(i);
 | 
			
		||||
    QTreeWidgetItem *current_char_list_item = ui_char_list->findItems(QString::number(i), Qt::MatchFixedString, 1)[0];
 | 
			
		||||
 | 
			
		||||
    // It seems passwording characters is unimplemented yet?
 | 
			
		||||
    // Until then, this will stay here, I suppose.
 | 
			
		||||
    // if (ui_char_passworded->isChecked() && character_is_passworded??)
 | 
			
		||||
    //    continue;
 | 
			
		||||
 | 
			
		||||
    if (!ui_char_taken->isChecked() && char_list.at(i).taken)
 | 
			
		||||
    if (!ui_char_taken->isChecked() && char_list.at(i).taken) {
 | 
			
		||||
      current_char_list_item->setHidden(true);
 | 
			
		||||
      continue;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    if (!char_list.at(i).name.contains(ui_char_search->text(),
 | 
			
		||||
                                       Qt::CaseInsensitive))
 | 
			
		||||
                                       Qt::CaseInsensitive)) {
 | 
			
		||||
      current_char_list_item->setHidden(true);
 | 
			
		||||
      continue;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
    // We only really need to update the fact that a character is taken
 | 
			
		||||
    // for the buttons that actually appear.
 | 
			
		||||
    // You'd also update the passwordedness and etc. here later.
 | 
			
		||||
    current_char->reset();
 | 
			
		||||
    current_char_list_item->setHidden(false);
 | 
			
		||||
    current_char->set_taken(char_list.at(i).taken);
 | 
			
		||||
    current_char_list_item->setText(0, char_list.at(i).name);
 | 
			
		||||
    // reset disabled
 | 
			
		||||
    current_char_list_item->setDisabled(false);
 | 
			
		||||
    if (char_list.at(i).taken) // woops, we are taken
 | 
			
		||||
      current_char_list_item->setDisabled(true);
 | 
			
		||||
 | 
			
		||||
    ui_char_button_list_filtered.append(current_char);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@ -29,6 +29,7 @@ Lobby::Lobby(AOApplication *p_ao_app) : QMainWindow()
 | 
			
		||||
  ui_server_list = new QTreeWidget(this);
 | 
			
		||||
  ui_server_list->setHeaderLabels({"#", "Name"}); //, "Players"});
 | 
			
		||||
  ui_server_list->hideColumn(0);
 | 
			
		||||
  ui_server_list->setHeaderHidden(true);
 | 
			
		||||
 | 
			
		||||
  ui_server_search = new QLineEdit(this);
 | 
			
		||||
  ui_server_search->setFrame(false);
 | 
			
		||||
 | 
			
		||||
@ -667,6 +667,12 @@ QString AOApplication::get_blips(QString p_char)
 | 
			
		||||
  return f_result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString AOApplication::get_category(QString p_char)
 | 
			
		||||
{
 | 
			
		||||
  QString f_result = read_char_ini(p_char, "category", "Options");
 | 
			
		||||
  return f_result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString AOApplication::get_chat(QString p_char)
 | 
			
		||||
{
 | 
			
		||||
  if (p_char == "default")
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user