本文整理汇总了C++中Item::GetDisplayName方法的典型用法代码示例。如果您正苦于以下问题:C++ Item::GetDisplayName方法的具体用法?C++ Item::GetDisplayName怎么用?C++ Item::GetDisplayName使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Item
的用法示例。
在下文中一共展示了Item::GetDisplayName方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: HandleItemSelection
void InventoryView::HandleItemSelection() {
Player* p = DataManager::Instance()->GetPlayer();
Inventory& inv = p->GetInventory();
if(m_inInventoryArea) {
if(inv.NumItems() > 0) {
Item* toUse = inv.ItemAtIndex(m_selectIdx);
Item* oldItem = NULL;
if(!toUse->CanUse()) {
stringstream s;
s << toUse->GetDisplayName() << " requires level " << toUse->GetRequiredLevel();
string toDisp = s.str();
DataManager::Instance()->AppendStatusString(toDisp);
return;
}
switch(toUse->GetClass()) {
case E_HELM:
inv.RemoveItem(toUse);
oldItem = p->GetHeadItem();
p->SetHeadItem((ArmorItem*)toUse);
if(oldItem) {
inv.AddItem(oldItem);
}
break;
case E_BODY:
inv.RemoveItem(toUse);
oldItem = p->GetBodyItem();
p->SetBodyItem((ArmorItem*)toUse);
if(oldItem) {
inv.AddItem(oldItem);
}
break;
case E_LEGS:
inv.RemoveItem(toUse);
oldItem = p->GetLegsItem();
p->SetLegsItem((ArmorItem*)toUse);
if(oldItem) {
inv.AddItem(oldItem);
}
break;
case E_WEAPON:
inv.RemoveItem(toUse);
oldItem = p->GetWeaponItem();
p->SetWeaponItem((Weapon*)toUse);
if(oldItem) {
inv.AddItem(oldItem);
}
break;
case E_IMPLANT:
inv.RemoveItem(toUse);
oldItem = p->GetImplantItem();
p->SetImplantItem((Implant*)toUse);
if(oldItem) {
inv.AddItem(oldItem);
}
break;
case E_CONSUMABLE:
if(toUse->CanStack()) {
Consumable* c = (Consumable*)toUse;
c->ApplyEffect();
if(toUse->GetStackSize() < 1) {
inv.RemoveItem(toUse);
}
}
break;
default:
break;
}
}
}
else {
switch(m_selectIdx) {
case 0:
p->ReturnHeadItemToInventory();
break;
case 1:
p->ReturnBodyItemToInventory();
break;
case 2:
p->ReturnLegsItemToInventory();
break;
case 3:
p->ReturnWeaponItemToInventory();
break;
case 4:
p->ReturnImplantItemToInventory();
break;
}
}
}
示例2: Update
void InventoryView::Update() {
Clear();
for(int y = 0; y < 24; y++) {
SetCharAt(49, y, '|', WHITE);
}
string toDraw = "Equipped Items";
int wd2 = toDraw.length() / 2;
SetStringAt(25 - wd2, 1, toDraw, WHITE);
toDraw = "Inventory";
wd2 = toDraw.length() / 2;
SetStringAt(65 - wd2, 1, toDraw, WHITE);
toDraw = "(Arrows navigate, Enter selects, 'd' discards, Esc exits. List scrolls)";
wd2 = toDraw.length() / 2;
SetStringAt(40 - wd2, 23, toDraw, WHITE);
toDraw = DataManager::Instance()->GetStatusString();
DataManager::Instance()->ClearStatusString();
if(toDraw != "()") {
wd2 = toDraw.length() / 2;
SetStringAt(1, 22, toDraw, YELLOW_BOLD);
}
toDraw = "Head: ";
SetStringAt(10, 6, toDraw, WHITE);
toDraw = "Body: ";
SetStringAt(10, 8, toDraw, WHITE);
toDraw = "Legs: ";
SetStringAt(10, 10, toDraw, WHITE);
toDraw = "Weapon: ";
SetStringAt(8, 12, toDraw, WHITE);
toDraw = "Implant: ";
SetStringAt(7, 14, toDraw, WHITE);
// Show inventory items
Player* p = DataManager::Instance()->GetPlayer();
Inventory inv = p->GetInventory();
if(inv.NumItems() == 0) {
int attr = WHITE;
if(m_inInventoryArea) {
attr = YELLOW_BOLD;
}
toDraw = "<empty>";
SetStringAt(51, 3, toDraw, attr);
}
else {
ItemList items = inv.GetItems();
int counter = m_scrollY;
stringstream s;
for(ItemList::iterator i = items.begin(); i != items.end(); i++) {
if(counter < m_scrollY) {
continue;
}
if(counter >= m_scrollY + 19) {
break;
}
int attr = WHITE;
if(m_inInventoryArea && counter == m_selectIdx) {
attr = YELLOW_BOLD;
}
Item* toShow = *i;
s.str("");
s << (counter + 1) << ". " << toShow->GetDisplayName();
if(toShow->CanStack()) {
s << " (" << toShow->GetStackSize() << ")";
}
toDraw = s.str();
if(toDraw.length() > 28) {
toDraw.erase(28);
}
SetStringAt(51, 3 + counter - m_scrollY, toDraw, attr);
counter++;
}
}
// Show the equipped items
DrawPaperDollItem(p->GetHeadItem(), 6, 0);
DrawPaperDollItem(p->GetBodyItem(), 8, 1);
DrawPaperDollItem(p->GetLegsItem(), 10, 2);
DrawPaperDollItem(p->GetWeaponItem(), 12, 3);
DrawPaperDollItem(p->GetImplantItem(), 14, 4);
//stringstream s;
//s << "scrolly: " << m_scrollY << " selectidx: " << m_selectIdx;
//toDraw = s.str();
//SetStringAt(1, 22, toDraw, WHITE);
}