/** * @brief Adds a system to the selection. */ static void uniedit_selectAdd( StarSystem *sys ) { /* Allocate if needed. */ if (uniedit_msys < uniedit_nsys+1) { if (uniedit_msys == 0) uniedit_msys = 1; uniedit_msys *= 2; uniedit_sys = realloc( uniedit_sys, sizeof(StarSystem*) * uniedit_msys ); } /* Add system. */ uniedit_sys[ uniedit_nsys ] = sys; uniedit_nsys++; /* Set text again. */ uniedit_selectText(); /* Enable buttons again. */ window_enableButton( uniedit_wid, "btnJump" ); window_enableButton( uniedit_wid, "btnRename" ); window_enableButton( uniedit_wid, "btnEdit" ); if (uniedit_nsys == 1) window_enableButton( uniedit_wid, "btnOpen" ); else window_disableButton( uniedit_wid, "btnOpen" ); }
/** * @brief Opens up a system. */ static void uniedit_btnOpen( unsigned int wid_unused, char *unused ) { (void) wid_unused; (void) unused; if (uniedit_nsys != 1) return; sysedit_open( uniedit_sys[0] ); /* Update sidebar text. */ uniedit_selectText(); }
/** * @brief Removes a system from the selection. */ static void uniedit_selectRm( StarSystem *sys ) { int i; for (i=0; i<uniedit_nsys; i++) { if (uniedit_sys[i] == sys) { uniedit_nsys--; memmove( &uniedit_sys[i], &uniedit_sys[i+1], sizeof(StarSystem*) * (uniedit_nsys - i) ); uniedit_selectText(); if (uniedit_nsys == 1) window_enableButton( uniedit_wid, "btnOpen" ); else window_disableButton( uniedit_wid, "btnOpen" ); return; } } WARN("Trying to remove system '%s' from selection when not selected.", sys->name); }
/** * @brief Toggles the jump point for the selected systems. */ static void uniedit_toggleJump( StarSystem *sys ) { int i, j, rm; StarSystem *isys, *target; for (i=0; i<uniedit_nsys; i++) { isys = uniedit_sys[i]; rm = 0; for (j=0; j<isys->njumps; j++) { target = isys->jumps[j].target; /* Target already exists, remove. */ if (target == sys) { uniedit_jumpRm( isys, sys ); uniedit_jumpRm( sys, isys ); rm = 1; break; } } /* Target doesn't exist, add. */ if (!rm) { uniedit_jumpAdd( isys, sys ); uniedit_jumpAdd( sys, isys ); } } /* Reconstruct jumps just in case. */ systems_reconstructJumps(); /* Reconstruct universe presences. */ space_reconstructPresences(); if (conf.devautosave) { dsys_saveSystem( sys ); dsys_saveSystem( isys ); } /* Update sidebar text. */ uniedit_selectText(); }