15#include "dev_uniedit.h"
20#include "dev_sysedit.h"
21#include "dev_system.h"
32#include "tk/toolkit_priv.h"
36#define BUTTON_WIDTH 100
37#define BUTTON_HEIGHT 30
39#define UNIEDIT_EDIT_WIDTH 400
40#define UNIEDIT_EDIT_HEIGHT 450
42#define UNIEDIT_FIND_WIDTH 400
43#define UNIEDIT_FIND_HEIGHT 500
45#define UNIEDIT_DRAG_THRESHOLD 300
46#define UNIEDIT_MOVE_THRESHOLD 10
47#define UNIEDIT_CLICK_THRESHOLD 20.
48#define UNIEDIT_DOUBLECLICK_THRESHOLD 300
50#define UNIEDIT_ZOOM_STEP 1.2
51#define UNIEDIT_ZOOM_MAX 5.
52#define UNIEDIT_ZOOM_MIN -5.
57typedef enum UniEditMode_ {
65typedef enum UniEditViewMode_ {
67 UNIEDIT_VIEW_VIRTUALSPOBS,
70 UNIEDIT_VIEW_BACKGROUND,
71 UNIEDIT_VIEW_ASTEROIDS,
72 UNIEDIT_VIEW_INTERFERENCE,
74 UNIEDIT_VIEW_PRESENCE_SUM,
75 UNIEDIT_VIEW_PRESENCE,
133static void uniedit_chkNolanes(
unsigned int wid,
const char *wgtname );
149static void uniedit_btnTagsClose(
unsigned int wid,
const char *unused );
152static void uniedit_render(
double bx,
double by,
double w,
double h,
void *data );
155static int uniedit_mouse(
unsigned int wid,
const SDL_Event* event,
double mx,
double my,
156 double w,
double h,
double rx,
double ry,
void *data );
157static void uniedit_renderFactionDisks(
double x,
double y,
double r );
158static void uniedit_renderVirtualSpobs(
double x,
double y,
double r );
160static void uniedit_close(
unsigned int wid,
const char *wgt );
161static void uniedit_save(
unsigned int wid_unused,
const char *unused );
162static void uniedit_btnView(
unsigned int wid_unused,
const char *unused );
163static void uniedit_btnJump(
unsigned int wid_unused,
const char *unused );
165static void uniedit_btnEdit(
unsigned int wid_unused,
const char *unused );
166static void uniedit_btnNew(
unsigned int wid_unused,
const char *unused );
167static void uniedit_btnOpen(
unsigned int wid_unused,
const char *unused );
168static void uniedit_btnFind(
unsigned int wid_unused,
const char *unused );
170static int uniedit_keys(
unsigned int wid, SDL_Keycode key, SDL_Keymod mod,
int isrepeat );
181 const glColour cBG = { 0., 0., 0., 0.95 };
204 wid =
window_create(
"wdwUniverseEditor", _(
"Universe Editor"), -1, -1, -1, -1 );
211 window_addCust( wid, 0, 0, SCREEN_W, SCREEN_H,
216 window_addRect( wid, SCREEN_W-130, 0, 130, SCREEN_H,
"rctRCol", &cBG, 0 );
217 window_addRect( wid, 0, 0, SCREEN_W, 60,
"rctBBar", &cBG, 0 );
225 window_addCheckbox( wid, -150, 25, SCREEN_W/2 - 150, 20,
226 "chkEditAutoSave", _(
"Automatically save changes"), uniedit_autosave, conf.
devautosave );
230 "btnSave", _(
"Save All"), uniedit_save );
273 window_addText( wid, -10, -20, 110, 200, 0,
"txtNebula",
277 window_addText( wid, -10, -80-
gl_smallFont.
h-5, 110, 200, 0,
"txtPresence",
281 window_addText( wid, 140, 10, SCREEN_W/2 - 140, 30, 0,
291static int uniedit_keys(
unsigned int wid, SDL_Keycode key, SDL_Keymod mod,
int isrepeat )
304 if (mod & (KMOD_LCTRL | KMOD_RCTRL)) {
318 for (
int i=0; i<n; i++) {
353static void uniedit_save(
unsigned int wid_unused,
const char *unused )
365void uniedit_autosave(
unsigned int wid_unused,
const char *unused )
370 conf.
devautosave = window_checkboxState( wid_unused,
"chkEditAutoSave" );
376void uniedit_updateAutosave (
void)
381static int factionGenerates(
int f,
int tocheck,
double *w )
385 if (fg[i].
id==tocheck) {
415 if ((p->presence.faction != f) && !factionGenerates(p->presence.faction,f,NULL))
417 if (p->presence.base==0. && p->presence.bonus==0.)
432 str = malloc(
sizeof(
char*) * (
array_size(factions)+n) );
433 str[0]= strdup(_(
"Default"));
434 str[1]= strdup(_(
"Virtual Spobs"));
435 str[2]= strdup(_(
"System Radius"));
436 str[3]= strdup(_(
"No Lanes"));
437 str[4]= strdup(_(
"Background"));
438 str[5]= strdup(_(
"Asteroids"));
439 str[6]= strdup(_(
"Interference"));
440 str[7]= strdup(_(
"Tech"));
441 str[8]= strdup(_(
"Sum of Presences"));
448 qsort( &str[n], k-n,
sizeof(
char*),
strsort );
450 window_addList( wid, 20, -40,
UNIEDIT_EDIT_WIDTH-40, h,
"lstViewModes", str, k, 0, NULL,
uniedit_btnViewModeSet );
533static void uniedit_renderFactionDisks(
double x,
double y,
double r )
537 double tx, ty, sr, presence;
564static void uniedit_renderVirtualSpobs(
double x,
double y,
double r )
566 const glColour
c = { .r=1., .g=1., .b=1., .a=0.3 };
583static void uniedit_renderRadius(
double x,
double y,
double r )
585 const glColour
c = { .r=1., .g=1., .b=1., .a=0.3 };
602static void uniedit_renderNolanes(
double x,
double y,
double r )
604 const glColour
c = { .r=1., .g=1., .b=1., .a=0.3 };
610 if (!sys_isFlag( sys, SYSTEM_NOLANES ))
624static void uniedit_renderBackground(
double x,
double y,
double r )
626 const glColour
c = { .r=1., .g=1., .b=1., .a=0.3 };
632 if (sys->background==NULL)
646static void uniedit_renderAsteroids(
double x,
double y,
double r )
648 const glColour
c = { .r=1., .g=1., .b=1., .a=0.3 };
653 double density = sys->asteroid_density;
668static void uniedit_renderInterference(
double x,
double y,
double r )
670 const glColour
c = { .r=1., .g=1., .b=1., .a=0.3 };
680 sr = 5.*M_PI*sqrt(sys->interference / 20.) *
uniedit_zoom;
687static void uniedit_renderTech(
double x,
double y,
double r )
689 const glColour
c = { .r=1., .g=1., .b=1., .a=0.3 };
696 for (
int j=0; j<
array_size(sys->spobs); j++) {
697 if (sys->spobs[j]->tech != NULL) {
715static void uniedit_renderPresenceSum(
double x,
double y,
double r )
717 const glColour
c = { .r=1., .g=1., .b=1., .a=0.3 };
724 for (
int j=0; j<
array_size(sys->presence); j++)
725 total +=
MAX( 0., sys->presence[j].value );
740void uniedit_renderMap(
double bx,
double by,
double w,
double h,
double x,
double y,
double zoom,
double r )
745 if (UNIEDIT_VIEW_DEFAULT)
746 map_renderDecorators( x, y, zoom, 1, 1. );
750 case UNIEDIT_VIEW_DEFAULT:
751 map_renderFactionDisks( x, y, zoom, r, 1, 1. );
752 map_renderSystemEnvironment( x, y, zoom, 1, 1. );
755 case UNIEDIT_VIEW_VIRTUALSPOBS:
756 uniedit_renderVirtualSpobs( x, y, r );
759 case UNIEDIT_VIEW_RADIUS:
760 uniedit_renderRadius( x, y, r );
763 case UNIEDIT_VIEW_NOLANES:
764 uniedit_renderNolanes( x, y, r );
767 case UNIEDIT_VIEW_BACKGROUND:
768 uniedit_renderBackground( x, y, r );
771 case UNIEDIT_VIEW_ASTEROIDS:
772 uniedit_renderAsteroids( x, y, r );
775 case UNIEDIT_VIEW_INTERFERENCE:
776 uniedit_renderInterference( x, y, r );
779 case UNIEDIT_VIEW_TECH:
780 uniedit_renderTech( x, y, r );
783 case UNIEDIT_VIEW_PRESENCE_SUM:
784 uniedit_renderPresenceSum( x, y, r );
787 case UNIEDIT_VIEW_PRESENCE:
789 uniedit_renderFactionDisks( x, y, r );
794 map_renderJumps( x, y, zoom, r, 1 );
797 map_renderSystems( bx, by, x, y, zoom, w, h, r, MAPMODE_EDITOR );
800 map_renderNames( bx, by, x, y, zoom, w, h, 1, 1. );
802 glClear( GL_DEPTH_BUFFER_BIT );
808static void uniedit_render(
double bx,
double by,
double w,
double h,
void *data )
819 uniedit_renderMap( bx, by, w, h, x, y,
uniedit_zoom, r );
824 glUseProgram( shaders.selectspob.program );
825 glUniform1f( shaders.selectspob.dt,
uniedit_dt );
827 1.5*r, 1.5*r, 0., &shaders.selectspob, &cWhite, 1 );
831static char getValCol(
double val )
839static int getPresenceVal(
int f,
SpobPresence *ap,
double *base,
double *bonus )
843 if ((ap->
faction!=f) && !(gf=factionGenerates(ap->
faction, f, &w)))
850 *base = ap->
base * w;
851 *bonus = ap->
bonus * w;
861 double x,y, mx,my, sx,sy;
862 double value, base, bonus;
863 char buf[STRMAX] = {
'\0'};
864 StarSystem *sys, *cur, *mousesys;
882 double l, r, b, t, rx, ry;
883 const glColour col = { .r = 0.2, .g = 0.2, .b = 0.8, .a = 0.5 };
898 if ((x > SCREEN_W-130) || (y < 60))
923 if (mousesys == NULL)
938 for (
int j=0; j<
array_size(sys->spobs_virtual); j++) {
940 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"%s%s", (l>0)?
"\n":
"", va->
name );
949 scnprintf( &buf[0],
sizeof(buf), _(
"System Radius: %s"),
num2strU( sys->radius, 0 ));
956 if (sys->background != NULL) {
957 scnprintf( &buf[0],
sizeof(buf), _(
"Background: %s"), sys->background );
967 l =
scnprintf( &buf[l],
sizeof(buf)-l, _(
"Density: %g"), sys->asteroid_density );
968 for (
int i=0; i<
array_size(sys->asteroids); i++) {
980 if (sys->interference > 0.) {
981 scnprintf( &buf[0],
sizeof(buf), _(
"Interference: %.0f%%"), sys->interference );
991 const int len =
sizeof(techlist) /
sizeof(
char*);
999 for (
int j=0; j<
array_size(sys->spobs); j++) {
1000 Spob *spob = sys->spobs[j];
1003 if (spob->
tech==NULL)
1006 for (
int k=0; (k<n) && (ntechs<len-1) ; k++)
1007 techlist[ ntechs++ ] = techs[k];
1010 qsort( techlist, ntechs,
sizeof(
char*),
strsort );
1011 for (
int k=0; k<ntechs; k++) {
1012 if ((k>0) && (strcmp(techlist[k-1],techlist[k])==0))
1014 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"%s%s", (l>0)?
"\n":
"", techlist[k] );
1016 for (
int k=0; k<ntechs; k++)
1017 free( techlist[k] );
1031 for (
int j=0; j<
array_size(sys->presence); j++)
1032 value +=
MAX( sys->presence[j].value, 0. );
1035 l =
scnprintf( buf,
sizeof(buf), _(
"Total: %.0f"), value );
1036 for (
int j=0; j<
array_size(sys->presence); j++) {
1037 sp = &sys->presence[j];
1055 l =
scnprintf( buf,
sizeof(buf),
"#%c%.0f#0 = #%c%.0f#0 + #%c%.0f#0 [%s - %s]",
1056 getValCol(value), value, getValCol(base), base, getValCol(bonus), bonus,
1060 for (
int j=0; j<
array_size(sys->spobs); j++) {
1061 Spob *spob = sys->spobs[j];
1062 if (!getPresenceVal( f, &spob->
presence, &base, &bonus ))
1064 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n#%c%.0f#0 (#%c%+.0f#0) [%s]",
1065 getValCol(base), base, getValCol(bonus), bonus,
spob_name(spob) );
1067 for (
int j=0; j<
array_size(sys->spobs_virtual); j++) {
1070 if (!getPresenceVal( f, &va->
presences[p], &base, &bonus ))
1072 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n#%c%.0f#0 (#%c%+.0f#0) [%s]",
1073 getValCol(base), base, getValCol(bonus), bonus, _(va->
name) );
1078 for (
int k=0; k<
array_size(sys->jumps); k++) {
1079 cur = sys->jumps[k].target;
1080 for (
int j=0; j<
array_size(cur->spobs); j++) {
1081 Spob *spob = cur->spobs[j];
1082 if (!getPresenceVal( f, &spob->
presence, &base, &bonus ))
1084 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n#%c%.0f#0 (#%c%+.0f#0) [%s (%s)]",
1085 getValCol(base), base*0.5, getValCol(bonus), bonus*0.5,
spob_name(spob), _(cur->name) );
1087 for (
int j=0; j<
array_size(cur->spobs_virtual); j++) {
1090 if (!getPresenceVal( f, &va->
presences[p], &base, &bonus ))
1092 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"\n#%c%.0f#0 (#%c%+.0f#0) [%s (%s)]",
1093 getValCol(base), base*0.5, getValCol(bonus), bonus*0.5, _(va->
name), _(cur->name) );
1116static int uniedit_mouse(
unsigned int wid,
const SDL_Event* event,
double mx,
double my,
1117 double w,
double h,
double rx,
double ry,
void *data )
1120 unsigned int lastClick;
1121 StarSystem *clickedsys;
1126 mod = SDL_GetModState();
1128 switch (event->type) {
1130 case SDL_MOUSEWHEEL:
1132 if ((mx < 0.) || (mx > w-130.) || (my < 60.) || (my > h))
1135 if (event->wheel.y > 0)
1137 else if (event->wheel.y < 0)
1142 case SDL_MOUSEBUTTONDOWN:
1144 if ((mx < 0.) || (mx > w-130.) || (my < 60.) || (my > h))
1188 if (clickedsys != NULL) {
1210 if ((clickedsys != NULL) && inselection) {
1214 if (mod & (KMOD_LCTRL | KMOD_RCTRL))
1223 if (clickedsys != NULL) {
1225 if (!(mod & (KMOD_LCTRL | KMOD_RCTRL)))
1235 if (mod & (KMOD_LCTRL | KMOD_RCTRL | KMOD_LSHIFT | KMOD_RSHIFT)) {
1236 if (mod & (KMOD_LSHIFT | KMOD_RSHIFT))
1249 case SDL_MOUSEBUTTONUP:
1291 double x = sys->pos.x;
1292 double y = sys->pos.y;
1293 if ((x >= l) && (x <= r) && (y >= b) && (y <= t))
1301 case SDL_MOUSEMOTION:
1308 double a1, a2, amod;
1315 a1 = atan2( cy, cx );
1318 a2 = atan2( cy, cx );
1325 double a = atan2( sy, sx );
1326 double m = hypot( sx, sy );
1368 dialogue_alert( _(
"The Star System '%s' already exists!"), name );
1375char *uniedit_nameFilter(
const char *name )
1377 char *out = calloc( 1, (strlen(name)+1) );
1379 for (
int i=0; i<(int)strlen(name); i++) {
1380 if (!ispunct(name[i])) {
1384 out[pos] = tolower(name[i]);
1397 int cancelall_prompt = 0;
1399 char *name, *oldName, *newName, *filtered;
1403 name =
dialogue_input( _(
"Rename Star System"), 1, 32, _(
"What do you want to rename #r%s#0?"), sys->name );
1408 if (
dialogue_YesNoRaw( _(
"Cancel batch renaming?"), _(
"Do you want to cancel renaming all selected star systems?")))
1410 cancelall_prompt = 1;
1423 filtered = uniedit_nameFilter(sys->name);
1424 SDL_asprintf(&oldName,
"%s/%s.xml", conf.
dev_save_sys, filtered);
1427 filtered = uniedit_nameFilter(name);
1428 SDL_asprintf(&newName,
"%s/%s.xml", conf.
dev_save_sys, filtered);
1431 if (rename(oldName, newName))
1432 WARN(_(
"Failed to rename '%s' to '%s'!"),oldName,newName);
1456 name =
dialogue_inputRaw( _(
"New Star System Creation"), 1, 32, _(
"What do you want to name the new system?") );
1476 sys->spacedust = DUST_DENSITY_DEFAULT;
1477 sys->radius = RADIUS_DEFAULT;
1492 StarSystem *isys = NULL;
1496 for (
int j=0; j<
array_size(isys->jumps); j++) {
1497 StarSystem *target = isys->jumps[j].target;
1499 if (target == sys) {
1537 memset( jp, 0,
sizeof(JumpPoint) );
1541 jp->targetid = targ->id;
1543 jp->flags = JP_AUTOPOS;
1544 jp->hide = HIDE_DEFAULT_JUMP;
1556 if (sys->jumps[i].target == targ)
1561 WARN(_(
"Jump for system '%s' not found in system '%s' for removal."), targ->name, sys->name);
1566 array_erase( &sys->jumps, &sys->jumps[i], &sys->jumps[i+1] );
1582 window_modifyText(
uniedit_wid,
"txtSelected", _(
"No selection") );
1583 window_modifyText(
uniedit_wid,
"txtNebula", _(
"N/A") );
1584 window_modifyText(
uniedit_wid,
"txtPresence", _(
"N/A") );
1626 WARN(_(
"Trying to remove system '%s' from selection when not selected."), sys->name);
1646 window_modifyText(
uniedit_wid,
"txtSelected", buf );
1654 if (sys->nebu_density > 0.)
1655 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%.0f Density\n%.1f Volatility\n%.0f Hue"), sys->nebu_density, sys->nebu_volatility, sys->nebu_hue*360.);
1656 if (sys->interference > 0.)
1657 l +=
scnprintf( &buf[l],
sizeof(buf)-l, _(
"%s%.1f Interference"), (l>0)?
"\n":
"", sys->interference);
1659 window_modifyText(
uniedit_wid,
"txtNebula", buf );
1662 map_updateFactionPresence(
uniedit_wid,
"txtPresence", sys, 1 );
1665 window_modifyText(
uniedit_wid,
"txtNebula", _(
"Multiple selected") );
1666 window_modifyText(
uniedit_wid,
"txtPresence", _(
"Multiple selected") );
1687 if (strcmp(str,
"btnZoomIn")==0) {
1691 else if (strcmp(str,
"btnZoomOut")==0) {
1724 "inpFind", 32, 1, NULL );
1743 int n, nspobs, nsystems;
1745 char **spobs, **systems;
1748 name = window_getInput( wid,
"inpFind" );
1758 found = malloc(
sizeof(
map_find_t) * (nspobs + nsystems) );
1762 for (
int i=0; i<nspobs; i++) {
1769 if (sysname == NULL)
1777 found[n].
spob = spob;
1781 snprintf( found[n].display,
sizeof(found[n].display),
1782 _(
"%s (%s system)"), spobs[i], sys->name );
1788 for (
int i=0; i<nsystems; i++) {
1792 found[n].
spob = NULL;
1795 strncpy(found[n].display, sys->name,
sizeof(found[n].
display)-1);
1823 str = malloc(
sizeof(
char*) );
1824 str[0] = strdup(_(
"None"));
1830 str = malloc(
sizeof(
char*) * n );
1831 for (
int i=0; i<n; i++)
1832 str[i] = strdup( found[i].display );
1867 pos = toolkit_getListPos( wid,
"lstResults" );
1890 return strcasecmp( f1->
sys->name, f2->
sys->name );
1900 char buf[STRMAX_SHORT];
1923 window_addText( wid, x, y, 180, 15, 0,
"txtName", &
gl_smallFont, NULL, buf );
1932 window_addText( wid, x, y, l, 20, 1,
"txtRadius",
1934 window_addInput( wid, x += l + 7, y, 80, 20,
"inpRadius", 10, 1, NULL );
1935 window_setInputFilter( wid,
"inpRadius", INPUT_FILTER_NUMBER );
1937 s = _(
"(Scales spob positions)");
1939 window_addText( wid, x, y, l, 20, 1,
"txtRadiusComment",
1948 window_addText( wid, x, y, l, 20, 1,
"txtDust",
1950 window_addInput( wid, x += l + 7, y, 50, 20,
"inpDust", 4, 1, NULL );
1951 window_setInputFilter( wid,
"inpDust", INPUT_FILTER_NUMBER );
1954 s = _(
"Interference");
1956 window_addText( wid, x, y, l, 20, 1,
"txtInterference",
1958 window_addInput( wid, x += l + 7, y, 55, 20,
"inpInterference", 5, 1, NULL );
1959 window_setInputFilter( wid,
"inpInterference", INPUT_FILTER_NUMBER );
1967 window_addText( wid, x, y, l, 20, 1,
"txtNebula",
1969 window_addInput( wid, x += l + 7, y, 50, 20,
"inpNebula", 4, 1, NULL );
1970 window_setInputFilter( wid,
"inpNebula", INPUT_FILTER_NUMBER );
1973 s = _(
"Volatility");
1975 window_addText( wid, x, y, l, 20, 1,
"txtVolatility",
1977 window_addInput( wid, x += l + 7, y, 50, 20,
"inpVolatility", 4, 1, NULL );
1978 window_setInputFilter( wid,
"inpVolatility", INPUT_FILTER_NUMBER );
1983 window_addText( wid, x, y, l, 20, 1,
"txtHue",
1985 window_addInput( wid, x += l + 7, y, 50, 20,
"inpHue", 4, 1, NULL );
1986 window_setInputFilter( wid,
"inpHue", INPUT_FILTER_NUMBER );
1994 window_addCheckbox( wid, x, y, 100,
gl_defFont.
h,
"chkNolanes", s, uniedit_chkNolanes, sys_isFlag( sys, SYSTEM_NOLANES ) );
1999 l =
scnprintf( buf,
sizeof(buf),
"#n%s#0", _(
"Tags: ") );
2001 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"%s%s", (i==0)?
"":
", ", sys->tags[i] );
2002 window_addText( wid, x, y,
UNIEDIT_EDIT_WIDTH-40, 20, 0,
"txtTags", NULL, NULL, buf );
2005 snprintf( buf,
sizeof(buf),
"%g", sys->radius );
2006 window_setInput( wid,
"inpRadius", buf );
2007 snprintf( buf,
sizeof(buf),
"%d", sys->spacedust );
2008 window_setInput( wid,
"inpDust", buf );
2009 snprintf( buf,
sizeof(buf),
"%g", sys->interference );
2010 window_setInput( wid,
"inpInterference", buf );
2011 snprintf( buf,
sizeof(buf),
"%g", sys->nebu_density );
2012 window_setInput( wid,
"inpNebula", buf );
2013 snprintf( buf,
sizeof(buf),
"%g", sys->nebu_volatility );
2014 window_setInput( wid,
"inpVolatility", buf );
2015 snprintf( buf,
sizeof(buf),
"%g", sys->nebu_hue*360. );
2016 window_setInput( wid,
"inpHue", buf );
2031 int y, h, has_spobs;
2046 str = malloc(
sizeof(
char*) * (n+1) );
2049 for (
int i=0; i<n; i++) {
2050 va = sys->spobs_virtual[i];
2051 str[j++] = strdup( va->
name );
2055 str[j++] = strdup(_(
"None"));
2060 "lstSpobs", str, j, 0, NULL, NULL );
2088 scale = atof(window_getInput( wid,
"inpRadius" )) / sys->radius;
2091 sys->spacedust = atoi(window_getInput( wid,
"inpDust" ));
2092 sys->interference = atof(window_getInput( wid,
"inpInterference" ));
2093 sys->nebu_density = atof(window_getInput( wid,
"inpNebula" ));
2094 sys->nebu_volatility = atof(window_getInput( wid,
"inpVolatility" ));
2095 sys->nebu_hue = atof(window_getInput( wid,
"inpHue" )) / 360.;
2117 const char *selected;
2121 selected = toolkit_getList( wid,
"lstSpobs" );
2124 if ((selected==NULL) || (strcmp(selected,_(
"None"))==0))
2130 dialogue_alert( _(
"Failed to remove virtual spob '%s'!"), selected );
2156 dialogue_alert( _(
"No virtual spobs to add! Please add virtual spobs to the '%s' directory first."), VIRTUALSPOB_DATA_PATH );
2165 str = malloc(
sizeof(
char*) *
array_size(va) );
2167 str[i] = strdup( va[i].name );
2170 "lstSpobs", str,
array_size(va), 0, NULL, NULL );
2186 const char *selected;
2190 selected = toolkit_getList( wid,
"lstSpobs" );
2191 if (selected == NULL)
2197 dialogue_alert( _(
"Failed to add virtual spob '%s'!"), selected );
2232 "btnClose", _(
"Close"), uniedit_btnTagsClose );
2251 for (
int i=0; i<
array_size(systems_all); i++) {
2252 StarSystem *s = &systems_all[i];
2254 char *t = s->tags[j];
2274static void uniedit_btnTagsClose(
unsigned int wid,
const char *unused )
2276 char buf[STRMAX_SHORT];
2278 int l =
scnprintf( buf,
sizeof(buf),
"#n%s#0", _(
"Tags: ") );
2280 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"%s%s", ((i>0) ?
", " :
""), s->tags[i] );
2292 char **have, **lack;
2293 int n, x, y, w, h, hpos, lpos, empty;
2300 hpos = toolkit_getListPos( wid,
"lstTagsHave" );
2301 lpos = toolkit_getListPos( wid,
"lstTagsLacked" );
2315 have = malloc( n *
sizeof(
char*) );
2316 for (
int i=0; i<n; i++)
2317 have[i] = strdup(s->tags[i]);
2321 have = malloc(
sizeof(
char*) );
2322 have[n++] = strdup(_(
"None"));
2327 window_addList( wid, x, y, w, h,
"lstTagsHave", have, n, 0, NULL,
uniedit_btnRmTag );
2336 lack[n++] = strdup(t);
2340 if (strcmp( s->tags[j], t )==0) {
2345 lack[n++] = strdup( t );
2350 window_addList( wid, x, y, w, h,
"lstTagsLacked", lack, n, 0, NULL,
uniedit_btnAddTag );
2353 if (hpos != -1 && lpos != -1) {
2354 toolkit_setListPos( wid,
"lstTagsHave", hpos );
2355 toolkit_setListPos( wid,
"lstTagsLacked", lpos );
2365 const char *selected;
2368 selected = toolkit_getList( wid,
"lstTagsLacked" );
2369 if ((selected == NULL) || (strcmp(selected,_(
"None"))==0))
2373 if (s->tags == NULL)
2387 const char *selected;
2391 selected = toolkit_getList( wid,
"lstTagsHave" );
2392 if ((selected == NULL) || (strcmp(selected,_(
"None"))==0))
2397 if (strcmp( selected, s->tags[i] )==0)
2402 array_erase( &s->tags, &s->tags[i], &s->tags[i+1] );
2416 char *tag =
dialogue_input( _(
"Add New System Tag"), 1, 128, _(
"Please write the new tag to add to the system.") );
2421 if (s->tags == NULL)
2438 char buf[STRMAX_SHORT];
2445 window_modifyText( wid,
"txtName", buf );
2453 const char *selected;
2457 pos = toolkit_getListPos( wid,
"lstViewModes" );
2506 selected = toolkit_getList( wid,
"lstViewModes" );
2507 if (selected == NULL)
2517static void uniedit_chkNolanes(
unsigned int wid,
const char *wgtname )
2519 int s = window_checkboxState( wid, wgtname );
2522 sys_setFlag( sys, SYSTEM_NOLANES );
2524 sys_rmFlag( sys, SYSTEM_NOLANES );
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
#define array_erase(ptr_array, first, last)
Erases elements in interval [first, last).
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
int dpl_saveAll(void)
Saves all the star spobs.
void sysedit_open(StarSystem *sys)
Opens the system editor interface.
void sysedit_sysScale(StarSystem *sys, double factor)
Scales a system.
int dsys_saveSystem(StarSystem *sys)
Saves a star system.
int dsys_saveAll(void)
Saves all the star systems.
static UniEditMode uniedit_mode
static void uniedit_btnOpen(unsigned int wid_unused, const char *unused)
Opens up a system.
static void uniedit_btnEditRename(unsigned int wid, const char *unused)
Renames the systems in the system editor.
static double uniedit_rotate
static int uniedit_checkName(const char *name)
Checks to see if a system name is already in use.
static void uniedit_renderOverlay(double bx, double by, double bw, double bh, void *data)
Renders the overlay.
static double uniedit_xpos
void uniedit_open(unsigned int wid_unused, const char *unused)
Opens the system editor interface.
static void uniedit_close(unsigned int wid, const char *wgt)
Closes the system editor widget.
#define UNIEDIT_CLICK_THRESHOLD
static double uniedit_dragSelX
static unsigned int uniedit_widFind
#define UNIEDIT_DOUBLECLICK_THRESHOLD
static map_find_t * found_cur
static void uniedit_btnEditAddSpobAdd(unsigned int wid, const char *unused)
Actually adds the virtual spob.
static void uniedit_btnNewTag(unsigned int wid, const char *unused)
Adds a tech to a system.
static void uniedit_deselect(void)
Deselects selected targets.
static void uniedit_btnAddTag(unsigned int wid, const char *unused)
Adds a tech to a spob.
static void uniedit_editSys(void)
Edits an individual system or group of systems.
#define UNIEDIT_FIND_WIDTH
static void uniedit_newSys(double x, double y)
Creates a new system.
static double uniedit_ypos
static void uniedit_btnNew(unsigned int wid_unused, const char *unused)
Enters the editor in new system mode.
static char ** uniedit_tagslist
#define UNIEDIT_ZOOM_STEP
static StarSystem ** uniedit_sys
#define UNIEDIT_EDIT_HEIGHT
static void uniedit_toggleJump(StarSystem *sys)
Toggles the jump point for the selected systems.
static void uniedit_editGenList(unsigned int wid)
Generates the virtual spob list.
static int uniedit_keys(unsigned int wid, SDL_Keycode key, SDL_Keymod mod, int isrepeat)
Handles keybindings.
static unsigned int uniedit_widEdit
static void uniedit_buttonZoom(unsigned int wid, const char *str)
Handles the button zoom clicks.
static void uniedit_renameSys(void)
Renames all the currently selected systems.
static void uniedit_findSys(void)
Finds systems and spobs.
static void uniedit_jumpAdd(StarSystem *sys, StarSystem *targ)
Adds a new Star System jump.
static void uniedit_btnFind(unsigned int wid_unused, const char *unused)
Opens the system property editor.
static int uniedit_dragSys
#define UNIEDIT_FIND_HEIGHT
static void uniedit_findShowResults(unsigned int wid, map_find_t *found, int n)
Generates the virtual spob list.
static double uniedit_zoom
static unsigned int uniedit_lastClick
static double uniedit_dragSelY
static int uniedit_dragSel
static double uniedit_rotate_cx
static void uniedit_btnJump(unsigned int wid_unused, const char *unused)
Enters the editor in new jump mode.
static void uniedit_btnEdit(unsigned int wid_unused, const char *unused)
Opens the system property editor.
StarSystem * systems_stack
#define UNIEDIT_DRAG_THRESHOLD
static void uniedit_jumpRm(StarSystem *sys, StarSystem *targ)
Removes a Star System jump.
static void uniedit_editSysClose(unsigned int wid, const char *name)
Closes the system property editor, saving the changes made.
static int uniedit_sortCompare(const void *p1, const void *p2)
qsort compare function for map finds.
static int uniedit_mouse(unsigned int wid, const SDL_Event *event, double mx, double my, double w, double h, double rx, double ry, void *data)
System editor custom widget mouse handling.
static void uniedit_btnEditAddSpob(unsigned int wid, const char *unused)
Adds a new virtual spob.
static double uniedit_rotate_cy
static void uniedit_btnViewModeSet(unsigned int wid, const char *unused)
Actually adds the virtual spob.
static void uniedit_btnView(unsigned int wid_unused, const char *unused)
Allows selecting the view.
static void uniedit_selectAdd(StarSystem *sys)
Adds a system to the selection.
static void uniedit_centerSystem(unsigned int wid, const char *unused)
Centers the selected system.
static void uniedit_findSysClose(unsigned int wid, const char *name)
Closes the search dialogue.
static UniEditViewMode uniedit_viewmode
static unsigned int uniedit_wid
static void uniedit_findSearch(unsigned int wid, const char *str)
Searches for spobs and systems.
#define UNIEDIT_EDIT_WIDTH
static int uniedit_view_faction
#define UNIEDIT_MOVE_THRESHOLD
void uniedit_selectText(void)
Sets the selected system text.
static void uniedit_btnRename(unsigned int wid_unused, const char *unused)
Renames selected systems.
static void uniedit_btnRmTag(unsigned int wid, const char *unused)
Removes a tech from a spob.
static void uniedit_selectRm(StarSystem *sys)
Removes a system from the selection.
static void uniedit_focusLose(unsigned int wid, const char *wgtname)
Called when it's de-focused.
static void uniedit_btnEditRmSpob(unsigned int wid, const char *unused)
Removes a selected spob.
static void uniedit_btnEditTags(unsigned int wid, const char *unused)
Edits a spob's tags.
static void uniedit_render(double bx, double by, double w, double h, void *data)
System editor custom widget rendering.
static StarSystem * uniedit_tsys
static void uniedit_genTagsList(unsigned int wid)
Generates the spob tech list.
char * dialogue_inputRaw(const char *title, int min, int max, const char *msg)
Creates a dialogue that allows the player to write a message.
void dialogue_alert(const char *fmt,...)
Displays an alert popup with only an ok button and a message.
char * dialogue_input(const char *title, int min, int max, const char *fmt,...)
Creates a dialogue that allows the player to write a message.
int dialogue_YesNoRaw(const char *caption, const char *msg)
Runs a dialogue with both yes and no options.
int economy_execQueued(void)
Calls economy_refresh if an economy update is queued.
const char * faction_name(int f)
Gets a factions "real" (internal) name.
const FactionGenerator * faction_generators(int f)
Gets the faction's generators.
const glColour * faction_colour(int f)
Gets the colour of the faction.
int * faction_getAll(void)
Returns all faction IDs in an array (array.h).
int faction_get(const char *name)
Gets a faction ID by name.
int gl_printWidthRaw(const glFont *ft_font, const char *text)
Gets the width that it would take to print some text.
void gl_print(const glFont *ft_font, const double x, const double y, const glColour *c, const char *fmt,...)
Prints text on screen like printf.
double naev_getrealdt(void)
Gets the last delta-tick.
Header file with generic functions and naev-specifics.
int strsort(const void *p1, const void *p2)
Sort function for sorting strings with qsort().
int scnprintf(char *text, size_t maxlen, const char *fmt,...)
Like snprintf(), but returns the number of characters ACTUALLY "printed" into the buffer....
const char * num2strU(double n, int decimals)
Unsafe version of num2str that uses an internal buffer. Every call overwrites the return value.
void gl_renderShader(double x, double y, double w, double h, double r, const SimpleShader *shd, const glColour *c, int center)
Renders a simple shader.
void gl_renderRect(double x, double y, double w, double h, const glColour *c)
Renders a rectangle.
void gl_renderCircle(double cx, double cy, double r, const glColour *c, int filled)
Draws a circle.
void pause_game(void)
Pauses the game.
void unpause_game(void)
Unpauses the game.
void safelanes_recalculate(void)
Update the safe lane locations in response to the universe changing (e.g., diff applied).
void space_reconstructPresences(void)
Reset the presence of all systems.
void systems_reconstructJumps(void)
Reconstructs the jumps.
double system_getPresenceFull(const StarSystem *sys, int faction, double *base, double *bonus)
Get the presence of a faction in a system.
Spob * spob_getAll(void)
Gets an array (array.h) of all spobs.
Spob * spob_get(const char *spobname)
Gets a spob based on its name.
int system_addVirtualSpob(StarSystem *sys, const char *spobname)
Adds a virtual spob to a system.
StarSystem * system_getIndex(int id)
Get the system by its index.
StarSystem * system_new(void)
Creates a new star system.
StarSystem * system_getAll(void)
Gets an array (array.h) of all star systems.
char ** spob_searchFuzzyCase(const char *spobname, int *n)
Does a fuzzy case matching. Searches spob_name() but returns internal names.
char ** system_searchFuzzyCase(const char *sysname, int *n)
Does a fuzzy case matching. Searches translated names but returns internal names.
StarSystem * system_get(const char *sysname)
Get the system from its name.
const char * spob_getSystem(const char *spobname)
Get the name of a system from a spobname.
double system_getPresence(const StarSystem *sys, int faction)
Get the presence of a faction in a system.
int system_rmVirtualSpob(StarSystem *sys, const char *spobname)
Removes a virtual spob from a system.
VirtualSpob * virtualspob_getAll(void)
Gets all the virtual spobs.
const char * spob_name(const Spob *p)
Gets the translated name of a spob.
Represents an asteroid field anchor.
AsteroidTypeGroup ** groups
Represents the presence of a spob.
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...
Represents presence in a system.
Basically modifies system parameters without creating any real objects.
Represents a found target.
char display[STRMAX_SHORT]
char ** tech_getItemNames(const tech_group_t *tech, int *n)
Gets the names of all techs within a given group.
void diff_clear(void)
Removes all active diffs. (Call before economy_destroy().)