/** * @brief Sets the map to sane defaults */ void map_clear (void) { map_setZoom(1.); if (cur_system != NULL) { map_xpos = cur_system->pos.x; map_ypos = cur_system->pos.y; } else { map_xpos = 0.; map_ypos = 0.; } if (map_path != NULL) { free(map_path); map_path = NULL; map_npath = 0; } /* default system is current system */ map_selectCur(); }
/** * @brief Shows a map at x, y (relative to wid) with size w,h. * * @param wid Window to show map on. * @param x X position to put map at. * @param y Y position to put map at. * @param w Width of map to open. * @param h Height of map to open. * @param zoom Default zoom to use. */ void map_show( int wid, int x, int y, int w, int h, double zoom ) { StarSystem *sys; /* mark systems as needed */ mission_sysMark(); /* Set position to focus on current system. */ map_xpos = cur_system->pos.x * zoom; map_ypos = cur_system->pos.y * zoom; /* Set zoom. */ map_setZoom(zoom); /* Make sure selected is sane. */ sys = system_getIndex( map_selected ); if (!(sys_isFlag(sys, SYSTEM_MARKED | SYSTEM_CMARKED)) && !sys_isKnown(sys) && !space_sysReachable(sys)) map_selectCur(); window_addCust( wid, x, y, w, h, "cstMap", 1, map_render, map_mouse, NULL ); }
/** * @brief Handles the button zoom clicks. * * @param wid Unused. * @param str Name of the button creating the event. */ static void map_buttonZoom( unsigned int wid, char* str ) { (void) wid; /* Transform coords to normal. */ map_xpos /= map_zoom; map_ypos /= map_zoom; /* Apply zoom. */ if (strcmp(str,"btnZoomIn")==0) { map_zoom += (map_zoom >= 1.) ? 0.5 : 0.25; map_zoom = MIN(2.5, map_zoom); } else if (strcmp(str,"btnZoomOut")==0) { map_zoom -= (map_zoom > 1.) ? 0.5 : 0.25; map_zoom = MAX(0.5, map_zoom); } map_setZoom(map_zoom); /* Transform coords back. */ map_xpos *= map_zoom; map_ypos *= map_zoom; }
/** * @brief Opens the system editor interface. */ void uniedit_open( unsigned int wid_unused, char *unused ) { (void) wid_unused; (void) unused; unsigned int wid; /* Pause. */ pause_game(); /* Needed to generate faction disk. */ map_setZoom( 1. ); /* Must have no diffs applied. */ diff_clear(); /* Reset some variables. */ uniedit_mode = UNIEDIT_DEFAULT; uniedit_drag = 0; uniedit_dragSys = 0; uniedit_tsys = NULL; uniedit_tadd = 0; uniedit_zoom = 1.; uniedit_xpos = 0.; uniedit_ypos = 0.; /* Create the window. */ wid = window_create( "Universe Editor", -1, -1, -1, -1 ); window_handleKeys( wid, uniedit_keys ); uniedit_wid = wid; /* Close button. */ window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT, "btnClose", "Close", uniedit_close ); /* Jump toggle. */ window_addButton( wid, -20, 20+(BUTTON_HEIGHT+20)*3, BUTTON_WIDTH, BUTTON_HEIGHT, "btnJump", "Jump", uniedit_btnJump ); /* Rename system. */ window_addButton( wid, -20, 20+(BUTTON_HEIGHT+20)*4, BUTTON_WIDTH, BUTTON_HEIGHT, "btnRename", "Rename", uniedit_btnRename ); /* Edit system. */ window_addButton( wid, -20, 20+(BUTTON_HEIGHT+20)*5, BUTTON_WIDTH, BUTTON_HEIGHT, "btnEdit", "Edit", uniedit_btnEdit ); /* New system. */ window_addButton( wid, -20, 20+(BUTTON_HEIGHT+20)*6, BUTTON_WIDTH, BUTTON_HEIGHT, "btnNew", "New Sys", uniedit_btnNew ); /* Open a system. */ window_addButton( wid, -20, 20+(BUTTON_HEIGHT+20)*7, BUTTON_WIDTH, BUTTON_HEIGHT, "btnOpen", "Open", uniedit_btnOpen ); /* Zoom buttons */ window_addButton( wid, 40, 20, 30, 30, "btnZoomIn", "+", uniedit_buttonZoom ); window_addButton( wid, 80, 20, 30, 30, "btnZoomOut", "-", uniedit_buttonZoom ); /* Presence. */ window_addText( wid, -20, -140, 90, 20, 0, "txtSPresence", &gl_smallFont, &cDConsole, "Presence:" ); window_addText( wid, -20, -140-gl_smallFont.h-5, 80, 100, 0, "txtPresence", &gl_smallFont, &cBlack, "N/A" ); /* Selected text. */ window_addText( wid, 140, 10, SCREEN_W - 80 - 30 - 30 - BUTTON_WIDTH - 20, 30, 0, "txtSelected", &gl_smallFont, &cBlack, NULL ); /* Actual viewport. */ window_addCust( wid, 20, -40, SCREEN_W - 150, SCREEN_H - 100, "cstSysEdit", 1, uniedit_render, uniedit_mouse, NULL ); window_custSetOverlay( wid, "cstSysEdit", uniedit_renderOverlay ); /* Deselect everything. */ uniedit_deselect(); }