16#include "dev_sysedit.h"
21#include "dev_system.h"
22#include "dev_uniedit.h"
29#include "opengl_render.h"
32#include "tk/toolkit_priv.h"
36#define BUTTON_WIDTH 100
37#define BUTTON_HEIGHT 30
39#define SYSEDIT_EDIT_WIDTH 500
40#define SYSEDIT_EDIT_HEIGHT 400
42#define SYSEDIT_DRAG_THRESHOLD 300
43#define SYSEDIT_MOVE_THRESHOLD 10
45#define SYSEDIT_ZOOM_STEP 1.2
46#define SYSEDIT_ZOOM_MAX 1
47#define SYSEDIT_ZOOM_MIN -23
63typedef struct Select_s {
104static void sysedit_render(
double bx,
double by,
double w,
double h,
void *data );
107static void sysedit_renderBG(
double bx,
double bw,
double w,
double h,
double x,
double y );
109 int sx,
int sy,
const glColour *
c,
int selected,
const char *caption );
111static int sysedit_mouseTrySelect(
const Select_t *sel,
double x,
double y,
double t,
double mx,
double my, SDL_Keymod mod,
void (*func)(
void) );
112static int sysedit_mouse(
unsigned int wid, SDL_Event* event,
double mx,
double my,
113 double w,
double h,
double xr,
double yr,
void *data );
115static void sysedit_close(
unsigned int wid,
const char *wgt );
118static void sysedit_btnRename(
unsigned int wid_unused,
const char *unused );
122static void sysedit_btnGrid(
unsigned int wid_unused,
const char *unused );
123static void sysedit_btnEdit(
unsigned int wid_unused,
const char *unused );
137static void sysedit_spobGFX(
unsigned int wid_unused,
const char *wgt );
147static void sysedit_editAsteroidsClose(
unsigned int wid,
const char *unused );
148static void sysedit_genAsteroidsList(
unsigned int wid );
149static void sysedit_btnAsteroidsDelete(
unsigned int wid,
const char *unused );
150static void sysedit_btnRmAsteroid(
unsigned int wid,
const char *unused );
151static void sysedit_btnAddAsteroid(
unsigned int wid,
const char *unused );
153static void sysedit_editExclusion (
void);
154static void sysedit_editExclusionClose(
unsigned int wid,
const char *unused );
155static void sysedit_btnExclusionDelete(
unsigned int wid,
const char *unused );
157static int sysedit_keys(
unsigned int wid, SDL_Keycode key, SDL_Keymod mod );
174 const glColour cBG = { 0., 0., 0., 0.95 };
190 snprintf( buf,
sizeof(buf), _(
"%s - Star System Editor"), sys->name );
199 window_addCust( wid, 0, 0, SCREEN_W, SCREEN_H,
203 window_addRect( wid, SCREEN_W-130, 0, 130, SCREEN_H,
"rctRCol", &cBG, 0 );
204 window_addRect( wid, 0, 0, SCREEN_W, 60,
"rctBBar", &cBG, 0 );
212 window_addCheckbox( wid, -150, 25, SCREEN_W/2 - 150, 20,
213 "chkEditAutoSave", _(
"Automatically save changes"), uniedit_autosave, conf.
devautosave );
237 "btnRename", _(
"Rename"), sysedit_btnRename );
259 snprintf( buf,
sizeof(buf), _(
"Radius: %.0f"), sys->radius );
260 window_addText( wid, 140, 10, SCREEN_W/2-140, 30, 0,
270static int sysedit_keys(
unsigned int wid, SDL_Keycode key, SDL_Keymod mod )
314 uniedit_updateAutosave();
329 p->population = (uint64_t)strtoull( window_getInput(
sysedit_widEdit,
"inpPop" ), 0, 10);
337 p->class = strdup( inp );
342 if ((inp == NULL) || (strlen(inp) == 0))
345 p->lua_file = strdup( inp );
347 p->presence.base = atof(window_getInput(
sysedit_widEdit,
"inpPresenceBase" ));
348 p->presence.bonus = atof(window_getInput(
sysedit_widEdit,
"inpPresenceBonus" ));
349 p->presence.range = atoi(window_getInput(
sysedit_widEdit,
"inpPresenceRange" ));
376 name =
dialogue_inputRaw( _(
"New Spob Creation"), 1, 32, _(
"What do you want to name the new spob?") );
382 dialogue_alert( _(
"Spob by the name of #r'%s'#0 already exists in the #r'%s'#0 system"),
395 p->class = strdup( b->class );
396 p->gfx_spacePath = strdup( b->gfx_spacePath );
397 p->gfx_spaceName = strdup( b->gfx_spaceName );
398 p->gfx_exterior = strdup( b->gfx_exterior );
399 p->gfx_exteriorPath = strdup( b->gfx_exteriorPath );
402 p->hide = HIDE_DEFAULT_SPOB;
403 p->radius = b->radius;
426 const char *title, *caption, *ret;
427 const char *opts[] = {
433 title = _(
"Add asteriod field or exclusion zone?");
434 caption = _(
"Do you wish to add an asteroid field or an asteroid exclusion zone that will remove all asteroids that will appear in it?");
442 if (strcmp(ret, opts[0])==0) {
445 ast->
density = ASTEROID_DEFAULT_DENSITY;
449 ast->
maxspeed = ASTEROID_DEFAULT_MAXSPEED;
450 ast->
thrust = ASTEROID_DEFAULT_THRUST;
467static void sysedit_btnRename(
unsigned int wid_unused,
const char *unused )
474 char *name, *oldName, *newName, *filtered;
479 _(
"What do you want to rename the spob #r%s#0?"), p->name );
485 dialogue_alert( _(
"Spob by the name of #r'%s'#0 already exists in the #r'%s'#0 system"),
492 filtered = uniedit_nameFilter(p->name);
493 asprintf(&oldName,
"dat/spob/%s.xml", filtered);
496 filtered = uniedit_nameFilter(name);
497 asprintf(&newName,
"dat/spob/%s.xml", filtered);
500 rename(oldName, newName);
520 char *file, *filtered;
522 if (
dialogue_YesNo( _(
"Remove selected objects (excluding jumps)?"), _(
"This can not be undone.") )) {
527 filtered = uniedit_nameFilter( sp->
name );
528 asprintf(&file,
"dat/spob/%s.xml", filtered);
563 sysedit_sys[i].jumps[ sel->
u.jump ].flags |= JP_AUTOPOS;
582 str =
dialogue_inputRaw( _(
"Scale Star System"), 1, 32, _(
"By how much do you want to scale the star system?") );
591 if ((s < 0.1) || (s > 10.)) {
592 int i =
dialogue_YesNo( _(
"Scale Star System"), _(
"Are you sure you want to scale the star system by %.2f (from %.2f to %.2f)?"),
593 s, sys->radius, sys->radius*s );
609 sys->radius *= factor;
610 snprintf( buf,
sizeof(buf), _(
"Radius: %.0f"), sys->radius );
612 window_modifyText(
sysedit_wid,
"txtSelected", buf );
615 for (
int i=0; i<
array_size(sys->spobs); i++) {
616 Spob *p = sys->spobs[i];
617 vec2_cset( &p->pos, p->pos.x*factor, p->pos.y*factor );
621 for (
int i=0; i<
array_size(sys->jumps); i++) {
622 JumpPoint *jp = &sys->jumps[i];
623 vec2_cset( &jp->pos, jp->pos.x*factor, jp->pos.y*factor );
627 for (
int i=0; i<
array_size(sys->asteroids); i++) {
629 vec2_cset( &ast->
pos, ast->
pos.
x*factor, ast->
pos.
y*factor );
632 for (
int i=0; i<
array_size(sys->astexclude); i++) {
634 vec2_cset( &exc->
pos, exc->
pos.
x*factor, exc->
pos.
y*factor );
656static void sysedit_render(
double bx,
double by,
double w,
double h,
void *data )
674 for (
int i=0; i<
array_size(sys->spobs); i++) {
675 Spob *p = sys->spobs[i];
685 for (
int i=0; i<
array_size(sys->jumps); i++) {
687 JumpPoint *jp = &sys->jumps[i];
695 c = (jp->flags & JP_AUTOPOS) ? &cGreen : NULL;
699 jp->
sx, jp->sy,
c, selected, jp->target->name );
703 for (
int i=0; i<
array_size(sys->asteroids); i++) {
714 for (
int i=0; i<
array_size(sys->astexclude); i++) {
733 for (
int j=0; j<2; j++) {
735 case SAFELANE_LOC_SPOB:
737 posns[j] = &pnt->
pos;
739 case SAFELANE_LOC_DEST_SYS:
741 posns[j] = &njp->pos;
744 ERR( _(
"Invalid vertex type.") );
752 double x1, y1, x2, y2, ry, rx, r, rw, rh;
753 x1 = x + posns[0]->
x * z;
754 y1 = y + posns[0]->
y * z;
755 x2 = x + posns[1]->
x * z;
756 y2 = y + posns[1]->
y * z;
764 glUseProgram(shaders.safelane.program);
765 gl_renderShader( (x1+x2)/2., (y1+y2)/2., rw, rh, r, &shaders.safelane, &col, 1 );
771 &cWhite,
"% 9.2f x % 9.2f",
788 tx = bx + ast->
pos.
x*z;
789 ty = by + ast->
pos.
y*z;
792 const glColour csel = COL_ALPHA( cFontBlue, 0.5 );
799 (selected) ? &cRed : NULL, -1., _(
"Asteroid Field") );
808 double tx, ty, z, r, rr;
815 tx = bx + aexcl->
pos.
x*z;
816 ty = by + aexcl->
pos.
y*z;
818 rr = r * sin(M_PI / 4.);
821 const glColour csel = COL_ALPHA( cFontBlue, 0.5 );
825 col = (selected) ? &cWhite : &cRed;
835static void sysedit_renderBG(
double bx,
double by,
double w,
double h,
double x,
double y )
839 const double s = 1000.;
842 double startx, starty, spacing;
858 startx = bx + fmod( x - bx, spacing );
859 starty = by + fmod( y - by, spacing );
861 nx = lround( w / spacing );
862 ny = lround( h / spacing );
865 for (
int i=0; i<nx; i++) {
866 double d = startx + (i * spacing);
870 for (
int i=0; i<ny; i++) {
871 double d = starty + (i * spacing);
882 int sx,
int sy,
const glColour *
c,
int selected,
const char *caption )
892 const glColour csel = COL_ALPHA( cFontBlue, 0.5 );
897 tx = bx + (x - gfx->
sw/2.)*z;
898 ty = by + (y - gfx->
sh/2.)*z;
903 if (caption != NULL) {
923static int sysedit_mouseTrySelect(
const Select_t *sel,
double x,
double y,
double t,
double mx,
double my, SDL_Keymod mod,
void (*func)(
void) )
940 if (mod & (KMOD_LCTRL | KMOD_RCTRL))
959 if (mod & (KMOD_LCTRL | KMOD_RCTRL))
977static int sysedit_mouse(
unsigned int wid, SDL_Event* event,
double mx,
double my,
978 double w,
double h,
double xr,
double yr,
void *data )
982 SDL_Keymod mod = SDL_GetModState();
984 switch (event->type) {
988 if ((mx < 0.) || (mx > w) || (my < 0.) || (my > h))
991 if (event->wheel.y > 0)
993 else if (event->wheel.y < 0)
998 case SDL_MOUSEBUTTONDOWN:
1000 if ((mx < 0.) || (mx > w) || (my < 0.) || (my > h))
1009 for (
int i=0; i<
array_size(sys->spobs); i++) {
1010 Spob *p = sys->spobs[i];
1017 double t = p->gfx_space->sw * p->gfx_space->sh / 4.;
1021 if (sysedit_mouseTrySelect( &sel, p->pos.x, p->pos.y, t, mx, my, mod,
sysedit_editPnt ))
1026 for (
int i=0; i<
array_size(sys->jumps); i++) {
1027 JumpPoint *jp = &sys->jumps[i];
1038 if (sysedit_mouseTrySelect( &sel, jp->pos.x, jp->pos.y, t, mx, my, mod,
sysedit_editJump ))
1043 for (
int i=0; i<
array_size(sys->astexclude); i++) {
1052 if (sysedit_mouseTrySelect( &sel, exc->
pos.
x, exc->
pos.
y, t, mx, my, mod, sysedit_editExclusion ))
1057 for (
int i=0; i<
array_size(sys->asteroids); i++) {
1071 if (!(mod & (KMOD_LCTRL | KMOD_RCTRL))) {
1079 case SDL_MOUSEBUTTONUP:
1113 case SDL_MOUSEMOTION:
1139 switch (sel->
type) {
1141 p = sys->spobs[ sel->
u.spob ];
1147 jp = &sys->jumps[ sel->
u.jump ];
1148 jp->flags &= ~(JP_AUTOPOS);
1155 ast->
pos.
x += xmove;
1156 ast->
pos.
y += ymove;
1160 exc = &sys->astexclude[ sel->
u.astexclude ];
1161 exc->
pos.
x += xmove;
1162 exc->
pos.
y += ymove;
1192 if (strcmp(str,
"btnZoomIn")==0) {
1196 else if (strcmp(str,
"btnZoomOut")==0) {
1226 int sel_spob, sel_jump, sel_asteroid, sel_exclusion;
1235 switch (sel->
type) {
1252 if (sel_spob || sel_asteroid || sel_exclusion)
1311 WARN(_(
"Trying to deselect item that is not in selection!"));
1321 return (memcmp(a, b,
sizeof(
Select_t)) == 0);
1342 char buf[STRMAX_SHORT], title[128];
1349 snprintf(title,
sizeof(title), _(
"Spob Property Editor - %s"), p->name);
1359 snprintf( buf,
sizeof(buf),
"%s ", _(
"Name:") );
1361 window_addText( wid, 20, y, 180, 15, 0,
"txtNameLabel", &
gl_smallFont, NULL, buf );
1362 snprintf( buf,
sizeof(buf),
"%s", p->name );
1363 window_addText( wid, 20 + w, y, 180, 15, 0,
"txtName", &
gl_smallFont, NULL, buf );
1365 _(
"Rename"), sysedit_btnRename );
1371 snprintf( buf,
sizeof(buf),
"%s ", _(
"Faction:") );
1373 window_addText( wid, 20, y, 180, 15, 0,
"txtFactionLabel", &
gl_smallFont, NULL, buf );
1374 snprintf( buf,
sizeof(buf),
"%s", p->presence.faction >= 0 ?
faction_name( p->presence.faction ) : _(
"None") );
1375 window_addText( wid, 20 + w, y, 180, 15, 0,
"txtFaction", &
gl_smallFont, NULL, buf );
1380 s = _(
"Population");
1382 window_addText( wid, x, y, l, 20, 1,
"txtPop",
1384 window_addInput( wid, x += l + 5, y, 80, 20,
"inpPop", 12, 1, NULL );
1385 window_setInputFilter( wid,
"inpPop", INPUT_FILTER_NUMBER );
1390 window_addText( wid, x, y, l, 20, 1,
"txtClass",
1392 window_addInput( wid, x += l + 5, y, 30, 20,
"inpClass", 1, 1, NULL );
1397 window_addText( wid, x, y, l, 20, 1,
"txtLua",
1399 window_addInput( wid, x += l + 5, y, 150, 20,
"inpLua", 20, 1, NULL );
1404 s = _(
"Base Presence");
1406 window_addText( wid, x, y, l, 20, 1,
"txtPresenceBase",
1408 window_addInput( wid, x += l + 5, y, 50, 20,
"inpPresenceBase", 5, 1, NULL );
1409 window_setInputFilter( wid,
"inpPresenceBase", INPUT_FILTER_NUMBER );
1412 s = _(
"Bonus Presence");
1414 window_addText( wid, x, y, l, 20, 1,
"txtPresenceBonus",
1416 window_addInput( wid, x += l + 5, y, 50, 20,
"inpPresenceBonus", 5, 1, NULL );
1417 window_setInputFilter( wid,
"inpPresenceBonus", INPUT_FILTER_NUMBER );
1422 window_addText( wid, x, y, l, 20, 1,
"txtPresenceRange",
1424 window_addInput( wid, x += l + 5, y, 30, 20,
"inpPresenceRange", 1, 1, NULL );
1425 window_setInputFilter( wid,
"inpPresenceRange", INPUT_FILTER_NUMBER );
1432 window_addText( wid, x, y, l, 20, 1,
"txtHide",
1434 window_addInput( wid, x += l + 5, y, 50, 20,
"inpHide", 4, 1, NULL );
1435 window_setInputFilter( wid,
"inpHide", INPUT_FILTER_NUMBER );
1441 l =
scnprintf( buf,
sizeof(buf),
"#n%s#0", _(
"Tags:") );
1443 l +=
scnprintf( &buf[l],
sizeof(buf)-l,
"%s %s", ((i>0) ?
"," :
""), p->tags[i] );
1444 window_addText( wid, x, y, 300, 20, 0,
"txtTags", NULL, NULL, buf );
1453 window_addButton( wid, -20 - bw*3 - 15*3, 20, bw,
BUTTON_HEIGHT,
1455 window_addButton( wid, -20 - bw*2 - 15*2, 20, bw,
BUTTON_HEIGHT,
1457 window_addButton( wid, -20 - bw - 15, 20, bw,
BUTTON_HEIGHT,
1463 snprintf( buf,
sizeof(buf),
"%"PRIu64, p->population );
1464 window_setInput( wid,
"inpPop", buf );
1465 snprintf( buf,
sizeof(buf),
"%s", p->class );
1466 window_setInput( wid,
"inpClass", buf );
1467 window_setInput( wid,
"inpLua", p->lua_file );
1468 snprintf( buf,
sizeof(buf),
"%g", p->presence.base );
1469 window_setInput( wid,
"inpPresenceBase", buf );
1470 snprintf( buf,
sizeof(buf),
"%g", p->presence.bonus );
1471 window_setInput( wid,
"inpPresenceBonus", buf );
1472 snprintf( buf,
sizeof(buf),
"%d", p->presence.range );
1473 window_setInput( wid,
"inpPresenceRange", buf );
1474 snprintf( buf,
sizeof(buf),
"%g", p->hide );
1475 window_setInput( wid,
"inpHide", buf );
1493 window_checkboxSet( wid,
"chkHidden",
jp_hidden );
1494 window_checkboxSet( wid,
"chkExit",
jp_exit );
1509 window_checkboxSet( wid,
"chkHidden",
jp_hidden );
1510 window_checkboxSet( wid,
"chkExit",
jp_exit );
1520 char buf[STRMAX_SHORT];
1532 snprintf( buf,
sizeof(buf), _(
"Target: ") );
1534 window_addText( wid, 20, y, 180, 15, 0,
"txtTargetLabel", &
gl_smallFont, NULL, buf );
1535 snprintf( buf,
sizeof(buf),
"%s", j->target->name );
1536 window_addText( wid, 20 + w, y, 180, 15, 0,
"txtName", &
gl_smallFont, NULL, buf );
1546 if (jp_isFlag( j, JP_HIDDEN ))
1548 else if (jp_isFlag( j, JP_EXITONLY ))
1551 window_addCheckbox( wid, x, y, 100, 20,
1554 window_addCheckbox( wid, x, y, 100, 20,
1560 window_addText( wid, x, y, l, 20, 1,
"txtHide",
1562 window_addInput( wid, x + l + 8, y, 50, 20,
"inpHide", 4, 1, NULL );
1563 window_setInputFilter( wid,
"inpHide", INPUT_FILTER_NUMBER );
1571 snprintf( buf,
sizeof(buf),
"%g", j->hide );
1572 window_setInput( wid,
"inpHide", buf );
1583 jp_setFlag( j, JP_HIDDEN );
1584 jp_rmFlag( j, JP_EXITONLY );
1587 jp_setFlag( j, JP_EXITONLY );
1588 jp_rmFlag( j, JP_HIDDEN );
1591 jp_rmFlag( j, JP_HIDDEN );
1592 jp_rmFlag( j, JP_EXITONLY );
1606 char buf[STRMAX_SHORT];
1622 window_addText( wid, x, y, l, 20, 1,
"txtDensity", NULL, NULL, s );
1623 window_addInput( wid, x + l + 8, y, 80, 20,
"inpDensity", 10, 1, NULL );
1624 window_setInputFilter( wid,
"inpDensity", INPUT_FILTER_NUMBER );
1628 window_addText( wid, x, y, l, 20, 1,
"txtInput", NULL, NULL, s );
1629 window_addInput( wid, x + l + 8, y, 80, 20,
"inpRadius", 10, 1, NULL );
1630 window_setInputFilter( wid,
"inpRadius", INPUT_FILTER_NUMBER );
1633 s = _(
"Max Speed: ");
1635 window_addText( wid, x, y, l, 20, 1,
"txtMaxspeed", NULL, NULL, s );
1636 window_addInput( wid, x + l + 8, y, 80, 20,
"inpMaxspeed", 10, 1, NULL );
1637 window_setInputFilter( wid,
"inpMaxspeed", INPUT_FILTER_NUMBER );
1641 window_addText( wid, x, y, l, 20, 1,
"txtThrust", NULL, NULL, s );
1642 window_addInput( wid, x + l + 8, y, 80, 20,
"inpThrust", 10, 1, NULL );
1643 window_setInputFilter( wid,
"inpThrust", INPUT_FILTER_NUMBER );
1646 sysedit_genAsteroidsList( wid );
1653 1,
"txtAsteroidsHave", NULL, NULL, _(
"Asteroids") );
1655 1,
"txtAsteroidsAvailable", NULL, NULL, _(
"Available") );
1659 "btnRmAsteroid", _(
"Rm Asteroid"), sysedit_btnRmAsteroid );
1661 "btnAddAsteroid", _(
"Add Asteroid"), sysedit_btnAddAsteroid );
1662 window_addButton( wid, 20 + 2*(bw + 15), 20, bw,
BUTTON_HEIGHT,
1663 "btnDelete", _(
"Delete"), sysedit_btnAsteroidsDelete );
1665 "btnClose", _(
"Close"), sysedit_editAsteroidsClose );
1668 snprintf( buf,
sizeof(buf),
"%g", ast->
density );
1669 window_setInput( wid,
"inpDensity", buf );
1670 snprintf( buf,
sizeof(buf),
"%g", ast->
radius );
1671 window_setInput( wid,
"inpRadius", buf );
1672 snprintf( buf,
sizeof(buf),
"%g", ast->
maxspeed );
1673 window_setInput( wid,
"inpMaxspeed", buf );
1674 snprintf( buf,
sizeof(buf),
"%g", ast->
thrust );
1675 window_setInput( wid,
"inpThrust", buf );
1678static void sysedit_genAsteroidsList(
unsigned int wid )
1684 char **have, **available;
1689 hpos = toolkit_getListPos( wid,
"lstAsteroidsHave" );
1690 apos = toolkit_getListPos( wid,
"lstAsteroidsAvailable" );
1705 window_addList( wid, x, y, w, h,
"lstAsteroidsHave", have,
array_size(ast->
groups), 0, NULL, sysedit_btnRmAsteroid );
1710 available = malloc(
sizeof(
char*) *
array_size(astgroups) );
1712 available[i] = strdup( astgroups[i].name );
1714 window_addList( wid, x, y, w, h,
"lstAsteroidsAvailable", available,
array_size(astgroups), 0, NULL, sysedit_btnAddAsteroid );
1717 if (hpos != -1 && apos != -1) {
1718 toolkit_setListPos( wid,
"lstAsteroidsHave", hpos );
1719 toolkit_setListPos( wid,
"lstAsteroidsAvailable", apos );
1723static void sysedit_btnRmAsteroid(
unsigned int wid,
const char *unused )
1726 int pos = toolkit_getListPos( wid,
"lstAsteroidsHave" );
1732 sysedit_genAsteroidsList( wid );
1735static void sysedit_btnAddAsteroid(
unsigned int wid,
const char *unused )
1738 const char *selected = toolkit_getList( wid,
"lstAsteroidsAvailable" );
1743 sysedit_genAsteroidsList( wid );
1746static void sysedit_btnAsteroidsDelete(
unsigned int wid,
const char *unused )
1748 int i =
dialogue_YesNo( _(
"Remove Asteroid Field"), _(
"Are you sure you want to remove this asteroid field?") );
1763static void sysedit_editAsteroidsClose(
unsigned int wid,
const char *unused )
1781static void sysedit_editExclusion (
void)
1785 char buf[STRMAX_SHORT];
1799 window_addText( wid, x, y, l, 20, 1,
"txtInput", NULL, NULL, s );
1800 window_addInput( wid, x + l + 8, y, 80, 20,
"inpRadius", 10, 1, NULL );
1801 window_setInputFilter( wid,
"inpRadius", INPUT_FILTER_NUMBER );
1805 window_addButton( wid, -20 - 15 - bw, 20, bw,
BUTTON_HEIGHT,
1806 "btnDelete", _(
"Delete"), sysedit_btnExclusionDelete );
1808 "btnClose", _(
"Close"), sysedit_editExclusionClose );
1811 snprintf( buf,
sizeof(buf),
"%g", exc->
radius );
1812 window_setInput( wid,
"inpRadius", buf );
1815static void sysedit_btnExclusionDelete(
unsigned int wid,
const char *unused )
1817 int i =
dialogue_YesNo( _(
"Remove Asteroid Exclusion Zone"), _(
"Are you sure you want to remove this asteroid exclusion zone?") );
1831static void sysedit_editExclusionClose(
unsigned int wid,
const char *unused )
1851 const char *desc, *bardesc;
1857 snprintf(title,
sizeof(title), _(
"Spob Information - %s"), p->name);
1865 desc = p->description ? p->description : _(
"None");
1866 bardesc = p->bar_description ? p->bar_description : _(
"None");
1869 window_addButton( wid, -20 - bw*3 - 15*3, 20, bw,
BUTTON_HEIGHT,
1877 _(
"Landing Description") );
1879 window_addInput( wid, x, y, w, h,
"txtDescription", 1024, 0,
1881 window_setInputFilter( wid,
"txtDescription",
1885 window_setInput( wid,
"txtDescription", desc );
1889 _(
"Bar Description") );
1891 window_addInput( wid, x, y, w, h,
"txtBarDescription", 1024, 0,
1893 window_setInputFilter( wid,
"txtBarDescription",
1896 window_setInput( wid,
"txtBarDescription", bardesc );
1905 const char *mydesc, *mybardesc;
1909 mydesc = window_getInput( wid,
"txtDescription" );
1910 mybardesc = window_getInput( wid,
"txtBarDescription" );
1912 free(p->description);
1913 free(p->bar_description);
1914 p->description = NULL;
1915 p->bar_description = NULL;
1918 p->description = strdup( mydesc );
1919 if (mybardesc != NULL)
1920 p->bar_description = strdup( mybardesc );
1939 int j, n, nservices;
1941 char **have, **lack;
1942 int x, y, w, h, hpos, lpos;
1949 hpos = toolkit_getListPos( wid,
"lstServicesHave" );
1950 lpos = toolkit_getListPos( wid,
"lstServicesLacked" );
1963 for (
int i=1; i<SPOB_SERVICES_MAX; i<<=1) {
1964 if (!spob_hasService(p, i) && (i != SPOB_SERVICE_INHABITED))
1971 have = malloc(
sizeof(
char*) *
MAX(nservices - n, 1) );
1973 have[j++] = strdup(_(
"None"));
1975 for (
int i=1; i<SPOB_SERVICES_MAX; i<<=1)
1976 if (spob_hasService(p, i) && (i != SPOB_SERVICE_INHABITED))
1980 window_addList( wid, x, y, w, h,
"lstServicesHave", have, j, 0, NULL,
sysedit_btnRmService );
1985 lack = malloc(
sizeof(
char*) *
MAX(1, n) );
1987 lack[j++] = strdup( _(
"None") );
1989 for (
int i=1; i<SPOB_SERVICES_MAX; i<<=1)
1990 if (!spob_hasService(p, i) && (i != SPOB_SERVICE_INHABITED))
1994 window_addList( wid, x, y, w, h,
"lstServicesLacked", lack, j, 0, NULL,
sysedit_btnAddService );
1997 if (hpos != -1 && lpos != -1) {
1998 toolkit_setListPos( wid,
"lstServicesHave", hpos );
1999 toolkit_setListPos( wid,
"lstServicesLacked", lpos );
2009 const char *selected;
2012 selected = toolkit_getList( wid,
"lstServicesLacked" );
2013 if ((selected == NULL) || (strcmp(selected,_(
"None"))==0))
2018 p->services |=
spob_getService(selected) | SPOB_SERVICE_INHABITED | SPOB_SERVICE_LAND;
2030 const char *selected;
2033 selected = toolkit_getList( wid,
"lstServicesHave" );
2034 if ((selected==NULL) || (strcmp(selected,_(
"None"))==0))
2042 if (strcmp(selected,
"Land")==0)
2085 char **have, **lack;
2086 int j, n, x, y, w, h, hpos, lpos;
2093 hpos = toolkit_getListPos( wid,
"lstTechsHave" );
2094 lpos = toolkit_getListPos( wid,
"lstTechsLacked" );
2107 if (p->tech != NULL)
2110 have = malloc(
sizeof(
char*) );
2111 have[n++] = strdup(_(
"None"));
2115 window_addList( wid, x, y, w, h,
"lstTechsHave", have, n, 0, NULL,
sysedit_btnRmTech );
2120 if (p->tech != NULL) {
2122 for (
int i=0; i<j; i++)
2127 lack = malloc(
sizeof(
char*) );
2128 lack[n++] = strdup(_(
"None"));
2131 lack = malloc(
sizeof(
char*) * j );
2133 for (
int i=0; i<j; i++)
2135 lack[n++] = strdup( tmp[i] );
2139 for (
int i=0; i<j; i++)
2148 window_addList( wid, x, y, w, h,
"lstTechsLacked", lack, n, 0, NULL,
sysedit_btnAddTech );
2151 if (hpos != -1 && lpos != -1) {
2152 toolkit_setListPos( wid,
"lstTechsHave", hpos );
2153 toolkit_setListPos( wid,
"lstTechsLacked", lpos );
2163 const char *selected;
2166 selected = toolkit_getList( wid,
"lstTechsLacked" );
2167 if ((selected == NULL) || (strcmp(selected,_(
"None"))==0))
2171 if (p->tech == NULL)
2185 const char *selected;
2189 selected = toolkit_getList( wid,
"lstTechsHave" );
2190 if ((selected == NULL) || (strcmp(selected,_(
"None"))==0))
2213 int pos, j, y, h, bw, *factions;
2226 str = malloc(
sizeof(
char*) * (
array_size(factions) + 1) );
2227 str[0] = strdup(_(
"None"));
2231 qsort( &str[1], j-1,
sizeof(
char*),
strsort );
2234 if (p->presence.faction >= 0) {
2237 for (
int i=0; i<j; i++)
2238 if (strcmp(s,str[i])==0)
2267 const char *selected;
2270 selected = toolkit_getList( wid,
"lstFactions" );
2271 if (selected == NULL)
2276 if (toolkit_getListPos( wid,
"lstFactions")==0) {
2277 p->presence.faction = -1;
2305 sysedit_editExclusion();
2316 char *path, buf[STRMAX_SHORT];
2319 ImageArrayCell *cells;
2324 land = (strcmp(wgt,
"btnLandGFX") == 0);
2328 snprintf( buf,
sizeof(buf), _(
"%s - Spob Properties"), p->name );
2344 path =
land ? SPOB_GFX_EXTERIOR_PATH : SPOB_GFX_SPACE_PATH;
2345 files = PHYSFS_enumerateFiles( path );
2346 for (nfiles=0; files[nfiles]; nfiles++) {}
2347 cells = calloc( nfiles,
sizeof(ImageArrayCell) );
2350 for (
size_t i=0; i<nfiles; i++) {
2351 PHYSFS_Stat path_stat;
2352 snprintf( buf,
sizeof(buf),
"%s/%s", path, files[i] );
2354 if (!PHYSFS_stat( buf, &path_stat )) {
2355 WARN(_(
"Unable to check file type for '%s'!"), buf);
2358 if (path_stat.filetype != PHYSFS_FILETYPE_REGULAR)
2365 cells[j].caption = strdup( files[i] );
2366 c = strcmp(files[i],
land ? p->gfx_exteriorPath : p->gfx_spacePath)==0 ? cOrange : cBlack;
2367 memcpy( &cells[j].bg, &
c,
sizeof(glColour) );
2370 PHYSFS_freeList( files );
2373 window_addImageArray( wid, 20, 20, w-60-
BUTTON_WIDTH, h-60,
"iarGFX", 128, 128, cells, j, NULL, NULL, NULL );
2374 toolkit_setImageArray( wid,
"iarGFX", path );
2395 land = (strcmp(wgt,
"btnApplyLand") == 0);
2399 str = toolkit_getImageArray( wid,
"iarGFX" );
2404 path =
land ? SPOB_GFX_EXTERIOR_PATH : SPOB_GFX_SPACE_PATH;
2405 snprintf( buf,
sizeof(buf),
"%s/%s", path, str );
2408 free( p->gfx_exteriorPath );
2409 free( p->gfx_exterior );
2410 snprintf( buf,
sizeof(buf), SPOB_GFX_EXTERIOR_PATH
"%s", str );
2411 p->gfx_exteriorPath = strdup( str );
2412 p->gfx_exterior = strdup( buf );
2415 free( p->gfx_spaceName );
2416 free( p->gfx_spacePath );
2417 p->gfx_spaceName = strdup( buf );
2418 p->gfx_spacePath = strdup( str );
2420 p->gfx_space = NULL;
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’.
void asteroids_computeInternals(AsteroidAnchor *a)
Updates internal alues of an asteroid field.
const AsteroidTypeGroup * astgroup_getAll(void)
Gets all the asteroid type groups.
void asteroid_free(AsteroidAnchor *ast)
Frees an asteroid anchor.
AsteroidTypeGroup * astgroup_getName(const char *name)
Gets an asteroid type group by name.
int dpl_saveSpob(const Spob *p)
Saves a spob.
static Select_t sysedit_tsel
#define SYSEDIT_ZOOM_STEP
static void sysedit_btnGFXApply(unsigned int wid, const char *wgt)
Apply new graphics.
static double sysedit_xpos
static int sysedit_nselect
static unsigned int sysedit_wid
static void jp_type_check_exit_update(unsigned int wid, const char *str)
Updates the jump point checkboxes.
static void sysedit_close(unsigned int wid, const char *wgt)
Closes the system editor widget.
static void sysedit_editPntClose(unsigned int wid, const char *unused)
Closes the spob editor, saving the changes made.
static void sysedit_buttonZoom(unsigned int wid, const char *str)
Handles the button zoom clicks.
static void sysedit_selectAdd(const Select_t *sel)
Adds a system to the selection.
static void sysedit_focusLose(unsigned int wid, const char *wgtname)
Called when it's de-focused.
static void sysedit_btnGrid(unsigned int wid_unused, const char *unused)
Toggles the grid.
static void sysedit_btnNewSpob(unsigned int wid_unused, const char *unused)
Enters the editor in new spob mode.
static int sysedit_selectCmp(const Select_t *a, const Select_t *b)
Compares two selections to see if they are the same.
#define SYSEDIT_EDIT_WIDTH
static void sysedit_btnReset(unsigned int wid_unused, const char *unused)
Resets jump points.
static void sysedit_render(double bx, double by, double w, double h, void *data)
System editor custom widget rendering.
static double sysedit_ypos
static int sysedit_isSelected(const Select_t *s)
Check to see if something is selected.
static void sysedit_renderAsteroidsField(double bx, double by, const AsteroidAnchor *ast, int selected)
Draws an asteroid field on the map.
static int sysedit_keys(unsigned int wid, SDL_Keycode key, SDL_Keymod mod)
Handles keybindings.
static unsigned int sysedit_widEdit
static void sysedit_renderSprite(glTexture *gfx, double bx, double by, double x, double y, int sx, int sy, const glColour *c, int selected, const char *caption)
Renders a sprite for the custom widget.
static int sysedit_mouse(unsigned int wid, SDL_Event *event, double mx, double my, double w, double h, double xr, double yr, void *data)
System editor custom widget mouse handling.
static void sysedit_btnAddService(unsigned int wid, const char *unused)
Adds a service to a spob.
static void sysedit_genTechList(unsigned int wid)
Generates the spob tech list.
static void sysedit_btnGFXClose(unsigned int wid, const char *wgt)
Closes the spob graphic editor.
static void sysedit_deselect(void)
Deselects everything.
static void sysedit_checkButtons(void)
Checks to see which buttons should be active and the likes.
static void sysedit_btnRmTech(unsigned int wid, const char *unused)
Removes a tech from a spob.
static double sysedit_zoom
static void sysedit_btnFaction(unsigned int wid_unused, const char *unused)
Edits a spob's faction.
static void sysedit_spobGFX(unsigned int wid_unused, const char *wgt)
Opens the spob landing or space graphic editor.
static void sysedit_editAsteroids(void)
Opens the asteroid editor.
static void sysedit_selectRm(Select_t *sel)
Removes a system from the selection.
static StarSystem * sysedit_sys
#define SYSEDIT_DRAG_THRESHOLD
static void sysedit_btnEdit(unsigned int wid_unused, const char *unused)
Opens the system property editor.
#define SYSEDIT_MOVE_THRESHOLD
static void sysedit_renderAsteroidExclusion(double bx, double by, const AsteroidExclusion *aexcl, int selected)
Draws an asteroid exclusion zone on the map.
static void sysedit_spobDescClose(unsigned int wid, const char *unused)
Closes both the spob description window and the properties window.
static void sysedit_btnFactionSet(unsigned int wid, const char *unused)
Actually modifies the faction.
static unsigned int sysedit_dragTime
#define SYSEDIT_EDIT_HEIGHT
static void sysedit_spobDesc(unsigned int wid, const char *unused)
Displays the spob landing description and bar description in a separate window.
static void sysedit_editJumpClose(unsigned int wid, const char *unused)
Closes the jump editor, saving the changes made.
static void sysedit_btnScale(unsigned int wid_unused, const char *unused)
Interface for scaling a system from the system view.
static int sysedit_mselect
static void sysedit_genServicesList(unsigned int wid)
Generates the spob services list.
static void sysedit_btnRemove(unsigned int wid_unused, const char *unused)
Removes spobs.
void sysedit_open(StarSystem *sys)
Opens the system editor interface.
static void sysedit_btnRmService(unsigned int wid, const char *unused)
Removes a service from a spob.
static void sysedit_renderBG(double bx, double bw, double w, double h, double x, double y)
Renders the custom widget background.
static void sysedit_editPnt(void)
Edits a spob.
static void sysedit_spobDescReturn(unsigned int wid, const char *unused)
Closes the spob description window and returns to the properties window.
static void sysedit_btnAddTech(unsigned int wid, const char *unused)
Adds a tech to a spob.
void sysedit_sysScale(StarSystem *sys, double factor)
Scales a system.
static void jp_type_check_hidden_update(unsigned int wid, const char *str)
Updates the jump point checkboxes.
static void sysedit_btnTechEdit(unsigned int wid, const char *unused)
Edits a spob's tech.
static int sysedit_dragSel
static void sysedit_btnNewAsteroids(unsigned int wid_unused, const char *unused)
Enters the editor in new spob mode.
static void sysedit_editJump(void)
Edits a jump.
static Select_t * sysedit_select
int dsys_saveSystem(StarSystem *sys)
Saves a star system.
void uniedit_selectText(void)
Sets the selected system text.
char * dialogue_runChoice(void)
Run the dialog and return the clicked string.
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.
void dialogue_addChoice(const char *caption, const char *msg, const char *opt)
Add a choice to the dialog.
void dialogue_makeChoice(const char *caption, const char *msg, int opts)
Create the choice dialog. Need to add choices with below method.
int dialogue_YesNo(const char *caption, const char *fmt,...)
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 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.
int gl_printMidRaw(const glFont *ft_font, int width, double x, double y, const glColour *c, double outlineR, const char *text)
Displays text centered in position and width.
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.
void land(Spob *p, int load)
Opens up all the land dialogue stuff.
Header file with generic functions and naev-specifics.
int asprintf(char **strp, const char *fmt,...)
Like sprintf(), but it allocates a large-enough string and returns the pointer in the first argument....
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....
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_renderLine(double x1, double y1, double x2, double y2, const glColour *c)
Draws a line.
void gl_renderScaleSprite(const glTexture *sprite, double bx, double by, int sx, int sy, double bw, double bh, const glColour *c)
Blits a scaled sprite, position is in absolute screen coordinates.
void gl_renderRectEmpty(double x, double y, double w, double h, const glColour *c)
Renders a rectangle.
void gl_renderCross(double x, double y, double r, const glColour *c)
Renders a cross at a given position.
void gl_renderCircle(double cx, double cy, double r, const glColour *c, int filled)
Draws a circle.
glTexture * gl_newImage(const char *path, const unsigned int flags)
Loads an image as a texture.
void gl_freeTexture(glTexture *texture)
Frees a texture.
void safelanes_recalculate(void)
Update the safe lane locations in response to the universe changing (e.g., diff applied).
SafeLane * safelanes_get(int faction, int standing, const StarSystem *system)
Gets a set of safelanes for a faction and system.
void space_reconstructPresences(void)
Reset the presence of all systems.
int spob_exists(const char *spobname)
Check to see if a spob exists.
void systems_reconstructJumps(void)
Reconstructs the jumps.
int spob_getService(const char *name)
Converts name to spob service flag.
void system_setFaction(StarSystem *sys)
Sets the system faction based on the spobs it has.
Spob * spob_get(const char *spobname)
Gets a spob based on its name.
const char * space_getRndSpob(int landable, unsigned int services, int(*filter)(Spob *p))
Gets the name of a random spob.
StarSystem * system_getIndex(int id)
Get the system by its index.
JumpPoint * jump_getTarget(const StarSystem *target, const StarSystem *sys)
Less safe version of jump_get that works with pointers.
char * spob_getSystem(const char *spobname)
Get the name of a system from a spobname.
void system_updateAsteroids(StarSystem *sys)
Updates some internal calculations about asteroids in a system.
int system_addSpob(StarSystem *sys, const char *spobname)
Adds a spob to a star system.
void spob_gfxLoad(Spob *spob)
Loads a spob's graphics (and radius).
Spob * spob_getIndex(int ind)
Gets spob by index.
const char * spob_getServiceName(int service)
Gets the (English) name for a service code.
Spob * spob_new(void)
Creates a new spob.
glTexture * jumppoint_gfx
void space_gfxLoad(StarSystem *sys)
Loads all the graphics for a star system.
int system_rmSpob(StarSystem *sys, const char *spobname)
Removes a spob from a star system.
Represents an asteroid field anchor.
AsteroidTypeGroup ** groups
Represents an asteroid exclusion zone.
Represents a group of asteroids.
Describes a safe lane, patrolled by a faction, within a system.
SafeLaneLocType point_type[2]
Selection generic for stuff in a system.
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...
Abstraction for rendering sprite sheets.
int tech_rmItemTech(tech_group_t *tech, const char *value)
Removes an item from a tech.
tech_group_t * tech_groupCreate(void)
Creates a tech group.
int tech_getItemCount(const tech_group_t *tech)
Gets the number of techs within a given group.
int tech_hasItem(const tech_group_t *tech, const char *item)
Checks whether a given tech group has the specified item.
int tech_addItemTech(tech_group_t *tech, const char *value)
Adds an item to a tech.
char ** tech_getItemNames(const tech_group_t *tech, int *n)
Gets the names of all techs within a given group.
char ** tech_getAllItemNames(int *n)
Gets the names of all techs.