Esempio n. 1
0
bool UiBarter::SwapFunctor(InventoryObject* object, Inventory& from, Inventory& to)
{
  if (from.IncludesObject(object))
  {
    string                          object_name = object->GetName();
    function<void (unsigned short)> swap_callback([this, &from, &to, object_name](unsigned short quantity)
    {
      while (quantity--)
      {
        InventoryObject* swapping = from.GetObject(object_name);

        to.AddObject(swapping);
        from.DelObject(swapping);
      }
      Update();
      if (_quantity_picker)
        _quantity_picker->SetModal(false);
    });
    
    if (from.ContainsHowMany(object->GetName()) > 1)
    {
      if (_quantity_picker) delete _quantity_picker;
      _quantity_picker = new UiObjectQuantityPicker(window, context, from, object);
      _quantity_picker->SetModal(true);
      _quantity_picker->QuantityPicked.Connect(swap_callback);
      _quantity_picker->Observer.Connect(VisibilityToggledOff, *_quantity_picker, &UiBase::Hide);
    }
    else
      swap_callback(1);
    return (true);
  }
  return (false);
}
Esempio n. 2
0
void UiBarter::DropInventory(Inventory& from, Inventory& to)
{
  Inventory::Content::iterator it, end;

  it  = from.GetContent().begin();
  end = from.GetContent().end();
  while (it != end)
  {
    to.AddObject(*it);
    from.DelObject(*it);
    it = from.GetContent().begin();
  }
}