void InventoryItem::onHandDragStop(Event::Mouse* event, HAND hand) { // Check if mouse is over this item if (!Rect::inRect(event->position(), position(), size())) { return; } if (ItemsList* itemsList = dynamic_cast<ItemsList*>(event->target())) { InventoryItem* itemUi = itemsList->draggedItem(); auto item = itemUi->item(); itemsList->removeItem(itemUi, 1); // place current weapon back to inventory if (_item) { itemsList->addItem(this, 1); } this->setItem(item); auto player = Game::getInstance()->player(); if (hand == HAND::LEFT) { player->setLeftHandSlot(item); } else { player->setRightHandSlot(item); } } }
void InventoryItem::onArmorDragStop(Event::Mouse* event) { // Check if mouse is over this item if (!Rect::inRect(event->position(), position(), size())) { return; } if (ItemsList* itemsList = dynamic_cast<ItemsList*>(event->target())) { InventoryItem* draggedItem = itemsList->draggedItem(); auto itemObject = draggedItem->item(); if(itemObject->subtype() != Game::ItemObject::Subtype::ARMOR) return; itemsList->removeItem(draggedItem, 1); // place current armor back to inventory if (_item) { itemsList->addItem(this, 1); } this->setItem(itemObject); if (auto armor = dynamic_cast<Game::ArmorItemObject*>(itemObject)) { Game::getInstance()->player()->setArmorSlot(armor); } } }
bool AICurrentItemCondition::fireCondition() { InventoryItem *item = ((PegasusEngine *)g_engine)->getCurrentInventoryItem(); if (_item == kNoItemID) return item == 0; return item != 0 && item->getObjectID() == _item; }
/******************************************************** * showValues * * This function displays the member data stored in the * * InventoryItem object passed to it by value. * ********************************************************/ void showValues(InventoryItem item) { cout << fixed << showpoint << setprecision(2) << endl;; cout << "Part Number : " << item.getPartNum() << endl; cout << "Description : " << item.getDescription() << endl; cout << "Units On Hand: " << item.getOnHand() << endl; cout << "Price : $" << item.getPrice() << endl; }
void Client::clickActiveObject(u8 button, u16 id, u16 item_i) { if(connectedAndInitialized() == false){ infostream<<"Client::clickActiveObject() " "cancelled (not connected)" <<std::endl; return; } Player *player = m_env.getLocalPlayer(); if(player == NULL) return; ClientActiveObject *obj = m_env.getActiveObject(id); if(obj){ if(button == 0){ ToolItem *titem = NULL; std::string toolname = ""; InventoryList *mlist = player->inventory.getList("main"); if(mlist != NULL) { InventoryItem *item = mlist->getItem(item_i); if(item && (std::string)item->getName() == "ToolItem") { titem = (ToolItem*)item; toolname = titem->getToolName(); } } v3f playerpos = player->getPosition(); v3f objpos = obj->getPosition(); v3f dir = (objpos - playerpos).normalize(); bool disable_send = obj->directReportPunch(toolname, dir); if(disable_send) return; } } /* length: 7 [0] u16 command [2] u8 button (0=left, 1=right) [3] u16 id [5] u16 item */ u8 datasize = 2 + 1 + 6 + 2 + 2; SharedBuffer<u8> data(datasize); writeU16(&data[0], TOSERVER_CLICK_ACTIVEOBJECT); writeU8(&data[2], button); writeU16(&data[3], id); writeU16(&data[5], item_i); Send(0, data, true); }
//----------------------------------------------------------------------------// void InventoryModel::updateItemName(const ModelIndex& index, const String& newName) { ModelIndex parent_index = getParentIndex(index); notifyChildrenDataWillChange(parent_index, 0, 1); InventoryItem* item = static_cast<InventoryItem*>(index.d_modelData); item->setText(newName); notifyChildrenDataChanged(parent_index, 0, 1); }
//------------------------------------------------------------------------------// void InventoryReceiver::removeItem(InventoryItem& item) { if (item.getParent() != this || item.locationOnReceiverX() == -1 || item.locationOnReceiverY() == -1) return; eraseItemFromContentMap(item); item.setLocationOnReceiver(-1, -1); removeChild(&item); }
video::ITexture * ItemObject::getItemImage() { /* Create an inventory item to see what is its image */ video::ITexture *texture = NULL; InventoryItem *item = createInventoryItem(); if(item) texture = item->getImage(); if(item) delete item; return texture; }
void restoreItemInBackpack( Item* item, int inventoryPosX, int inventoryPosY, size_t stackSize ) { InventoryItem* invItem = new InventoryItem( item, inventoryPosX, inventoryPosY, Globals::getPlayer() ); invItem->setCurrentStackSize( stackSize ); Globals::getPlayer()->getInventory()->insertItemWithExchangeAt( invItem, inventoryPosX, inventoryPosY ); }
//------------------------------------------------------------------------------// void InventoryItemRenderer::render() { const WidgetLookFeel& wlf = getLookNFeel(); InventoryItem* item = dynamic_cast<InventoryItem*>(d_window); if (!item) // render basic imagery wlf.getStateImagery(d_window->isDisabled() ? "Disabled" : "Enabled").render(*d_window); if (item->isBeingDragged()) wlf.getStateImagery(item->currentDropTargetIsValid() ? "DraggingValidTarget" : "DraggingInvalidTarget").render(*item); else wlf.getStateImagery("Normal").render(*item); }
void GenericPlayerCharacter::EquipCharacter(int choosenObject) { for(Vector<InventoryItem*>::iterator playerObject = playerInventory.begin(); playerObject < playerInventory.end(); playerObject++) { InventoryItem* currentItem = *playerObject; if(currentItem->getObjectWorldID() == choosenObject) { playerAttackPoints = playerAttackPoints - currentEquipedObject->getAttackBoost(); playerDefencePoints = playerDefencePoints - currentEquipedObject->getDefenceBoost(); playerAttackPoints = playerAttackPoints - currentItem->getAttackBoost(); playerDefencePoints = playerDefencePoints - currentItem->getDefenceBoost(); break; } } }
InventoryItem* Item::AddLootItem(InventoryItem* pItem, int slotX, int slotY) { if(pItem != NULL) { InventoryItem* pAddedLootItem = AddLootItem(pItem->m_filename.c_str(), pItem->m_Iconfilename.c_str(), pItem->m_itemType, pItem->m_item, pItem->m_status, pItem->m_equipSlot, pItem->m_itemQuality, pItem->m_title.c_str(), pItem->m_description.c_str(), pItem->m_left, pItem->m_right, pItem->m_placementR, pItem->m_placementG, pItem->m_placementB, pItem->m_quantity, slotX, slotY); for(int i = 0; i < (int)pItem->m_vpStatAttributes.size(); i++) { pAddedLootItem->AddStatAttribute(pItem->m_vpStatAttributes[i]->GetType(), pItem->m_vpStatAttributes[i]->GetModifyAmount()); } return pAddedLootItem; } return NULL; }
//------------------------------------------------------------------------------// void InventoryReceiver::onDragDropItemDropped(DragDropEventArgs &e) { InventoryItem* item = dynamic_cast<InventoryItem*>(e.dragDropItem); if (!item) return; const Sizef square_size(squarePixelSize()); Rectf item_area(item->getUnclippedOuterRect().get()); item_area.offset(Vector2f(square_size.d_width / 2, square_size.d_height / 2)); const int drop_x = gridXLocationFromPixelPosition(item_area.left()); const int drop_y = gridYLocationFromPixelPosition(item_area.top()); addItemAtLocation(*item, drop_x, drop_y); }
//------------------------------------------------------------------------------// bool InventoryReceiver::itemWillFitAtLocation(const InventoryItem& item, int x, int y) { if (x < 0 || y < 0) return false; if (x + item.contentWidth() > d_content.width() || y + item.contentHeight() > d_content.height()) return false; const bool already_attached = this == item.getParent(); // if item is already attatched erase its data from the content map so the // test result is reliable. if (already_attached) eraseItemFromContentMap(item); bool result = true; for (int item_y = 0; item_y < item.contentHeight() && result; ++item_y) { for (int item_x = 0; item_x < item.contentWidth() && result; ++item_x) { if (d_content.elementAtLocation(item_x + x, item_y + y) && item.isSolidAtLocation(item_x, item_y)) result = false; } } // re-write item into content map if we erased it earlier. if (already_attached) writeItemToContentMap(item); return result; }
//------------------------------------------------------------------------------// bool InventoryReceiver::addItemAtLocation(InventoryItem& item, int x, int y) { if (itemWillFitAtLocation(item, x, y)) { InventoryReceiver* old_receiver = dynamic_cast<InventoryReceiver*>(item.getParent()); if (old_receiver) old_receiver->removeItem(item); item.setLocationOnReceiver(x, y); writeItemToContentMap(item); addChild(&item); // set position and size. This ensures the items visually match the // logical content map. item.setPosition(UVector2(UDim(static_cast<float>(x) / contentWidth(), 0), UDim(static_cast<float>(y) / contentHeight(), 0))); item.setSize(USize( UDim(static_cast<float>(item.contentWidth()) / contentWidth(), 0), UDim(static_cast<float>(item.contentHeight()) / contentHeight(), 0))); return true; } return false; }
std::string Inventory::getReloadText() { std::ostringstream oss; oss << "-- Player's inventory" << std::endl; oss << "-- Items in Backpack" << std::endl; for( size_t backpackNr=0; backpackNr<backpackItems.size(); ++backpackNr ) { InventoryItem* curBackpackItem = backpackItems[ backpackNr ]; Item* curItem = curBackpackItem->getItem(); oss << "DawnInterface.restoreItemInBackpack( itemDatabase[\"" << curItem->getID() << "\"], " << curBackpackItem->getInventoryPosX() << ", " << curBackpackItem->getInventoryPosY() << ", " << curBackpackItem->getCurrentStackSize() << " );" << std::endl; } oss << "-- equipped Items" << std::endl; size_t numEquippable = static_cast<size_t>( ItemSlot::COUNT ); for( size_t curEquippable=0; curEquippable<numEquippable; ++curEquippable ) { if( equippedItems[ curEquippable ] != NULL ) { Item* curItem = equippedItems[ curEquippable ]->getItem(); /* if the item is two-handed and we're inspecting the off-hand slot don't output it. */ if( !( curItem->isTwoHandedWeapon() == true && curEquippable == static_cast<size_t>( ItemSlot::OFF_HAND ) ) ) { oss << "DawnInterface.restoreWieldItem( " << curEquippable << ", " << "itemDatabase[\"" << curItem->getID() << "\"] " << ");" << std::endl; } } } return oss.str(); }
InventoryItem* Inventory::getItemAt( size_t invPosX, size_t invPosY ) { assert( !isPositionFree( invPosX, invPosY ) ); size_t numBackItems = backpackItems.size(); for( size_t curBackItemNr=0; curBackItemNr<numBackItems; ++curBackItemNr ) { InventoryItem* curItem = backpackItems[ curBackItemNr ]; size_t itemPosX = curItem->getInventoryPosX(); size_t itemPosY = curItem->getInventoryPosY(); size_t itemSizeX = curItem->getItem()->getSizeX(); size_t itemSizeY = curItem->getItem()->getSizeY(); if( itemPosX <= invPosX && itemPosX + itemSizeX > invPosX && itemPosY <= invPosY && itemPosY + itemSizeY > invPosY ) { return curItem; } } // should have found an item so should never reach here abort(); }
//----------------------------------------------------------------------------------------- void InventoryList::render(bool eggTransparency) { InventoryItem *draggedItem = nullptr; for(auto& item: _slotItems) { if(item.second->type() != InventoryItem::Type::DRAG) { item.second->render(); } else { draggedItem = item.second.get(); } } ItemsList::render(eggTransparency); if(draggedItem) { draggedItem->render(); } }
//------------------------------------------------------------------------------// void InventoryReceiver::writeItemToContentMap(const InventoryItem& item) { if (item.locationOnReceiverX() == -1 || item.locationOnReceiverY() == -1) return; for (int y = 0; y < item.contentHeight(); ++y) { const int map_y = item.locationOnReceiverY() + y; for (int x = 0; x < item.contentWidth(); ++x) { const int map_x = item.locationOnReceiverX() + x; bool val = d_content.elementAtLocation(map_x, map_y) | item.isSolidAtLocation(x, y); d_content.setElementAtLocation(map_x, map_y, val); } } invalidate(); }
/********************************************************** * storeValues * * This function stores user input data in the members of * * an InventoryItem object passed to it by reference. * * ********************************************************/ void storeValues(InventoryItem &item) { int partNum; // Local variables to hold user input string description; int qty; double price; // Get the data from the user cout << "Enter data for the new part number \n"; cout << "Part number: "; cin >> partNum; cout << "Description: "; cin.get(); // Move past the '\n' left in the // input buffer by the last input getline(cin, description); cout << "Quantity on hand: "; cin >> qty; cout << "Unit price: "; cin >> price; // Store the data in the InventoryItem object item.storeInfo(partNum, description, qty, price); }
string Inventory::getInventoryString() { stringstream result; result << "{"; vector<Entity*> inventoryItems = getVectorItems(); for (vector<Entity*>::iterator i = inventoryItems.begin(); i != inventoryItems.end(); i++) { Entity* theItem = *i; InventoryItem* theInventoryItem = theItem->getInventoryItem(); if (theInventoryItem->getType() == "INVENTORYFOOD") { result << "F"; result << theInventoryItem->getItem()->getID() << ":"; result << theInventoryItem->getCurrentStackCount() << ":"; result << ((InventoryFood*)theInventoryItem)->getFoodState(); } else if (theInventoryItem->getType() == "INVENTORYEQUIPMENT") { result << "E"; result << theInventoryItem->getItem()->getID() << ":"; result << theInventoryItem->getCurrentStackCount() << ":"; result << ((InventoryEquipment*)theInventoryItem)->getSmithingMaterial()->getID(); } else if (theInventoryItem->getType() == "INVENTORYBOOST") { result << "B"; result << theInventoryItem->getItem()->getID() << ":"; result << theInventoryItem->getCurrentStackCount() << ":"; } else { result << theInventoryItem->getItem()->getID() << ":"; result << theInventoryItem->getCurrentStackCount() << ":"; } result << ","; } result << "}"; return result.str(); }
void game_create_pickup(const ScriptArguments& args) { glm::vec3 pos (args[2].real, args[3].real, args[4].real); int id; int type = args[1].integer; switch(args[0].type) { case TInt8: id = (std::int8_t)args[0].integer; break; case TInt16: id = (std::int16_t)args[0].integer; break; default: RW_ERROR("Unhandled integer type"); *args[5].globalInteger = 0; return; } if ( id < 0 ) { id = -id; auto model = args.getVM()->getFile()->getModels()[id]; std::transform(model.begin(), model.end(), model.begin(), ::tolower); id = args.getWorld()->data->findModelObject(model); args.getWorld()->data->loadDFF(model+".dff"); args.getWorld()->data->loadTXD("icons.txd"); } else { auto data = args.getWorld()->data->findObjectType<ObjectData>(id); if ( ! ( id >= 170 && id <= 184 ) ) { args.getWorld()->data->loadDFF(data->modelName+".dff"); } args.getWorld()->data->loadTXD(data->textureName+".txd"); } PickupObject* pickup = nullptr; if ( id >= 170 && id <= 184 ) { // Find the item for this model ID auto world = args.getWorld(); InventoryItem *item = nullptr; for (auto i = 0; i < maxInventorySlots; ++i) { item = world->getInventoryItem(i); if (item->getModelID() == id) { auto pickuptype = (PickupObject::PickupType)type; pickup = new ItemPickup(args.getWorld(), pos, pickuptype, item); world->pickupPool.insert( pickup ); world->allObjects.push_back(pickup); *args[5].globalInteger = pickup->getGameObjectID(); } } } else { RW_UNIMPLEMENTED("non-item pickups"); *args[5].globalInteger = 0; } }
void Player::update(float frameTime, LevelController* lc) { // 1-Press NoClip if (noClipButtonReleased && input->isKeyDown(VK_F2)) { noClip = !noClip; noClipButtonReleased = false; } else { noClipButtonReleased = true; } velocityX = getVelocity().x; velocityY = getVelocity().y; // Handle NoClip if (noClip) { if (input->isKeyDown(PLAYER_RIGHT)) { velocityX = playerNS::NOCLIP_SPEED * frameTime; orientation = Right; } else if (input->isKeyDown(PLAYER_LEFT)) { velocityX = -playerNS::NOCLIP_SPEED * frameTime; orientation = Left; } else { velocityX = 0; } if (input->isKeyDown(PLAYER_UP)) { velocityY = -playerNS::NOCLIP_SPEED * frameTime; orientation = Up; } else if (input->isKeyDown(PLAYER_DOWN)) { velocityY = playerNS::NOCLIP_SPEED * frameTime; orientation = Down; } else { velocityY = 0; } velocity = VECTOR2(velocityX, velocityY); frameDelay = 1000000; Item* activeItem = inventory->getActiveItem()->getItem(); if (inventory->getActiveItem()->getItem()->getItemType() == Item::Equipable) { Gun* gun = dynamic_cast<Gun*>(activeItem); if (gun != 0) { gun->update(frameTime, orientation, getX(), getY(), input, lc); } } Entity::update(frameTime); return; } // Set Obj Vars levelController = lc; // Debug Messages OSD::instance()->addLine("Jump Distance: " + std::to_string(jumpdistance) + " / " + std::to_string(playerNS::JUMP_HEIGHT)); OSD::instance()->addLine("Can | Left: " + std::to_string(canMoveLeft(true)) + " | Right: " + std::to_string(canMoveRight(true)) + " | Up: " + std::to_string(canMoveUp(true)) + " | Down: " + std::to_string(canMoveDown(true))); // Stuck Hotfix if (!canMoveLeft() && !canMoveRight() && !canMoveUp() && !canMoveDown()) { setX(spawnPos.x); setY(spawnPos.y); } // Update Guns inventory->update(frameTime, input); // Boss Audio if (lc->getMapX() * -1.0 > 1900) { audio->stopCue(BK_MUSIC); audio->playCue(BOSS_MUSIC); } // Start of Player Movement if (healthStatus != Dead) { if (!canMoveDown()) { if (!input->isKeyDown(PLAYER_UP) && !input->isKeyDown(PLAYER_JUMP)) canJump = true; canFall = false; falling = false; } else { canFall = true; falling = true; } // Move Left and Right if (input->isKeyDown(PLAYER_RIGHT) && canMoveRight()) { velocityX = playerNS::SPEED * frameTime; while (!canMoveRight()) { spriteData.x -= 0.1; velocityX = 0; } orientation = Right; } else if (input->isKeyDown(PLAYER_LEFT) && canMoveLeft()) { velocityX = -playerNS::SPEED * frameTime; while (!canMoveLeft()) { spriteData.x += 0.1; velocityX = 0; } orientation = Left; } else { velocityX = 0; if (input->isKeyDown(PLAYER_UP)) { orientation = Up; } if (input->isKeyDown(PLAYER_DOWN)) { orientation = Down; } } // Handle Jumping if (jumping || (((input->isKeyDown(PLAYER_JUMP) || input->isKeyDown(PLAYER_UP)) && canMoveUp() && canJump))) { jumpdistance = jumpOriginY - getY(); if (canJump && !jumping) jumpOriginY = getY(); if (jumpdistance > playerNS::JUMP_HEIGHT || !canMoveUp()) { jumping = false; canJump = false; falling = true; } else { if (!jumping) velocityY = -playerNS::JUMP_SPEED * frameTime; else velocityY += 0.5 * frameTime; jumping = true; canJump = false; } } if (!jumping) jumpOriginY = getY(); if (falling && !jumping) { if (canMoveDown()) { velocityY = playerNS::FALLING_SPEED * frameTime; } else { velocityY = 0; } } // Handle Stuck while (canMoveUp() && !canMoveDown() && !canMoveLeft() && !canMoveRight()) { spriteData.y -= 0.1; } while (!canMoveUp() && !canMoveDown() && !canMoveLeft() && canMoveRight()) { spriteData.x += 0.1; } while (!canMoveUp() && !canMoveDown() && canMoveLeft() && !canMoveRight()) { spriteData.x -= 0.1; } // Final Sanity Check if (!canMoveLeft() && velocityX < 0 || !canMoveRight() && velocityX > 0) velocityX = 0; if (!canMoveUp() && velocityY < 0 || !canMoveDown() && velocityY > 0) velocityY = 0; setVelocity(VECTOR2(velocityX, velocityY)); // Handle Orientations if (input->isKeyDown(PLAYER_UP)) orientation = Up; else if (input->isKeyDown(PLAYER_DOWN)) orientation = Down; switch (orientation) { case Right: currentFrame = 953; spriteData.flipHorizontal = true; break; case Down: currentFrame = 954; break; case Left: currentFrame = 953; spriteData.flipHorizontal = false; break; case Up: currentFrame = 952; break; } // Draw Items Item* activeItem = inventory->getActiveItem()->getItem(); if (inventory->getActiveItem()->getItem()->getItemType() == Item::Equipable) { Gun* gun = dynamic_cast<Gun*>(activeItem); if (gun != 0) { gun->update(frameTime, orientation, getX(), getY(), input, lc); } } // Crate Collision if (lc->collidedWithCrate() == 1 && lc->getCrateItem() != -1) { audio->playCue(RELOAD); if (lc->collidedWithCrate() == 1 && lc->getCrateItem() != -1) { int itemid = lc->getCrateItem(); InventoryItem *invItem; std::vector<InventoryItem*>* itemList = inventory->getItems(); switch (itemid) { case playerNS::ItemType::shotGun: shotgun = new Shotgun(); shotgun->initialize(gameptr, 136, 41, 2, gunTexture); shotgun->setCurrentFrame(6); invItem = new InventoryItem(shotgun); break; case playerNS::ItemType::machineGun: machineGun = new MachineGun(); machineGun->initialize(gameptr, 136, 41, 2, gunTexture); machineGun->setCurrentFrame(0); invItem = new InventoryItem(machineGun); break; case 3: break; } for (int i = 0; i < itemList->size(); i++) { InventoryItem *iItem = itemList->at(i); Item* item = iItem->getItem(); Item* newItem = invItem->getItem(); if (item->getItemType() == Item::Equipable && newItem->getItemType() == Item::Equipable) { Gun* gunInvItem = dynamic_cast<Gun*>(item); Gun* gunNewItem = dynamic_cast<Gun*>(newItem); if (gunInvItem->getGunId() == gunNewItem->getGunId()) { gunInvItem->addAmmo(); lc->setCrateCollided(0); return; // Should this be return or break? } } else if (item->getItemType() == Item::Usable && newItem->getItemType() == Item::Usable) { lc->setCrateCollided(0); return; } // Should this be return or break? } inventory->addItem(invItem); lc->setCrateCollided(0); lc->setCrateItem(-1); } } Entity::update(frameTime); } }
Command *Command::opItemSelectInInventory(const ResourceReference &itemRef) { InventoryItem *item = itemRef.resolve<InventoryItem>(); StarkUserInterface->selectInventoryItem(item->getIndex()); return nextCommand(); }
//----------------------------------------------------------------------------// void InventoryModel::load() { InventoryItem* backpack = InventoryItem::make("Trip backpack", 2.0f, d_root); InventoryItem* prev_matryoshka = 0; // matryoshka Z to A for (char chr = 'Z'; chr >= 'A'; --chr) { InventoryItem* matryoshka = InventoryItem::make("Matryoshka " + String(1, chr), 1.0f, backpack); matryoshka->setIcon("DriveIcons/DriveStack"); if (prev_matryoshka != 0) { prev_matryoshka->setParent(matryoshka); matryoshka->addItem(prev_matryoshka); } prev_matryoshka = matryoshka; } backpack->addItem(InventoryItem::make("Gepäckaufbewahrungsschein: Wiener Neustadt", 1.0f, backpack)); backpack->addItem(InventoryItem::make("Gepäckaufbewahrungsschein: Frankfurt am Main", 1.0f, backpack)); backpack->addItem(InventoryItem::make("Gepäckaufbewahrungsschein: Sankt Johann im Pongau", 1.0f, backpack)); backpack->addItem(InventoryItem::make("Gepäckaufbewahrungsschein: Seekirchen am Wallersee", 1.0f, backpack)); InventoryItem* beans_can = InventoryItem::make("Beans can", 1.0f, backpack); beans_can->setIcon("DriveIcons/GlobalDrive"); InventoryItem* beans = InventoryItem::make("Beans!", 0.1f, beans_can); beans_can->addItem(beans); backpack->addItem(prev_matryoshka); backpack->addItem(beans_can); d_root->addItem(backpack); InventoryItem* bow = InventoryItem::make("Bow", 23.451f, d_root); for (int i = 25; i >= 0; --i) { InventoryItem* arrow = InventoryItem::make( "arrow " + PropertyHelper<int>::toString(i), 0.2f, bow); bow->addItem(arrow); } d_root->addItem(bow); // generate *many* items :D for (int i = 2000; i >= 1960; i -= 2) { InventoryItem* almanach = InventoryItem::make( "Almanach " + PropertyHelper<int>::toString(i), 0.34f, d_root); if (i % 2 == 0) almanach->setIcon("DriveIcons/Lime"); d_root->addItem(almanach); } }
void drawPlayerInfo(PlayerController* player, GameWorld* world, GameRenderer* render) { float infoTextX = render->getRenderer()->getViewport().x - (ui_outerMargin + ui_weaponSize + ui_infoMargin); float infoTextY = 0.f + ui_outerMargin; float iconX = render->getRenderer()->getViewport().x - (ui_outerMargin + ui_weaponSize); float iconY = ui_outerMargin; float wantedX = render->getRenderer()->getViewport().x - (ui_outerMargin); float wantedY = ui_outerMargin + ui_weaponSize + 3.f; TextRenderer::TextInfo ti; ti.font = 1; ti.size = ui_textSize; ti.align = TextRenderer::TextInfo::Right; { std::stringstream ss; ss << std::setw(2) << std::setfill('0') << world->getHour() << std::setw(0) << ":" << std::setw(2) << world->getMinute(); ti.text = ss.str(); } ti.baseColour = ui_shadowColour; ti.screenPosition = glm::vec2(infoTextX + 1.f, infoTextY+1.f); render->text.renderText(ti); ti.baseColour = ui_timeColour; ti.screenPosition = glm::vec2(infoTextX, infoTextY); render->text.renderText(ti); infoTextY += ui_textHeight; ti.text = "$" + std::to_string(world->state->playerInfo.money); ti.baseColour = ui_shadowColour; ti.screenPosition = glm::vec2(infoTextX + 1.f, infoTextY+1.f); render->text.renderText(ti); ti.baseColour = ui_moneyColour; ti.screenPosition = glm::vec2(infoTextX, infoTextY); render->text.renderText(ti); infoTextY += ui_textHeight; { std::stringstream ss; ss << "@" << std::setw(3) << std::setfill('0') << (int)player->getCharacter()->getCurrentState().health; ti.text = ss.str(); } ti.baseColour = ui_shadowColour; ti.screenPosition = glm::vec2(infoTextX + 1.f, infoTextY+1.f); render->text.renderText(ti); ti.baseColour = ui_healthColour; ti.screenPosition = glm::vec2(infoTextX, infoTextY); render->text.renderText(ti); if (player->getCharacter()->getCurrentState().armour > 0) { std::stringstream ss; ss << "[" << std::setw(3) << std::setfill('0') << (int)player->getCharacter()->getCurrentState().armour; ti.text = ss.str(); ti.baseColour = ui_shadowColour; ti.screenPosition = glm::vec2(infoTextX + 1.f - ui_armourOffset, infoTextY+1.f); render->text.renderText(ti); ti.baseColour = ui_armourColour; ti.screenPosition = glm::vec2(infoTextX - ui_armourOffset, infoTextY); render->text.renderText(ti); } std::string s; for (int i = 0; i < ui_maxWantedLevel; ++i) { s += "]"; } ti.text = s; ti.baseColour = ui_shadowColour; ti.screenPosition = glm::vec2(wantedX + 1.f, wantedY + 1.f); render->text.renderText(ti); #if 0 // Useful for debugging ti.text = "ABCDEFGHIJKLMANOQRTSWXYZ\nM0123456789"; ti.size = 30; ti.align = TextRenderer::TextInfo::Left; ti.baseColour = glm::vec3(0.f, 0.f, 0.f); ti.screenPosition = glm::vec2(101.f, 202.f); render->text.renderText(ti); ti.baseColour = glm::vec3(1.f, 1.f, 1.f); ti.screenPosition = glm::vec2(100.f, 200.f); render->text.renderText(ti); #endif InventoryItem *current = player->getCharacter()->getActiveItem(); std::string itemTextureName = "fist"; if (current) { uint16_t model = current->getModelID(); if (model > 0) { ObjectDataPtr weaponData = world ->data ->findObjectType<ObjectData>(model); if (weaponData != nullptr) { itemTextureName = weaponData->modelName; } } } // Urgh if (itemTextureName == "colt45") { itemTextureName = "pistol"; } TextureData::Handle itemTexture = render->getData()->findTexture(itemTextureName); RW_CHECK(itemTexture != nullptr, "Item has 0 texture"); if (itemTexture != nullptr) { RW_CHECK(itemTexture->getName() != 0, "Item has 0 texture"); render->drawTexture(itemTexture.get(), glm::vec4(iconX, iconY, ui_weaponSize, ui_weaponSize)); } if (current) { WeaponItem* wep = static_cast<WeaponItem*>(current); if (wep->getWeaponData()->fireType != WeaponData::MELEE) { const CharacterState& cs = player->getCharacter()->getCurrentState(); const CharacterWeaponSlot& slotInfo = cs.weapons[cs.currentWeapon]; ti.text = std::to_string(slotInfo.bulletsClip) + "-" + std::to_string(slotInfo.bulletsTotal); ti.baseColour = ui_shadowColour; ti.font = 2; ti.size = ui_ammoSize; ti.align = TextRenderer::TextInfo::Center; ti.screenPosition = glm::vec2(iconX + ui_weaponSize / 2.f, iconY + ui_weaponSize - ui_ammoHeight); render->text.renderText(ti); } } }