/** * @brief Displays an alert popup with only an ok button and a message. * * @param fmt Printf style message to display. */ void dialogue_alert( const char *fmt, ... ) { char msg[512]; va_list ap; unsigned int wdw; int h, done; if (fmt == NULL) return; else { /* get the message */ va_start(ap, fmt); vsnprintf(msg, 512, fmt, ap); va_end(ap); } h = gl_printHeightRaw( &gl_smallFont, 260, msg ); /* create the window */ wdw = window_create( "Warning", -1, -1, 300, 90 + h ); window_setData( wdw, &done ); window_addText( wdw, 20, -30, 260, h, 0, "txtAlert", &gl_smallFont, &cBlack, msg ); window_addButton( wdw, 135, 20, 50, 30, "btnOK", "OK", dialogue_close ); dialogue_open++; toolkit_loop( &done ); }
/** * @brief Updates the missions in the spaceport bar. * @param wid Window to update the outfits in. * @param str Unused. */ static void bar_update( unsigned int wid, char* str ) { (void) str; int pos; int w, h, iw, ih, bw, bh, dh; /* Get dimensions. */ bar_getDim( wid, &w, &h, &iw, &ih, &bw, &bh ); dh = gl_printHeightRaw( &gl_smallFont, w - iw - 60, land_planet->bar_description ); /* Get array. */ pos = toolkit_getImageArrayPos( wid, "iarMissions" ); /* See if is news. */ if (pos==0) { /* News selected. */ if (!widget_exists(wid, "cstNews")) { /* Destroy portrait. */ if (widget_exists(wid, "imgPortrait")) { window_destroyWidget(wid, "imgPortrait"); } /* Disable button. */ window_disableButton( wid, "btnApproach" ); /* Clear text. */ window_modifyText( wid, "txtPortrait", NULL ); window_modifyText( wid, "txtMission", NULL ); /* Create news. */ news_widget( wid, iw + 60, -40 - (40 + dh), w - iw - 100, h - 40 - (dh+20) - 40 - bh - 20 ); } return; } /* Shift to ignore news now. */ pos--; /* Destroy news widget if needed. */ if (widget_exists(wid, "cstNews")) { window_destroyWidget( wid, "cstNews" ); } /* Create widgets if needed. */ if (!widget_exists(wid, "imgPortrait")) { window_addImage( wid, iw + 40 + (w-iw-60-PORTRAIT_WIDTH)/2, -(40 + dh + 40 + gl_defFont.h + 20 + PORTRAIT_HEIGHT), 0, 0, "imgPortrait", NULL, 1 ); } /* Enable button. */ window_enableButton( wid, "btnApproach" ); /* Set portrait. */ window_modifyText( wid, "txtPortrait", npc_getName( pos ) ); window_modifyImage( wid, "imgPortrait", npc_getTexture( pos ), 0, 0 ); /* Set mission description. */ window_modifyText( wid, "txtMission", npc_getDesc( pos )); }
/** * @brief Creates a dialogue that allows the player to write a message. * * You must free the result if it's not null. * * @param title Title of the dialogue window. * @param min Minimum length of the message (must be non-zero). * @param max Maximum length of the message (must be non-zero). * @param msg Message to be displayed. * @return The message the player typed or NULL if it was cancelled. */ char* dialogue_inputRaw( const char* title, int min, int max, const char *msg ) { char *input; int h, done; /* get text height */ h = gl_printHeightRaw( &gl_smallFont, 200, msg ); /* create window */ input_dialogue.input_wid = window_create( title, -1, -1, 240, h+140 ); window_setData( input_dialogue.input_wid, &done ); window_setAccept( input_dialogue.input_wid, dialogue_inputClose ); window_setCancel( input_dialogue.input_wid, dialogue_cancel ); /* text */ window_addText( input_dialogue.input_wid, 30, -30, 200, h, 0, "txtInput", &gl_smallFont, &cDConsole, msg ); /* input */ window_addInput( input_dialogue.input_wid, 20, -50-h, 200, 20, "inpInput", max, 1, NULL ); window_setInputFilter( input_dialogue.input_wid, "inpInput", "/" ); /* Remove illegal stuff. */ /* button */ window_addButton( input_dialogue.input_wid, -20, 20, 80, 30, "btnClose", "Done", dialogue_inputClose ); /* tricky secondary loop */ dialogue_open++; done = 0; input = NULL; while ((done >= 0) && (!input || ((int)strlen(input) < min))) { /* must be longer than min */ if (input) { dialogue_alert( "Input must be at least %d character%s long!", min, (min==1) ? "s" : "" ); free(input); input = NULL; } if (toolkit_loop( &done ) != 0) /* error in loop -> quit */ return NULL; /* save the input */ if (done < 0) input = NULL; else input = strdup( window_getInput( input_dialogue.input_wid, "inpInput" ) ); } /* cleanup */ if (input != NULL) { window_destroy( input_dialogue.input_wid ); dialogue_open--; } input_dialogue.input_wid = 0; /* return the result */ return input; }
/** * @brief Gets the size needed for the dialogue. * * @param title Title of the dialogue. * @param msg Message of the dialogue. * @param[out] width Gets the width needed. * @param[out] height Gets the height needed. * @return The font that matches the size. */ static glFont* dialogue_getSize( const char* title, const char* msg, int* width, int* height ) { glFont* font; double w, h, d; int titlelen; #if 0 int len; len = strlen(msg); #endif /* Get title length. */ titlelen = gl_printWidthRaw( &gl_defFont, title ); w = MAX(300, titlelen+40); /* Default width to try. */ /* First we split by text length. */ #if 0 if (len < 50) { font = &gl_defFont; h = gl_printHeightRaw( font, w-40, msg ); } else { #endif /* Now we look at proportion. */ font = &gl_smallFont; /* font = &gl_defFont; */ h = gl_printHeightRaw( font, w-40, msg ); d = ((double)w/(double)h)*(3./4.); /* deformation factor. */ if (fabs(d) > 0.3) { if (h > w) w = h; h = gl_printHeightRaw( font, w-40, msg ); } #if 0 } #endif /* Set values. */ (*width) = w; (*height) = h; return font; }
/** * @brief Gets the size needed for the dialogue. * * @param title Title of the dialogue. * @param msg Message of the dialogue. * @param[out] width Gets the width needed. * @param[out] height Gets the height needed. * @return The font that matches the size. */ static glFont* dialogue_getSize( const char* title, const char* msg, int* width, int* height ) { glFont* font; double w, h, d; int i, titlelen, msglen; /* Get title length. */ titlelen = gl_printWidthRaw( &gl_defFont, title ); msglen = gl_printWidthRaw( &gl_smallFont, msg ); /* Try widths from 300 to 800 in 50 px increments. * Each subsequent width gets an additional line, following this table: * * 300 px: 2 lines, 540 px total * 350 px: 3 lines, 930 px total * ... * 800 px: 12 lines, 9600 px total */ for (i=0; i<11; i++) if (msglen < (260 + i * 50) * (2 + i)) break; w = 300 + i * 50; w = MAX(w, titlelen+40); /* Expand width if the title is long. */ /* Now we look at proportion. */ font = &gl_smallFont; h = gl_printHeightRaw( font, w-40, msg ); d = ((double)w/(double)h)*(3./4.); /* deformation factor. */ if (fabs(d) > 0.3) { if (h > w) w = h; h = gl_printHeightRaw( font, w-40, msg ); } /* Set values. */ (*width) = w; (*height) = h; return font; }
/** * @brief Draws an alt text. * * @param bx X position to draw at. * @param by Y position to draw at. * @param alt Text to draw. */ void toolkit_drawAltText( int bx, int by, const char *alt ) { double w, h; double x, y, o; glColour c; glColour c2; /* Get dimensions. */ w = 160.; h = gl_printHeightRaw( &gl_smallFont, w, alt ); /* One check to make bigger. */ if (h > 160.) { w = 200; h = gl_printHeightRaw( &gl_smallFont, w, alt ); } /* Choose position. */ x = bx + 10.; y = by - h - gl_smallFont.h - 10.; if (y < -SCREEN_H/2+10) { o = -(SCREEN_H/2 + y) + 10; y += o; } /* Set colours. */ c.r = cGrey80.r; c.g = cGrey80.g; c.b = cGrey80.b; c.a = 0.8; c2.r = cGrey30.r; c2.g = cGrey30.g; c2.b = cGrey30.b; c2.a = 0.7; toolkit_drawRect( x-1, y-5, w+6, h+6, &c2, NULL ); toolkit_drawRect( x-3, y-3, w+6, h+6, &c, NULL ); gl_printTextRaw( &gl_smallFont, w, h, x+SCREEN_W/2, y+SCREEN_H/2, &cBlack, alt ); }
/** * @brief Gets the height of the text if it were printed. * * Does not display the text on screen. * * @param ft_font Font to use (NULL defaults to gl_defFont). * @param width Width to jump to next line once reached. * @param fmt Text to get the height of in printf format. * @return The height of the text. */ int gl_printHeight( const glFont *ft_font, const int width, const char *fmt, ... ) { char text[1024]; /* holds the string */ va_list ap; if (fmt == NULL) return -1; else { /* convert the symbols to text */ va_start(ap, fmt); vsnprintf(text, 1024, fmt, ap); va_end(ap); } return gl_printHeightRaw( ft_font, width, text ); }
/** * @brief Opens the spaceport bar window. */ static void bar_open( unsigned int wid ) { int w, h, iw, ih, bw, bh, dh, th; /* Mark as generated. */ land_tabGenerate(LAND_WINDOW_BAR); /* Set window functions. */ window_onClose( wid, bar_close ); /* Get dimensions. */ bar_getDim( wid, &w, &h, &iw, &ih, &bw, &bh ); dh = gl_printHeightRaw( &gl_smallFont, w - iw - 60, land_planet->bar_description ); /* Approach when pressing enter */ window_setAccept( wid, bar_approach ); /* Buttons */ window_addButtonKey( wid, -20, 20, bw, bh, "btnCloseBar", "Take Off", land_buttonTakeoff, SDLK_t ); window_addButtonKey( wid, -20 - bw - 20, 20, bw, bh, "btnApproach", "Approach", bar_approach, SDLK_a ); /* Bar description. */ window_addText( wid, iw + 40, -40, w - iw - 60, dh, 0, "txtDescription", &gl_smallFont, &cBlack, land_planet->bar_description ); /* Add portrait text. */ th = -40 - dh - 40; window_addText( wid, iw + 40, th, w - iw - 60, gl_defFont.h, 1, "txtPortrait", &gl_defFont, &cDConsole, NULL ); /* Add mission description text. */ th -= 20 + PORTRAIT_HEIGHT + 20 + 20; window_addText( wid, iw + 60, th, w - iw - 100, h + th - (2*bh+60), 0, "txtMission", &gl_smallFont, &cBlack, NULL ); /* Generate the mission list. */ bar_genList( wid ); /* Set default keyboard focuse to the list */ window_setFocus( wid , "iarMissions" ); }
/** * @brief Gets the size of the text to print. * * @usage len = gfx.printDim( nil, "Hello World!" ) -- Length of string with normal font * @usage height = gfx.printDim( true, "Longer text", 20 ) -- Dimensions of text block * * @luaparam small Whether or not to use the small font. * @luaparam str Text to calculate length of. * @luaparam width Optional parameter to indicate it is a block of text and to use this width. * @luafunc printDim( small, str, width ) */ static int gfxL_printDim( lua_State *L ) { const char *str; int width; glFont *font; /* Parse parameters. */ font = lua_toboolean(L,1) ? &gl_smallFont : &gl_defFont; str = luaL_checkstring(L,2); if (lua_gettop(L) > 2) width = luaL_checkinteger(L,3); else width = 0; /* Print length. */ if (width == 0) lua_pushnumber( L, gl_printWidthRaw( font, str ) ); else lua_pushnumber( L, gl_printHeightRaw( font, width, str ) ); return 1; }
/** * @brief Opens the spaceport bar window. */ static void bar_open( unsigned int wid ) { int w, h, iw, ih, bw, bh, dh, th; /* Set window functions. */ window_onClose( wid, bar_close ); /* Get dimensions. */ bar_getDim( wid, &w, &h, &iw, &ih, &bw, &bh ); dh = gl_printHeightRaw( &gl_smallFont, w - iw - 60, land_planet->bar_description ); /* Buttons */ window_addButton( wid, -20, 20, bw, bh, "btnCloseBar", "Takeoff", land_buttonTakeoff ); window_addButton( wid, -20 - bw - 20, 20, bw, bh, "btnApproach", "Approach", bar_approach ); /* Bar description. */ window_addText( wid, iw + 40, -40, w - iw - 60, dh, 0, "txtDescription", &gl_smallFont, &cBlack, land_planet->bar_description ); /* Add portrait text. */ th = -40 - dh - 40; window_addText( wid, iw + 40, th, w - iw - 60, gl_defFont.h, 1, "txtPortrait", &gl_defFont, &cDConsole, NULL ); /* Add mission description text. */ th -= 20 + PORTRAIT_HEIGHT + 20 + 20; window_addText( wid, iw + 60, th, w - iw - 100, h + th - (2*bh+60), 0, "txtMission", &gl_smallFont, &cBlack, NULL ); /* Generate the mission list. */ bar_genList( wid ); }
/** * @brief Opens the shipyard window. */ void shipyard_open( unsigned int wid ) { int i; Ship **ships; char **sships; glTexture **tships; int nships; int w, h; int iw, ih; int bw, bh, padding, off; int th; int y; const char *buf; /* Mark as generated. */ land_tabGenerate(LAND_WINDOW_SHIPYARD); /* Init vars. */ shipyard_selected = NULL; /* Get window dimensions. */ window_dimWindow( wid, &w, &h ); /* Calculate image array dimensions. */ iw = 310 + (w-800); ih = h - 60; /* Left padding + per-button padding * nbuttons */ padding = 40 + 20 * 4; /* Calculate button dimensions. */ bw = (w - iw - padding) / 4; bh = LAND_BUTTON_HEIGHT; /* buttons */ window_addButtonKey( wid, off = -20, 20, bw, bh, "btnCloseShipyard", "Take Off", land_buttonTakeoff, SDLK_t ); window_addButtonKey( wid, off -= 20+bw, 20, bw, bh, "btnTradeShip", "Trade-In", shipyard_trade, SDLK_r ); window_addButtonKey( wid, off -= 20+bw, 20, bw, bh, "btnBuyShip", "Buy", shipyard_buy, SDLK_b ); window_addButtonKey( wid, off -= 20+bw, 20, bw, bh, "btnFindShips", "Find Ships", shipyard_find, SDLK_f ); /* target gfx */ window_addRect( wid, -41, -50, SHIP_TARGET_W, SHIP_TARGET_H, "rctTarget", &cBlack, 0 ); window_addImage( wid, -40, -50, SHIP_TARGET_W, SHIP_TARGET_H, "imgTarget", NULL, 1 ); /* slot types */ window_addCust( wid, -20, -160, 148, 70, "cstSlots", 0., shipyard_renderSlots, NULL, NULL ); /* stat text */ window_addText( wid, -40, -240, 128, 200, 0, "txtStats", &gl_smallFont, &cBlack, NULL ); /* text */ buf = "Model:\n" "Class:\n" "Fabricator:\n" "Crew:\n" "\n" "CPU:\n" "Mass:\n" "Thrust:\n" "Speed:\n" "Turn:\n" "\n" "Absorption:\n" "Shield:\n" "Armour:\n" "Energy:\n" "Cargo Space:\n" "Fuel:\n" "Fuel Use:\n" "Price:\n" "Money:\n" "License:\n"; th = gl_printHeightRaw( &gl_smallFont, 100, buf ); y = -55; window_addText( wid, 40+iw+20, y, 100, th, 0, "txtSDesc", &gl_smallFont, &cDConsole, buf ); window_addText( wid, 40+iw+20+100, y, w-(40+iw+20+100)-20, th, 0, "txtDDesc", &gl_smallFont, &cBlack, NULL ); y -= th; window_addText( wid, 20+iw+40, y, w-(20+iw+40) - 180, 185, 0, "txtDescription", &gl_smallFont, NULL, NULL ); /* set up the ships to buy/sell */ ships = tech_getShip( land_planet->tech, &nships ); if (nships <= 0) { sships = malloc(sizeof(char*)); sships[0] = strdup("None"); tships = malloc(sizeof(glTexture*)); tships[0] = NULL; nships = 1; } else { sships = malloc(sizeof(char*)*nships); tships = malloc(sizeof(glTexture*)*nships); for (i=0; i<nships; i++) { sships[i] = strdup(ships[i]->name); tships[i] = ships[i]->gfx_store; } free(ships); } window_addImageArray( wid, 20, 20, iw, ih, "iarShipyard", 64./96.*128., 64., tships, sships, nships, shipyard_update, shipyard_rmouse ); /* write the shipyard stuff */ shipyard_update(wid, NULL); /* Set default keyboard focuse to the list */ window_setFocus( wid , "iarShipyard" ); }
/** * @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 ); }
/** * @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
/** * @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 ); }