diff --git a/src/map.c b/src/map.c index ea341a1..2220624 100644 --- a/src/map.c +++ b/src/map.c @@ -22,6 +22,7 @@ extern int systems_nstack; static void map_render(double bx, double by, double w, double h); static void map_close(char* str); +static void map_update(void); // Open the map window. void map_open(void) { @@ -32,11 +33,29 @@ void map_open(void) { map_ypos = cur_system->pos.y; map_wid = window_create("Star Map", -1, -1, MAP_WIDTH, MAP_HEIGHT); + + window_addText(map_wid, -20, -20, 100, 20, 1, "txtSysname", + &gl_defFont, &cDConsole, systems_stack[map_selected].name); + + window_addText(map_wid, -20, -60, 90, 20, 0, "txtSFaction", + &gl_smallFont, &cDConsole, "Faction:"); + + window_addText(map_wid, -20, -60-gl_smallFont.h-5, 80, 100, 0, "txtFaction", + &gl_smallFont, &cBlack, NULL); + + window_addText(map_wid, -20, -110, 90, 20, 0, "txtSPlanets", + &gl_smallFont, &cDConsole, "Planets:"); + + window_addText(map_wid, -20, -110-gl_smallFont.h-5, 80, 100, 0, "txtPlanets", + &gl_smallFont, &cBlack, NULL); window_addCust(map_wid, 20, 20, MAP_WIDTH - 150, MAP_HEIGHT - 60, "cstMap", 1, map_render); + window_addButton(map_wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", map_close); + + map_update(); } static void map_close(char* str) { @@ -47,6 +66,49 @@ static void map_close(char* str) { } } +static void map_update(void) { + int i; + StarSystem* sys; + Faction* f; + char buf[100]; + + sys = &systems_stack[map_selected]; + + window_modifyText(map_wid, "txtSysname", sys->name); + + if(sys->nplanets == 0) + // No planets -> no factions. + snprintf(buf, 100, "NA"); + else { + f = NULL; + for(i = 0; i < sys->nplanets; i++) { + if(f == NULL) + f = sys->planets[i].faction; + else if(f != sys->planets[i].faction) { + // TODO: more verbosity. + snprintf(buf, 100, "Multiple"); + break; + } + } + if(i == sys->nplanets) + // Saw them all, and all the same. + snprintf(buf, 100, "%s", f->name); + } + + window_modifyText(map_wid, "txtFaction", buf); + + buf[0] = '\0'; + if(sys->nplanets == 0) + snprintf(buf, 100, "None"); + else { + for(i = 0; i < sys->nplanets; i++) { + strcat(buf, sys->planets[i].name); + strcat(buf, "\n"); + } + } + window_modifyText(map_wid, "txtPlanets", buf); +} + // Render the map as a custom widget. static void map_render(double bx, double by, double w, double h) { int i; @@ -61,7 +123,7 @@ static void map_render(double bx, double by, double w, double h) { COLOUR(cYellow); for(i = 0; i < systems_nstack; i++) { - if(i == map_selected) COLOUR(cRadar_targ); + if(&systems_stack[i] == cur_system) COLOUR(cRadar_targ); else COLOUR(cYellow); gl_drawCircleInRect(bx + systems_stack[i].pos.x - map_xpos + w/2, by + systems_stack[i].pos.y - map_ypos + h/2,