Beispiel #1
0
int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks)
{
	cItem ToAdd(a_Item);
	int res = 0;

	// When the item is a armor, try to set it directly to the armor slot.
	if (ItemCategory::IsArmor(a_Item.m_ItemType))
	{
		for (int i = 0; i < m_ArmorSlots.GetNumSlots(); i++)
		{
			if (m_ArmorSlots.GetSlot(i).IsEmpty() && cSlotAreaArmor::CanPlaceArmorInSlot(i, a_Item))
			{
				m_ArmorSlots.SetSlot(i, a_Item);
				return a_Item.m_ItemCount;
			}
		}
	}

	for (int SlotIdx = 0; SlotIdx < m_InventorySlots.GetNumSlots(); ++SlotIdx)
	{
		auto & Slot = m_InventorySlots.GetSlot(SlotIdx);
		if (Slot.IsEqual(a_Item))
		{
			cItemHandler Handler(Slot.m_ItemType);
			int AmountToAdd = std::min(static_cast<char>(Handler.GetMaxStackSize() - Slot.m_ItemCount), ToAdd.m_ItemCount);
			res += AmountToAdd;

			cItem SlotAdjusted(Slot);
			SlotAdjusted.m_ItemCount += AmountToAdd;
			m_InventorySlots.SetSlot(SlotIdx, SlotAdjusted);

			ToAdd.m_ItemCount -= AmountToAdd;
			if (ToAdd.m_ItemCount == 0)
			{
				return res;
			}
		}
	}

	res += m_HotbarSlots.AddItem(ToAdd, a_AllowNewStacks);
	ToAdd.m_ItemCount = a_Item.m_ItemCount - res;
	if (ToAdd.m_ItemCount == 0)
	{
		return res;
	}
	
	res += m_InventorySlots.AddItem(ToAdd, a_AllowNewStacks);
	return res;
}
Beispiel #2
0
int cInventory::AddItem(const cItem & a_Item, bool a_AllowNewStacks, bool a_tryToFillEquippedFirst)
{
	cItem ToAdd(a_Item);
	int res = 0;
	if (ItemCategory::IsArmor(a_Item.m_ItemType))
	{
		res = m_ArmorSlots.AddItem(ToAdd, a_AllowNewStacks);
		ToAdd.m_ItemCount -= res;
		if (ToAdd.m_ItemCount == 0)
		{
			return res;
		}
	}

	res += m_HotbarSlots.AddItem(ToAdd, a_AllowNewStacks, a_tryToFillEquippedFirst ? m_EquippedSlotNum : -1);
	ToAdd.m_ItemCount = a_Item.m_ItemCount - res;
	if (ToAdd.m_ItemCount == 0)
	{
		return res;
	}
	
	res += m_InventorySlots.AddItem(ToAdd, a_AllowNewStacks);
	return res;
}
Beispiel #3
0
                       SettingsDialog::Page_Seafile) {
  QSettings s;
  s.beginGroup(kSettingsGroup);
  access_token_ = s.value("access_token").toString();
  server_ = s.value("server").toString();

  QByteArray tree_bytes = s.value("tree").toByteArray();

  if (!tree_bytes.isEmpty()) {
    QDataStream stream(&tree_bytes, QIODevice::ReadOnly);
    stream >> tree_;
  }

  app->player()->RegisterUrlHandler(new SeafileUrlHandler(this, this));

  connect(&tree_, SIGNAL(ToAdd(QString, QString, SeafileTree::Entry)), this,
          SLOT(AddEntry(QString, QString, SeafileTree::Entry)));
  connect(&tree_, SIGNAL(ToDelete(QString, QString, SeafileTree::Entry)), this,
          SLOT(DeleteEntry(QString, QString, SeafileTree::Entry)));
  connect(&tree_, SIGNAL(ToUpdate(QString, QString, SeafileTree::Entry)), this,
          SLOT(UpdateEntry(QString, QString, SeafileTree::Entry)));
}

bool SeafileService::has_credentials() const {
  return !access_token_.isEmpty();
}

void SeafileService::AddAuthorizationHeader(QNetworkRequest* request) const {
  request->setRawHeader("Authorization",
                        QString("Token %1").arg(access_token_).toAscii());
}