예제 #1
0
/**
 * @brief Updates the quantity counter for the outfits.
 *
 *    @param wid Window to update counters of.
 */
void outfits_updateQuantities( unsigned int wid )
{
   Outfit **outfits, *o;
   int noutfits;
   char **quantity;
   int len, owned;
   int i;

   /* Get outfits. */
   outfits = tech_getOutfit( land_planet->tech, &noutfits );
   if (noutfits <= 0)
      return;

   quantity = malloc(sizeof(char*)*noutfits);
   for (i=0; i<noutfits; i++) {
      o = outfits[i];
      owned = player_outfitOwned(o);
      len = owned / 10 + 4;
      if (owned >= 1) {
         quantity[i] = malloc( len );
         snprintf( quantity[i], len, "%d", owned );
      }
      else
         quantity[i] = NULL;
   }
   free(outfits);
   toolkit_setImageArrayQuantity( wid, "iarOutfits", quantity );
}
예제 #2
0
파일: nlua_planet.c 프로젝트: naev/naev
/**
 * @brief Gets the outfits sold at a planet.
 *
 *    @luatparam Planet p Planet to get outfits sold at.
 *    @luatreturn {Outfit,...} An ordered table containing all the outfits sold (empty if none sold).
 * @luafunc outfitsSold( p )
 */
static int planetL_outfitsSold( lua_State *L )
{
   Planet *p;
   int i, n;
   Outfit **o;

   /* Get result and tech. */
   p = luaL_validplanet(L,1);
   o = tech_getOutfit( p->tech, &n );

   /* Push results in a table. */
   lua_newtable(L);
   for (i=0; i<n; i++) {
      lua_pushnumber(L,i+1); /* index, starts with 1 */
      lua_pushoutfit(L,o[i]); /* value = LuaOutfit */
      lua_rawset(L,-3); /* store the value in the table */
   }

   return 1;
}
예제 #3
0
/**
 * @brief Opens the outfit exchange center window.
 */
void outfits_open( unsigned int wid )
{
   int i;
   Outfit **outfits;
   char **soutfits;
   glTexture **toutfits;
   int noutfits;
   int w, h;
   int iw, ih;
   int bw, bh;
   glColour *bg, blend;
   const glColour *c;
   char **slottype;
   const char *slotname;

   /* Get dimensions. */
   outfits_getSize( wid, &w, &h, &iw, &ih, &bw, &bh );

   /* will allow buying from keyboard */
   window_setAccept( wid, outfits_buy );

   /* buttons */
   window_addButton( wid, -20, 20,
         bw, bh, "btnCloseOutfits",
         "Takeoff", land_buttonTakeoff );
   window_addButton( wid, -40-bw, 20,
         bw, bh, "btnSellOutfit",
         "Sell", outfits_sell );
   window_addButton( wid, -60-bw*2, 20,
         bw, bh, "btnBuyOutfit",
         "Buy", outfits_buy );

   /* fancy 128x128 image */
   window_addRect( wid, 19 + iw + 20, -50, 128, 129, "rctImage", &cBlack, 0 );
   window_addImage( wid, 20 + iw + 20, -50-128, 0, 0, "imgOutfit", NULL, 1 );

   /* cust draws the modifier */
   window_addCust( wid, -40-bw, 60+2*bh,
         bw, bh, "cstMod", 0, outfits_renderMod, NULL, NULL );

   /* the descriptive text */
   window_addText( wid, 20 + iw + 20 + 128 + 20, -60,
         320, 160, 0, "txtOutfitName", &gl_defFont, &cBlack, NULL );
   window_addText( wid, 20 + iw + 20 + 128 + 20, -60 - gl_defFont.h - 20,
         320, 160, 0, "txtDescShort", &gl_smallFont, &cBlack, NULL );
   window_addText( wid, 20 + iw + 20, -60-128-10,
         60, 160, 0, "txtSDesc", &gl_smallFont, &cDConsole,
         "Owned:\n"
         "\n"
         "Slot:\n"
         "Size:\n"
         "Mass:\n"
         "\n"
         "Price:\n"
         "Money:\n"
         "License:\n" );
   window_addText( wid, 20 + iw + 20 + 60, -60-128-10,
         250, 160, 0, "txtDDesc", &gl_smallFont, &cBlack, NULL );
   window_addText( wid, 20 + iw + 20, -60-128-10-160,
         w-(iw+80), 180, 0, "txtDescription",
         &gl_smallFont, NULL, NULL );

   /* set up the outfits to buy/sell */
   outfits = tech_getOutfit( land_planet->tech, &noutfits );
   if (noutfits <= 0) { /* No outfits */
      soutfits    = malloc(sizeof(char*));
      soutfits[0] = strdup("None");
      toutfits    = malloc(sizeof(glTexture*));
      toutfits[0] = NULL;
      noutfits    = 1;
      bg          = NULL;
      slottype    = NULL;
   }
   else {
      /* Create the outfit arrays. */
      soutfits = malloc(sizeof(char*)*noutfits);
      toutfits = malloc(sizeof(glTexture*)*noutfits);
      bg       = malloc(sizeof(glColour)*noutfits);
      slottype = malloc(sizeof(char*)*noutfits );
      for (i=0; i<noutfits; i++) {
         soutfits[i] = strdup(outfits[i]->name);
         toutfits[i] = outfits[i]->gfx_store;

         /* Background colour. */
         c = outfit_slotSizeColour( &outfits[i]->slot );
         if (c == NULL)
            c = &cBlack;
         col_blend( &blend, c, &cGrey70, 0.4 );
         memcpy( &bg[i], &blend, sizeof(glColour) );

         /* Get slot name. */
         slotname = outfit_slotName(outfits[i]);
         if ((strcmp(slotname,"NA") != 0) && (strcmp(slotname,"NULL") != 0)) {
            slottype[i]    = malloc( 2 );
            slottype[i][0] = outfit_slotName(outfits[i])[0];
            slottype[i][1] = '\0';
         }
         else
            slottype[i] = NULL;
      }
      free(outfits);
   }
   window_addImageArray( wid, 20, 20,
         iw, ih, "iarOutfits", 64, 64,
         toutfits, soutfits, noutfits, outfits_update, outfits_rmouse );

   /* write the outfits stuff */
   outfits_update( wid, NULL );
   outfits_updateQuantities( wid );
   toolkit_setImageArraySlotType( wid, "iarOutfits", slottype );
   toolkit_setImageArrayBackground( wid, "iarOutfits", bg );
}