naev 0.11.5
dev_uniedit.c
Go to the documentation of this file.
1/*
2 * See Licensing and Copyright notice in naev.h
3 */
10#include "SDL.h"
11
12#include "naev.h"
15#include "dev_uniedit.h"
16
17#include "array.h"
18#include "conf.h"
19#include "dev_spob.h"
20#include "dev_sysedit.h"
21#include "dev_system.h"
22#include "dialogue.h"
23#include "economy.h"
24#include "map.h"
25#include "map_find.h"
26#include "ndata.h"
27#include "nstring.h"
28#include "opengl.h"
29#include "pause.h"
30#include "safelanes.h"
31#include "space.h"
32#include "tk/toolkit_priv.h"
33#include "toolkit.h"
34#include "unidiff.h"
35
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.
54/*
55 * The editor modes.
56 */
64
65typedef enum UniEditViewMode_ {
66 UNIEDIT_VIEW_DEFAULT,
67 UNIEDIT_VIEW_VIRTUALSPOBS,
68 UNIEDIT_VIEW_RADIUS,
69 UNIEDIT_VIEW_NOLANES,
70 UNIEDIT_VIEW_BACKGROUND,
71 UNIEDIT_VIEW_ASTEROIDS,
72 UNIEDIT_VIEW_INTERFERENCE,
73 UNIEDIT_VIEW_TECH,
74 UNIEDIT_VIEW_PRESENCE_SUM,
75 UNIEDIT_VIEW_PRESENCE,
76} UniEditViewMode;
77
78extern StarSystem *systems_stack;
79
81static UniEditViewMode uniedit_viewmode = UNIEDIT_VIEW_DEFAULT;
82static int uniedit_view_faction = -1;
83static unsigned int uniedit_wid = 0;
84static unsigned int uniedit_widEdit = 0;
85static unsigned int uniedit_widFind = 0;
86static double uniedit_xpos = 0.;
87static double uniedit_ypos = 0.;
88static double uniedit_zoom = 1.;
89static int uniedit_moved = 0;
90static unsigned int uniedit_lastClick = 0;
91static int uniedit_drag = 0;
92static int uniedit_dragSys = 0;
93static int uniedit_dragSel = 0;
94static double uniedit_dragSelX= 0;
95static double uniedit_dragSelY= 0;
96static double uniedit_rotate = 0.;
97static double uniedit_rotate_cx = 0.;
98static double uniedit_rotate_cy = 0.;
99static StarSystem **uniedit_sys = NULL;
100static StarSystem *uniedit_tsys = NULL;
101static int uniedit_tadd = 0;
102static double uniedit_mx = 0.;
103static double uniedit_my = 0.;
104static double uniedit_dt = 0.;
105static char** uniedit_tagslist = NULL;
107static map_find_t *found_cur = NULL;
108static int found_ncur = 0;
110/*
111 * Universe editor Prototypes.
112 */
113/* Selection. */
114static void uniedit_deselect (void);
115static void uniedit_selectAdd( StarSystem *sys );
116static void uniedit_selectRm( StarSystem *sys );
117/* System and spob search. */
118static void uniedit_findSys (void);
119static void uniedit_findSysClose( unsigned int wid, const char *name );
120static void uniedit_findSearch( unsigned int wid, const char *str );
121static void uniedit_findShowResults( unsigned int wid, map_find_t *found, int n );
122static void uniedit_centerSystem( unsigned int wid, const char *unused );
123static int uniedit_sortCompare( const void *p1, const void *p2 );
124/* System editing. */
125static void uniedit_editSys (void);
126static void uniedit_editSysClose( unsigned int wid, const char *name );
127static void uniedit_editGenList( unsigned int wid );
128static void uniedit_btnEditRename( unsigned int wid, const char *unused );
129static void uniedit_btnEditRmSpob( unsigned int wid, const char *unused );
130static void uniedit_btnEditAddSpob( unsigned int wid, const char *unused );
131static void uniedit_btnEditAddSpobAdd( unsigned int wid, const char *unused );
132static void uniedit_btnViewModeSet( unsigned int wid, const char *unused );
133static void uniedit_chkNolanes( unsigned int wid, const char *wgtname );
134/* System renaming. */
135static int uniedit_checkName( const char *name );
136static void uniedit_renameSys (void);
137/* New system. */
138static void uniedit_newSys( double x, double y );
139/* Jump handling. */
140static void uniedit_toggleJump( StarSystem *sys );
141static void uniedit_jumpAdd( StarSystem *sys, StarSystem *targ );
142static void uniedit_jumpRm( StarSystem *sys, StarSystem *targ );
143/* Tags. */
144static void uniedit_btnEditTags( unsigned int wid, const char *unused );
145static void uniedit_genTagsList( unsigned int wid );
146static void uniedit_btnAddTag( unsigned int wid, const char *unused );
147static void uniedit_btnRmTag( unsigned int wid, const char *unused );
148static void uniedit_btnNewTag( unsigned int wid, const char *unused );
149static void uniedit_btnTagsClose( unsigned int wid, const char *unused );
150/* Custom system editor widget. */
151static void uniedit_buttonZoom( unsigned int wid, const char* str );
152static void uniedit_render( double bx, double by, double w, double h, void *data );
153static void uniedit_renderOverlay( double bx, double by, double bw, double bh, void* data );
154static void uniedit_focusLose( unsigned int wid, const char* wgtname );
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 );
159/* Button functions. */
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 );
164static void uniedit_btnRename( 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 );
169/* Keybindings handling. */
170static int uniedit_keys( unsigned int wid, SDL_Keycode key, SDL_Keymod mod, int isrepeat );
171
175void uniedit_open( unsigned int wid_unused, const char *unused )
176{
177 (void) wid_unused;
178 (void) unused;
179 unsigned int wid;
180 int buttonPos = 0;
181 const glColour cBG = { 0., 0., 0., 0.95 };
182
183 /* Pause. */
184 pause_game();
185
186 /* Must have no diffs applied. */
187 diff_clear();
188
189 /* Reset some variables. */
191 uniedit_viewmode = UNIEDIT_VIEW_DEFAULT;
193 uniedit_drag = 0;
194 uniedit_dragSys = 0;
195 uniedit_dragSel = 0;
196 uniedit_tsys = NULL;
197 uniedit_tadd = 0;
198 uniedit_zoom = 1.;
199 uniedit_xpos = 0.;
200 uniedit_ypos = 0.;
201 uniedit_dt = 0.;
202
203 /* Create the window. */
204 wid = window_create( "wdwUniverseEditor", _("Universe Editor"), -1, -1, -1, -1 );
205 window_setDynamic( wid, 1 );
207 window_setBorder( wid, 0 );
208 uniedit_wid = wid;
209
210 /* Actual viewport, below everything. */
211 window_addCust( wid, 0, 0, SCREEN_W, SCREEN_H,
212 "cstSysEdit", 1, uniedit_render, uniedit_mouse, NULL, uniedit_focusLose, NULL );
213 window_custSetOverlay( wid, "cstSysEdit", uniedit_renderOverlay );
214
215 /* Overlay background. */
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 );
218
219 /* Close button. */
220 window_addButtonKey( wid, -20, 20+(BUTTON_HEIGHT+20)*buttonPos, BUTTON_WIDTH, BUTTON_HEIGHT,
221 "btnClose", _("Exit"), uniedit_close, SDLK_x );
222 buttonPos++;
223
224 /* Autosave toggle. */
225 window_addCheckbox( wid, -150, 25, SCREEN_W/2 - 150, 20,
226 "chkEditAutoSave", _("Automatically save changes"), uniedit_autosave, conf.devautosave );
227
228 /* Save button. */
229 window_addButton( wid, -20, 20+(BUTTON_HEIGHT+20)*buttonPos, BUTTON_WIDTH, BUTTON_HEIGHT,
230 "btnSave", _("Save All"), uniedit_save );
231 buttonPos++;
232
233 /* View button. */
234 window_addButton( wid, -20, 20+(BUTTON_HEIGHT+20)*buttonPos, BUTTON_WIDTH, BUTTON_HEIGHT,
235 "btnView", _("View Mode"), uniedit_btnView );
236 buttonPos++;
237
238 /* Jump toggle. */
239 window_addButtonKey( wid, -20, 20+(BUTTON_HEIGHT+20)*buttonPos, BUTTON_WIDTH, BUTTON_HEIGHT,
240 "btnJump", _("Jump"), uniedit_btnJump, SDLK_j );
241 buttonPos++;
242
243 /* Rename system. */
244 window_addButton( wid, -20, 20+(BUTTON_HEIGHT+20)*buttonPos, BUTTON_WIDTH, BUTTON_HEIGHT,
245 "btnRename", _("Rename"), uniedit_btnRename );
246 buttonPos++;
247
248 /* Edit system. */
249 window_addButtonKey( wid, -20, 20+(BUTTON_HEIGHT+20)*buttonPos, BUTTON_WIDTH, BUTTON_HEIGHT,
250 "btnEdit", _("Edit"), uniedit_btnEdit, SDLK_e );
251 buttonPos++;
252
253 /* New system. */
254 window_addButtonKey( wid, -20, 20+(BUTTON_HEIGHT+20)*buttonPos, BUTTON_WIDTH, BUTTON_HEIGHT,
255 "btnNew", _("New Sys"), uniedit_btnNew, SDLK_n );
256 buttonPos++;
257
258 /* Open a system. */
259 window_addButtonKey( wid, -20, 20+(BUTTON_HEIGHT+20)*buttonPos, BUTTON_WIDTH, BUTTON_HEIGHT,
260 "btnOpen", _("Open"), uniedit_btnOpen, SDLK_o );
261 buttonPos++;
262
263 /* Find a system or spob. */
264 window_addButtonKey( wid, -20, 20+(BUTTON_HEIGHT+20)*buttonPos, BUTTON_WIDTH, BUTTON_HEIGHT,
265 "btnFind", _("Find"), uniedit_btnFind, SDLK_f );
266 buttonPos++;
267
268 /* Zoom buttons */
269 window_addButton( wid, 40, 20, 30, 30, "btnZoomIn", "+", uniedit_buttonZoom );
270 window_addButton( wid, 80, 20, 30, 30, "btnZoomOut", "-", uniedit_buttonZoom );
271
272 /* Nebula. */
273 window_addText( wid, -10, -20, 110, 200, 0, "txtNebula",
274 &gl_smallFont, NULL, _("N/A") );
275
276 /* Presence. */
277 window_addText( wid, -10, -80-gl_smallFont.h-5, 110, 200, 0, "txtPresence",
278 &gl_smallFont, NULL, _("N/A") );
279
280 /* Selected text. */
281 window_addText( wid, 140, 10, SCREEN_W/2 - 140, 30, 0,
282 "txtSelected", &gl_smallFont, NULL, NULL );
283
284 /* Deselect everything. */
286}
287
291static int uniedit_keys( unsigned int wid, SDL_Keycode key, SDL_Keymod mod, int isrepeat )
292{
293 (void) wid;
294 (void) isrepeat;
295 int n;
296
297 switch (key) {
298 /* Mode changes. */
299 case SDLK_ESCAPE:
301 return 1;
302
303 case SDLK_a:
304 if (mod & (KMOD_LCTRL | KMOD_RCTRL)) {
306 for (int i=0; i<array_size(systems_stack); i++)
308 return 1;
309 }
310 return 0;
311
312 case SDLK_r:
314 if (n > 1) {
316 uniedit_rotate = 0.; /* Initialize rotation. */
318 for (int i=0; i<n; i++) {
319 uniedit_rotate_cx += uniedit_sys[i]->pos.x;
320 uniedit_rotate_cy += uniedit_sys[i]->pos.y;
321 }
322 uniedit_rotate_cx /= (double) n;
323 uniedit_rotate_cy /= (double) n;
324 }
325 return 1;
326
327 default:
328 return 0;
329 }
330}
331
335static void uniedit_close( unsigned int wid, const char *wgt )
336{
337 /* Frees some memory. */
339
340 /* Reconstruct jumps. */
342
343 /* Unpause. */
344 unpause_game();
345
346 /* Close the window. */
347 window_close( wid, wgt );
348}
349
350/*
351 * @brief Saves the systems.
352 */
353static void uniedit_save( unsigned int wid_unused, const char *unused )
354{
355 (void) wid_unused;
356 (void) unused;
357
358 dsys_saveAll();
359 dpl_saveAll();
360}
361
362/*
363 * @brief Toggles autosave.
364 */
365void uniedit_autosave( unsigned int wid_unused, const char *unused )
366{
367 (void) wid_unused;
368 (void) unused;
369
370 conf.devautosave = window_checkboxState( wid_unused, "chkEditAutoSave" );
371}
372
373/*
374 * @brief Updates autosave check box.
375 */
376void uniedit_updateAutosave (void)
377{
378 window_checkboxSet( uniedit_wid, "chkEditAutoSave", conf.devautosave );
379}
380
381static int factionGenerates( int f, int tocheck, double *w )
382{
383 const FactionGenerator *fg = faction_generators( f );
384 for (int i=0; i<array_size(fg); i++) {
385 if (fg[i].id==tocheck) {
386 if (w!=NULL)
387 *w = fg[i].weight;
388 return 1;
389 }
390 }
391 return 0;
392}
393
397static void uniedit_btnView( unsigned int wid_unused, const char *unused )
398{
399 (void) wid_unused;
400 (void) unused;
401 unsigned int wid;
402 int n, h, k;
403 Spob *spobs;
404 char **str;
405 int *factions;
406
407 /* Find usable factions. */
408 factions = faction_getAll();
409 spobs = spob_getAll();
410 for (int i=0; i<array_size(factions); i++) {
411 int f = factions[i];
412 int hasfact = 0;
413 for (int j=0; j<array_size(spobs); j++) {
414 Spob *p = &spobs[j];
415 if ((p->presence.faction != f) && !factionGenerates(p->presence.faction,f,NULL))
416 continue;
417 if (p->presence.base==0. && p->presence.bonus==0.)
418 continue;
419 hasfact = 1;
420 break;
421 }
422 if (!hasfact)
423 factions[i] = -1;
424 }
425
426 /* Create the window. */
427 wid = window_create( "wdwUniEditView", _("Select a View Mode"), -1, -1, UNIEDIT_EDIT_WIDTH, UNIEDIT_EDIT_HEIGHT );
429
430 /* Add virtual spob list. */
431 n = 9; /* Number of special cases. */
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"));
442 k = n;
443 for (int i=0; i<array_size(factions); i++) {
444 int f = factions[i];
445 if (f>=0)
446 str[k++] = strdup( faction_name( f ) ); /* Not translating so we can use faction_get */
447 }
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 );
451
452 /* Close button. */
453 window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
454 "btnClose", _("Close"), window_close );
455
456 /* Add button. */
457 window_addButton( wid, -20-(BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT,
458 "btnSet", _("Set"), uniedit_btnViewModeSet );
459
460 /* Clean up. */
461 array_free( factions );
462}
463
467static void uniedit_btnJump( unsigned int wid_unused, const char *unused )
468{
469 (void) wid_unused;
470 (void) unused;
471
473}
474
478static void uniedit_btnRename( unsigned int wid_unused, const char *unused )
479{
480 (void) wid_unused;
481 (void) unused;
482
484}
485
489static void uniedit_btnNew( unsigned int wid_unused, const char *unused )
490{
491 (void) wid_unused;
492 (void) unused;
493
495}
496
500static void uniedit_btnOpen( unsigned int wid_unused, const char *unused )
501{
502 (void) wid_unused;
503 (void) unused;
504
505 if (array_size(uniedit_sys) != 1)
506 return;
507
509}
510
514static void uniedit_btnFind( unsigned int wid_unused, const char *unused )
515{
516 (void) wid_unused;
517 (void) unused;
518
520}
521
525static void uniedit_btnEdit( unsigned int wid_unused, const char *unused )
526{
527 (void) wid_unused;
528 (void) unused;
529
531}
532
533static void uniedit_renderFactionDisks( double x, double y, double r )
534{
535 const glColour *col;
536 glColour c;
537 double tx, ty, sr, presence;
538
540 c.r = col->r;
541 c.g = col->g;
542 c.b = col->b;
543 c.a = 0.5;
544
545 for (int i=0; i<array_size(systems_stack); i++) {
546 StarSystem *sys = system_getIndex( i );
547
548 tx = x + sys->pos.x*uniedit_zoom;
549 ty = y + sys->pos.y*uniedit_zoom;
550
551 presence = system_getPresence( sys, uniedit_view_faction );
552
553 /* draws the disk representing the faction */
554 sr = 0.5*M_PI*sqrt(presence) * uniedit_zoom;
555
556 //glUseProgram(shaders.factiondisk.program);
557 //glUniform1f(shaders.factiondisk.paramf, r / sr );
558 //gl_renderShader( tx, ty, sr, sr, 0., &shaders.factiondisk, &c, 1 );
559 (void) r;
560 gl_renderCircle( tx, ty, sr, &c, 1 );
561 }
562}
563
564static void uniedit_renderVirtualSpobs( double x, double y, double r )
565{
566 const glColour c = { .r=1., .g=1., .b=1., .a=0.3 };
567
568 for (int i=0; i<array_size(systems_stack); i++) {
569 double tx, ty, sr;
570 StarSystem *sys = system_getIndex( i );
571
572 tx = x + sys->pos.x*uniedit_zoom;
573 ty = y + sys->pos.y*uniedit_zoom;
574
575 /* draws the disk representing the faction */
576 sr = 5.*M_PI*sqrt((double)array_size(sys->spobs_virtual)) * uniedit_zoom;
577
578 (void) r;
579 gl_renderCircle( tx, ty, sr, &c, 1 );
580 }
581}
582
583static void uniedit_renderRadius( double x, double y, double r )
584{
585 const glColour c = { .r=1., .g=1., .b=1., .a=0.3 };
586
587 for (int i=0; i<array_size(systems_stack); i++) {
588 double tx, ty, sr;
589 StarSystem *sys = system_getIndex( i );
590
591 tx = x + sys->pos.x*uniedit_zoom;
592 ty = y + sys->pos.y*uniedit_zoom;
593
594 /* draws the disk representing the faction */
595 sr = 5.*M_PI*sqrt(sys->radius / 10e3) * uniedit_zoom;
596
597 (void) r;
598 gl_renderCircle( tx, ty, sr, &c, 1 );
599 }
600}
601
602static void uniedit_renderNolanes( double x, double y, double r )
603{
604 const glColour c = { .r=1., .g=1., .b=1., .a=0.3 };
605
606 for (int i=0; i<array_size(systems_stack); i++) {
607 double tx, ty, sr;
608 StarSystem *sys = system_getIndex( i );
609
610 if (!sys_isFlag( sys, SYSTEM_NOLANES ))
611 continue;
612
613 tx = x + sys->pos.x*uniedit_zoom;
614 ty = y + sys->pos.y*uniedit_zoom;
615
616 /* draws the disk representing the faction */
617 sr = 5.*M_PI * uniedit_zoom;
618
619 (void) r;
620 gl_renderCircle( tx, ty, sr, &c, 1 );
621 }
622}
623
624static void uniedit_renderBackground( double x, double y, double r )
625{
626 const glColour c = { .r=1., .g=1., .b=1., .a=0.3 };
627
628 for (int i=0; i<array_size(systems_stack); i++) {
629 double tx, ty, sr;
630 StarSystem *sys = system_getIndex( i );
631
632 if (sys->background==NULL)
633 continue;
634
635 tx = x + sys->pos.x*uniedit_zoom;
636 ty = y + sys->pos.y*uniedit_zoom;
637
638 /* draws the disk representing the faction */
639 sr = 7.*M_PI * uniedit_zoom;
640
641 (void) r;
642 gl_renderCircle( tx, ty, sr, &c, 1 );
643 }
644}
645
646static void uniedit_renderAsteroids( double x, double y, double r )
647{
648 const glColour c = { .r=1., .g=1., .b=1., .a=0.3 };
649
650 for (int i=0; i<array_size(systems_stack); i++) {
651 double tx, ty, sr;
652 StarSystem *sys = system_getIndex( i );
653 double density = sys->asteroid_density;
654
655 if (density <= 0.)
656 continue;
657
658 tx = x + sys->pos.x*uniedit_zoom;
659 ty = y + sys->pos.y*uniedit_zoom;
660
661 /* Draw disk. */
662 sr = 0.3*M_PI*sqrt(density) * uniedit_zoom;
663 (void) r;
664 gl_renderCircle( tx, ty, sr, &c, 1 );
665 }
666}
667
668static void uniedit_renderInterference( double x, double y, double r )
669{
670 const glColour c = { .r=1., .g=1., .b=1., .a=0.3 };
671
672 for (int i=0; i<array_size(systems_stack); i++) {
673 double tx, ty, sr;
674 StarSystem *sys = system_getIndex( i );
675
676 tx = x + sys->pos.x*uniedit_zoom;
677 ty = y + sys->pos.y*uniedit_zoom;
678
679 /* draws the disk representing the faction */
680 sr = 5.*M_PI*sqrt(sys->interference / 20.) * uniedit_zoom;
681
682 (void) r;
683 gl_renderCircle( tx, ty, sr, &c, 1 );
684 }
685}
686
687static void uniedit_renderTech( double x, double y, double r )
688{
689 const glColour c = { .r=1., .g=1., .b=1., .a=0.3 };
690
691 for (int i=0; i<array_size(systems_stack); i++) {
692 double tx, ty, sr;
693 StarSystem *sys = system_getIndex( i );
694 int hastech = 0;
695
696 for (int j=0; j<array_size(sys->spobs); j++) {
697 if (sys->spobs[j]->tech != NULL) {
698 hastech = 1;
699 break;
700 }
701 }
702 if (!hastech)
703 continue;
704
705 tx = x + sys->pos.x*uniedit_zoom;
706 ty = y + sys->pos.y*uniedit_zoom;
707
708 /* Draw disk. */
709 sr = 7.*M_PI * uniedit_zoom;
710 (void) r;
711 gl_renderCircle( tx, ty, sr, &c, 1 );
712 }
713}
714
715static void uniedit_renderPresenceSum( double x, double y, double r )
716{
717 const glColour c = { .r=1., .g=1., .b=1., .a=0.3 };
718
719 for (int i=0; i<array_size(systems_stack); i++) {
720 double tx, ty, sr;
721 StarSystem *sys = system_getIndex( i );
722
723 double total = 0.;
724 for (int j=0; j<array_size(sys->presence); j++)
725 total += MAX( 0., sys->presence[j].value );
726
727 tx = x + sys->pos.x*uniedit_zoom;
728 ty = y + sys->pos.y*uniedit_zoom;
729
730 /* draws the disk representing the faction */
731 sr = 0.2*M_PI*sqrt(total) * uniedit_zoom;
732
733 (void) r;
734 gl_renderCircle( tx, ty, sr, &c, 1 );
735 }
736}
737
738/* @brief Renders important map stuff.
739 */
740void uniedit_renderMap( double bx, double by, double w, double h, double x, double y, double zoom, double r )
741{
742 /* background */
743 gl_renderRect( bx, by, w, h, &cBlack );
744
745 if (UNIEDIT_VIEW_DEFAULT)
746 map_renderDecorators( x, y, zoom, 1, 1. );
747
748 /* Render faction disks. */
749 switch (uniedit_viewmode) {
750 case UNIEDIT_VIEW_DEFAULT:
751 map_renderFactionDisks( x, y, zoom, r, 1, 1. );
752 map_renderSystemEnvironment( x, y, zoom, 1, 1. );
753 break;
754
755 case UNIEDIT_VIEW_VIRTUALSPOBS:
756 uniedit_renderVirtualSpobs( x, y, r );
757 break;
758
759 case UNIEDIT_VIEW_RADIUS:
760 uniedit_renderRadius( x, y, r );
761 break;
762
763 case UNIEDIT_VIEW_NOLANES:
764 uniedit_renderNolanes( x, y, r );
765 break;
766
767 case UNIEDIT_VIEW_BACKGROUND:
768 uniedit_renderBackground( x, y, r );
769 break;
770
771 case UNIEDIT_VIEW_ASTEROIDS:
772 uniedit_renderAsteroids( x, y, r );
773 break;
774
775 case UNIEDIT_VIEW_INTERFERENCE:
776 uniedit_renderInterference( x, y, r );
777 break;
778
779 case UNIEDIT_VIEW_TECH:
780 uniedit_renderTech( x, y, r );
781 break;
782
783 case UNIEDIT_VIEW_PRESENCE_SUM:
784 uniedit_renderPresenceSum( x, y, r );
785 break;
786
787 case UNIEDIT_VIEW_PRESENCE:
789 uniedit_renderFactionDisks( x, y, r );
790 break;
791 }
792
793 /* Render jump paths. */
794 map_renderJumps( x, y, zoom, r, 1 );
795
796 /* Render systems. */
797 map_renderSystems( bx, by, x, y, zoom, w, h, r, MAPMODE_EDITOR );
798
799 /* Render system names. */
800 map_renderNames( bx, by, x, y, zoom, w, h, 1, 1. );
801
802 glClear( GL_DEPTH_BUFFER_BIT );
803}
804
808static void uniedit_render( double bx, double by, double w, double h, void *data )
809{
810 (void) data;
811 double x,y,r;
812
814
815 /* Parameters. */
816 map_renderParams( bx, by, uniedit_xpos, uniedit_ypos, w, h, uniedit_zoom, &x, &y, &r );
817
818 /* Render map stuff. */
819 uniedit_renderMap( bx, by, w, h, x, y, uniedit_zoom, r );
820
821 /* Render the selected system selections. */
822 for (int i=0; i<array_size(uniedit_sys); i++) {
823 StarSystem *sys = uniedit_sys[i];
824 glUseProgram( shaders.selectspob.program );
825 glUniform1f( shaders.selectspob.dt, uniedit_dt );
826 gl_renderShader( x + sys->pos.x * uniedit_zoom, y + sys->pos.y * uniedit_zoom,
827 1.5*r, 1.5*r, 0., &shaders.selectspob, &cWhite, 1 );
828 }
829}
830
831static char getValCol( double val )
832{
833 if (val > 0.)
834 return 'g';
835 else if (val < 0.)
836 return 'r';
837 return '0';
838}
839static int getPresenceVal( int f, SpobPresence *ap, double *base, double *bonus )
840{
841 int gf = 0;
842 double w;
843 if ((ap->faction!=f) && !(gf=factionGenerates(ap->faction, f, &w)))
844 return 0;
845 if (gf == 0) {
846 *base = ap->base;
847 *bonus = ap->bonus;
848 }
849 else {
850 *base = ap->base * w;
851 *bonus = ap->bonus * w;
852 }
853 return 1;
854}
855
859static void uniedit_renderOverlay( double bx, double by, double bw, double bh, void* data )
860{
861 double x,y, mx,my, sx,sy;
862 double value, base, bonus;
863 char buf[STRMAX] = {'\0'};
864 StarSystem *sys, *cur, *mousesys;
865 SystemPresence *sp;
866 (void) data;
867
868 x = bx + uniedit_mx;
869 y = by + uniedit_my;
870
871 /* Correct coordinates. */
872 mx = uniedit_mx - bw/2. + uniedit_xpos;
873 my = uniedit_my - bh/2. + uniedit_ypos;
874 mx /= uniedit_zoom;
875 my /= uniedit_zoom;
876
877 /* Display location. */
878 gl_print( &gl_defFontMono, bx+5, by+65, &cWhite, "% 7.2f x % 7.2f", mx, my );
879
880 /* Select drag stuff. */
881 if (uniedit_dragSel) {
882 double l, r, b, t, rx, ry;
883 const glColour col = { .r = 0.2, .g = 0.2, .b = 0.8, .a = 0.5 };
884
885 l = MIN( uniedit_dragSelX, mx );
886 r = MAX( uniedit_dragSelX, mx );
887 b = MIN( uniedit_dragSelY, my );
888 t = MAX( uniedit_dragSelY, my );
889
890 /* Project back to screen space. */
891 rx = (l * uniedit_zoom) + bw/2. - uniedit_xpos;
892 ry = (b * uniedit_zoom) + bh/2. - uniedit_ypos;
893
894 gl_renderRect( rx, ry, (r-l)*uniedit_zoom, (t-b)*uniedit_zoom, &col );
895 }
896
897 /* Don't cover up stuff if possible. */
898 if ((x > SCREEN_W-130) || (y < 60))
899 return;
900
902 toolkit_drawAltText( x, y, _("Click to add a new system"));
903 return;
904 }
905 else if (uniedit_mode == UNIEDIT_JUMP) {
906 toolkit_drawAltText( x, y, _("Click to toggle jump route"));
907 return;
908 }
909 else if (uniedit_viewmode == UNIEDIT_VIEW_DEFAULT)
910 return;
911
912 /* Find mouse over system. */
913 mousesys = NULL;
914 for (int i=0; i<array_size(systems_stack); i++) {
915 sys = system_getIndex(i);
916 sx = sys->pos.x;
917 sy = sys->pos.y;
918 if ((pow2(sx-mx)+pow2(sy-my)) > pow2(UNIEDIT_CLICK_THRESHOLD))
919 continue;
920 mousesys = sys;
921 break;
922 }
923 if (mousesys == NULL)
924 return;
925 sys = mousesys;
926 sx = sys->pos.x;
927 sy = sys->pos.y;
928
929 /* Handle virtual spob viewer. */
930 if (uniedit_viewmode == UNIEDIT_VIEW_VIRTUALSPOBS) {
931 int l;
932
933 if (array_size(sys->spobs_virtual)==0)
934 return;
935
936 /* Count spobs. */
937 l = 0;
938 for (int j=0; j<array_size(sys->spobs_virtual); j++) {
939 VirtualSpob *va = sys->spobs_virtual[j];
940 l += scnprintf( &buf[l], sizeof(buf)-l, "%s%s", (l>0)?"\n":"", va->name );
941 }
942
943 toolkit_drawAltText( x, y, buf);
944 return;
945 }
946
947 /* Handle radius view. */
948 else if (uniedit_viewmode == UNIEDIT_VIEW_RADIUS) {
949 scnprintf( &buf[0], sizeof(buf), _("System Radius: %s"), num2strU( sys->radius, 0 ));
950 toolkit_drawAltText( x, y, buf);
951 return;
952 }
953
954 /* Handle background. */
955 else if (uniedit_viewmode == UNIEDIT_VIEW_BACKGROUND) {
956 if (sys->background != NULL) {
957 scnprintf( &buf[0], sizeof(buf), _("Background: %s"), sys->background );
958 toolkit_drawAltText( x, y, buf);
959 }
960 return;
961 }
962
963 /* Handle asteroids. */
964 else if (uniedit_viewmode == UNIEDIT_VIEW_ASTEROIDS) {
965 if (array_size(sys->asteroids) > 0) {
966 int l = 0;
967 l = scnprintf( &buf[l], sizeof(buf)-l, _("Density: %g"), sys->asteroid_density );
968 for (int i=0; i<array_size(sys->asteroids); i++) {
969 AsteroidAnchor *ast = &sys->asteroids[i];
970 for (int j=0; j<array_size(ast->groups); j++)
971 l += scnprintf( &buf[l], sizeof(buf)-l, "%s%s", (l>0)?"\n":"", ast->groups[j]->name );
972 }
973 toolkit_drawAltText( x, y, buf);
974 }
975 return;
976 }
977
978 /* Handle interference. */
979 else if (uniedit_viewmode == UNIEDIT_VIEW_INTERFERENCE) {
980 if (sys->interference > 0.) {
981 scnprintf( &buf[0], sizeof(buf), _("Interference: %.0f%%"), sys->interference );
982 toolkit_drawAltText( x, y, buf);
983 }
984 return;
985 }
986
987 /* Handle tech radius. */
988 else if (uniedit_viewmode == UNIEDIT_VIEW_TECH) {
989 char *techlist[256];
990 int ntechs = 0;
991 const int len = sizeof(techlist) / sizeof(char*);
992 int l;
993
994 if (array_size(sys->spobs)==0)
995 return;
996
997 /* Count spobs. */
998 l = 0;
999 for (int j=0; j<array_size(sys->spobs); j++) {
1000 Spob *spob = sys->spobs[j];
1001 int n;
1002 char **techs;
1003 if (spob->tech==NULL)
1004 continue;
1005 techs = tech_getItemNames( spob->tech, &n );
1006 for (int k=0; (k<n) && (ntechs<len-1) ; k++)
1007 techlist[ ntechs++ ] = techs[k];
1008 free( techs );
1009 }
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))
1013 continue;
1014 l += scnprintf( &buf[l], sizeof(buf)-l, "%s%s", (l>0)?"\n":"", techlist[k] );
1015 }
1016 for (int k=0; k<ntechs; k++)
1017 free( techlist[k] );
1018
1019 toolkit_drawAltText( x, y, buf);
1020 return;
1021 }
1022
1023 /* Handle presence sum. */
1024 else if (uniedit_viewmode == UNIEDIT_VIEW_PRESENCE_SUM) {
1025 int l;
1026
1027 if (array_size(sys->presence)==0)
1028 return;
1029
1030 value = 0.;
1031 for (int j=0; j<array_size(sys->presence); j++)
1032 value += MAX( sys->presence[j].value, 0. );
1033
1034 /* Count spobs. */
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];
1038 if (sp->value<=0.)
1039 continue;
1040 l += scnprintf( &buf[l], sizeof(buf)-l, "\n%s: %.0f = %.0f + %.0f", faction_name(sp->faction), sp->value, sp->base, sp->bonus);
1041 }
1042 toolkit_drawAltText( x, y, buf);
1043 return;
1044 }
1045
1046 /* Handle presence mode. */
1047 else if (uniedit_viewmode == UNIEDIT_VIEW_PRESENCE) {
1048 int l;
1049 int f = uniedit_view_faction;
1050 if (f < 0)
1051 return;
1052
1053 /* Total presence. */
1054 value = system_getPresenceFull( sys, f, &base, &bonus );
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,
1057 _(sys->name), faction_name(f) );
1058
1059 /* Local presence sources. */
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 ))
1063 continue;
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) );
1066 }
1067 for (int j=0; j<array_size(sys->spobs_virtual); j++) {
1068 VirtualSpob *va = sys->spobs_virtual[j];
1069 for (int p=0; p<array_size(va->presences); p++) {
1070 if (!getPresenceVal( f, &va->presences[p], &base, &bonus ))
1071 continue;
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) );
1074 }
1075 }
1076
1077 /* Find neighbours if possible. */
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 ))
1083 continue;
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) );
1086 }
1087 for (int j=0; j<array_size(cur->spobs_virtual); j++) {
1088 VirtualSpob *va = cur->spobs_virtual[j];
1089 for (int p=0; p<array_size(va->presences); p++) {
1090 if (!getPresenceVal( f, &va->presences[p], &base, &bonus ))
1091 continue;
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) );
1094 }
1095 }
1096 }
1097
1098 toolkit_drawAltText( x, y, buf);
1099 return;
1100 }
1101}
1102
1106static void uniedit_focusLose( unsigned int wid, const char* wgtname )
1107{
1108 (void) wid;
1109 (void) wgtname;
1111}
1112
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 )
1118{
1119 (void) data;
1120 unsigned int lastClick;
1121 StarSystem *clickedsys;
1122 int inselection;
1123 SDL_Keymod mod;
1124
1125 /* Handle modifiers. */
1126 mod = SDL_GetModState();
1127
1128 switch (event->type) {
1129
1130 case SDL_MOUSEWHEEL:
1131 /* Must be in bounds. */
1132 if ((mx < 0.) || (mx > w-130.) || (my < 60.) || (my > h))
1133 return 0;
1134
1135 if (event->wheel.y > 0)
1136 uniedit_buttonZoom( 0, "btnZoomIn" );
1137 else if (event->wheel.y < 0)
1138 uniedit_buttonZoom( 0, "btnZoomOut" );
1139
1140 return 1;
1141
1142 case SDL_MOUSEBUTTONDOWN:
1143 /* Must be in bounds. */
1144 if ((mx < 0.) || (mx > w-130.) || (my < 60.) || (my > h))
1145 return 0;
1146 window_setFocus( wid, "cstSysEdit" );
1147 lastClick = uniedit_lastClick;
1148 uniedit_lastClick = SDL_GetTicks();
1149
1150 /* Selecting star system */
1151 mx -= w/2. - uniedit_xpos;
1152 my -= h/2. - uniedit_ypos;
1153 mx /= uniedit_zoom;
1154 my /= uniedit_zoom;
1155
1156 /* Finish rotation. */
1159 return 1;
1160 }
1161
1162 /* Create new system if applicable. */
1164 uniedit_newSys( mx, my );
1166 return 1;
1167 }
1168
1169 /* Find clicked system. */
1170 clickedsys = NULL;
1171 for (int i=0; i<array_size(systems_stack); i++) {
1172 StarSystem *sys = system_getIndex(i);
1173 if ((pow2(mx-sys->pos.x)+pow2(my-sys->pos.y)) > pow2(UNIEDIT_CLICK_THRESHOLD))
1174 continue;
1175 clickedsys = sys;
1176 break;
1177 }
1178
1179 /* Set jump if applicable. */
1180 if (clickedsys!=NULL && uniedit_mode==UNIEDIT_JUMP) {
1181 uniedit_toggleJump( clickedsys );
1183 return 1;
1184 }
1185
1186 /* See if it is selected. */
1187 inselection = 0;
1188 if (clickedsys != NULL) {
1189 for (int i=0; i<array_size(uniedit_sys); i++) {
1190 if (uniedit_sys[i] != clickedsys)
1191 continue;
1192 inselection = 1;
1193 break;
1194 }
1195 }
1196
1197 /* Handle double click. */
1198 if (clickedsys!=NULL && inselection && array_size(uniedit_sys)==1) {
1199 if ((SDL_GetTicks()-lastClick < UNIEDIT_DOUBLECLICK_THRESHOLD)
1202 uniedit_drag = 0;
1203 uniedit_dragSys = 0;
1204 uniedit_dragSel = 0;
1205 return 1;
1206 }
1207 }
1208
1209 /* Clicked on selected system. */
1210 if ((clickedsys != NULL) && inselection) {
1211 uniedit_dragSys = 1;
1212 uniedit_tsys = clickedsys;
1213 /* Check modifier. */
1214 if (mod & (KMOD_LCTRL | KMOD_RCTRL))
1215 uniedit_tadd = 0;
1216 else
1217 uniedit_tadd = -1;
1218 uniedit_moved = 0;
1219 return 1;
1220 }
1221
1222 /* Clicked on non-selected system. */
1223 if (clickedsys != NULL) {
1224 /* Add the system if not selected. */
1225 if (!(mod & (KMOD_LCTRL | KMOD_RCTRL)))
1227 uniedit_selectAdd( clickedsys );
1228 uniedit_tsys = NULL;
1229 return 1;
1230 }
1231
1232 /* Start dragging. */
1233 uniedit_moved = 0;
1234 uniedit_tsys = NULL;
1235 if (mod & (KMOD_LCTRL | KMOD_RCTRL | KMOD_LSHIFT | KMOD_RSHIFT)) {
1236 if (mod & (KMOD_LSHIFT | KMOD_RSHIFT))
1238 uniedit_dragSel = 1;
1239 uniedit_dragSelX = mx;
1240 uniedit_dragSelY = my;
1241 return 1;
1242 }
1243 else {
1244 uniedit_drag = 1;
1245 return 1;
1246 }
1247 break;
1248
1249 case SDL_MOUSEBUTTONUP:
1250 if (uniedit_drag) {
1252 if (uniedit_tsys == NULL)
1254 else
1256 }
1257 uniedit_drag = 0;
1258 }
1259 if (uniedit_dragSys) {
1260 if ((SDL_GetTicks()-uniedit_lastClick < UNIEDIT_DRAG_THRESHOLD) &&
1262 if (uniedit_tadd == 0)
1264 else {
1267 }
1268 }
1269 uniedit_dragSys = 0;
1270 if (conf.devautosave)
1271 for (int i=0; i<array_size(uniedit_sys); i++)
1273 }
1274 if (uniedit_dragSel) {
1275 double l, r, b, t;
1276
1277 /* Selecting star system */
1278 mx -= w/2. - uniedit_xpos;
1279 my -= h/2. - uniedit_ypos;
1280 mx /= uniedit_zoom;
1281 my /= uniedit_zoom;
1282
1283 /* Get bounds. */
1284 l = MIN( uniedit_dragSelX, mx );
1285 r = MAX( uniedit_dragSelX, mx );
1286 b = MIN( uniedit_dragSelY, my );
1287 t = MAX( uniedit_dragSelY, my );
1288
1289 for (int i=0; i<array_size(systems_stack); i++) {
1290 StarSystem *sys = &systems_stack[i];
1291 double x = sys->pos.x;
1292 double y = sys->pos.y;
1293 if ((x >= l) && (x <= r) && (y >= b) && (y <= t))
1294 uniedit_selectAdd( sys );
1295 }
1296
1297 uniedit_dragSel = 0;
1298 }
1299 break;
1300
1301 case SDL_MOUSEMOTION:
1302 /* Update mouse positions. */
1303 uniedit_mx = mx;
1304 uniedit_my = my;
1305
1306 /* Handle rotation. */
1308 double a1, a2, amod;
1309 double cx = mx - w/2. + uniedit_xpos;
1310 double cy = my - h/2. + uniedit_ypos;
1311 cx /= uniedit_zoom;
1312 cy /= uniedit_zoom;
1313 cx -= uniedit_rotate_cx;
1314 cy -= uniedit_rotate_cy;
1315 a1 = atan2( cy, cx );
1316 cx -= rx / uniedit_zoom;
1317 cy += ry / uniedit_zoom;
1318 a2 = atan2( cy, cx );
1319 amod = a1-a2;
1320 uniedit_rotate += amod;
1321 for (int i=0; i<array_size(uniedit_sys); i++) {
1322 StarSystem *s = uniedit_sys[i];
1323 double sx = s->pos.x - uniedit_rotate_cx;
1324 double sy = s->pos.y - uniedit_rotate_cy;
1325 double a = atan2( sy, sx );
1326 double m = hypot( sx, sy );
1327 s->pos.x = uniedit_rotate_cx + m*cos(a+amod);
1328 s->pos.y = uniedit_rotate_cy + m*sin(a+amod);
1329 }
1330 }
1331
1332 /* Handle dragging. */
1333 if (uniedit_drag) {
1334 /* axis is inverted */
1335 uniedit_xpos -= rx;
1336 uniedit_ypos += ry;
1337
1338 /* Update mouse movement. */
1339 uniedit_moved += ABS(rx) + ABS(ry);
1340 }
1341 else if (uniedit_dragSys && (array_size(uniedit_sys) > 0)) {
1343 for (int i=0; i<array_size(uniedit_sys); i++) {
1344 uniedit_sys[i]->pos.x += rx / uniedit_zoom;
1345 uniedit_sys[i]->pos.y -= ry / uniedit_zoom;
1346 }
1347 }
1348
1349 /* Update mouse movement. */
1350 uniedit_moved += ABS(rx) + ABS(ry);
1351 }
1352 break;
1353 }
1354
1355 return 0;
1356}
1357
1363static int uniedit_checkName( const char *name )
1364{
1365 /* Avoid name collisions. */
1366 for (int i=0; i<array_size(systems_stack); i++) {
1367 if (strcmp(name, system_getIndex(i)->name)==0) {
1368 dialogue_alert( _("The Star System '%s' already exists!"), name );
1369 return 1;
1370 }
1371 }
1372 return 0;
1373}
1374
1375char *uniedit_nameFilter( const char *name )
1376{
1377 char *out = calloc( 1, (strlen(name)+1) );
1378 int pos = 0;
1379 for (int i=0; i<(int)strlen(name); i++) {
1380 if (!ispunct(name[i])) {
1381 if (name[i] == ' ')
1382 out[pos] = '_';
1383 else
1384 out[pos] = tolower(name[i]);
1385 pos++;
1386 }
1387 }
1388
1389 return out;
1390}
1391
1395static void uniedit_renameSys (void)
1396{
1397 int cancelall_prompt = 0;
1398 for (int i=0; i<array_size(uniedit_sys); i++) {
1399 char *name, *oldName, *newName, *filtered;
1400 StarSystem *sys = uniedit_sys[i];
1401
1402 /* Get name. */
1403 name = dialogue_input( _("Rename Star System"), 1, 32, _("What do you want to rename #r%s#0?"), sys->name );
1404
1405 /* Keep current name. */
1406 if (name == NULL) {
1407 if (!cancelall_prompt && (i < array_size(uniedit_sys))) {
1408 if (dialogue_YesNoRaw( _("Cancel batch renaming?"), _("Do you want to cancel renaming all selected star systems?")))
1409 break;
1410 cancelall_prompt = 1;
1411 }
1412 continue;
1413 }
1414
1415 /* Try again. */
1416 if (uniedit_checkName( name )) {
1417 free(name);
1418 i--;
1419 continue;
1420 }
1421
1422 /* Change the name. */
1423 filtered = uniedit_nameFilter(sys->name);
1424 SDL_asprintf(&oldName, "%s/%s.xml", conf.dev_save_sys, filtered);
1425 free(filtered);
1426
1427 filtered = uniedit_nameFilter(name);
1428 SDL_asprintf(&newName, "%s/%s.xml", conf.dev_save_sys, filtered);
1429 free(filtered);
1430
1431 if (rename(oldName, newName))
1432 WARN(_("Failed to rename '%s' to '%s'!"),oldName,newName);
1433
1434 free(oldName);
1435 free(newName);
1436 free(sys->name);
1437
1438 sys->name = name;
1439 dsys_saveSystem(sys);
1440
1441 /* Re-save adjacent systems. */
1442 for (int j=0; j<array_size(sys->jumps); j++)
1443 dsys_saveSystem( sys->jumps[j].target );
1444 }
1445}
1446
1450static void uniedit_newSys( double x, double y )
1451{
1452 char *name;
1453 StarSystem *sys;
1454
1455 /* Get name. */
1456 name = dialogue_inputRaw( _("New Star System Creation"), 1, 32, _("What do you want to name the new system?") );
1457
1458 /* Abort. */
1459 if (name == NULL) {
1460 dialogue_alert( _("Star System creation aborted!") );
1461 return;
1462 }
1463
1464 /* Make sure there is no collision. */
1465 if (uniedit_checkName( name )) {
1466 free(name);
1467 uniedit_newSys( x, y );
1468 return;
1469 }
1470
1471 /* Create the system. */
1472 sys = system_new();
1473 sys->name = name;
1474 sys->pos.x = x;
1475 sys->pos.y = y;
1476 sys->spacedust = DUST_DENSITY_DEFAULT;
1477 sys->radius = RADIUS_DEFAULT;
1478
1479 /* Select new system. */
1481 uniedit_selectAdd( sys );
1482
1483 if (conf.devautosave)
1484 dsys_saveSystem( sys );
1485}
1486
1490static void uniedit_toggleJump( StarSystem *sys )
1491{
1492 StarSystem *isys = NULL;
1493 for (int i=0; i<array_size(uniedit_sys); i++) {
1494 int rm = 0;
1495 isys = uniedit_sys[i];
1496 for (int j=0; j<array_size(isys->jumps); j++) {
1497 StarSystem *target = isys->jumps[j].target;
1498 /* Target already exists, remove. */
1499 if (target == sys) {
1500 uniedit_jumpRm( isys, sys );
1501 uniedit_jumpRm( sys, isys );
1502 rm = 1;
1503 break;
1504 }
1505 }
1506 /* Target doesn't exist, add. */
1507 if (!rm) {
1508 uniedit_jumpAdd( isys, sys );
1509 uniedit_jumpAdd( sys, isys );
1510 }
1511 }
1512
1513 /* Reconstruct jumps just in case. */
1515
1516 /* Reconstruct universe presences. */
1519
1520 if (conf.devautosave) {
1521 dsys_saveSystem( sys );
1522 if (isys != NULL)
1523 dsys_saveSystem( isys );
1524 }
1525
1526 /* Update sidebar text. */
1528}
1529
1533static void uniedit_jumpAdd( StarSystem *sys, StarSystem *targ )
1534{
1535 /* Add the jump. */
1536 JumpPoint *jp = &array_grow( &sys->jumps );
1537 memset( jp, 0, sizeof(JumpPoint) );
1538
1539 /* Fill it out with basics. */
1540 jp->target = targ;
1541 jp->targetid = targ->id;
1542 jp->radius = 200.;
1543 jp->flags = JP_AUTOPOS; /* Will automatically create position. */
1544 jp->hide = HIDE_DEFAULT_JUMP;
1545}
1546
1550static void uniedit_jumpRm( StarSystem *sys, StarSystem *targ )
1551{
1552 int i;
1553
1554 /* Find associated jump. */
1555 for (i=0; i<array_size(sys->jumps); i++)
1556 if (sys->jumps[i].target == targ)
1557 break;
1558
1559 /* Not found. */
1560 if (i >= array_size(sys->jumps)) {
1561 WARN(_("Jump for system '%s' not found in system '%s' for removal."), targ->name, sys->name);
1562 return;
1563 }
1564
1565 /* Remove the jump. */
1566 array_erase( &sys->jumps, &sys->jumps[i], &sys->jumps[i+1] );
1567}
1568
1572static void uniedit_deselect (void)
1573{
1575 uniedit_sys = NULL;
1576
1577 /* Change window stuff. */
1578 window_disableButton( uniedit_wid, "btnJump" );
1579 window_disableButton( uniedit_wid, "btnRename" );
1580 window_disableButton( uniedit_wid, "btnEdit" );
1581 window_disableButton( uniedit_wid, "btnOpen" );
1582 window_modifyText( uniedit_wid, "txtSelected", _("No selection") );
1583 window_modifyText( uniedit_wid, "txtNebula", _("N/A") );
1584 window_modifyText( uniedit_wid, "txtPresence", _("N/A") );
1585}
1586
1590static void uniedit_selectAdd( StarSystem *sys )
1591{
1592 if (uniedit_sys == NULL)
1593 uniedit_sys = array_create( StarSystem* );
1594
1596
1597 /* Set text again. */
1599
1600 /* Enable buttons again. */
1601 window_enableButton( uniedit_wid, "btnJump" );
1602 window_enableButton( uniedit_wid, "btnRename" );
1603 window_enableButton( uniedit_wid, "btnEdit" );
1604 if (array_size(uniedit_sys) == 1)
1605 window_enableButton( uniedit_wid, "btnOpen" );
1606 else
1607 window_disableButton( uniedit_wid, "btnOpen" );
1608}
1609
1613static void uniedit_selectRm( StarSystem *sys )
1614{
1615 for (int i=0; i<array_size(uniedit_sys); i++) {
1616 if (uniedit_sys[i] == sys) {
1619 if (array_size(uniedit_sys) == 1)
1620 window_enableButton( uniedit_wid, "btnOpen" );
1621 else
1622 window_disableButton( uniedit_wid, "btnOpen" );
1623 return;
1624 }
1625 }
1626 WARN(_("Trying to remove system '%s' from selection when not selected."), sys->name);
1627}
1628
1633{
1634 int l;
1635 char buf[STRMAX];
1636
1637 l = 0;
1638 for (int i=0; i<array_size(uniedit_sys); i++) {
1639 l += scnprintf( &buf[l], sizeof(buf)-l, "%s%s", uniedit_sys[i]->name,
1640 (i == array_size(uniedit_sys)-1) ? "" : ", " );
1641 }
1642
1643 if (l == 0)
1645 else {
1646 window_modifyText( uniedit_wid, "txtSelected", buf );
1647
1648 /* Presence text. */
1649 if (array_size(uniedit_sys) == 1) {
1650 StarSystem *sys = uniedit_sys[0];
1651
1652 buf[0] = '\0';
1653 l = 0;
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);
1658
1659 window_modifyText( uniedit_wid, "txtNebula", buf );
1660
1661 /* Update presence stuff. */
1662 map_updateFactionPresence( uniedit_wid, "txtPresence", sys, 1 );
1663 }
1664 else {
1665 window_modifyText( uniedit_wid, "txtNebula", _("Multiple selected") );
1666 window_modifyText( uniedit_wid, "txtPresence", _("Multiple selected") );
1667 }
1668 }
1669
1670 window_moveWidget( uniedit_wid, "txtPresence", -10, -40-window_getTextHeight( uniedit_wid, "txtNebula" ) );
1671}
1672
1679static void uniedit_buttonZoom( unsigned int wid, const char* str )
1680{
1681 (void) wid;
1682 /* Transform coords to normal. */
1685
1686 /* Apply zoom. */
1687 if (strcmp(str,"btnZoomIn")==0) {
1690 }
1691 else if (strcmp(str,"btnZoomOut")==0) {
1694 }
1695
1696 /* Transform coords back. */
1699}
1700
1704static void uniedit_findSys (void)
1705{
1706 unsigned int wid;
1707 int x, y;
1708
1709 x = 40;
1710
1711 /* Create the window. */
1712 wid = window_create( "wdwFindSystemsandSpobs", _("Find Systems and Spobs"), x, -1, UNIEDIT_FIND_WIDTH, UNIEDIT_FIND_HEIGHT );
1713 uniedit_widFind = wid;
1714
1715 x = 20;
1716
1717 /* Close button. */
1718 window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
1719 "btnClose", _("Close"), uniedit_findSysClose );
1720
1721 /* Find input widget. */
1722 y = -45;
1723 window_addInput( wid, x, y, UNIEDIT_FIND_WIDTH - 40, 20,
1724 "inpFind", 32, 1, NULL );
1725 window_setInputCallback( wid, "inpFind", uniedit_findSearch );
1726
1727 /* Close when escape is pressed. */
1729
1730 /* Generate the list. */
1731 uniedit_findSearch( wid, NULL );
1732
1733 /* Focus the input widget. */
1734 window_setFocus( wid, "inpFind" );
1735}
1736
1740static void uniedit_findSearch( unsigned int wid, const char *str )
1741{
1742 (void) str;
1743 int n, nspobs, nsystems;
1744 const char *name;
1745 char **spobs, **systems;
1746 map_find_t *found;
1747
1748 name = window_getInput( wid, "inpFind" );
1749
1750 /* Search for names. */
1751 spobs = spob_searchFuzzyCase( name, &nspobs );
1752 systems = system_searchFuzzyCase( name, &nsystems );
1753
1754 free(found_cur);
1755 found_cur = NULL;
1756
1757 /* Construct found table. */
1758 found = malloc( sizeof(map_find_t) * (nspobs + nsystems) );
1759 n = 0;
1760
1761 /* Add spobs to the found table. */
1762 for (int i=0; i<nspobs; i++) {
1763 /* Spob must be real. */
1764 Spob *spob = spob_get( spobs[i] );
1765 if (spob == NULL)
1766 continue;
1767
1768 const char *sysname = spob_getSystem( spobs[i] );
1769 if (sysname == NULL)
1770 continue;
1771
1772 StarSystem *sys = system_get( sysname );
1773 if (sys == NULL)
1774 continue;
1775
1776 /* Set some values. */
1777 found[n].spob = spob;
1778 found[n].sys = sys;
1779
1780 /* Set fancy name. */
1781 snprintf( found[n].display, sizeof(found[n].display),
1782 _("%s (%s system)"), spobs[i], sys->name );
1783 n++;
1784 }
1785 free(spobs);
1786
1787 /* Add systems to the found table. */
1788 for (int i=0; i<nsystems; i++) {
1789 StarSystem *sys = system_get( systems[i] );
1790
1791 /* Set some values. */
1792 found[n].spob = NULL;
1793 found[n].sys = sys;
1794
1795 strncpy(found[n].display, sys->name, sizeof(found[n].display)-1);
1796 n++;
1797 }
1798 free(systems);
1799
1800 /* Globals. */
1801 found_cur = found;
1802 found_ncur = n;
1803
1804 /* Display results. */
1805 uniedit_findShowResults( wid, found, n );
1806}
1807
1811static void uniedit_findShowResults( unsigned int wid, map_find_t *found, int n )
1812{
1813 int y, h;
1814 char **str;
1815
1816 /* Destroy if exists. */
1817 if (widget_exists( wid, "lstResults" ))
1818 window_destroyWidget( wid, "lstResults" );
1819
1820 y = -45 - BUTTON_HEIGHT - 20;
1821
1822 if (n == 0) {
1823 str = malloc( sizeof(char*) );
1824 str[0] = strdup(_("None"));
1825 n = 1;
1826 }
1827 else {
1828 qsort( found, n, sizeof(map_find_t), uniedit_sortCompare );
1829
1830 str = malloc( sizeof(char*) * n );
1831 for (int i=0; i<n; i++)
1832 str[i] = strdup( found[i].display );
1833 }
1834
1835 /* Add list. */
1836 h = UNIEDIT_FIND_HEIGHT + y - BUTTON_HEIGHT - 30;
1837 window_addList( wid, 20, y, UNIEDIT_FIND_WIDTH-40, h,
1838 "lstResults", str, n, 0, uniedit_centerSystem, NULL );
1839}
1840
1844static void uniedit_findSysClose( unsigned int wid, const char *name )
1845{
1846 /* Clean up if necessary. */
1847 free( found_cur );
1848 found_cur = NULL;
1849
1850 /* Close the window. */
1851 window_close( wid, name );
1852}
1853
1857static void uniedit_centerSystem( unsigned int wid, const char *unused )
1858{
1859 (void) unused;
1860 StarSystem *sys;
1861 int pos;
1862
1863 /* Make sure it's valid. */
1864 if (found_ncur == 0 || found_cur == NULL)
1865 return;
1866
1867 pos = toolkit_getListPos( wid, "lstResults" );
1868 sys = found_cur[ pos ].sys;
1869
1870 if (sys == NULL)
1871 return;
1872
1873 /* Center. */
1874 uniedit_xpos = sys->pos.x * uniedit_zoom;
1875 uniedit_ypos = sys->pos.y * uniedit_zoom;
1876}
1877
1881static int uniedit_sortCompare( const void *p1, const void *p2 )
1882{
1883 map_find_t *f1, *f2;
1884
1885 /* Convert pointer. */
1886 f1 = (map_find_t*) p1;
1887 f2 = (map_find_t*) p2;
1888
1889 /* Sort by name, nothing more. */
1890 return strcasecmp( f1->sys->name, f2->sys->name );
1891}
1892
1896static void uniedit_editSys (void)
1897{
1898 unsigned int wid;
1899 int x, y, l;
1900 char buf[STRMAX_SHORT];
1901 const char *s;
1902 StarSystem *sys;
1903
1904 /* Must have a system. */
1905 if (array_size(uniedit_sys)==0)
1906 return;
1907 sys = uniedit_sys[0];
1908
1909 /* Create the window. */
1910 wid = window_create( "wdwStarSystemPropertyEditor", _("Star System Property Editor"), -1, -1, UNIEDIT_EDIT_WIDTH, UNIEDIT_EDIT_HEIGHT );
1911 uniedit_widEdit = wid;
1913
1914 x = 20;
1915
1916 /* Close button. */
1917 window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
1918 "btnClose", _("Close"), uniedit_editSysClose );
1919
1920 /* Rename button. */
1921 y = -45;
1922 snprintf( buf, sizeof(buf), "%s #n%s", _("Name:"), (array_size(uniedit_sys) > 1) ? _("#rvarious") : uniedit_sys[0]->name );
1923 window_addText( wid, x, y, 180, 15, 0, "txtName", &gl_smallFont, NULL, buf );
1924 window_addButton( wid, 200, y+3, BUTTON_WIDTH, 21, "btnRename", _("Rename"), uniedit_btnEditRename );
1925
1926 /* New row. */
1927 y -= gl_defFont.h + 15;
1928
1929 /* Add general stats */
1930 s = _("Radius");
1931 l = gl_printWidthRaw( NULL, s );
1932 window_addText( wid, x, y, l, 20, 1, "txtRadius",
1933 NULL, NULL, s );
1934 window_addInput( wid, x += l + 7, y, 80, 20, "inpRadius", 10, 1, NULL );
1935 window_setInputFilter( wid, "inpRadius", INPUT_FILTER_NUMBER );
1936 x += 80 + 12;
1937 s = _("(Scales spob positions)");
1938 l = gl_printWidthRaw( NULL, s );
1939 window_addText( wid, x, y, l, 20, 1, "txtRadiusComment",
1940 NULL, NULL, s );
1941
1942 /* New row. */
1943 x = 20;
1944 y -= gl_defFont.h + 15;
1945
1946 s = _("Dust");
1947 l = gl_printWidthRaw( NULL, s );
1948 window_addText( wid, x, y, l, 20, 1, "txtDust",
1949 NULL, NULL, s );
1950 window_addInput( wid, x += l + 7, y, 50, 20, "inpDust", 4, 1, NULL );
1951 window_setInputFilter( wid, "inpDust", INPUT_FILTER_NUMBER );
1952 x += 50 + 12;
1953
1954 s = _("Interference");
1955 l = gl_printWidthRaw( NULL, s );
1956 window_addText( wid, x, y, l, 20, 1, "txtInterference",
1957 NULL, NULL, s );
1958 window_addInput( wid, x += l + 7, y, 55, 20, "inpInterference", 5, 1, NULL );
1959 window_setInputFilter( wid, "inpInterference", INPUT_FILTER_NUMBER );
1960
1961 /* New row. */
1962 x = 20;
1963 y -= gl_defFont.h + 15;
1964
1965 s = _("Nebula");
1966 l = gl_printWidthRaw( NULL, s );
1967 window_addText( wid, x, y, l, 20, 1, "txtNebula",
1968 NULL, NULL, s );
1969 window_addInput( wid, x += l + 7, y, 50, 20, "inpNebula", 4, 1, NULL );
1970 window_setInputFilter( wid, "inpNebula", INPUT_FILTER_NUMBER );
1971 x += 50 + 12;
1972
1973 s = _("Volatility");
1974 l = gl_printWidthRaw( NULL, s );
1975 window_addText( wid, x, y, l, 20, 1, "txtVolatility",
1976 NULL, NULL, s );
1977 window_addInput( wid, x += l + 7, y, 50, 20, "inpVolatility", 4, 1, NULL );
1978 window_setInputFilter( wid, "inpVolatility", INPUT_FILTER_NUMBER );
1979 x += 50 + 12;
1980
1981 s = _("Hue");
1982 l = gl_printWidthRaw( NULL, s );
1983 window_addText( wid, x, y, l, 20, 1, "txtHue",
1984 NULL, NULL, s );
1985 window_addInput( wid, x += l + 7, y, 50, 20, "inpHue", 4, 1, NULL );
1986 window_setInputFilter( wid, "inpHue", INPUT_FILTER_NUMBER );
1987 x += 50 + 12;
1988
1989 /* Next row. */
1990 x = 20;
1991 y -= gl_defFont.h + 15;
1992
1993 s = _("No lanes");
1994 window_addCheckbox( wid, x, y, 100, gl_defFont.h, "chkNolanes", s, uniedit_chkNolanes, sys_isFlag( sys, SYSTEM_NOLANES ) );
1995
1996 /* Tags. */
1997 x = 20;
1998 y -= gl_defFont.h + 15;
1999 l = scnprintf( buf, sizeof(buf), "#n%s#0", _("Tags: ") );
2000 for (int i=0; i<array_size(sys->tags); i++)
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 );
2003
2004 /* Load values */
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 );
2017
2018 /* Generate the list. */
2019 uniedit_editGenList( wid );
2020}
2021
2025static void uniedit_editGenList( unsigned int wid )
2026{
2027 int j, n;
2028 StarSystem *sys;
2029 const VirtualSpob *va;
2030 char **str;
2031 int y, h, has_spobs;
2032
2033 /* Destroy if exists. */
2034 if (widget_exists( wid, "lstSpobs" ))
2035 window_destroyWidget( wid, "lstSpobs" );
2036
2037 y = -180;
2038
2039 /* Check to see if it actually has virtual spobs. */
2040 sys = uniedit_sys[0];
2041 n = array_size( sys->spobs_virtual );
2042 has_spobs = !!n;
2043
2044 /* Generate list. */
2045 j = 0;
2046 str = malloc( sizeof(char*) * (n+1) );
2047 if (has_spobs) {
2048 /* Virtual spob button. */
2049 for (int i=0; i<n; i++) {
2050 va = sys->spobs_virtual[i];
2051 str[j++] = strdup( va->name );
2052 }
2053 }
2054 else
2055 str[j++] = strdup(_("None"));
2056
2057 /* Add list. */
2058 h = UNIEDIT_EDIT_HEIGHT+y-20 - 2*(BUTTON_HEIGHT+20);
2059 window_addList( wid, 20, y, UNIEDIT_EDIT_WIDTH-40, h,
2060 "lstSpobs", str, j, 0, NULL, NULL );
2061 y -= h + 20;
2062
2063 /* Add buttons if needed. */
2064 if (!widget_exists( wid, "btnRmSpob" ))
2065 window_addButton( wid, -20, y+3, BUTTON_WIDTH, BUTTON_HEIGHT,
2066 "btnRmSpob", _("Remove"), uniedit_btnEditRmSpob );
2067 if (!widget_exists( wid, "btnAddSpob" ))
2068 window_addButton( wid, -20-(20+BUTTON_WIDTH), y+3, BUTTON_WIDTH, BUTTON_HEIGHT,
2069 "btnAddSpob", _("Add"), uniedit_btnEditAddSpob );
2070
2071 if (!widget_exists( wid, "btnEditTags" ))
2072 window_addButton( wid, -20-(20+BUTTON_WIDTH)*2, y+3, BUTTON_WIDTH, BUTTON_HEIGHT,
2073 "btnEditTags", _("Edit Tags"), uniedit_btnEditTags );
2074}
2075
2079static void uniedit_editSysClose( unsigned int wid, const char *name )
2080{
2081 StarSystem *sys;
2082 double scale;
2083
2084 /* We already know the system exists because we checked when opening the dialog. */
2085 sys = uniedit_sys[0];
2086
2087 /* Changes in radius need to scale the system spob positions. */
2088 scale = atof(window_getInput( wid, "inpRadius" )) / sys->radius;
2089 sysedit_sysScale(sys, scale);
2090
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.;
2096
2097 /* Reconstruct universe presences. */
2100
2101 /* Text might need changing. */
2103
2104 if (conf.devautosave)
2106
2107 /* Close the window. */
2108 window_close( wid, name );
2109}
2110
2114static void uniedit_btnEditRmSpob( unsigned int wid, const char *unused )
2115{
2116 (void) unused;
2117 const char *selected;
2118 int ret;
2119
2120 /* Get selection. */
2121 selected = toolkit_getList( wid, "lstSpobs" );
2122
2123 /* Make sure it's valid. */
2124 if ((selected==NULL) || (strcmp(selected,_("None"))==0))
2125 return;
2126
2127 /* Remove the spob. */
2128 ret = system_rmVirtualSpob( uniedit_sys[0], selected );
2129 if (ret != 0) {
2130 dialogue_alert( _("Failed to remove virtual spob '%s'!"), selected );
2131 return;
2132 }
2133
2134 /* Run galaxy modifications. */
2137
2138 uniedit_editGenList( wid );
2139}
2140
2144static void uniedit_btnEditAddSpob( unsigned int parent, const char *unused )
2145{
2146 (void) parent;
2147 (void) unused;
2148 unsigned int wid;
2149 const VirtualSpob *va;
2150 char **str;
2151 int h;
2152
2153 /* Get all spobs. */
2154 va = virtualspob_getAll();
2155 if (array_size(va)==0) {
2156 dialogue_alert( _("No virtual spobs to add! Please add virtual spobs to the '%s' directory first."), VIRTUALSPOB_DATA_PATH );
2157 return;
2158 }
2159
2160 /* Create the window. */
2161 wid = window_create( "wdwAddaVirtualSpob", _("Add a Virtual Spob"), -1, -1, UNIEDIT_EDIT_WIDTH, UNIEDIT_EDIT_HEIGHT );
2163
2164 /* Add virtual spob list. */
2165 str = malloc( sizeof(char*) * array_size(va) );
2166 for (int i=0; i<array_size(va); i++)
2167 str[i] = strdup( va[i].name );
2169 window_addList( wid, 20, -40, UNIEDIT_EDIT_WIDTH-40, h,
2170 "lstSpobs", str, array_size(va), 0, NULL, NULL );
2171
2172 /* Close button. */
2173 window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
2174 "btnClose", _("Close"), window_close );
2175
2176 /* Add button. */
2177 window_addButton( wid, -20-(BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT,
2178 "btnAdd", _("Add"), uniedit_btnEditAddSpobAdd );
2179}
2180
2184static void uniedit_btnEditAddSpobAdd( unsigned int wid, const char *unused )
2185{
2186 const char *selected;
2187 int ret;
2188
2189 /* Get selection. */
2190 selected = toolkit_getList( wid, "lstSpobs" );
2191 if (selected == NULL)
2192 return;
2193
2194 /* Add virtual presence. */
2195 ret = system_addVirtualSpob( uniedit_sys[0], selected );
2196 if (ret != 0) {
2197 dialogue_alert( _("Failed to add virtual spob '%s'!"), selected );
2198 return;
2199 }
2200
2201 /* Run galaxy modifications. */
2204
2205 /* Regenerate the list. */
2207
2208 if (conf.devautosave)
2210
2211 /* Close the window. */
2212 window_close( wid, unused );
2213}
2214
2218static void uniedit_btnEditTags( unsigned int wid, const char *unused )
2219{
2220 (void) unused;
2221 int y, w, bw;
2222
2223 /* Create the window. */
2224 wid = window_create( "wdwSystemTagsEditor", _("System Tags Editor"), -1, -1, UNIEDIT_EDIT_WIDTH, UNIEDIT_EDIT_HEIGHT );
2225 window_setCancel( wid, uniedit_btnTagsClose );
2226
2227 w = (UNIEDIT_EDIT_WIDTH - 40 - 15) / 2.;
2228 bw = (UNIEDIT_EDIT_WIDTH - 40 - 15 * 3) / 4.;
2229
2230 /* Close button. */
2231 window_addButton( wid, -20, 20, bw, BUTTON_HEIGHT,
2232 "btnClose", _("Close"), uniedit_btnTagsClose );
2233 y = 20 + BUTTON_HEIGHT + 15;
2234
2235 /* Remove button. */
2236 window_addButton( wid, -20-(w+15), y, w, BUTTON_HEIGHT,
2237 "btnRm", _("Rm Tag"), uniedit_btnRmTag );
2238
2239 /* Add button. */
2240 window_addButton( wid, -20, y, w, BUTTON_HEIGHT,
2241 "btnAdd", _("Add Tag"), uniedit_btnAddTag );
2242
2243 /* New tag. */
2244 window_addButton( wid, -20-(w+15), 20, w, BUTTON_HEIGHT,
2245 "btnNew", _("New Tag"), uniedit_btnNewTag );
2246
2247 /* Generate list of tags. */
2248 if (uniedit_tagslist == NULL) {
2249 StarSystem *systems_all = system_getAll();
2250 uniedit_tagslist = array_create( char* );
2251 for (int i=0; i<array_size(systems_all); i++) {
2252 StarSystem *s = &systems_all[i];
2253 for (int j=0; j<array_size(s->tags); j++) {
2254 char *t = s->tags[j];
2255 int found = 0;
2256 for (int k=0; k<array_size(uniedit_tagslist); k++)
2257 if (strcmp(uniedit_tagslist[k], t)==0) {
2258 found = 1;
2259 break;
2260 }
2261 if (!found)
2262 array_push_back( &uniedit_tagslist, strdup(t) );
2263 }
2264 }
2265 qsort( uniedit_tagslist, array_size(uniedit_tagslist), sizeof(char*), strsort );
2266 }
2267
2268 uniedit_genTagsList( wid );
2269}
2270
2271/*
2272 * Tags are closed so update tags.
2273 */
2274static void uniedit_btnTagsClose( unsigned int wid, const char *unused )
2275{
2276 char buf[STRMAX_SHORT];
2277 StarSystem *s = uniedit_sys[0];
2278 int l = scnprintf( buf, sizeof(buf), "#n%s#0", _("Tags: ") );
2279 for (int i=0; i<array_size(s->tags); i++)
2280 l += scnprintf( &buf[l], sizeof(buf)-l, "%s%s", ((i>0) ? ", " : ""), s->tags[i] );
2281 window_modifyText( uniedit_widEdit, "txtTags", buf );
2282
2283 window_close( wid, unused );
2284}
2285
2289static void uniedit_genTagsList( unsigned int wid )
2290{
2291 StarSystem *s;
2292 char **have, **lack;
2293 int n, x, y, w, h, hpos, lpos, empty;
2294
2295 hpos = lpos = -1;
2296
2297 /* Destroy if exists. */
2298 if (widget_exists( wid, "lstTagsHave" ) &&
2299 widget_exists( wid, "lstTagsLacked" )) {
2300 hpos = toolkit_getListPos( wid, "lstTagsHave" );
2301 lpos = toolkit_getListPos( wid, "lstTagsLacked" );
2302 window_destroyWidget( wid, "lstTagsHave" );
2303 window_destroyWidget( wid, "lstTagsLacked" );
2304 }
2305
2306 s = uniedit_sys[0];
2307 w = (UNIEDIT_EDIT_WIDTH - 40 - 15) / 2.;
2308 x = -20 - w - 15;
2309 y = 20 + BUTTON_HEIGHT * 2 + 30;
2310 h = UNIEDIT_EDIT_HEIGHT - y - 30;
2311
2312 /* Get all the techs the spob has. */
2313 n = array_size(s->tags);
2314 if (n>0) {
2315 have = malloc( n * sizeof(char*) );
2316 for (int i=0; i<n; i++)
2317 have[i] = strdup(s->tags[i]);
2318 empty = 0;
2319 }
2320 else {
2321 have = malloc( sizeof(char*) );
2322 have[n++] = strdup(_("None"));
2323 empty = 1;
2324 }
2325
2326 /* Add list. */
2327 window_addList( wid, x, y, w, h, "lstTagsHave", have, n, 0, NULL, uniedit_btnRmTag );
2328 x += w + 15;
2329
2330 /* Omit the techs that the spob already has from the list. */
2331 n = 0;
2332 lack = malloc( array_size(uniedit_tagslist) * sizeof(char*) );
2333 for (int i=0; i<array_size(uniedit_tagslist); i++) {
2334 char *t = uniedit_tagslist[i];
2335 if (empty)
2336 lack[n++] = strdup(t);
2337 else {
2338 int found = 0;
2339 for (int j=0; j<array_size(s->tags); j++)
2340 if (strcmp( s->tags[j], t )==0) {
2341 found = 1;
2342 break;
2343 }
2344 if (!found)
2345 lack[n++] = strdup( t );
2346 }
2347 }
2348
2349 /* Add list. */
2350 window_addList( wid, x, y, w, h, "lstTagsLacked", lack, n, 0, NULL, uniedit_btnAddTag );
2351
2352 /* Restore positions. */
2353 if (hpos != -1 && lpos != -1) {
2354 toolkit_setListPos( wid, "lstTagsHave", hpos );
2355 toolkit_setListPos( wid, "lstTagsLacked", lpos );
2356 }
2357}
2358
2362static void uniedit_btnAddTag( unsigned int wid, const char *unused )
2363{
2364 (void) unused;
2365 const char *selected;
2366 StarSystem *s;
2367
2368 selected = toolkit_getList( wid, "lstTagsLacked" );
2369 if ((selected == NULL) || (strcmp(selected,_("None"))==0))
2370 return;
2371
2372 s = uniedit_sys[0];
2373 if (s->tags == NULL)
2374 s->tags = array_create( char* );
2375 array_push_back( &s->tags, strdup(selected) );
2376
2377 /* Regenerate the list. */
2378 uniedit_genTagsList( wid );
2379}
2380
2384static void uniedit_btnRmTag( unsigned int wid, const char *unused )
2385{
2386 (void) unused;
2387 const char *selected;
2388 StarSystem *s;
2389 int i;
2390
2391 selected = toolkit_getList( wid, "lstTagsHave" );
2392 if ((selected == NULL) || (strcmp(selected,_("None"))==0))
2393 return;
2394
2395 s = uniedit_sys[0];
2396 for (i=0; i<array_size(s->tags); i++)
2397 if (strcmp( selected, s->tags[i] )==0)
2398 break;
2399 if (i >= array_size(s->tags))
2400 return;
2401 free( s->tags[i] );
2402 array_erase( &s->tags, &s->tags[i], &s->tags[i+1] );
2403
2404 /* Regenerate the list. */
2405 uniedit_genTagsList( wid );
2406}
2407
2411static void uniedit_btnNewTag( unsigned int wid, const char *unused )
2412{
2413 (void) unused;
2414 StarSystem *s;
2415
2416 char *tag = dialogue_input( _("Add New System Tag"), 1, 128, _("Please write the new tag to add to the system.") );
2417 if (tag==NULL)
2418 return;
2419
2420 s = uniedit_sys[0];
2421 if (s->tags == NULL)
2422 s->tags = array_create( char* );
2423 array_push_back( &s->tags, tag ); /* gets freed later */
2424
2425 /* Also add to list of all tags. */
2426 array_push_back( &uniedit_tagslist, strdup(tag) );
2427
2428 /* Regenerate the list. */
2429 uniedit_genTagsList( wid );
2430}
2431
2435static void uniedit_btnEditRename( unsigned int wid, const char *unused )
2436{
2437 (void) unused;
2438 char buf[STRMAX_SHORT];
2439
2440 /* Rename systems. */
2442
2443 /* Update text. */
2444 snprintf( buf, sizeof(buf), "%s #n%s", _("Name:"), (array_size(uniedit_sys) > 1) ? _("#rvarious") : uniedit_sys[0]->name );
2445 window_modifyText( wid, "txtName", buf );
2446}
2447
2451static void uniedit_btnViewModeSet( unsigned int wid, const char *unused )
2452{
2453 const char *selected;
2454 int pos;
2455
2456 /* Check default. */
2457 pos = toolkit_getListPos( wid, "lstViewModes" );
2459 if (pos==0) {
2460 uniedit_viewmode = UNIEDIT_VIEW_DEFAULT;
2461 window_close( wid, unused );
2462 return;
2463 }
2464 else if (pos==1) {
2465 uniedit_viewmode = UNIEDIT_VIEW_VIRTUALSPOBS;
2466 window_close( wid, unused );
2467 return;
2468 }
2469 else if (pos==2) {
2470 uniedit_viewmode = UNIEDIT_VIEW_RADIUS;
2471 window_close( wid, unused );
2472 return;
2473 }
2474 else if (pos==3) {
2475 uniedit_viewmode = UNIEDIT_VIEW_NOLANES;
2476 window_close( wid, unused );
2477 return;
2478 }
2479 else if (pos==4) {
2480 uniedit_viewmode = UNIEDIT_VIEW_BACKGROUND;
2481 window_close( wid, unused );
2482 return;
2483 }
2484 else if (pos==5) {
2485 uniedit_viewmode = UNIEDIT_VIEW_ASTEROIDS;
2486 window_close( wid, unused );
2487 return;
2488 }
2489 else if (pos==6) {
2490 uniedit_viewmode = UNIEDIT_VIEW_INTERFERENCE;
2491 window_close( wid, unused );
2492 return;
2493 }
2494 else if (pos==7) {
2495 uniedit_viewmode = UNIEDIT_VIEW_TECH;
2496 window_close( wid, unused );
2497 return;
2498 }
2499 else if (pos==8) {
2500 uniedit_viewmode = UNIEDIT_VIEW_PRESENCE_SUM;
2501 window_close( wid, unused );
2502 return;
2503 }
2504
2505 /* Get selection. */
2506 selected = toolkit_getList( wid, "lstViewModes" );
2507 if (selected == NULL)
2508 return;
2509
2510 uniedit_viewmode = UNIEDIT_VIEW_PRESENCE;
2511 uniedit_view_faction = faction_get( selected );
2512
2513 /* Close the window. */
2514 window_close( wid, unused );
2515}
2516
2517static void uniedit_chkNolanes( unsigned int wid, const char *wgtname )
2518{
2519 int s = window_checkboxState( wid, wgtname );
2520 StarSystem *sys = uniedit_sys[0];
2521 if (s)
2522 sys_setFlag( sys, SYSTEM_NOLANES );
2523 else
2524 sys_rmFlag( sys, SYSTEM_NOLANES );
2525}
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
Definition array.h:158
#define array_erase(ptr_array, first, last)
Erases elements in interval [first, last).
Definition array.h:140
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
Definition array.h:168
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
Definition array.h:119
#define array_push_back(ptr_array, element)
Adds a new element at the end of the array.
Definition array.h:129
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
Definition array.h:93
int dpl_saveAll(void)
Saves all the star spobs.
Definition dev_spob.c:178
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.
Definition dev_system.c:83
int dsys_saveAll(void)
Saves all the star systems.
Definition dev_system.c:280
static UniEditMode uniedit_mode
Definition dev_uniedit.c:80
static void uniedit_btnOpen(unsigned int wid_unused, const char *unused)
Opens up a system.
static double uniedit_my
static void uniedit_btnEditRename(unsigned int wid, const char *unused)
Renames the systems in the system editor.
static double uniedit_rotate
Definition dev_uniedit.c:96
static double uniedit_dt
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
Definition dev_uniedit.c:86
void uniedit_open(unsigned int wid_unused, const char *unused)
Opens the system editor interface.
static int uniedit_tadd
static void uniedit_close(unsigned int wid, const char *wgt)
Closes the system editor widget.
#define UNIEDIT_CLICK_THRESHOLD
Definition dev_uniedit.c:47
static double uniedit_dragSelX
Definition dev_uniedit.c:94
static unsigned int uniedit_widFind
Definition dev_uniedit.c:85
#define UNIEDIT_DOUBLECLICK_THRESHOLD
Definition dev_uniedit.c:48
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
Definition dev_uniedit.c:42
static void uniedit_newSys(double x, double y)
Creates a new system.
static double uniedit_ypos
Definition dev_uniedit.c:87
static int uniedit_drag
Definition dev_uniedit.c:91
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
Definition dev_uniedit.c:50
static StarSystem ** uniedit_sys
Definition dev_uniedit.c:99
#define UNIEDIT_EDIT_HEIGHT
Definition dev_uniedit.c:40
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_moved
Definition dev_uniedit.c:89
static int uniedit_keys(unsigned int wid, SDL_Keycode key, SDL_Keymod mod, int isrepeat)
Handles keybindings.
static unsigned int uniedit_widEdit
Definition dev_uniedit.c:84
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
Definition dev_uniedit.c:92
#define UNIEDIT_FIND_HEIGHT
Definition dev_uniedit.c:43
static void uniedit_findShowResults(unsigned int wid, map_find_t *found, int n)
Generates the virtual spob list.
#define BUTTON_HEIGHT
Definition dev_uniedit.c:37
static double uniedit_zoom
Definition dev_uniedit.c:88
static unsigned int uniedit_lastClick
Definition dev_uniedit.c:90
static double uniedit_dragSelY
Definition dev_uniedit.c:95
static int uniedit_dragSel
Definition dev_uniedit.c:93
static double uniedit_rotate_cx
Definition dev_uniedit.c:97
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
Definition space.c:92
#define UNIEDIT_DRAG_THRESHOLD
Definition dev_uniedit.c:45
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
Definition dev_uniedit.c:98
static void uniedit_btnViewModeSet(unsigned int wid, const char *unused)
Actually adds the virtual spob.
static int found_ncur
UniEditMode
Definition dev_uniedit.c:57
@ UNIEDIT_ROTATE
Definition dev_uniedit.c:61
@ UNIEDIT_NEWSYS
Definition dev_uniedit.c:60
@ UNIEDIT_DEFAULT
Definition dev_uniedit.c:58
@ UNIEDIT_JUMP
Definition dev_uniedit.c:59
static void uniedit_btnView(unsigned int wid_unused, const char *unused)
Allows selecting the view.
static double uniedit_mx
static void uniedit_selectAdd(StarSystem *sys)
Adds a system to the selection.
#define UNIEDIT_ZOOM_MAX
Definition dev_uniedit.c:51
#define UNIEDIT_ZOOM_MIN
Definition dev_uniedit.c:52
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
Definition dev_uniedit.c:81
static unsigned int uniedit_wid
Definition dev_uniedit.c:83
static void uniedit_findSearch(unsigned int wid, const char *str)
Searches for spobs and systems.
#define BUTTON_WIDTH
Definition dev_uniedit.c:36
#define UNIEDIT_EDIT_WIDTH
Definition dev_uniedit.c:39
static int uniedit_view_faction
Definition dev_uniedit.c:82
#define UNIEDIT_MOVE_THRESHOLD
Definition dev_uniedit.c:46
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.
Definition dialogue.c:469
void dialogue_alert(const char *fmt,...)
Displays an alert popup with only an ok button and a message.
Definition dialogue.c:132
char * dialogue_input(const char *title, int min, int max, const char *fmt,...)
Creates a dialogue that allows the player to write a message.
Definition dialogue.c:441
int dialogue_YesNoRaw(const char *caption, const char *msg)
Runs a dialogue with both yes and no options.
Definition dialogue.c:373
int economy_execQueued(void)
Calls economy_refresh if an economy update is queued.
Definition economy.c:483
const char * faction_name(int f)
Gets a factions "real" (internal) name.
Definition faction.c:306
const FactionGenerator * faction_generators(int f)
Gets the faction's generators.
Definition faction.c:1883
const glColour * faction_colour(int f)
Gets the colour of the faction.
Definition faction.c:469
int * faction_getAll(void)
Returns all faction IDs in an array (array.h).
Definition faction.c:195
int faction_get(const char *name)
Gets a faction ID by name.
Definition faction.c:184
glFont gl_smallFont
Definition font.c:154
int gl_printWidthRaw(const glFont *ft_font, const char *text)
Gets the width that it would take to print some text.
Definition font.c:961
glFont gl_defFont
Definition font.c:153
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.
Definition font.c:691
glFont gl_defFontMono
Definition font.c:155
double naev_getrealdt(void)
Gets the last delta-tick.
Definition naev.c:1174
Header file with generic functions and naev-specifics.
#define MIN(x, y)
Definition naev.h:40
#define ABS(x)
Definition naev.h:36
#define pow2(x)
Definition naev.h:46
#define MAX(x, y)
Definition naev.h:39
int strsort(const void *p1, const void *p2)
Sort function for sorting strings with qsort().
Definition nstring.c:81
int scnprintf(char *text, size_t maxlen, const char *fmt,...)
Like snprintf(), but returns the number of characters ACTUALLY "printed" into the buffer....
Definition nstring.c:99
const char * num2strU(double n, int decimals)
Unsafe version of num2str that uses an internal buffer. Every call overwrites the return value.
Definition nstring.c:163
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.
Definition pause.c:28
void unpause_game(void)
Unpauses the game.
Definition pause.c:46
static const double c[]
Definition rng.c:264
void safelanes_recalculate(void)
Update the safe lane locations in response to the universe changing (e.g., diff applied).
Definition safelanes.c:252
void space_reconstructPresences(void)
Reset the presence of all systems.
Definition space.c:4263
void systems_reconstructJumps(void)
Reconstructs the jumps.
Definition space.c:2738
double system_getPresenceFull(const StarSystem *sys, int faction, double *base, double *bonus)
Get the presence of a faction in a system.
Definition space.c:4210
Spob * spob_getAll(void)
Gets an array (array.h) of all spobs.
Definition space.c:1107
Spob * spob_get(const char *spobname)
Gets a spob based on its name.
Definition space.c:1051
int system_addVirtualSpob(StarSystem *sys, const char *spobname)
Adds a virtual spob to a system.
Definition space.c:2545
StarSystem * system_getIndex(int id)
Get the system by its index.
Definition space.c:989
StarSystem * system_new(void)
Creates a new star system.
Definition space.c:2673
StarSystem * system_getAll(void)
Gets an array (array.h) of all star systems.
Definition space.c:879
char ** spob_searchFuzzyCase(const char *spobname, int *n)
Does a fuzzy case matching. Searches spob_name() but returns internal names.
Definition space.c:1151
char ** system_searchFuzzyCase(const char *sysname, int *n)
Does a fuzzy case matching. Searches translated names but returns internal names.
Definition space.c:901
StarSystem * system_get(const char *sysname)
Get the system from its name.
Definition space.c:960
const char * spob_getSystem(const char *spobname)
Get the name of a system from a spobname.
Definition space.c:1025
double system_getPresence(const StarSystem *sys, int faction)
Get the presence of a faction in a system.
Definition space.c:4181
int system_rmVirtualSpob(StarSystem *sys, const char *spobname)
Removes a virtual spob from a system.
Definition space.c:2569
VirtualSpob * virtualspob_getAll(void)
Gets all the virtual spobs.
Definition space.c:1186
const char * spob_name(const Spob *p)
Gets the translated name of a spob.
Definition space.c:1752
Represents an asteroid field anchor.
Definition asteroid.h:100
Asteroid * asteroids
Definition asteroid.h:105
AsteroidTypeGroup ** groups
Definition asteroid.h:109
double weight
Definition faction.h:17
int devautosave
Definition conf.h:158
char * dev_save_sys
Definition conf.h:170
Represents the presence of a spob.
Definition space.h:66
double bonus
Definition space.h:69
double base
Definition space.h:68
int faction
Definition space.h:67
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...
Definition space.h:89
tech_group_t * tech
Definition space.h:118
SpobPresence presence
Definition space.h:104
Represents presence in a system.
Definition space.h:175
double value
Definition space.h:179
double base
Definition space.h:177
double bonus
Definition space.h:178
Basically modifies system parameters without creating any real objects.
Definition space.h:78
SpobPresence * presences
Definition space.h:80
char * name
Definition space.h:79
int h
Definition font.h:18
Represents a found target.
Definition map_find.h:11
StarSystem * sys
Definition map_find.h:13
char display[STRMAX_SHORT]
Definition map_find.h:14
Spob * spob
Definition map_find.h:12
char ** tech_getItemNames(const tech_group_t *tech, int *n)
Gets the names of all techs within a given group.
Definition tech.c:686
unsigned int window_create(const char *name, const char *displayname, const int x, const int y, const int w, const int h)
Creates a window.
Definition toolkit.c:691
void window_setDynamic(unsigned int wid, int dynamic)
Sets a window as dynamic, so that it is drawn every frame completely.
Definition toolkit.c:647
void window_setFocus(unsigned int wid, const char *wgtname)
Sets the focused widget in a window.
Definition toolkit.c:2471
void window_setCancel(unsigned int wid, void(*cancel)(unsigned int, const char *))
Sets the default cancel function of the window.
Definition toolkit.c:868
void toolkit_drawAltText(int bx, int by, const char *alt)
Draws an alt text.
Definition toolkit.c:1429
void window_moveWidget(unsigned int wid, const char *name, int x, int y)
Moves a widget.
Definition toolkit.c:465
void window_destroyWidget(unsigned int wid, const char *wgtname)
Destroys a widget in a window.
Definition toolkit.c:1165
void window_handleKeys(unsigned int wid, int(*keyhandler)(unsigned int, SDL_Keycode, SDL_Keymod, int))
Sets the key handler for the window.
Definition toolkit.c:960
void window_setBorder(unsigned int wid, int enable)
Sets or removes the border of a window.
Definition toolkit.c:941
int widget_exists(unsigned int wid, const char *wgtname)
Checks to see if a widget exists.
Definition toolkit.c:1142
void window_close(unsigned int wid, const char *str)
Helper function to automatically close the window calling it.
Definition toolkit.c:1026
void diff_clear(void)
Removes all active diffs. (Call before economy_destroy().)
Definition unidiff.c:1522