void CSimulatorWindowHandler::addToLog(const std::string &text) { unsigned int historySize = 7; unsigned int shortHistorySize = 3; std::ostringstream message; // If there's text then add it if(text.size()) { message << m_simulator->getReferee()->getMinute() << "' - " << text.c_str(); // Add the Editbox text to the history Listbox CEGUI::ListboxTextItem* logItem; if(m_logHistoryList->getItemCount() == historySize) { /* We have reached the capacity of the Listbox so re-use the first Listbox item. This code is a little crafty. By default the ListboxTextItem is created with the auto-delete flag set to true, which results in its automatic deletion when removed from the Listbox. So we change that flag to false, extract the item from the Listbox, change its text, put the auto-delete flag back to true, and finally put the item back into the Listbox. */ logItem = static_cast<CEGUI::ListboxTextItem*>(m_logHistoryList->getListboxItemFromIndex(0)); logItem->setAutoDeleted(false); m_logHistoryList->removeItem(logItem); logItem->setAutoDeleted(true); logItem->setText((CEGUI::utf8*)message.str().c_str()); } else { // Create a new listbox item logItem = new CEGUI::ListboxTextItem((CEGUI::utf8*)message.str().c_str()); } m_logHistoryList->addItem(logItem); m_logHistoryList->ensureItemIsVisible(m_logHistoryList->getItemCount()); if(m_logHistoryListShort->getItemCount() == shortHistorySize) { logItem = static_cast<CEGUI::ListboxTextItem*>(m_logHistoryListShort->getListboxItemFromIndex(0)); logItem->setAutoDeleted(false); m_logHistoryListShort->removeItem(logItem); logItem->setAutoDeleted(true); logItem->setText((CEGUI::utf8*)message.str().c_str()); } else { logItem = new CEGUI::ListboxTextItem((CEGUI::utf8*)message.str().c_str()); } m_logHistoryListShort->addItem(logItem); m_logHistoryListShort->ensureItemIsVisible(m_logHistoryListShort->getItemCount()); } }
void GameLog::print(const std::string& msg) { CEGUI::ListboxTextItem* text; if(log_->getItemCount() >= log_history_) { text = (CEGUI::ListboxTextItem*)log_->getListboxItemFromIndex(0); text->setAutoDeleted(false); log_->removeItem(text); text->setAutoDeleted(true); text->setText(msg); } else text = new CEGUI::ListboxTextItem(msg); text->setTextColours(CEGUI::Colour{0.f, 1.f, 0.f}); log_->addItem(text); //log_->getVertScrollbar()->scrollForwardsByStep(); log_->getVertScrollbar()->setScrollPosition(log_->getVertScrollbar()->getDocumentSize()); }
void ServerList::updateServer(Server *s) { size_t rows = m_listeServeurs->getRowCount(); int row = -1; for(size_t i=0;i<rows;++i) { if(m_listeServeurs->getItemAtGridReference(CEGUI::MCLGridRef(i, 0))->getUserData() == s) { row = i; break; } } if(row != -1) { CEGUI::ListboxTextItem *item; item = (CEGUI::ListboxTextItem*)m_listeServeurs->getItemAtGridReference(CEGUI::MCLGridRef(row, 0)); item->setText(s->nom); item = (CEGUI::ListboxTextItem*)m_listeServeurs->getItemAtGridReference(CEGUI::MCLGridRef(row, 1)); item->setText(s->ip); std::string joueurs = boost::lexical_cast<std::string>(s->nombre_joueurs_connectes); joueurs += "/"; joueurs += boost::lexical_cast<std::string>(s->nombre_joueurs_max); item = (CEGUI::ListboxTextItem*)m_listeServeurs->getItemAtGridReference(CEGUI::MCLGridRef(row, 2)); item->setText(joueurs); item = (CEGUI::ListboxTextItem*)m_listeServeurs->getItemAtGridReference(CEGUI::MCLGridRef(row, 3)); item->setText(s->carte_jouee); item = (CEGUI::ListboxTextItem*)m_listeServeurs->getItemAtGridReference(CEGUI::MCLGridRef(row, 4)); item->setText(boost::lexical_cast<std::string>(0)); item = (CEGUI::ListboxTextItem*)m_listeServeurs->getItemAtGridReference(CEGUI::MCLGridRef(row, 5)); item->setText((s->passwd) ?"OUI":"NON"); m_listeServeurs->handleUpdatedItemData(); } }