void StationShipMarketForm::UpdateShipList()
{
	m_shiplistBox->DeleteAllChildren();

	float line_height = Gui::Screen::GetFontHeight();

	std::vector<ShipFlavour> &ships = m_station->GetShipsOnSale();

	int num = 0;
	for (std::vector<ShipFlavour>::iterator i = ships.begin(); i!=ships.end(); ++i) {
		Gui::Fixed *f = new Gui::Fixed(450, line_height*1.5f);

		Gui::Label *l = new Gui::Label(ShipType::types[(*i).type].name);
		f->Add(l,0,0);
		f->Add(new Gui::Label(format_money((*i).price)), 200, 0);
		f->Add(new Gui::Label(format_money((*i).price - Pi::player->GetFlavour()->price) ), 275, 0);
		f->Add(new Gui::Label(stringf(Lang::NUMBER_TONNES, formatarg("mass", ShipType::types[(*i).type].capacity))), 370, 0);
		
		Gui::SolidButton *sb = new Gui::SolidButton();
		sb->onClick.connect(sigc::bind(sigc::mem_fun(this, &StationShipMarketForm::ViewShip), num));
		f->Add(sb, 430, 0);

		m_shiplistBox->PackEnd(f);

		num++;
	}
}
Esempio n. 2
0
std::string bulk_trade_inquire( const npc &, const itype_id &it )
{
    int you_have = g->u.charges_of( it );
    item tmp( it );
    int item_cost = tmp.price( true );
    tmp.charges = you_have;
    int total_cost = tmp.price( true );
    return string_format( _( "I'm willing to pay %s per batch for a total of %s" ),
                          format_money( item_cost ), format_money( total_cost ) );
}
void talk_function::bionic_remove( npc &p )
{
    bionic_collection all_bio = *g->u.my_bionics;
    if( all_bio.empty() ) {
        popup( _( "You don't have any bionics installed..." ) );
        return;
    }

    std::vector<itype_id> bionic_types;
    std::vector<std::string> bionic_names;
    for( auto &bio : all_bio ) {
        if( std::find( bionic_types.begin(), bionic_types.end(), bio.id.str() ) == bionic_types.end() ) {
            if( bio.id != bionic_id( "bio_power_storage" ) ||
                bio.id != bionic_id( "bio_power_storage_mkII" ) ) {
                bionic_types.push_back( bio.id.str() );
                if( item::type_is_defined( bio.id.str() ) ) {
                    item tmp = item( bio.id.str(), 0 );
                    bionic_names.push_back( tmp.tname() + " - " + format_money( 50000 + ( tmp.price( true ) / 4 ) ) );
                } else {
                    bionic_names.push_back( bio.id.str() + " - " + format_money( 50000 ) );
                }
            }
        }
    }
    // Choose bionic if applicable
    int bionic_index = uilist( _( "Which bionic do you wish to uninstall?" ),
                               bionic_names );
    // Did we cancel?
    if( bionic_index < 0 ) {
        popup( _( "You decide to hold off..." ) );
        return;
    }

    unsigned int price;
    if( item::type_is_defined( bionic_types[bionic_index] ) ) {
        price = 50000 + ( item( bionic_types[bionic_index], 0 ).price( true ) / 4 );
    } else {
        price = 50000;
    }
    if( price > g->u.cash ) {
        popup( _( "You can't afford the procedure..." ) );
        return;
    }

    //Makes the doctor awesome at installing but not perfect
    if( g->u.uninstall_bionic( bionic_id( bionic_types[bionic_index] ), p, false ) ) {
        g->u.cash -= price;
        p.cash += price;
        g->u.amount_of( bionic_types[bionic_index] ); // ??? this does nothing, it just queries the count
    }

}
Esempio n. 4
0
/*
 * Function: Money
 *
 * Create a string representation of the given money value.
 *
 * > string = Format.Money(money)
 * > string = Format.Money(money, showCents)
 *
 * Parameters:
 *
 *   money - a money value, in dollars
 *
 *   showCents - A boolean. If true (default), includes the fractinoal
 *               part of the amount. If false, omitts the fractional
 *               part.
 *
 * Return:
 *
 *   string - the string representation
 *
 * Availability:
 *
 *   alpha 10
 *
 * Status:
 *
 *   stable
 */
static int l_format_money(lua_State *l)
{
	double t = luaL_checknumber(l, 1);
	double intpart;
	modf(t*100.0, &intpart);
	if (lua_isboolean(l, 2)){
		bool show_cents = lua_toboolean(l, 2);
		lua_pushstring(l, format_money(intpart, show_cents).c_str());
	}
	else
		lua_pushstring(l, format_money(intpart).c_str());

	return 1;
}
Esempio n. 5
0
void SpaceStationView::Update()
{
	char buf[64];
	m_money->SetText(format_money(Pi::player->GetMoney()));

	const shipstats_t &stats = Pi::player->GetStats();
	snprintf(buf, sizeof(buf), "%dt", stats.used_capacity - stats.used_cargo);
	m_equipmentMass->SetText(buf);

	snprintf(buf, sizeof(buf), "%dt", stats.used_cargo);
	m_cargoSpaceUsed->SetText(buf);

	snprintf(buf, sizeof(buf), "%dt", stats.free_capacity);
	m_cargoSpaceFree->SetText(buf);

	snprintf(buf, sizeof(buf), "%d", Pi::player->m_equipment.Count(Equip::SLOT_CABIN, Equip::PASSENGER_CABIN));
	m_cabinsUsed->SetText(buf);

	snprintf(buf, sizeof(buf), "%d", Pi::player->m_equipment.Count(Equip::SLOT_CABIN, Equip::UNOCCUPIED_CABIN));
	m_cabinsFree->SetText(buf);

	if (m_formStack->Size() > 1)
		m_backButtonBox->Show();
	else
		m_backButtonBox->Hide();

	if (static_cast<Form*>(m_formStack->Top())->GetType() == Form::BLANK)
		m_statusBox->Hide();
	else
		m_statusBox->Show();
}
void StationShipRepairForm::UpdateLabels()
{
	float hullPercent = Pi::player->GetPercentHull();

	if (hullPercent >= 100.0f)
	{
		m_working->Show();
		m_tableBox->Hide();
	}

	else {
		m_repairAllDesc->SetText(stringf(Lang::REPAIR_ENTIRE_HULL, formatarg("repairpercent", 100.0f - hullPercent)));
		const float hullDamage = 100.0f - hullPercent;
		m_repairOneCost->SetText(format_money(GetRepairCost(std::min(hullDamage, 1.0f))));
		m_repairAllCost->SetText(format_money(GetRepairCost(hullDamage)));

		m_working->Hide();
		m_tableBox->Show();
	}
}
void talk_function::bionic_install( npc &p )
{
    std::vector<item *> bionic_inv = g->u.items_with( []( const item & itm ) {
        return itm.is_bionic();
    } );
    if( bionic_inv.empty() ) {
        popup( _( "You have no bionics to install!" ) );
        return;
    }

    std::vector<itype_id> bionic_types;
    std::vector<std::string> bionic_names;
    for( auto &bio : bionic_inv ) {
        if( std::find( bionic_types.begin(), bionic_types.end(), bio->typeId() ) == bionic_types.end() ) {
            if( !g->u.has_bionic( bionic_id( bio->typeId() ) ) || bio->typeId() ==  "bio_power_storage" ||
                bio->typeId() ==  "bio_power_storage_mkII" ) {

                bionic_types.push_back( bio->typeId() );
                bionic_names.push_back( bio->tname() + " - " + format_money( bio->price( true ) * 2 ) );
            }
        }
    }
    // Choose bionic if applicable
    int bionic_index = uilist( _( "Which bionic do you wish to have installed?" ),
                               bionic_names );
    // Did we cancel?
    if( bionic_index < 0 ) {
        popup( _( "You decide to hold off..." ) );
        return;
    }

    const item tmp = item( bionic_types[bionic_index], 0 );
    const itype &it = *tmp.type;
    unsigned int price = tmp.price( true ) * 2;

    if( price > g->u.cash ) {
        popup( _( "You can't afford the procedure..." ) );
        return;
    }

    //Makes the doctor awesome at installing but not perfect
    if( g->u.install_bionics( it, p, false, 20 ) ) {
        g->u.cash -= price;
        p.cash += price;
        g->u.amount_of( bionic_types[bionic_index] );
        std::vector<item_comp> comps;
        comps.push_back( item_comp( tmp.typeId(), 1 ) );
        g->u.consume_items( comps, 1 );
    }
}
Esempio n. 8
0
void print_list(My402List *list)
{
	print_title();

    My402ListElem * elem = NULL;
    int balance_value = 0, amount_value = 0;
    for (elem = My402ListFirst(list); elem != NULL; elem = My402ListNext(list, elem))
    {
        My402TransData * data = (My402TransData *)(elem -> obj);
        char line[LINE_LENGTH + 1], buffer[26];
        time_t timestamp;
        timestamp = data -> timestamp;
        strncpy(buffer, ctime(&timestamp), sizeof(buffer));
        format_line(line);
        format_time(line, buffer, 2);
        format_description(line, data -> description, 19);
        amount_value = cal_amount(data -> amount, data -> type);
        format_money(line, amount_value, 46, 61);
        balance_value = cal_balance(balance_value, data -> amount, data -> type);
        format_money(line, balance_value, 63, 78);
        fprintf(stdout, "%s\n", line);
    }
    print_line();
}
Esempio n. 9
0
void print_list(My402List *list)
{
	print_title();

    My402ListElem * elem = NULL;
    long long balance_value = 0;
    int amount_value = 0;
    for (elem = My402ListFirst(list); elem != NULL; elem = My402ListNext(list, elem))
    {
        My402TransData * data = (My402TransData *)(elem -> obj);
        char buffer[26], date[16], description[25], amount[15], balance[15];
        time_t timestamp;
        timestamp = data -> timestamp;
        strncpy(buffer, ctime(&timestamp), sizeof(buffer));
        format_time(date, buffer);
        format_description(description, data -> description);
        amount_value = cal_amount(data -> amount, data -> type);
        format_money(amount, amount_value);
        balance_value = cal_balance(balance_value, data -> amount, data -> type);
        format_money(balance, balance_value);
        print_data(date, description, amount, balance);
    }
    print_line();
}
Esempio n. 10
0
NumberLabel *NumberLabel::SetValue(double v)
{
	m_value = v;
	switch (m_format) {
		case FORMAT_NUMBER_2DP:
			SetText(to_string(v, "f.2"));
			break;

		case FORMAT_INTEGER:
			SetText(to_string(Uint32(v+0.5), "u"));
			break;

		case FORMAT_PERCENT:
			SetText(stringf("%0{f.2}%%", v*100.0));
			break;

		case FORMAT_PERCENT_INTEGER:
			SetText(stringf("%0{u}%%", Uint32(v*100.0+0.5)));
			break;

		case FORMAT_MASS_TONNES:
			SetText(stringf(Lang::NUMBER_TONNES, formatarg("mass", v)));
			break;

		case FORMAT_MONEY:
			SetText(format_money(Sint64(v*100)));
			break;

		case FORMAT_DISTANCE_M:
			SetText(format_distance(v, 3));
			break;

		case FORMAT_DISTANCE_LY:
			SetText(stringf(Lang::NUMBER_LY, formatarg("distance", v)));
			break;

		default:
		case FORMAT_NUMBER:
			SetText(to_string(v, "f"));
			break;
	}

	return this;
}
Esempio n. 11
0
void FormatProductSummary()
{
  FORMAT_PRODUCTS_REC *prodptr;
  int i=0;
  char *money;

  trace("FormatProductSummary","writing to page structure");

  /* reset formatted flag on OCC array */
  mark_unformatted(new_charge_array);

  /* for each product, do RC, NRC, USAGE, DISCOUNT, and TAXES tables */
  for( i=0; i<=UsesRA(format_products_rec_array); i++)
  {
    prodptr = (FORMAT_PRODUCTS_REC *) RAIndex(format_products_rec_array, i);
    
    g_curr_prod = prodptr->product_line_id;
    ARB_NUM_SET_ZERO (&g_table_grand_total);
    /* supress automatic page handling on first page */
    g_curr_page = 0;
    if (/* bpr_table(new_charge_array, TABLE_COUNT) || all RCs are in rc_table */
	rc_table(new_charge_array, TABLE_COUNT) ||
	nrc_table(new_charge_array, TABLE_COUNT) ||
	usage_table(new_charge_array, TABLE_COUNT)) {
      do_new_page();
      LINE_FEED(2);
      write_product_header(g_curr_page, g_curr_prod); 
      /* enable automatic page handling */
      g_curr_page = PAGE_ACTIVITY_SUMMARY;
      /* write_table(BPR_TABLE, new_charge_array, bpr_table); all RCs are in rc_table */
      write_table(RC_TABLE, new_charge_array, rc_table);
      write_table(NRC_TABLE, new_charge_array, nrc_table);
      write_table(USAGE_TABLE, new_charge_array, usage_table);

      /* write the line if we've printed a table so far and we're 
       * going to be printing another table on the page
       */
      if ((!arb_num_is_zero (&g_table_grand_total)) && 
	  (discount_table(new_charge_array, TABLE_COUNT))) {
        safe_line_feed(3);
	put_bill_rectangle(COL_TABLE_RECT, 
				  TINY_AMOUNT_YOU_PAY_RECT, MONEY_ADJUST);
        put_bill_markup(get_markup(MARKUP_SUBTOTAL_NEW_CHARGES));
	LINE_FEED(-1);
	ALIGN(ALEFT);
        putf_bill(COL_TABLE_TOTAL,get_field(SUBTOTAL_NEW_CHARGES),
	    get_product_line_desc(prodptr->product_line_id));
	money=format_money(&g_table_grand_total,DOLLAR_SIGN,NULL,MINUS_POS, bill_inv.currency);
	flush_right(money);

	SET_CURRENCY(bill_inv.currency);

	set_generic_text(BOLD_FIXED, money);
	MONEY_put_bill(COL_TABLE_AMOUNT, get_generic(BOLD_FIXED), VOL);
	ALIGN(ALEFT);
        safe_line_feed(2);
      }
      
      write_table(DISCOUNT_TABLE, new_charge_array, discount_table);

      /* page footer */
      safe_line_feed(3);
      put_bill_rectangle(COL_TABLE_RECT, 
				TINY_AMOUNT_YOU_PAY_RECT, MONEY_ADJUST);
      put_bill_markup(get_markup(MARKUP_NET_NEW_CHARGES));
      LINE_FEED(-1);
      ALIGN(ALEFT);
      putf_bill(COL_TABLE_TOTAL, get_field(NET_NEW_CHARGES), 
	       get_product_line_desc(prodptr->product_line_id));
      money=format_money(&g_table_grand_total,DOLLAR_SIGN,NULL,MINUS_POS, bill_inv.currency);
      flush_right(money);

      SET_CURRENCY(bill_inv.currency);

      set_generic_text(BOLD_FIXED, money);
      ALIGN(AMONEY);
      put_bill(COL_TABLE_AMOUNT, get_generic(BOLD_FIXED), VOL);
      ALIGN(ALEFT);
    }
  }
  g_curr_page = 0;
}
Esempio n. 12
0
static void finish_table (void)
{   
  Arb_numeric amount;
  char *money;
  int rows_required;
  WRAPVECT wrapv;
  char *text;

  /* for long tables, we put the total amount even with the last row of the 
   * table.  (Note this requires putting the shaded box on the row *after* the
   * last row, which is where the cursor starts.)
   * For shorter tables, we make sure that the text above the total does not go
   * above the first line of the table, or g_top_of_table.
   * The rows required are 2 + the number of rows of text.
   * (1 row of text except for RC, NRC, and USAGE tables.)
   *
   * In addition, the page delimiter is written two rows about ROW_BOTTOM, 
   * so rows_required has 2 added to it.
   */

  if (NUM_ROWS_LEFT <= 3)
      safe_line_feed(NUM_ROWS_LEFT);

  safe_line_feed(1);
  /* write the label */
  ALIGN(ALEFT);
  switch (g_curr_table)
    {
      case PAYMENTS_TABLE:
        put_bill_markup(get_markup(MARKUP_TOTAL_PAY_FOOTER));
	put_bill(COL_TABLE_TOTAL, get_field(TOTAL_PAY_FOOTER), NONVOL);
	break;
	
      case ADJUSTMENTS_TABLE:
        put_bill_markup(get_markup(MARKUP_TOTAL_ADJ_FOOTER));
	put_bill(COL_TABLE_TOTAL, get_field(TOTAL_ADJ_FOOTER), NONVOL);
	break;
       
      case OCC_TABLE:
        put_bill_markup(get_markup(MARKUP_TOTAL_OTHER_FOOTER));
	put_bill(COL_TABLE_TOTAL, get_field(TOTAL_OTHER_FOOTER), NONVOL);
	break;
       
      case COMPONENT_TABLE:
        put_bill_markup(get_markup(MARKUP_COMPONENT_CHGS_FOOTER));
	putf_bill(COL_TABLE_TOTAL,get_field(COMPONENT_CHGS_FOOTER),g_curr_owning);
	break;

      case RC_TABLE:
        put_bill_markup(get_markup(MARKUP_RC_CHGS_FOOTER));
	put_bill(COL_TABLE_TOTAL, get_field(RC_CHGS_FOOTER), NONVOL);
	break;
	
      case NRC_TABLE:
        put_bill_markup(get_markup(MARKUP_NRC_CHGS_FOOTER));
	put_bill(COL_TABLE_TOTAL, get_field(NRC_CHGS_FOOTER),NONVOL);
	break;

      case USAGE_TABLE:
        put_bill_markup(get_markup(MARKUP_USAGE_CHGS_FOOTER));
	put_bill(COL_TABLE_TOTAL, get_field(USAGE_CHGS_FOOTER), NONVOL);
	break;

      case DISCOUNT_TABLE:
        put_bill_markup(get_markup(MARKUP_DISCOUNT_FOOTER));
	put_bill(COL_TABLE_TOTAL, get_field(DISC_FOOTER), NONVOL);
	break;

      case BPR_TABLE:
        put_bill_markup(get_markup(MARKUP_BPR_CHGS_FOOTER));
	put_bill(COL_TABLE_TOTAL, get_field(BPR_CHGS_FOOTER), NONVOL);
	break;
      }

     LINE_FEED(1);
     put_bill_rectangle(COL_TABLE_RECT,TINY_AMOUNT_YOU_PAY_RECT, MONEY_ADJUST);

  /* undo last line feed from table */
  LINE_FEED(-1);

  /* write the amount */
  amount = g_table_total;
  money=format_money(&amount,DOLLAR_SIGN,NULL,MINUS_POS, bill_inv.currency);
  flush_right(money);

  SET_CURRENCY(bill_inv.currency);

  set_generic_text(BOLD_FIXED, money);
  MONEY_put_bill_FEED(COL_TABLE_AMOUNT, get_generic(BOLD_FIXED), VOL);
  g_in_a_table = FALSE;
  put_bill_markup(get_markup(MARKUP_TABLE_END));
  ALIGN(ALEFT);
} /* finish_table */
Esempio n. 13
0
	virtual void UpdateInfo() {
		const float YSEP = Gui::Screen::GetFontHeight() * 1.5f;
		DeleteAllChildren();

		Gui::Label *l = new Gui::Label(Lang::MISSIONS);
		Add(l, 20, 20);

		l = new Gui::Label(Lang::TYPE);
		Add(l, 20, 20+YSEP*2);
		
		l = new Gui::Label(Lang::CLIENT);
		Add(l, 100, 20+YSEP*2);
		
		l = new Gui::Label(Lang::LOCATION);
		Add(l, 260, 20+YSEP*2);
		
		l = new Gui::Label(Lang::DUE);
		Add(l, 420, 20+YSEP*2);
		
		l = new Gui::Label(Lang::REWARD);
		Add(l, 580, 20+YSEP*2);

		l = new Gui::Label(Lang::STATUS);
		Add(l, 680, 20+YSEP*2);

		ShowChildren();

		Gui::VScrollBar *scroll = new Gui::VScrollBar();
		Gui::VScrollPortal *portal = new Gui::VScrollPortal(760);
		scroll->SetAdjustment(&portal->vscrollAdjust);

		const std::list<const Mission*> &missions = Pi::player->missions.GetAll();
		Gui::Fixed *innerbox = new Gui::Fixed(760, YSEP*3 * missions.size());

		float ypos = 0;
		for (std::list<const Mission*>::const_iterator i = missions.begin(); i != missions.end(); ++i) {
			SystemPath path = (*i)->location;
			StarSystem *s = StarSystem::GetCached(path);
			SBody *sbody = s->GetBodyByPath(&path);

			l = new Gui::Label((*i)->type);
			innerbox->Add(l, 0, ypos);
			
			l = new Gui::Label((*i)->client);
			innerbox->Add(l, 80, ypos);
			
			l = new Gui::Label(stringf("%0,\n%1 [%2{d},%3{d},%4{d}]", sbody->name.c_str(), s->GetName().c_str(), path.sectorX, path.sectorY, path.sectorZ));
			innerbox->Add(l, 240, ypos);
			
			l = new Gui::Label(format_date((*i)->due));
			innerbox->Add(l, 400, ypos);

			l = new Gui::Label(format_money((*i)->reward));
			innerbox->Add(l, 560, ypos);

			switch ((*i)->status) {
                case Mission::FAILED: l = new Gui::Label(std::string("#f00")+std::string(Lang::FAILED)); break;
                case Mission::COMPLETED: l = new Gui::Label(std::string("#ff0")+std::string(Lang::COMPLETED)); break;
				default:
                case Mission::ACTIVE: l = new Gui::Label(std::string("#0f0")+std::string(Lang::ACTIVE)); break;
			}
			innerbox->Add(l, 660, ypos);

			ypos += YSEP*3;
		}
		Add(portal, 20, 20 + YSEP*3);
		Add(scroll, 780, 20 + YSEP*3);
		scroll->ShowAll();
		portal->Add(innerbox);
		portal->ShowAll();
	}
Esempio n. 14
0
/*
 * Function: Money
 *
 * Create a string representation of the given money value.
 *
 * > string = Format.Money(money)
 *
 * Parameters:
 *
 *   money - a money value, in dollars
 *
 * Return:
 *
 *   string - the string representation
 *
 * Availability:
 *
 *   alpha 10
 *
 * Status:
 *
 *   stable
 */
static int l_format_money(lua_State *l)
{
	double t = luaL_checknumber(l, 1);
	lua_pushstring(l, format_money(Sint64(t*100.0)).c_str());
	return 1;
}
StationShipEquipmentForm::StationShipEquipmentForm(FormController *controller) : FaceForm(controller)
{
    m_station = Pi::player->GetDockedWith();

    SetTitle(stringf(Lang::SOMEWHERE_SHIP_EQUIPMENT, formatarg("station", m_station->GetLabel())));

    Gui::VScrollBar *scroll = new Gui::VScrollBar();
    Gui::VScrollPortal *portal = new Gui::VScrollPortal(450);
    scroll->SetAdjustment(&portal->vscrollAdjust);

    int NUM_ITEMS = 0;
    const float YSEP = floor(Gui::Screen::GetFontHeight() * 1.5f);
    for (int i=Equip::FIRST_SHIPEQUIP; i<=Equip::LAST_SHIPEQUIP; i++) {
        if (m_station->GetStock(static_cast<Equip::Type>(i)))
            NUM_ITEMS++;
    }

    Gui::VBox *outerbox = new Gui::VBox();

    Gui::Fixed *innerbox = new Gui::Fixed(450, NUM_ITEMS*YSEP);
    innerbox->SetTransparency(true);

    for (int i=Equip::FIRST_SHIPEQUIP, num=0; i<=Equip::LAST_SHIPEQUIP; i++) {
        Equip::Type type = static_cast<Equip::Type>(i);
        int stock = m_station->GetStock(type);
        if (!stock) continue;
        Gui::Label *l = new Gui::Label(Equip::types[i].name);
        if (Equip::types[i].description) {
            l->SetToolTip(Equip::types[i].description);
        }
        innerbox->Add(l,0,num*YSEP);

        innerbox->Add(new Gui::Label(format_money(m_station->GetPrice(type))), 200, num*YSEP);

        innerbox->Add(new Gui::Label(format_money(REMOVAL_VALUE_PERCENT * m_station->GetPrice(type) / 100)),
                      275, num*YSEP);

        innerbox->Add(new Gui::Label(stringf(Lang::NUMBER_TONNES, formatarg("mass", Equip::types[i].mass))), 360, num*YSEP);

        ButtonPair pair;
        pair.type = type;

        pair.add = new Gui::SolidButton();
        pair.add->onClick.connect(sigc::bind(sigc::mem_fun(this, &StationShipEquipmentForm::FitItem), type));
        innerbox->Add(pair.add, 400, num*YSEP);

        pair.remove = new Gui::SolidButton();
        pair.remove->onClick.connect(sigc::bind(sigc::mem_fun(this, &StationShipEquipmentForm::RemoveItem), type));
        innerbox->Add(pair.remove, 420, num*YSEP);

        m_buttons.push_back(pair);

        num++;
    }

    portal->Add(innerbox);

    Gui::Fixed *heading = new Gui::Fixed(470, Gui::Screen::GetFontHeight());
    const float *col = Gui::Theme::Colors::tableHeading;
    heading->Add((new Gui::Label(Lang::ITEM))->Color(col), 0, 0);
    heading->Add((new Gui::Label(Lang::PRICE_TO_FIT))->Color(col), 200, 0);
    heading->Add((new Gui::Label(Lang::PRICE_TO_REMOVE))->Color(col), 275, 0);
    heading->Add((new Gui::Label(Lang::WT))->Color(col), 360, 0);
    heading->Add((new Gui::Label(Lang::FIT))->Color(col), 400, 0);
    heading->Add((new Gui::Label(Lang::REMOVE))->Color(col), 420, 0);
    outerbox->PackEnd(heading);

    Gui::HBox *body = new Gui::HBox();
    body->PackEnd(portal);
    body->PackEnd(scroll);
    outerbox->PackEnd(body);

    outerbox->SetSpacing(YSEP-Gui::Screen::GetFontHeight());
    Add(outerbox, 0, 0);

}
Esempio n. 16
0
StationShipViewForm::StationShipViewForm(FormController *controller, int marketIndex) :
	BlankForm(controller),
	m_marketIndex(marketIndex)
{
	m_station = Pi::player->GetDockedWith();

	m_flavour = m_station->GetShipsOnSale()[marketIndex];

	const ShipType &type = ShipType::types[m_flavour.type];

	SetTitle(stringf(Lang::SOMEWHERE_SHIP_MARKET, formatarg("station", m_station->GetLabel())));

	Add(new ShipSpinnerWidget(m_flavour, 400, 400), 0, 0);


	Gui::VBox *layoutBox = new Gui::VBox();
	layoutBox->SetSpacing(10.0f);
	Add(layoutBox, 420, 0);

	Gui::HBox *statsBox = new Gui::HBox();
	statsBox->SetSpacing(20.0f);
	layoutBox->PackEnd(statsBox);

	Gui::VBox *labelBox = new Gui::VBox();
	labelBox->PackEnd(new Gui::Label(Lang::SHIP_TYPE));
	labelBox->PackEnd(new Gui::Label(Lang::PRICE));
	labelBox->PackEnd(new Gui::Label(Lang::PART_EX));
	labelBox->PackEnd(new Gui::Label(Lang::REGISTRATION_ID));
	labelBox->PackEnd(new Gui::Label(" "));
	labelBox->PackEnd(new Gui::Label(Lang::WEIGHT_EMPTY));
	labelBox->PackEnd(new Gui::Label(Lang::WEIGHT_FULLY_LADEN));
	labelBox->PackEnd(new Gui::Label(Lang::CAPACITY));
	labelBox->PackEnd(new Gui::Label(" "));
	labelBox->PackEnd(new Gui::Label(Lang::FORWARD_ACCEL_EMPTY));
	labelBox->PackEnd(new Gui::Label(Lang::FORWARD_ACCEL_LADEN));
	labelBox->PackEnd(new Gui::Label(Lang::REVERSE_ACCEL_EMPTY));
	labelBox->PackEnd(new Gui::Label(Lang::REVERSE_ACCEL_LADEN));
	labelBox->PackEnd(new Gui::Label(" "));
	labelBox->PackEnd(new Gui::Label(Lang::HYPERDRIVE_FITTED));
	statsBox->PackEnd(labelBox);

	float forward_accel_empty = type.linThrust[ShipType::THRUSTER_FORWARD] / (-9.81f*1000.0f*(type.hullMass));
	float forward_accel_laden = type.linThrust[ShipType::THRUSTER_FORWARD] / (-9.81f*1000.0f*(type.hullMass+type.capacity));
	float reverse_accel_empty = -type.linThrust[ShipType::THRUSTER_REVERSE] / (-9.81f*1000.0f*(type.hullMass));
	float reverse_accel_laden = -type.linThrust[ShipType::THRUSTER_REVERSE] / (-9.81f*1000.0f*(type.hullMass+type.capacity));

	Gui::VBox *dataBox = new Gui::VBox();
	dataBox->PackEnd(new Gui::Label(type.name));
	dataBox->PackEnd(new Gui::Label(format_money(m_flavour.price)));
	dataBox->PackEnd(new Gui::Label(format_money(m_flavour.price - Pi::player->GetFlavour()->price)));
	dataBox->PackEnd(new Gui::Label(m_flavour.regid));
	dataBox->PackEnd(new Gui::Label(" "));
	dataBox->PackEnd(new Gui::Label(stringf(Lang::NUMBER_TONNES, formatarg("mass", type.hullMass))));
	dataBox->PackEnd(new Gui::Label(stringf(Lang::NUMBER_TONNES, formatarg("mass", type.hullMass + type.capacity))));
	dataBox->PackEnd(new Gui::Label(stringf( Lang::NUMBER_TONNES, formatarg("mass", type.capacity))));
	dataBox->PackEnd(new Gui::Label(" "));
	dataBox->PackEnd(new Gui::Label(stringf(Lang::NUMBER_G, formatarg("acceleration", forward_accel_empty))));
	dataBox->PackEnd(new Gui::Label(stringf(Lang::NUMBER_G, formatarg("acceleration", forward_accel_laden))));
	dataBox->PackEnd(new Gui::Label(stringf(Lang::NUMBER_G, formatarg("acceleration", reverse_accel_empty))));
	dataBox->PackEnd(new Gui::Label(stringf(Lang::NUMBER_G, formatarg("acceleration", reverse_accel_laden))));
	dataBox->PackEnd(new Gui::Label(" "));
	dataBox->PackEnd(new Gui::Label(EquipType::types[type.hyperdrive].name));
	statsBox->PackEnd(dataBox);


	Gui::HBox *row = new Gui::HBox();
	row->SetSpacing(10.0f);

	int row_size = 5, pos = 0;
	for (int drivetype = Equip::DRIVE_CLASS1; drivetype <= Equip::DRIVE_CLASS9; drivetype++) {
		if (type.capacity < EquipType::types[drivetype].mass)
			break;

		int hyperclass = EquipType::types[drivetype].pval;
		// for the sake of hyperspace range, we count ships mass as 60% of original.
		float range = Pi::CalcHyperspaceRange(hyperclass, type.hullMass + type.capacity);

		Gui::VBox *cell = new Gui::VBox();
		row->PackEnd(cell);

		cell->PackEnd(new Gui::Label(stringf(Lang::CLASS_NUMBER, formatarg("class", hyperclass))));
		if (type.capacity < EquipType::types[drivetype].mass)
			cell->PackEnd(new Gui::Label("---"));
		else
			cell->PackEnd(new Gui::Label(stringf(Lang::NUMBER_LY, formatarg("distance", range))));

		if (++pos == row_size) {
			layoutBox->PackEnd(row);

			row = new Gui::HBox();
			row->SetSpacing(15.0f);

			pos = 0;
		}
	}

	if (pos > 0)
		layoutBox->PackEnd(row);


	Gui::HBox *buttonBox = new Gui::HBox();
	buttonBox->SetSpacing(5.0f);

	Gui::SolidButton *b = new Gui::SolidButton();
	b->onClick.connect(sigc::mem_fun(this, &StationShipViewForm::BuyShip));
	buttonBox->PackEnd(b);
	buttonBox->PackEnd(new Gui::Label(Lang::BUY_THIS_SHIP));
	Add(buttonBox, 650, 30);
}
Esempio n. 17
0
// Pick up items at (pos).
void Pickup::pick_up( const tripoint &pos, int min )
{
    int cargo_part = -1;

    const optional_vpart_position vp = g->m.veh_at( pos );
    vehicle *const veh = veh_pointer_or_null( vp );
    bool from_vehicle = false;

    if( min != -1 ) {
        switch( interact_with_vehicle( veh, pos, vp ? vp->part_index() : -1 ) ) {
            case DONE:
                return;
            case ITEMS_FROM_CARGO: {
                const cata::optional<vpart_reference> carg = vp.part_with_feature( "CARGO", false );
                cargo_part = carg ? carg->part_index() : -1;
            }
            from_vehicle = cargo_part >= 0;
            break;
            case ITEMS_FROM_GROUND:
                // Nothing to change, default is to pick from ground anyway.
                if( g->m.has_flag( "SEALED", pos ) ) {
                    return;
                }

                break;
        }
    }

    if( !from_vehicle ) {
        bool isEmpty = ( g->m.i_at( pos ).empty() );

        // Hide the pickup window if this is a toilet and there's nothing here
        // but water.
        if( ( !isEmpty ) && g->m.furn( pos ) == f_toilet ) {
            isEmpty = true;
            for( auto maybe_water : g->m.i_at( pos ) ) {
                if( maybe_water.typeId() != "water" ) {
                    isEmpty = false;
                    break;
                }
            }
        }

        if( isEmpty && ( min != -1 || !get_option<bool>( "AUTO_PICKUP_ADJACENT" ) ) ) {
            return;
        }
    }

    // which items are we grabbing?
    std::vector<item> here;
    if( from_vehicle ) {
        auto vehitems = veh->get_items( cargo_part );
        here.resize( vehitems.size() );
        std::copy( vehitems.begin(), vehitems.end(), here.begin() );
    } else {
        auto mapitems = g->m.i_at( pos );
        here.resize( mapitems.size() );
        std::copy( mapitems.begin(), mapitems.end(), here.begin() );
    }

    if( min == -1 ) {
        // Recursively pick up adjacent items if that option is on.
        if( get_option<bool>( "AUTO_PICKUP_ADJACENT" ) && g->u.pos() == pos ) {
            //Autopickup adjacent
            direction adjacentDir[8] = {NORTH, NORTHEAST, EAST, SOUTHEAST, SOUTH, SOUTHWEST, WEST, NORTHWEST};
            for( auto &elem : adjacentDir ) {

                tripoint apos = tripoint( direction_XY( elem ), 0 );
                apos += pos;

                pick_up( apos, min );
            }
        }

        // Bail out if this square cannot be auto-picked-up
        if( g->check_zone( zone_type_id( "NO_AUTO_PICKUP" ), pos ) ) {
            return;
        } else if( g->m.has_flag( "SEALED", pos ) ) {
            return;
        }
    }

    // Not many items, just grab them
    if( ( int )here.size() <= min && min != -1 ) {
        g->u.assign_activity( activity_id( "ACT_PICKUP" ) );
        g->u.activity.placement = pos - g->u.pos();
        g->u.activity.values.push_back( from_vehicle );
        // Only one item means index is 0.
        g->u.activity.values.push_back( 0 );
        // auto-pickup means pick up all.
        g->u.activity.values.push_back( 0 );
        return;
    }

    std::vector<std::list<item_idx>> stacked_here;
    for( size_t i = 0; i < here.size(); i++ ) {
        item &it = here[i];
        bool found_stack = false;
        for( auto &stack : stacked_here ) {
            if( stack.begin()->_item.stacks_with( it ) ) {
                item_idx el = { it, i };
                stack.push_back( el );
                found_stack = true;
                break;
            }
        }
        if( !found_stack ) {
            std::list<item_idx> newstack;
            newstack.push_back( { it, i } );
            stacked_here.push_back( newstack );
        }
    }
    std::reverse( stacked_here.begin(), stacked_here.end() );

    if( min != -1 ) { // don't bother if we're just autopickuping
        g->temp_exit_fullscreen();
    }
    bool sideStyle = use_narrow_sidebar();

    // Otherwise, we have Autopickup, 2 or more items and should list them, etc.
    int maxmaxitems = sideStyle ? TERMY : getmaxy( g->w_messages ) - 3;

    int itemsH = std::min( 25, TERMY / 2 );
    int pickupBorderRows = 3;

    // The pickup list may consume the entire terminal, minus space needed for its
    // header/footer and the item info window.
    int minleftover = itemsH + pickupBorderRows;
    if( maxmaxitems > TERMY - minleftover ) {
        maxmaxitems = TERMY - minleftover;
    }

    const int minmaxitems = sideStyle ? 6 : 9;

    std::vector<pickup_count> getitem( stacked_here.size() );

    int maxitems = stacked_here.size();
    maxitems = ( maxitems < minmaxitems ? minmaxitems : ( maxitems > maxmaxitems ? maxmaxitems :
                 maxitems ) );

    int itemcount = 0;

    if( min == -1 ) { //Auto Pickup, select matching items
        if( !select_autopickup_items( stacked_here, getitem ) ) {
            // If we didn't find anything, bail out now.
            return;
        }
    } else {
        int pickupH = maxitems + pickupBorderRows;
        int pickupW = getmaxx( g->w_messages );
        int pickupY = VIEW_OFFSET_Y;
        int pickupX = getbegx( g->w_messages );

        int itemsW = pickupW;
        int itemsY = sideStyle ? pickupY + pickupH : TERMY - itemsH;
        int itemsX = pickupX;

        catacurses::window w_pickup = catacurses::newwin( pickupH, pickupW, pickupY, pickupX );
        catacurses::window w_item_info = catacurses::newwin( itemsH,  itemsW,  itemsY,  itemsX );

        std::string action;
        long raw_input_char = ' ';
        input_context ctxt( "PICKUP" );
        ctxt.register_action( "UP" );
        ctxt.register_action( "DOWN" );
        ctxt.register_action( "RIGHT" );
        ctxt.register_action( "LEFT" );
        ctxt.register_action( "NEXT_TAB", _( "Next page" ) );
        ctxt.register_action( "PREV_TAB", _( "Previous page" ) );
        ctxt.register_action( "SCROLL_UP" );
        ctxt.register_action( "SCROLL_DOWN" );
        ctxt.register_action( "CONFIRM" );
        ctxt.register_action( "SELECT_ALL" );
        ctxt.register_action( "QUIT", _( "Cancel" ) );
        ctxt.register_action( "ANY_INPUT" );
        ctxt.register_action( "HELP_KEYBINDINGS" );
        ctxt.register_action( "FILTER" );

        int start = 0;
        int cur_it = 0;
        bool update = true;
        mvwprintw( w_pickup, 0, 0, _( "PICK UP" ) );
        int selected = 0;
        int iScrollPos = 0;

        std::string filter;
        std::string new_filter;
        std::vector<int> matches;//Indexes of items that match the filter
        bool filter_changed = true;
        if( g->was_fullscreen ) {
            g->draw_ter();
        }
        // Now print the two lists; those on the ground and about to be added to inv
        // Continue until we hit return or space
        do {
            const std::string pickup_chars =
                ctxt.get_available_single_char_hotkeys( "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ:;" );
            int idx = -1;
            for( int i = 1; i < pickupH; i++ ) {
                mvwprintw( w_pickup, i, 0,
                           "                                                " );
            }
            if( action == "ANY_INPUT" &&
                raw_input_char >= '0' && raw_input_char <= '9' ) {
                int raw_input_char_value = ( char )raw_input_char - '0';
                itemcount *= 10;
                itemcount += raw_input_char_value;
                if( itemcount < 0 ) {
                    itemcount = 0;
                }
            } else if( action == "SCROLL_UP" ) {
                iScrollPos--;
            } else if( action == "SCROLL_DOWN" ) {
                iScrollPos++;
            } else if( action == "PREV_TAB" ) {
                if( start > 0 ) {
                    start -= maxitems;
                } else {
                    start = ( int )( ( matches.size() - 1 ) / maxitems ) * maxitems;
                }
                selected = start;
                mvwprintw( w_pickup, maxitems + 2, 0, "         " );
            } else if( action == "NEXT_TAB" ) {
                if( start + maxitems < ( int )matches.size() ) {
                    start += maxitems;
                } else {
                    start = 0;
                }
                iScrollPos = 0;
                selected = start;
                mvwprintw( w_pickup, maxitems + 2, pickupH, "            " );
            } else if( action == "UP" ) {
                selected--;
                iScrollPos = 0;
                if( selected < 0 ) {
                    selected = matches.size() - 1;
                    start = ( int )( matches.size() / maxitems ) * maxitems;
                    if( start >= ( int )matches.size() ) {
                        start -= maxitems;
                    }
                } else if( selected < start ) {
                    start -= maxitems;
                }
            } else if( action == "DOWN" ) {
                selected++;
                iScrollPos = 0;
                if( selected >= ( int )matches.size() ) {
                    selected = 0;
                    start = 0;
                } else if( selected >= start + maxitems ) {
                    start += maxitems;
                }
            } else if( selected >= 0 && selected < int( matches.size() ) &&
                       ( ( action == "RIGHT" && !getitem[matches[selected]].pick ) ||
                         ( action == "LEFT" && getitem[matches[selected]].pick ) ) ) {
                idx = selected;
            } else if( action == "FILTER" ) {
                new_filter = filter;
                string_input_popup popup;
                popup
                .title( _( "Set filter" ) )
                .width( 30 )
                .edit( new_filter );
                if( !popup.canceled() ) {
                    filter_changed = true;
                } else {
                    wrefresh( g->w_terrain );
                }
            } else if( action == "ANY_INPUT" && raw_input_char == '`' ) {
                std::string ext = string_input_popup()
                                  .title( _( "Enter 2 letters (case sensitive):" ) )
                                  .width( 3 )
                                  .max_length( 2 )
                                  .query_string();
                if( ext.size() == 2 ) {
                    int p1 = pickup_chars.find( ext.at( 0 ) );
                    int p2 = pickup_chars.find( ext.at( 1 ) );
                    if( p1 != -1 && p2 != -1 ) {
                        idx = pickup_chars.size() + ( p1 * pickup_chars.size() ) + p2;
                    }
                }
            } else if( action == "ANY_INPUT" ) {
                idx = ( raw_input_char <= 127 ) ? pickup_chars.find( raw_input_char ) : -1;
                iScrollPos = 0;
            }

            if( idx >= 0 && idx < ( int )matches.size() ) {
                size_t true_idx = matches[idx];
                if( itemcount != 0 || getitem[true_idx].count == 0 ) {
                    item &temp = stacked_here[true_idx].begin()->_item;
                    int amount_available = temp.count_by_charges() ? temp.charges : stacked_here[true_idx].size();
                    if( itemcount >= amount_available ) {
                        itemcount = 0;
                    }
                    getitem[true_idx].count = itemcount;
                    itemcount = 0;
                }

                // Note: this might not change the value of getitem[idx] at all!
                getitem[true_idx].pick = ( action == "RIGHT" ? true :
                                           ( action == "LEFT" ? false :
                                             !getitem[true_idx].pick ) );
                if( action != "RIGHT" && action != "LEFT" ) {
                    selected = idx;
                    start = ( int )( idx / maxitems ) * maxitems;
                }

                if( !getitem[true_idx].pick ) {
                    getitem[true_idx].count = 0;
                }
                update = true;
            }
            if( filter_changed ) {
                matches.clear();
                while( matches.empty() ) {
                    auto filter_func = item_filter_from_string( new_filter );
                    for( size_t index = 0; index < stacked_here.size(); index++ ) {
                        if( filter_func( stacked_here[index].begin()->_item ) ) {
                            matches.push_back( index );
                        }
                    }
                    if( matches.empty() ) {
                        popup( _( "Your filter returned no results" ) );
                        wrefresh( g->w_terrain );
                        // The filter must have results, or simply be emptied or canceled,
                        // as this screen can't be reached without there being
                        // items available
                        string_input_popup popup;
                        popup
                        .title( _( "Set filter" ) )
                        .width( 30 )
                        .edit( new_filter );
                        if( popup.canceled() ) {
                            new_filter = filter;
                            filter_changed = false;
                        }
                    }
                }
                if( filter_changed ) {
                    filter = new_filter;
                    filter_changed = false;
                    selected = 0;
                    start = 0;
                    iScrollPos = 0;
                }
                wrefresh( g->w_terrain );
            }
            item &selected_item = stacked_here[matches[selected]].begin()->_item;

            werase( w_item_info );
            if( selected >= 0 && selected <= ( int )stacked_here.size() - 1 ) {
                std::vector<iteminfo> vThisItem;
                std::vector<iteminfo> vDummy;
                selected_item.info( true, vThisItem );

                draw_item_info( w_item_info, "", "", vThisItem, vDummy, iScrollPos, true, true );
            }
            draw_custom_border( w_item_info, false );
            mvwprintw( w_item_info, 0, 2, "< " );
            trim_and_print( w_item_info, 0, 4, itemsW - 8, c_white, "%s >",
                            selected_item.display_name().c_str() );
            wrefresh( w_item_info );

            if( action == "SELECT_ALL" ) {
                int count = 0;
                for( auto i : matches ) {
                    if( getitem[i].pick ) {
                        count++;
                    }
                    getitem[i].pick = true;
                }
                if( count == ( int )stacked_here.size() ) {
                    for( size_t i = 0; i < stacked_here.size(); i++ ) {
                        getitem[i].pick = false;
                    }
                }
                update = true;
            }
            for( cur_it = start; cur_it < start + maxitems; cur_it++ ) {
                mvwprintw( w_pickup, 1 + ( cur_it % maxitems ), 0,
                           "                                        " );
                if( cur_it < ( int )matches.size() ) {
                    int true_it = matches[cur_it];
                    item &this_item = stacked_here[ true_it ].begin()->_item;
                    nc_color icolor = this_item.color_in_inventory();
                    if( cur_it == selected ) {
                        icolor = hilite( icolor );
                    }

                    if( cur_it < ( int )pickup_chars.size() ) {
                        mvwputch( w_pickup, 1 + ( cur_it % maxitems ), 0, icolor,
                                  char( pickup_chars[cur_it] ) );
                    } else if( cur_it < ( int )pickup_chars.size() + ( int )pickup_chars.size() *
                               ( int )pickup_chars.size() ) {
                        int p = cur_it - pickup_chars.size();
                        int p1 = p / pickup_chars.size();
                        int p2 = p % pickup_chars.size();
                        mvwprintz( w_pickup, 1 + ( cur_it % maxitems ), 0, icolor, "`%c%c",
                                   char( pickup_chars[p1] ), char( pickup_chars[p2] ) );
                    } else {
                        mvwputch( w_pickup, 1 + ( cur_it % maxitems ), 0, icolor, ' ' );
                    }
                    if( getitem[true_it].pick ) {
                        if( getitem[true_it].count == 0 ) {
                            wprintz( w_pickup, c_light_blue, " + " );
                        } else {
                            wprintz( w_pickup, c_light_blue, " # " );
                        }
                    } else {
                        wprintw( w_pickup, " - " );
                    }
                    std::string item_name;
                    if( stacked_here[true_it].begin()->_item.ammo_type() == "money" ) {
                        //Count charges
                        //TODO: transition to the item_location system used for the inventory
                        unsigned long charges_total = 0;
                        for( const auto item : stacked_here[true_it] ) {
                            charges_total += item._item.charges;
                        }
                        //Picking up none or all the cards in a stack
                        if( !getitem[true_it].pick || getitem[true_it].count == 0 ) {
                            item_name = stacked_here[true_it].begin()->_item.display_money( stacked_here[true_it].size(),
                                        charges_total );
                        } else {
                            unsigned long charges = 0;
                            int c = getitem[true_it].count;
                            for( auto it = stacked_here[true_it].begin(); it != stacked_here[true_it].end() &&
                                 c > 0; ++it, --c ) {
                                charges += it->_item.charges;
                            }
                            item_name = string_format( _( "%s of %s" ),
                                                       stacked_here[true_it].begin()->_item.display_money( getitem[true_it].count, charges ),
                                                       format_money( charges_total ) );
                        }
                    } else {
                        item_name = this_item.display_name( stacked_here[true_it].size() );
                    }
                    if( stacked_here[true_it].size() > 1 ) {
                        item_name = string_format( "%d %s", stacked_here[true_it].size(), item_name.c_str() );
                    }
                    if( get_option<bool>( "ITEM_SYMBOLS" ) ) {
                        item_name = string_format( "%s %s", this_item.symbol().c_str(),
                                                   item_name.c_str() );
                    }
                    trim_and_print( w_pickup, 1 + ( cur_it % maxitems ), 6, pickupW - 4, icolor,
                                    item_name );
                }
            }

            mvwprintw( w_pickup, maxitems + 1, 0, _( "[%s] Unmark" ),
                       ctxt.get_desc( "LEFT", 1 ).c_str() );

            center_print( w_pickup, maxitems + 1, c_light_gray, string_format( _( "[%s] Help" ),
                          ctxt.get_desc( "HELP_KEYBINDINGS", 1 ).c_str() ) );

            right_print( w_pickup, maxitems + 1, 0, c_light_gray, string_format( _( "[%s] Mark" ),
                         ctxt.get_desc( "RIGHT", 1 ).c_str() ) );

            mvwprintw( w_pickup, maxitems + 2, 0, _( "[%s] Prev" ),
                       ctxt.get_desc( "PREV_TAB", 1 ).c_str() );

            center_print( w_pickup, maxitems + 2, c_light_gray, string_format( _( "[%s] All" ),
                          ctxt.get_desc( "SELECT_ALL", 1 ).c_str() ) );

            right_print( w_pickup, maxitems + 2, 0, c_light_gray, string_format( _( "[%s] Next" ),
                         ctxt.get_desc( "NEXT_TAB", 1 ).c_str() ) );

            if( update ) { // Update weight & volume information
                update = false;
                for( int i = 9; i < pickupW; ++i ) {
                    mvwaddch( w_pickup, 0, i, ' ' );
                }
                units::mass weight_picked_up = 0;
                units::volume volume_picked_up = 0;
                for( size_t i = 0; i < getitem.size(); i++ ) {
                    if( getitem[i].pick ) {
                        item temp = stacked_here[i].begin()->_item;
                        if( temp.count_by_charges() && getitem[i].count < temp.charges && getitem[i].count != 0 ) {
                            temp.charges = getitem[i].count;
                        }
                        int num_picked = std::min( stacked_here[i].size(),
                                                   getitem[i].count == 0 ? stacked_here[i].size() : getitem[i].count );
                        weight_picked_up += temp.weight() * num_picked;
                        volume_picked_up += temp.volume() * num_picked;
                    }
                }

                auto weight_predict = g->u.weight_carried() + weight_picked_up;
                auto volume_predict = g->u.volume_carried() + volume_picked_up;

                mvwprintz( w_pickup, 0, 9, weight_predict > g->u.weight_capacity() ? c_red : c_white,
                           _( "Wgt %.1f" ), round_up( convert_weight( weight_predict ), 1 ) );

                wprintz( w_pickup, c_white, "/%.1f", round_up( convert_weight( g->u.weight_capacity() ), 1 ) );

                std::string fmted_volume_predict = format_volume( volume_predict );
                mvwprintz( w_pickup, 0, 24, volume_predict > g->u.volume_capacity() ? c_red : c_white,
                           _( "Vol %s" ), fmted_volume_predict.c_str() );

                std::string fmted_volume_capacity = format_volume( g->u.volume_capacity() );
                wprintz( w_pickup, c_white, "/%s", fmted_volume_capacity.c_str() );
            };

            wrefresh( w_pickup );

            action = ctxt.handle_input();
            raw_input_char = ctxt.get_raw_input().get_first_input();

        } while( action != "QUIT" && action != "CONFIRM" );

        bool item_selected = false;
        // Check if we have selected an item.
        for( auto selection : getitem ) {
            if( selection.pick ) {
                item_selected = true;
            }
        }
        if( action != "CONFIRM" || !item_selected ) {
            w_pickup = catacurses::window();
            w_item_info = catacurses::window();
            add_msg( _( "Never mind." ) );
            g->reenter_fullscreen();
            g->refresh_all();
            return;
        }
    }

    // At this point we've selected our items, register an activity to pick them up.
    g->u.assign_activity( activity_id( "ACT_PICKUP" ) );
    g->u.activity.placement = pos - g->u.pos();
    g->u.activity.values.push_back( from_vehicle );
    if( min == -1 ) {
        // Auto pickup will need to auto resume since there can be several of them on the stack.
        g->u.activity.auto_resume = true;
    }
    std::vector<std::pair<int, int>> pick_values;
    for( size_t i = 0; i < stacked_here.size(); i++ ) {
        const auto &selection = getitem[i];
        if( !selection.pick ) {
            continue;
        }

        const auto &stack = stacked_here[i];
        // Note: items can be both charged and stacked
        // For robustness, let's assume they can be both in the same stack
        bool pick_all = selection.count == 0;
        size_t count = selection.count;
        for( const item_idx &it : stack ) {
            if( !pick_all && count == 0 ) {
                break;
            }

            if( it._item.count_by_charges() ) {
                size_t num_picked = std::min( ( size_t )it._item.charges, count );
                pick_values.push_back( { static_cast<int>( it.idx ), static_cast<int>( num_picked ) } );
                count -= num_picked;
            } else {
                size_t num_picked = 1;
                pick_values.push_back( { static_cast<int>( it.idx ), 0 } );
                count -= num_picked;
            }
        }
    }
    // The pickup activity picks up items last-to-first from its values list, so make sure the
    // higher indices are at the end.
    std::sort( pick_values.begin(), pick_values.end() );
    for( auto &it : pick_values ) {
        g->u.activity.values.push_back( it.first );
        g->u.activity.values.push_back( it.second );
    }

    g->reenter_fullscreen();
}
Esempio n. 18
0
void CommodityTradeWidget::ShowAll()
{
	DeleteAllChildren();
	m_stockLabels.clear();
	m_cargoLabels.clear();

	SetTransparency(true);

	Gui::VScrollBar *scroll = new Gui::VScrollBar();
	Gui::VScrollPortal *portal = new Gui::VScrollPortal(450);
	scroll->SetAdjustment(&portal->vscrollAdjust);
	//int GetStock(Equip::Type t) const { return m_equipmentStock[t]; }

	int NUM_ITEMS = 0;
	const float YSEP = floor(Gui::Screen::GetFontHeight() * 2.5f);
	for (int i=Equip::FIRST_COMMODITY; i<=Equip::LAST_COMMODITY; i++) {
		assert(Equip::types[i].slot == Equip::SLOT_CARGO);

		if (m_seller->DoesSell(Equip::Type(i))) {
				NUM_ITEMS++;
		}
	}
	Gui::Fixed *innerbox = new Gui::Fixed(450, NUM_ITEMS*YSEP);
	innerbox->SetTransparency(true);

	const float iconOffset = 8.0f;
	for (int i=Equip::FIRST_COMMODITY, num=0; i<=Equip::LAST_COMMODITY; i++) {
		assert(Equip::types[i].slot == Equip::SLOT_CARGO);

		if (!m_seller->DoesSell(Equip::Type(i))) continue;
		int stock = m_seller->GetStock(static_cast<Equip::Type>(i));

        std::map<Equip::Type,std::string>::iterator icon_iter = s_iconMap.find(Equip::Type(i));
		if (icon_iter != s_iconMap.end()) {
			Gui::Image *icon = new Gui::Image(("icons/goods/" + (*icon_iter).second + ".png").c_str());
			// this forces the on-screen rendering to fit within (rescale) to these dimensions
			icon->SetRenderDimensions(38.0f, 32.0f);
			innerbox->Add(icon, 0, num*YSEP);
		}

		Gui::Label *l = new Gui::Label(Equip::types[i].name);
		if (Equip::types[i].description)
			l->SetToolTip(Equip::types[i].description);
		innerbox->Add(l,42,num*YSEP+iconOffset);
		Gui::RepeaterButton *b = new Gui::RepeaterButton(RBUTTON_DELAY, RBUTTON_REPEAT);
		sigc::slot<void> func = sigc::bind(sigc::mem_fun(this, &CommodityTradeWidget::OnClickBuy), i);
		b->onClick.connect(sigc::bind(sigc::mem_fun(this, &CommodityTradeWidget::ManageRButton), b, func));
		innerbox->Add(b, 380, num*YSEP+iconOffset);
		b = new Gui::RepeaterButton(RBUTTON_DELAY, RBUTTON_REPEAT);
		func = sigc::bind(sigc::mem_fun(this, &CommodityTradeWidget::OnClickSell), i);
		b->onClick.connect(sigc::bind(sigc::mem_fun(this, &CommodityTradeWidget::ManageRButton), b, func));
		innerbox->Add(b, 415, num*YSEP+iconOffset);
		char buf[128];
		innerbox->Add(new Gui::Label(
					format_money(m_seller->GetPrice(static_cast<Equip::Type>(i)))
					), 200, num*YSEP+iconOffset);

		snprintf(buf, sizeof(buf), "%dt", stock*Equip::types[i].mass);
		Gui::Label *stocklabel = new Gui::Label(buf);
		m_stockLabels[i] = stocklabel;
		innerbox->Add(stocklabel, 275, num*YSEP+iconOffset);

		snprintf(buf, sizeof(buf), "%dt", Pi::player->m_equipment.Count(Equip::SLOT_CARGO, static_cast<Equip::Type>(i))*Equip::types[i].mass);
		Gui::Label *cargolabel = new Gui::Label(buf);
		m_cargoLabels[i] = cargolabel;
		innerbox->Add(cargolabel, 325, num*YSEP+iconOffset);
		num++;
	}
	innerbox->ShowAll();

	portal->Add(innerbox);
	portal->ShowAll();

	Gui::Fixed *heading = new Gui::Fixed(470, Gui::Screen::GetFontHeight());
	const Color &col = Gui::Theme::Colors::tableHeading;
	heading->Add((new Gui::Label(Lang::ITEM))->Color(col), 0, 0);
	heading->Add((new Gui::Label(Lang::PRICE))->Color(col), 200, 0);
	heading->Add((new Gui::Label(Lang::BUY))->Color(col), 380, 0);
	heading->Add((new Gui::Label(Lang::SELL))->Color(col), 415, 0);
	heading->Add((new Gui::Label(Lang::STOCK))->Color(col), 275, 0);
	heading->Add((new Gui::Label(Lang::CARGO))->Color(col), 325, 0);
	PackEnd(heading);

	Gui::HBox *body = new Gui::HBox();
	body->PackEnd(portal);
	body->PackEnd(scroll);
	PackEnd(body);

	SetSpacing(YSEP-Gui::Screen::GetFontHeight());

	Gui::VBox::ShowAll();
}
Esempio n. 19
0
/* write the adjustments table if type == TABLE_PRINT
 * otherwise return TRUE if there's anything to print.
 */
static int adjustments_table(RA charges, int type)
{

  int count, index, index1;
  Arb_numeric amount;
  PREV_CHARGE *prev_chg, *prev_chg1;
  char datebuff[256];
  char *description;
  char *money, *money1;
  int lines_left;
  unsigned char display_type;

  g_curr_table = ADJUSTMENTS_TABLE;	/* set the g_curr_table for is_valid_prev_charge */

  count = UsesRA(charges);
  for(index = 0; index <= count; index++) {
    prev_chg = (PREV_CHARGE *) RAIndex(charges, index);

    /* check prev_chg to determine if it needs to be formatted */
    display_type = is_valid_prev_charge(prev_chg, g_curr_table, g_curr_prod);
    if (!display_type)
	continue;

    /* if it matches and type is TABLE_COUNT, return, otherwise print it */
    if (TABLE_COUNT == type)
      return TRUE;

    if ((lines_left = num_rows_left()) <= 4)
	safe_line_feed(lines_left);
    lookup_descr(&description, prev_chg->description_code);
    put_bill_markup(get_markup(MARKUP_ADJ_DETAIL));
    ALIGN(ALEFT);
    putf_bill(COL_ADJ_LEFT, get_field(ADJ_TABLE_FIELD), description);
    putf_bill(COL_ADJ_SRV, get_field(ADJ_SRV_FIELD), prev_chg->subscr_no_ext);
    format_formatted_date (&prev_chg->trans_date, language->date_fmt, datebuff, 20);
    putf_bill(COL_ADJ_DATE, get_field(ADJ_DATE_FIELD), datebuff);
    /* format the zero amount as specified or as $0.00 */
    ALIGN(ARIGHT);
    if (display_type == DISPLAY_TYPE_SPECIAL)
	MONEY_put_bill(COL_ADJ_AMT_AMONEY, get_field(ZERO_AMOUNT_FORMAT_LABEL), NONVOL);
    else
    {
    	money = format_money(&prev_chg->amount, DOLLAR_SIGN, NULL, MINUS_POS, bill_inv.currency);
    	flush_right(money);

	SET_CURRENCY(prev_chg->rate_currency_code);

    	set_generic_text(FIXED, money);
    	MONEY_put_bill(COL_ADJ_AMT_AMONEY, get_generic(FIXED), VOL);
    }
    money1 = format_money(&prev_chg->tax, DOLLAR_SIGN, NULL, MINUS_POS, bill_inv.currency);
    flush_right(money1);

    SET_CURRENCY(prev_chg->rate_currency_code);

    set_generic_text(FIXED, money1);
    MONEY_put_bill(COL_ADJ_VAT_AMONEY, get_generic(FIXED), VOL);
    ALIGN(ALEFT);
    safe_line_feed(1);

    prev_chg->is_formatted = TRUE;
    arb_num_arith (&amount, &prev_chg->amount, ARB_NUM_ADD, &prev_chg->tax);
    arb_num_arith (&g_table_total, &g_table_total, ARB_NUM_ADD, &amount);
  }
  return FALSE;
}