/** * @brief Opens the map window. */ void map_open (void) { unsigned int wid; StarSystem *cur; int w, h, x, y, rw; /* Not under manual control. */ if (pilot_isFlag( player.p, PILOT_MANUAL_CONTROL )) return; /* Destroy window if exists. */ wid = window_get(MAP_WDWNAME); if (wid > 0) { window_destroy( wid ); return; } /* set position to focus on current system */ map_xpos = cur_system->pos.x; map_ypos = cur_system->pos.y; /* mark systems as needed */ mission_sysMark(); /* Attempt to select current map if none is selected */ if (map_selected == -1) map_selectCur(); /* get the selected system. */ cur = system_getIndex( map_selected ); /* Set up window size. */ w = MAX(600, SCREEN_W - 100); h = MAX(540, SCREEN_H - 100); /* create the window. */ wid = window_create( MAP_WDWNAME, -1, -1, w, h ); window_setCancel( wid, window_close ); window_handleKeys( wid, map_keyHandler ); /* * SIDE TEXT * * $System * * Faction: * $Faction (or Multiple) * * Status: * $Status * * Planets: * $Planet1, $Planet2, ... * * Services: * $Services * * ... * [Autonav] * [ Find ] * [ Close ] */ x = -70; /* Right column X offset. */ y = -20; rw = ABS(x) + 60; /* Right column indented width maximum. */ /* System Name */ window_addText( wid, -90 + 80, y, 160, 20, 1, "txtSysname", &gl_defFont, &cDConsole, cur->name ); y -= 10; /* Faction image */ window_addImage( wid, -90 + 32, y - 32, 0, 0, "imgFaction", NULL, 0 ); y -= 64 + 10; /* Faction */ window_addText( wid, x, y, 90, 20, 0, "txtSFaction", &gl_smallFont, &cDConsole, "Faction:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtFaction", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Standing */ window_addText( wid, x, y, 90, 20, 0, "txtSStanding", &gl_smallFont, &cDConsole, "Standing:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtStanding", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Presence. */ window_addText( wid, x, y, 90, 20, 0, "txtSPresence", &gl_smallFont, &cDConsole, "Presence:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtPresence", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Planets */ window_addText( wid, x, y, 90, 20, 0, "txtSPlanets", &gl_smallFont, &cDConsole, "Planets:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 150, 0, "txtPlanets", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Services */ window_addText( wid, x, y, 90, 20, 0, "txtSServices", &gl_smallFont, &cDConsole, "Services:" ); window_addText( wid, x + 50, y-gl_smallFont.h-5, rw, 100, 0, "txtServices", &gl_smallFont, &cBlack, NULL ); y -= 2 * gl_smallFont.h + 5 + 15; /* Close button */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", window_close ); /* Find button */ window_addButton( wid, -20 - (BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnFind", "Find", map_inputFind ); /* Autonav button */ window_addButton( wid, -20 - 2*(BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnAutonav", "Autonav", player_autonavStartWindow ); /* * Bottom stuff * * [+] [-] Nebula, Asteroids, Interference */ /* Zoom buttons */ window_addButton( wid, 40, 20, 30, 30, "btnZoomIn", "+", map_buttonZoom ); window_addButton( wid, 80, 20, 30, 30, "btnZoomOut", "-", map_buttonZoom ); /* Situation text */ window_addText( wid, 140, 10, w - 80 - 30 - 30, 30, 0, "txtSystemStatus", &gl_smallFont, &cBlack, NULL ); /* * The map itself. */ map_show( wid, 20, -40, w-200, h-100, 1. ); /* Reset zoom. */ map_update( wid ); /* * Disable Autonav button if player lacks fuel. */ if ((player.p->fuel < HYPERSPACE_FUEL) || pilot_isFlag( player.p, PILOT_NOJUMP)) window_disableButton( wid, "btnAutonav" ); }
/** * @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; /* 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) { 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" ); 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 */ snprintf( 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; for (i=0; i < sys->npresence; i++) { if (sys->presence[i].value <= 0) continue; hasPresence = 1; t = faction_getColourChar(sys->presence[i].faction); /* Use map grey instead of default neutral colour */ l += snprintf( &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); } if (hasPresence == 0) snprintf(buf, PATH_MAX, "N/A"); window_moveWidget( wid, "txtSPresence", x, y ); window_moveWidget( wid, "txtPresence", x + 50, y-gl_smallFont.h-5 ); window_modifyText( wid, "txtPresence", buf ); /* Scroll down. */ h = gl_printHeightRaw( &gl_smallFont, w, buf ); y -= 40 + (h - gl_smallFont.h); /* Get planets */ hasPlanets = 0; p = 0; buf[0] = '\0'; for (i=0; i<sys->nplanets; i++) { if(sys->planets[i]->real != ASSET_REAL) continue; /* Colourize output. */ planet_updateLand(sys->planets[i]); t = planet_getColourChar(sys->planets[i]); if (t == 'N') t = 'M'; else if (t == 'R') t = 'S'; if (!hasPlanets) p += snprintf( &buf[p], PATH_MAX-p, "\e%c%s\en", t, sys->planets[i]->name ); else p += snprintf( &buf[p], PATH_MAX-p, ",\n\e%c%s\en", t, sys->planets[i]->name ); hasPlanets = 1; }