/** * @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 Generates the mission list for the bar. * * @param wid Window to create mission list for. */ static int bar_genList( unsigned int wid ) { glTexture **portraits; char **names, *focused; int w, h, iw, ih, bw, bh; int n; /* Get dimensions. */ bar_getDim( wid, &w, &h, &iw, &ih, &bw, &bh ); /* Save focus. */ focused = strdup(window_getFocus(wid)); /* Destroy widget if already exists. */ if (widget_exists( wid, "iarMissions" )) window_destroyWidget( wid, "iarMissions" ); /* We sort just in case. */ npc_sort(); /* Set up missions. */ if (mission_portrait == NULL) mission_portrait = gl_newImage( PORTRAIT_GFX_PATH"news.png", 0 ); n = npc_getArraySize(); if (n <= 0) { n = 1; portraits = malloc(sizeof(glTexture*)); portraits[0] = mission_portrait; names = malloc(sizeof(char*)); names[0] = strdup("News"); } else { n = n+1; portraits = malloc( sizeof(glTexture*) * n ); portraits[0] = mission_portrait; npc_getTextureArray( &portraits[1], n-1 ); names = malloc( sizeof(char*) * n ); names[0] = strdup("News"); npc_getNameArray( &names[1], n-1 ); } window_addImageArray( wid, 20, -40, iw, ih, "iarMissions", 100, 75, portraits, names, n, bar_update, NULL ); /* write the outfits stuff */ bar_update( wid, NULL ); /* Restore focus. */ window_setFocus( wid, focused ); free(focused); return 0; }
/** * @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 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 ); }