Exemplo n.º 1
0
Arquivo: menu.c Projeto: naev/naev
/**
 * @brief Resizes the main menu and its background.
 *
 * This is a one-off function that ensures the main menu's appearance
 * is consistent regardless of window resizing.
 */
void menu_main_resize (void)
{
   int w, h, bgw, bgh, tw, th;
   int offset_logo, offset_wdw, freespace;
   int menu_id, bg_id;
   Widget *wgt;

   if (!menu_isOpen(MENU_MAIN))
      return;

   menu_id = window_get("Main Menu");
   bg_id   = window_get("BG");

   window_dimWindow( menu_id, &w, &h );
   window_dimWindow( bg_id, &bgw, &bgh );

   freespace = SCREEN_H - main_naevLogo->sh - h;
   if (freespace < 0) {
      offset_logo = SCREEN_H - main_naevLogo->sh;
      offset_wdw  = 0;
   }
   else {
      offset_logo = -freespace/4;
      offset_wdw  = freespace/2;
   }

   window_moveWidget( bg_id, "imgLogo",
         (bgw - main_naevLogo->sw)/2., offset_logo );

   window_dimWidget( bg_id, "txtBG", &tw, &th );

   if (tw > SCREEN_W) {
      /* RIP abstractions. X must be set manually because window_moveWidget
       * transforms negative coordinates. */
      wgt = window_getwgt( bg_id, "txtBG" );
      if (wgt)
         wgt->x = (SCREEN_W - tw) / 2;
   }
   else
      window_moveWidget( bg_id, "txtBG", (SCREEN_W - tw)/2, 10. );

   window_move( menu_id, -1, offset_wdw );
}
Exemplo n.º 2
0
Arquivo: info.c Projeto: AvanWolf/naev
/**
 * @brief Updates the standings menu.
 */
static void standings_update( unsigned int wid, char* str )
{
   (void) str;
   int p, y;
   glTexture *t;
   int w, h, lw;
   char buf[128];
   int m;

   /* Get dimensions. */
   info_getDim( wid, &w, &h, &lw );

   /* Get faction. */
   p = toolkit_getListPos( wid, "lstStandings" );
   y = 0;

   /* Render logo. */
   t = faction_logoSmall( info_factions[p] );
   if (t != NULL) {
      window_modifyImage( wid, "imgLogo", t, 0, 0 );
      y  = -40;
      window_moveWidget( wid, "imgLogo", lw+40 + (w-(lw+60)-t->w)/2, y );
      y -= t->h;
   }
   else {
      window_modifyImage( wid, "imgLogo", NULL, 0, 0 );
      y = -20;
   }

   /* Modify text. */
   y -= 20;
   window_modifyText( wid, "txtName", faction_longname( info_factions[p] ) );
   window_moveWidget( wid, "txtName", lw+40, y );
   y -= 40;
   m = round( faction_getPlayer( info_factions[p] ) );
   snprintf( buf, sizeof(buf), "%+d%%   [ %s ]", m, faction_getStanding( m ) );
   window_modifyText( wid, "txtStanding", buf );
   window_moveWidget( wid, "txtStanding", lw+40, y );
}
Exemplo n.º 3
0
/**
 * @brief Updates the outfits in the outfit window.
 *    @param wid Window to update the outfits in.
 *    @param str Unused.
 */
void outfits_update( unsigned int wid, char* str )
{
   (void)str;
   char *outfitname;
   Outfit* outfit;
   char buf[PATH_MAX], buf2[ECON_CRED_STRLEN], buf3[ECON_CRED_STRLEN];
   double th;
   int iw, ih;
   int w, h;

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

   /* Get and set parameters. */
   outfitname = toolkit_getImageArray( wid, "iarOutfits" );
   if (strcmp(outfitname,"None")==0) { /* No outfits */
      window_modifyImage( wid, "imgOutfit", NULL, 0, 0 );
      window_disableButton( wid, "btnBuyOutfit" );
      window_disableButton( wid, "btnSellOutfit" );
      snprintf( buf, PATH_MAX,
            "NA\n"
            "\n"
            "NA\n"
            "NA\n"
            "NA\n"
            "\n"
            "NA\n"
            "NA\n"
            "NA\n" );
      window_modifyText( wid, "txtDDesc", buf );
      window_modifyText( wid, "txtOutfitName", "None" );
      window_modifyText( wid, "txtDescShort", NULL );
      /* Reposition. */
      window_moveWidget( wid, "txtSDesc", 20+iw+20, -60 );
      window_moveWidget( wid, "txtDDesc", 20+iw+20+60, -60 );
      window_moveWidget( wid, "txtDescription", 20+iw+40, -240 );
      return;
   }

   outfit = outfit_get( outfitname );

   /* new image */
   window_modifyImage( wid, "imgOutfit", outfit->gfx_store, 0, 0 );

   if (outfit_canBuy(outfit,1,0) > 0)
      window_enableButton( wid, "btnBuyOutfit" );
   else
      window_disableButton( wid, "btnBuyOutfit" );

   /* gray out sell button */
   if (outfit_canSell(outfit,1,0) > 0)
      window_enableButton( wid, "btnSellOutfit" );
   else
      window_disableButton( wid, "btnSellOutfit" );

   /* new text */
   window_modifyText( wid, "txtDescription", outfit->description );
   credits2str( buf2, outfit->price, 2 );
   credits2str( buf3, player.p->credits, 2 );
   snprintf( buf, PATH_MAX,
         "%d\n"
         "\n"
         "%s\n"
         "%s\n"
         "%.0f tons\n"
         "\n"
         "%s credits\n"
         "%s credits\n"
         "%s\n",
         player_outfitOwned(outfit),
         outfit_slotName(outfit),
         outfit_slotSize(outfit),
         outfit->mass,
         buf2,
         buf3,
         (outfit->license != NULL) ? outfit->license : "None" );
   window_modifyText( wid, "txtDDesc", buf );
   window_modifyText( wid, "txtOutfitName", outfit->name );
   window_modifyText( wid, "txtDescShort", outfit->desc_short );
   th = MAX( 128, gl_printHeightRaw( &gl_smallFont, 320, outfit->desc_short ) );
   window_moveWidget( wid, "txtSDesc", 40+iw+20, -60-th-20 );
   window_moveWidget( wid, "txtDDesc", 40+iw+20+60, -60-th-20 );
   th += gl_printHeightRaw( &gl_smallFont, 250, buf );
   window_moveWidget( wid, "txtDescription", 20+iw+40, -60-th-20 );
}
Exemplo n.º 4
0
Arquivo: map.c Projeto: Elderman/naev
/**
 * @brief Updates the map window.
 *
 *    @param wid Window id.
 */
static void map_update( unsigned int wid )
{
   int i;
   StarSystem* sys;
   int f, h, x, y;
   double standing, nstanding;
   unsigned int services;
   int l;
   int hasPresence, hasPlanets;
   char t;
   char buf[PATH_MAX];
   int p;
   glTexture *logo;
   double w;
   double unknownPresence;

   /* Needs map to update. */
   if (!map_isOpen())
      return;

   /* Get selected system. */
   sys = system_getIndex( map_selected );

   /* Not known and no markers. */
   if (!(sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)) &&
         !sys_isKnown(sys) && !space_sysReachable(sys)) {
      map_selectCur();
      sys = system_getIndex( map_selected );
   }

   /*
    * Right Text
    */

   x = -70; /* Side bar X offset. */
   w = ABS(x) + 60; /* Width of the side bar. */
   y = -20 - 20 - 64 - gl_defFont.h; /* Initialized to position for txtSFaction. */

   if (!sys_isKnown(sys)) { /* System isn't known, erase all */
      /*
       * Right Text
       */
      if (sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED))
         window_modifyText( wid, "txtSysname", sys->name );
      else
         window_modifyText( wid, "txtSysname", "Unknown" );;

      /* Faction */
      window_modifyImage( wid, "imgFaction", NULL, 0, 0 );
      window_moveWidget( wid, "txtSFaction", x, y);
      window_moveWidget( wid, "txtFaction", x + 50, y - gl_smallFont.h - 5 );
      window_modifyText( wid, "txtFaction", "Unknown" );
      y -= 2 * gl_smallFont.h + 5 + 15;

      /* Standing */
      window_moveWidget( wid, "txtSStanding", x, y );
      window_moveWidget( wid, "txtStanding", x + 50, y - gl_smallFont.h - 5 );
      window_modifyText( wid, "txtStanding", "Unknown" );
      y -= 2 * gl_smallFont.h + 5 + 15;

      /* Presence. */
      window_moveWidget( wid, "txtSPresence", x, y );
      window_moveWidget( wid, "txtPresence",  x + 50, y - gl_smallFont.h - 5 );
      window_modifyText( wid, "txtPresence", "Unknown" );
      y -= 2 * gl_smallFont.h + 5 + 15;

      /* Planets */
      window_moveWidget( wid, "txtSPlanets", x, y );
      window_moveWidget( wid, "txtPlanets", x + 50, y - gl_smallFont.h - 5 );
      window_modifyText( wid, "txtPlanets", "Unknown" );
      y -= 2 * gl_smallFont.h + 5 + 15;

      /* Services */
      window_moveWidget( wid, "txtSServices", x, y );
      window_moveWidget( wid, "txtServices", x + 50, y -gl_smallFont.h - 5 );
      window_modifyText( wid, "txtServices", "Unknown" );

      /*
       * Bottom Text
       */
      window_modifyText( wid, "txtSystemStatus", NULL );
      return;
   }

   /* System is known */
   window_modifyText( wid, "txtSysname", sys->name );

   standing  = 0.;
   nstanding = 0.;
   f         = -1;
   for (i=0; i<sys->nplanets; i++) {
      if (sys->planets[i]->real != ASSET_REAL)
         continue;
      if (!planet_isKnown(sys->planets[i]))
         continue;

      if ((f==-1) && (sys->planets[i]->faction>0)) {
         f = sys->planets[i]->faction;
         standing += faction_getPlayer( f );
         nstanding++;
      }
      else if (f != sys->planets[i]->faction && /** @todo more verbosity */
               (sys->planets[i]->faction>0)) {
         nsnprintf( buf, PATH_MAX, "Multiple" );
         break;
      }
   }
   if (f == -1) {
      window_modifyImage( wid, "imgFaction", NULL, 0, 0 );
      window_modifyText( wid, "txtFaction", "N/A" );
      window_modifyText( wid, "txtStanding", "N/A" );
      h = gl_smallFont.h;
   }
   else {
      if (i==sys->nplanets) /* saw them all and all the same */
         nsnprintf( buf, PATH_MAX, "%s", faction_longname(f) );

      /* Modify the image. */
      logo = faction_logoSmall(f);
      window_modifyImage( wid, "imgFaction", logo, 0, 0 );
      if (logo != NULL)
         window_moveWidget( wid, "imgFaction",
               -90 + logo->w/2, -20 - 32 - 10 - gl_defFont.h + logo->h/2);

      /* Modify the text */
      window_modifyText( wid, "txtFaction", buf );
      window_modifyText( wid, "txtStanding",
            faction_getStanding( standing / nstanding ) );

      h = gl_printHeightRaw( &gl_smallFont, w, buf );
   }

   /* Faction */
   window_moveWidget( wid, "txtSFaction", x, y);
   window_moveWidget( wid, "txtFaction", x + 50, y - gl_smallFont.h - 5 );
   y -= gl_smallFont.h + h + 5 + 15;

   /* Standing */
   window_moveWidget( wid, "txtSStanding", x, y );
   window_moveWidget( wid, "txtStanding", x + 50, y - gl_smallFont.h - 5 );
   y -= 2 * gl_smallFont.h + 5 + 15;

   /* Get presence. */
   hasPresence = 0;
   buf[0]      = '\0';
   l           = 0;
   unknownPresence = 0;
   for (i=0; i < sys->npresence; i++) {
      if (sys->presence[i].value <= 0)
         continue;
      hasPresence = 1;
      if (faction_isKnown( sys->presence[i].faction )) {
         t           = faction_getColourChar(sys->presence[i].faction);
         /* Use map grey instead of default neutral colour */
         l += nsnprintf( &buf[l], PATH_MAX-l, "%s\e0%s: \e%c%.0f",
                        (l==0)?"":"\n", faction_shortname(sys->presence[i].faction),
                        (t=='N')?'M':t, sys->presence[i].value);
      }
      else
Exemplo n.º 5
0
Arquivo: map.c Projeto: isfos/naev
/**
 * @brief Updates the map window.
 *
 *    @param wid Window id.
 */
static void map_update( unsigned int wid )
{
    int i;
    StarSystem* sys;
    int f, y, h, multiple_faction;
    double standing, nstanding;
    unsigned int services;
    char buf[PATH_MAX];
    int p;
    glTexture *logo;

    /* Needs map to update. */
    if (!map_isOpen())
        return;

    sys = system_getIndex( map_selected );

    /* Not known and no markers. */
    if (!(sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)) &&
            !sys_isKnown(sys) && !space_sysReachable(sys)) {
        map_selectCur();
        sys = system_getIndex( map_selected );
    }

    /*
     * Right Text
     */
    if (!sys_isKnown(sys)) { /* System isn't known, erase all */
        /*
         * Right Text
         */
        if (sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED))
            window_modifyText( wid, "txtSysname", sys->name );
        else
            window_modifyText( wid, "txtSysname", "Unknown" );
        window_modifyImage( wid, "imgFaction", NULL );
        window_moveWidget( wid, "txtSFaction", -20, -60 );
        window_moveWidget( wid, "txtFaction", -20, -60-gl_smallFont.h-5 );
        window_modifyText( wid, "txtFaction", "Unknown" );
        /* Standing */
        window_moveWidget( wid, "txtSStanding", -20, -100 );
        window_moveWidget( wid, "txtStanding", -20, -100-gl_smallFont.h-5 );
        window_modifyText( wid, "txtStanding", "Unknown" );
        /* Security. */
        window_moveWidget( wid, "txtSSecurity", -20, -140 );
        window_moveWidget( wid, "txtSecurity",  -20, -140-gl_smallFont.h-5 );
        window_modifyText( wid, "txtSecurity", "Unknown" );
        /* Planets */
        window_moveWidget( wid, "txtSPlanets", -20, -180 );
        window_moveWidget( wid, "txtPlanets", -20, -180-gl_smallFont.h-5 );
        window_modifyText( wid, "txtPlanets", "Unknown" );
        /* Services */
        window_moveWidget( wid, "txtSServices", -20, -220 );
        window_moveWidget( wid, "txtServices", -20, -220-gl_smallFont.h-5 );
        window_modifyText( wid, "txtServices", "Unknown" );

        /*
         * Bottom Text
         */
        window_modifyText( wid, "txtSystemStatus", NULL );
        return;
    }

    /* System is known */
    window_modifyText( wid, "txtSysname", sys->name );

    standing  = 0.;
    nstanding = 0.;
    f         = -1;
    multiple_faction = 0;
    for (i=0; i<sys->nplanets; i++) {
        if ((f==-1) && (sys->planets[i]->faction>0)) {
            f = sys->planets[i]->faction;
            standing += faction_getPlayer( f );
            nstanding++;
        }
        else if (f != sys->planets[i]->faction && /** @todo more verbosity */
                 (sys->planets[i]->faction>0)) {
            snprintf( buf, PATH_MAX, "Multiple" );
            multiple_faction = 1;
            break;
        }
    }
    if (f == -1) {
        window_modifyImage( wid, "imgFaction", NULL );
        window_moveWidget( wid, "txtSFaction", -20, -60 );
        window_moveWidget( wid, "txtFaction", -20, -60-gl_smallFont.h-5 );
        window_modifyText( wid, "txtFaction", "NA" );
        window_moveWidget( wid, "txtSStanding", -20, -100 );
        window_moveWidget( wid, "txtStanding", -20, -100-gl_smallFont.h-5 );
        window_modifyText( wid, "txtStanding", "NA" );
        y = -100;

    }
    else {
        if (i==sys->nplanets) /* saw them all and all the same */
            snprintf( buf, PATH_MAX, "%s", faction_longname(f) );

        y = -60;

        /* Modify the image. */
        logo = faction_logoSmall(f);
        window_modifyImage( wid, "imgFaction", logo );
        if (logo != NULL) {
            window_moveWidget( wid, "imgFaction",
                               -(90-logo->w)/2-20-logo->w, y-(64-logo->h)/2-logo->h );
            y -= 64 + 10;
        }

        /* Modify the text */
        window_modifyText( wid, "txtFaction", buf );
        window_modifyText( wid, "txtStanding",
                           faction_getStanding( standing / nstanding ) );

        /* Lower text if needed */
        window_moveWidget( wid, "txtSFaction", -20, y );
        window_moveWidget( wid, "txtFaction", -20, y-gl_smallFont.h-5 );
        h = gl_printHeightRaw( &gl_smallFont, 80, buf );
        window_moveWidget( wid, "txtSStanding", -20, y );
        window_moveWidget( wid, "txtStanding", -20, y-gl_smallFont.h-5 );
        y -= 40 + (h - gl_smallFont.h);
        window_moveWidget( wid, "txtSStanding", -20, y );
        window_moveWidget( wid, "txtStanding", -20, y-gl_smallFont.h-5 );
    }

    /* Get security. */
    y -= 40;
    if (sys->nfleets == 0)
        snprintf(buf, PATH_MAX, "NA" );
    else
        snprintf(buf, PATH_MAX, "%.0f %%", sys->security * 100.);
    window_moveWidget( wid, "txtSSecurity", -20, y );
    window_moveWidget( wid, "txtSecurity", -20, y-gl_smallFont.h-5 );
    window_modifyText( wid, "txtSecurity", buf );

    /* Get planets */
    if (sys->nplanets == 0) {
        strncpy( buf, "None", PATH_MAX );
        window_modifyText( wid, "txtPlanets", buf );
    }
    else {
        p = 0;
        buf[0] = '\0';
        if (sys->nplanets > 0)
            p += snprintf( &buf[p], PATH_MAX-p, "%s", sys->planets[0]->name );
        for (i=1; i<sys->nplanets; i++) {
            p += snprintf( &buf[p], PATH_MAX-p, ",\n%s", sys->planets[i]->name );
        }

        window_modifyText( wid, "txtPlanets", buf );
    }
    y -= 40;
    window_moveWidget( wid, "txtSPlanets", -20, y );
    window_moveWidget( wid, "txtPlanets", -20, y-gl_smallFont.h-5 );

    /* Get the services */
    h = gl_printHeightRaw( &gl_smallFont, 80, buf );
    y -= 40 + (h - gl_smallFont.h);
    window_moveWidget( wid, "txtSServices", -20, y );
    window_moveWidget( wid, "txtServices", -20, y-gl_smallFont.h-5 );
    services = 0;
    for (i=0; i<sys->nplanets; i++)
        services |= sys->planets[i]->services;
    buf[0] = '\0';
    p = 0;
    /*snprintf(buf, sizeof(buf), "%f\n", sys->prices[0]);*/ /*Hack to control prices. */
    if (services & PLANET_SERVICE_COMMODITY)
        p += snprintf( &buf[p], PATH_MAX-p, "Commodity\n");
    if (services & PLANET_SERVICE_OUTFITS)
        p += snprintf( &buf[p], PATH_MAX-p, "Outfits\n");
    if (services & PLANET_SERVICE_SHIPYARD)
        p += snprintf( &buf[p], PATH_MAX-p, "Shipyard\n");
    if (buf[0] == '\0')
        p += snprintf( &buf[p], PATH_MAX-p, "None");
    window_modifyText( wid, "txtServices", buf );


    /*
     * System Status
     */
    buf[0] = '\0';
    p = 0;
    /* Nebula. */
    if (sys->nebu_density > 0.) {

        /* Volatility */
        if (sys->nebu_volatility > 700.)
            p += snprintf(&buf[p], PATH_MAX-p, " Volatile");
        else if (sys->nebu_volatility > 300.)
            p += snprintf(&buf[p], PATH_MAX-p, " Dangerous");
        else if (sys->nebu_volatility > 0.)
            p += snprintf(&buf[p], PATH_MAX-p, " Unstable");

        /* Density */
        if (sys->nebu_density > 700.)
            p += snprintf(&buf[p], PATH_MAX-p, " Dense");
        else if (sys->nebu_density < 300.)
            p += snprintf(&buf[p], PATH_MAX-p, " Light");
        p += snprintf(&buf[p], PATH_MAX-p, " Nebula");
    }
    /* Interference. */
    if (sys->interference > 0.) {

        if (buf[0] != '\0')
            p += snprintf(&buf[p], PATH_MAX-p, ",");

        /* Density. */
        if (sys->interference > 700.)
            p += snprintf(&buf[p], PATH_MAX-p, " Dense");
        else if (sys->interference < 300.)
            p += snprintf(&buf[p], PATH_MAX-p, " Light");

        p += snprintf(&buf[p], PATH_MAX-p, " Interference");
    }
    window_modifyText( wid, "txtSystemStatus", buf );
}