naev 0.10.4
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 */
57typedef enum UniEditMode_ {
62
63typedef enum UniEditViewMode_ {
64 UNIEDIT_VIEW_DEFAULT,
65 UNIEDIT_VIEW_VIRTUALSPOBS,
66 UNIEDIT_VIEW_RADIUS,
67 UNIEDIT_VIEW_BACKGROUND,
68 UNIEDIT_VIEW_ASTEROIDS,
69 UNIEDIT_VIEW_TECH,
70 UNIEDIT_VIEW_PRESENCE_SUM,
71 UNIEDIT_VIEW_PRESENCE,
72} UniEditViewMode;
73
74extern StarSystem *systems_stack;
75
77static UniEditViewMode uniedit_viewmode = UNIEDIT_VIEW_DEFAULT;
78static int uniedit_view_faction = -1;
79static unsigned int uniedit_wid = 0;
80static unsigned int uniedit_widEdit = 0;
81static unsigned int uniedit_widFind = 0;
82static double uniedit_xpos = 0.;
83static double uniedit_ypos = 0.;
84static double uniedit_zoom = 1.;
85static int uniedit_moved = 0;
86static unsigned int uniedit_lastClick = 0;
87static int uniedit_drag = 0;
88static int uniedit_dragSys = 0;
89static int uniedit_dragSel = 0;
90static double uniedit_dragSelX= 0;
91static double uniedit_dragSelY= 0;
92static StarSystem **uniedit_sys = NULL;
93static StarSystem *uniedit_tsys = NULL;
94static int uniedit_tadd = 0;
95static double uniedit_mx = 0.;
96static double uniedit_my = 0.;
97static double uniedit_dt = 0.;
99static map_find_t *found_cur = NULL;
100static int found_ncur = 0;
102/*
103 * Universe editor Prototypes.
104 */
105/* Selection. */
106static void uniedit_deselect (void);
107static void uniedit_selectAdd( StarSystem *sys );
108static void uniedit_selectRm( StarSystem *sys );
109/* System and spob search. */
110static void uniedit_findSys (void);
111static void uniedit_findSysClose( unsigned int wid, const char *name );
112static void uniedit_findSearch( unsigned int wid, const char *str );
113static void uniedit_findShowResults( unsigned int wid, map_find_t *found, int n );
114static void uniedit_centerSystem( unsigned int wid, const char *unused );
115static int uniedit_sortCompare( const void *p1, const void *p2 );
116/* System editing. */
117static void uniedit_editSys (void);
118static void uniedit_editSysClose( unsigned int wid, const char *name );
119static void uniedit_editGenList( unsigned int wid );
120static void uniedit_btnEditRename( unsigned int wid, const char *unused );
121static void uniedit_btnEditRmSpob( unsigned int wid, const char *unused );
122static void uniedit_btnEditAddSpob( unsigned int wid, const char *unused );
123static void uniedit_btnEditAddSpobAdd( unsigned int wid, const char *unused );
124static void uniedit_btnViewModeSet( unsigned int wid, const char *unused );
125/* System renaming. */
126static int uniedit_checkName( const char *name );
127static void uniedit_renameSys (void);
128/* New system. */
129static void uniedit_newSys( double x, double y );
130/* Jump handling. */
131static void uniedit_toggleJump( StarSystem *sys );
132static void uniedit_jumpAdd( StarSystem *sys, StarSystem *targ );
133static void uniedit_jumpRm( StarSystem *sys, StarSystem *targ );
134/* Custom system editor widget. */
135static void uniedit_buttonZoom( unsigned int wid, const char* str );
136static void uniedit_render( double bx, double by, double w, double h, void *data );
137static void uniedit_renderOverlay( double bx, double by, double bw, double bh, void* data );
138static void uniedit_focusLose( unsigned int wid, const char* wgtname );
139static int uniedit_mouse( unsigned int wid, SDL_Event* event, double mx, double my,
140 double w, double h, double rx, double ry, void *data );
141static void uniedit_renderFactionDisks( double x, double y, double r );
142static void uniedit_renderVirtualSpobs( double x, double y, double r );
143/* Button functions. */
144static void uniedit_close( unsigned int wid, const char *wgt );
145static void uniedit_save( unsigned int wid_unused, const char *unused );
146static void uniedit_btnView( unsigned int wid_unused, const char *unused );
147static void uniedit_btnJump( unsigned int wid_unused, const char *unused );
148static void uniedit_btnRename( unsigned int wid_unused, const char *unused );
149static void uniedit_btnEdit( unsigned int wid_unused, const char *unused );
150static void uniedit_btnNew( unsigned int wid_unused, const char *unused );
151static void uniedit_btnOpen( unsigned int wid_unused, const char *unused );
152static void uniedit_btnFind( unsigned int wid_unused, const char *unused );
153/* Keybindings handling. */
154static int uniedit_keys( unsigned int wid, SDL_Keycode key, SDL_Keymod mod );
155
159void uniedit_open( unsigned int wid_unused, const char *unused )
160{
161 (void) wid_unused;
162 (void) unused;
163 unsigned int wid;
164 int buttonPos = 0;
165 const glColour cBG = { 0., 0., 0., 0.95 };
166
167 /* Pause. */
168 pause_game();
169
170 /* Must have no diffs applied. */
171 diff_clear();
172
173 /* Reset some variables. */
175 uniedit_viewmode = UNIEDIT_VIEW_DEFAULT;
177 uniedit_drag = 0;
178 uniedit_dragSys = 0;
179 uniedit_dragSel = 0;
180 uniedit_tsys = NULL;
181 uniedit_tadd = 0;
182 uniedit_zoom = 1.;
183 uniedit_xpos = 0.;
184 uniedit_ypos = 0.;
185 uniedit_dt = 0.;
186
187 /* Create the window. */
188 wid = window_create( "wdwUniverseEditor", _("Universe Editor"), -1, -1, -1, -1 );
190 window_setBorder( wid, 0 );
191 uniedit_wid = wid;
192
193 /* Actual viewport, below everything. */
194 window_addCust( wid, 0, 0, SCREEN_W, SCREEN_H,
195 "cstSysEdit", 1, uniedit_render, uniedit_mouse, NULL, uniedit_focusLose, NULL );
196 window_custSetOverlay( wid, "cstSysEdit", uniedit_renderOverlay );
197
198 /* Overlay background. */
199 window_addRect( wid, SCREEN_W-130, 0, 130, SCREEN_H, "rctRCol", &cBG, 0 );
200 window_addRect( wid, 0, 0, SCREEN_W, 60, "rctBBar", &cBG, 0 );
201
202 /* Close button. */
203 window_addButtonKey( wid, -20, 20+(BUTTON_HEIGHT+20)*buttonPos, BUTTON_WIDTH, BUTTON_HEIGHT,
204 "btnClose", _("Exit"), uniedit_close, SDLK_x );
205 buttonPos++;
206
207 /* Autosave toggle. */
208 window_addCheckbox( wid, -150, 25, SCREEN_W/2 - 150, 20,
209 "chkEditAutoSave", _("Automatically save changes"), uniedit_autosave, conf.devautosave );
210
211 /* Save button. */
212 window_addButton( wid, -20, 20+(BUTTON_HEIGHT+20)*buttonPos, BUTTON_WIDTH, BUTTON_HEIGHT,
213 "btnSave", _("Save All"), uniedit_save );
214 buttonPos++;
215
216 /* View button. */
217 window_addButton( wid, -20, 20+(BUTTON_HEIGHT+20)*buttonPos, BUTTON_WIDTH, BUTTON_HEIGHT,
218 "btnView", _("View Mode"), uniedit_btnView );
219 buttonPos++;
220
221 /* Jump toggle. */
222 window_addButtonKey( wid, -20, 20+(BUTTON_HEIGHT+20)*buttonPos, BUTTON_WIDTH, BUTTON_HEIGHT,
223 "btnJump", _("Jump"), uniedit_btnJump, SDLK_j );
224 buttonPos++;
225
226 /* Rename system. */
227 window_addButtonKey( wid, -20, 20+(BUTTON_HEIGHT+20)*buttonPos, BUTTON_WIDTH, BUTTON_HEIGHT,
228 "btnRename", _("Rename"), uniedit_btnRename, SDLK_r );
229 buttonPos++;
230
231 /* Edit system. */
232 window_addButtonKey( wid, -20, 20+(BUTTON_HEIGHT+20)*buttonPos, BUTTON_WIDTH, BUTTON_HEIGHT,
233 "btnEdit", _("Edit"), uniedit_btnEdit, SDLK_e );
234 buttonPos++;
235
236 /* New system. */
237 window_addButtonKey( wid, -20, 20+(BUTTON_HEIGHT+20)*buttonPos, BUTTON_WIDTH, BUTTON_HEIGHT,
238 "btnNew", _("New Sys"), uniedit_btnNew, SDLK_n );
239 buttonPos++;
240
241 /* Open a system. */
242 window_addButtonKey( wid, -20, 20+(BUTTON_HEIGHT+20)*buttonPos, BUTTON_WIDTH, BUTTON_HEIGHT,
243 "btnOpen", _("Open"), uniedit_btnOpen, SDLK_o );
244 buttonPos++;
245
246 /* Find a system or spob. */
247 window_addButtonKey( wid, -20, 20+(BUTTON_HEIGHT+20)*buttonPos, BUTTON_WIDTH, BUTTON_HEIGHT,
248 "btnFind", _("Find"), uniedit_btnFind, SDLK_f );
249 buttonPos++;
250
251 /* Zoom buttons */
252 window_addButton( wid, 40, 20, 30, 30, "btnZoomIn", "+", uniedit_buttonZoom );
253 window_addButton( wid, 80, 20, 30, 30, "btnZoomOut", "-", uniedit_buttonZoom );
254
255 /* Nebula. */
256 window_addText( wid, -20, -40, 100, 20, 0, "txtSNebula",
257 &gl_smallFont, &cFontGrey, _("Nebula:") );
258 window_addText( wid, -10, -40-gl_smallFont.h-5, 110, 60, 0, "txtNebula",
259 &gl_smallFont, NULL, _("N/A") );
260
261 /* Presence. */
262 window_addText( wid, -20, -100, 100, 20, 0, "txtSPresence",
263 &gl_smallFont, &cFontGrey, _("Presence:") );
264 window_addText( wid, -10, -100-gl_smallFont.h-5, 110, 140, 0, "txtPresence",
265 &gl_smallFont, NULL, _("N/A") );
266
267 /* Selected text. */
268 window_addText( wid, 140, 10, SCREEN_W/2 - 140, 30, 0,
269 "txtSelected", &gl_smallFont, NULL, NULL );
270
271 /* Deselect everything. */
273}
274
278static int uniedit_keys( unsigned int wid, SDL_Keycode key, SDL_Keymod mod )
279{
280 (void) wid;
281 (void) mod;
282
283 switch (key) {
284 /* Mode changes. */
285 case SDLK_ESCAPE:
287 return 1;
288
289 default:
290 return 0;
291 }
292}
293
297static void uniedit_close( unsigned int wid, const char *wgt )
298{
299 /* Frees some memory. */
301
302 /* Reconstruct jumps. */
304
305 /* Unpause. */
306 unpause_game();
307
308 /* Close the window. */
309 window_close( wid, wgt );
310}
311
312/*
313 * @brief Saves the systems.
314 */
315static void uniedit_save( unsigned int wid_unused, const char *unused )
316{
317 (void) wid_unused;
318 (void) unused;
319
320 dsys_saveAll();
321 dpl_saveAll();
322}
323
324/*
325 * @brief Toggles autosave.
326 */
327void uniedit_autosave( unsigned int wid_unused, const char *unused )
328{
329 (void) wid_unused;
330 (void) unused;
331
332 conf.devautosave = window_checkboxState( wid_unused, "chkEditAutoSave" );
333}
334
335/*
336 * @brief Updates autosave check box.
337 */
338void uniedit_updateAutosave (void)
339{
340 window_checkboxSet( uniedit_wid, "chkEditAutoSave", conf.devautosave );
341}
342
343static int factionGenerates( int f, int tocheck, double *w )
344{
345 const FactionGenerator *fg = faction_generators( f );
346 for (int i=0; i<array_size(fg); i++) {
347 if (fg[i].id==tocheck) {
348 if (w!=NULL)
349 *w = fg[i].weight;
350 return 1;
351 }
352 }
353 return 0;
354}
355
359static void uniedit_btnView( unsigned int wid_unused, const char *unused )
360{
361 (void) wid_unused;
362 (void) unused;
363 unsigned int wid;
364 int n, h, k;
365 Spob *spobs;
366 char **str;
367 int *factions;
368
369 /* Find usable factions. */
370 factions = faction_getAll();
371 spobs = spob_getAll();
372 for (int i=0; i<array_size(factions); i++) {
373 int f = factions[i];
374 int hasfact = 0;
375 for (int j=0; j<array_size(spobs); j++) {
376 Spob *p = &spobs[j];
377 if ((p->presence.faction != f) && !factionGenerates(p->presence.faction,f,NULL))
378 continue;
379 if (p->presence.base==0. && p->presence.bonus==0.)
380 continue;
381 hasfact = 1;
382 break;
383 }
384 if (!hasfact)
385 factions[i] = -1;
386 }
387
388 /* Create the window. */
389 wid = window_create( "wdwUniEditView", _("Select a View Mode"), -1, -1, UNIEDIT_EDIT_WIDTH, UNIEDIT_EDIT_HEIGHT );
391
392 /* Add virtual spob list. */
393 str = malloc( sizeof(char*) * (array_size(factions)+1) );
394 str[0]= strdup(_("Default"));
395 str[1]= strdup(_("Virtual Spobs"));
396 str[2]= strdup(_("System Radius"));
397 str[3]= strdup(_("Background"));
398 str[4]= strdup(_("Asteroids"));
399 str[5]= strdup(_("Tech"));
400 str[6]= strdup(_("Sum of Presences"));
401 n = 7; /* Number of special cases. */
402 k = n;
403 for (int i=0; i<array_size(factions); i++) {
404 int f = factions[i];
405 if (f>=0)
406 str[k++] = strdup( faction_name( f ) ); /* Not translating so we can use faction_get */
407 }
408 qsort( &str[n], k-n, sizeof(char*), strsort );
410 window_addList( wid, 20, -40, UNIEDIT_EDIT_WIDTH-40, h, "lstViewModes", str, k, 0, NULL, uniedit_btnViewModeSet );
411
412 /* Close button. */
413 window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
414 "btnClose", _("Close"), window_close );
415
416 /* Add button. */
417 window_addButton( wid, -20-(BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT,
418 "btnSet", _("Set"), uniedit_btnViewModeSet );
419
420 /* Clean up. */
421 array_free( factions );
422}
423
427static void uniedit_btnJump( unsigned int wid_unused, const char *unused )
428{
429 (void) wid_unused;
430 (void) unused;
431
433}
434
438static void uniedit_btnRename( unsigned int wid_unused, const char *unused )
439{
440 (void) wid_unused;
441 (void) unused;
442
444}
445
449static void uniedit_btnNew( unsigned int wid_unused, const char *unused )
450{
451 (void) wid_unused;
452 (void) unused;
453
455}
456
460static void uniedit_btnOpen( unsigned int wid_unused, const char *unused )
461{
462 (void) wid_unused;
463 (void) unused;
464
465 if (array_size(uniedit_sys) != 1)
466 return;
467
469}
470
474static void uniedit_btnFind( unsigned int wid_unused, const char *unused )
475{
476 (void) wid_unused;
477 (void) unused;
478
480}
481
485static void uniedit_btnEdit( unsigned int wid_unused, const char *unused )
486{
487 (void) wid_unused;
488 (void) unused;
489
491}
492
493static void uniedit_renderFactionDisks( double x, double y, double r )
494{
495 const glColour *col;
496 glColour c;
497 double tx, ty, sr, presence;
498
500 c.r = col->r;
501 c.g = col->g;
502 c.b = col->b;
503 c.a = 0.5;
504
505 for (int i=0; i<array_size(systems_stack); i++) {
506 StarSystem *sys = system_getIndex( i );
507
508 tx = x + sys->pos.x*uniedit_zoom;
509 ty = y + sys->pos.y*uniedit_zoom;
510
511 presence = system_getPresence( sys, uniedit_view_faction );
512
513 /* draws the disk representing the faction */
514 sr = 0.5*M_PI*sqrt(presence) * uniedit_zoom;
515
516 //glUseProgram(shaders.factiondisk.program);
517 //glUniform1f(shaders.factiondisk.paramf, r / sr );
518 //gl_renderShader( tx, ty, sr, sr, 0., &shaders.factiondisk, &c, 1 );
519 (void) r;
520 gl_renderCircle( tx, ty, sr, &c, 1 );
521 }
522}
523
524static void uniedit_renderVirtualSpobs( double x, double y, double r )
525{
526 const glColour c = { .r=1., .g=1., .b=1., .a=0.3 };
527
528 for (int i=0; i<array_size(systems_stack); i++) {
529 double tx, ty, sr;
530 StarSystem *sys = system_getIndex( i );
531
532 tx = x + sys->pos.x*uniedit_zoom;
533 ty = y + sys->pos.y*uniedit_zoom;
534
535 /* draws the disk representing the faction */
536 sr = 5.*M_PI*sqrt((double)array_size(sys->spobs_virtual)) * uniedit_zoom;
537
538 (void) r;
539 gl_renderCircle( tx, ty, sr, &c, 1 );
540 }
541}
542
543static void uniedit_renderRadius( double x, double y, double r )
544{
545 const glColour c = { .r=1., .g=1., .b=1., .a=0.3 };
546
547 for (int i=0; i<array_size(systems_stack); i++) {
548 double tx, ty, sr;
549 StarSystem *sys = system_getIndex( i );
550
551 tx = x + sys->pos.x*uniedit_zoom;
552 ty = y + sys->pos.y*uniedit_zoom;
553
554 /* draws the disk representing the faction */
555 sr = 5.*M_PI*sqrt(sys->radius / 10e3) * uniedit_zoom;
556
557 (void) r;
558 gl_renderCircle( tx, ty, sr, &c, 1 );
559 }
560}
561
562static void uniedit_renderBackground( double x, double y, double r )
563{
564 const glColour c = { .r=1., .g=1., .b=1., .a=0.3 };
565
566 for (int i=0; i<array_size(systems_stack); i++) {
567 double tx, ty, sr;
568 StarSystem *sys = system_getIndex( i );
569
570 if (sys->background==NULL)
571 continue;
572
573 tx = x + sys->pos.x*uniedit_zoom;
574 ty = y + sys->pos.y*uniedit_zoom;
575
576 /* draws the disk representing the faction */
577 sr = 7.*M_PI * uniedit_zoom;
578
579 (void) r;
580 gl_renderCircle( tx, ty, sr, &c, 1 );
581 }
582}
583
584static void uniedit_renderAsteroids( double x, double y, double r )
585{
586 const glColour c = { .r=1., .g=1., .b=1., .a=0.3 };
587
588 for (int i=0; i<array_size(systems_stack); i++) {
589 double tx, ty, sr;
590 StarSystem *sys = system_getIndex( i );
591 double density = sys->asteroid_density;
592
593 if (density <= 0.)
594 continue;
595
596 tx = x + sys->pos.x*uniedit_zoom;
597 ty = y + sys->pos.y*uniedit_zoom;
598
599 /* Draw disk. */
600 sr = 0.3*M_PI*sqrt(density) * uniedit_zoom;
601 (void) r;
602 gl_renderCircle( tx, ty, sr, &c, 1 );
603 }
604}
605
606static void uniedit_renderTech( double x, double y, double r )
607{
608 const glColour c = { .r=1., .g=1., .b=1., .a=0.3 };
609
610 for (int i=0; i<array_size(systems_stack); i++) {
611 double tx, ty, sr;
612 StarSystem *sys = system_getIndex( i );
613 int hastech = 0;
614
615 for (int j=0; j<array_size(sys->spobs); j++) {
616 if (sys->spobs[j]->tech != NULL) {
617 hastech = 1;
618 break;
619 }
620 }
621 if (!hastech)
622 continue;
623
624 tx = x + sys->pos.x*uniedit_zoom;
625 ty = y + sys->pos.y*uniedit_zoom;
626
627 /* Draw disk. */
628 sr = 7.*M_PI * uniedit_zoom;
629 (void) r;
630 gl_renderCircle( tx, ty, sr, &c, 1 );
631 }
632}
633
634static void uniedit_renderPresenceSum( double x, double y, double r )
635{
636 const glColour c = { .r=1., .g=1., .b=1., .a=0.3 };
637
638 for (int i=0; i<array_size(systems_stack); i++) {
639 double tx, ty, sr;
640 StarSystem *sys = system_getIndex( i );
641
642 double total = 0.;
643 for (int j=0; j<array_size(sys->presence); j++)
644 total += MAX( 0., sys->presence[j].value );
645
646 tx = x + sys->pos.x*uniedit_zoom;
647 ty = y + sys->pos.y*uniedit_zoom;
648
649 /* draws the disk representing the faction */
650 sr = 0.2*M_PI*sqrt(total) * uniedit_zoom;
651
652 (void) r;
653 gl_renderCircle( tx, ty, sr, &c, 1 );
654 }
655}
656
657/* @brief Renders important map stuff.
658 */
659void uniedit_renderMap( double bx, double by, double w, double h, double x, double y, double zoom, double r )
660{
661 /* background */
662 gl_renderRect( bx, by, w, h, &cBlack );
663
664 if (UNIEDIT_VIEW_DEFAULT)
665 map_renderDecorators( x, y, zoom, 1, 1. );
666
667 /* Render faction disks. */
668 switch (uniedit_viewmode) {
669 case UNIEDIT_VIEW_DEFAULT:
670 map_renderFactionDisks( x, y, zoom, r, 1, 1. );
671 map_renderSystemEnvironment( x, y, zoom, 1, 1. );
672 break;
673
674 case UNIEDIT_VIEW_VIRTUALSPOBS:
675 uniedit_renderVirtualSpobs( x, y, r );
676 break;
677
678 case UNIEDIT_VIEW_RADIUS:
679 uniedit_renderRadius( x, y, r );
680 break;
681
682 case UNIEDIT_VIEW_BACKGROUND:
683 uniedit_renderBackground( x, y, r );
684 break;
685
686 case UNIEDIT_VIEW_ASTEROIDS:
687 uniedit_renderAsteroids( x, y, r );
688 break;
689
690 case UNIEDIT_VIEW_TECH:
691 uniedit_renderTech( x, y, r );
692 break;
693
694 case UNIEDIT_VIEW_PRESENCE_SUM:
695 uniedit_renderPresenceSum( x, y, r );
696 break;
697
698 case UNIEDIT_VIEW_PRESENCE:
700 uniedit_renderFactionDisks( x, y, r );
701 break;
702 }
703
704 /* Render jump paths. */
705 map_renderJumps( x, y, zoom, r, 1 );
706
707 /* Render systems. */
708 map_renderSystems( bx, by, x, y, zoom, w, h, r, MAPMODE_EDITOR );
709
710 /* Render system names. */
711 map_renderNames( bx, by, x, y, zoom, w, h, 1, 1. );
712}
713
717static void uniedit_render( double bx, double by, double w, double h, void *data )
718{
719 (void) data;
720 double x,y,r;
721
723
724 /* Parameters. */
725 map_renderParams( bx, by, uniedit_xpos, uniedit_ypos, w, h, uniedit_zoom, &x, &y, &r );
726
727 /* Render map stuff. */
728 uniedit_renderMap( bx, by, w, h, x, y, uniedit_zoom, r );
729
730 /* Render the selected system selections. */
731 for (int i=0; i<array_size(uniedit_sys); i++) {
732 StarSystem *sys = uniedit_sys[i];
733 glUseProgram( shaders.selectspob.program );
734 glUniform1f( shaders.selectspob.dt, uniedit_dt );
735 gl_renderShader( x + sys->pos.x * uniedit_zoom, y + sys->pos.y * uniedit_zoom,
736 1.5*r, 1.5*r, 0., &shaders.selectspob, &cWhite, 1 );
737 }
738}
739
740static char getValCol( double val )
741{
742 if (val > 0.)
743 return 'g';
744 else if (val < 0.)
745 return 'r';
746 return '0';
747}
748static int getPresenceVal( int f, SpobPresence *ap, double *base, double *bonus )
749{
750 int gf = 0;
751 double w;
752 if ((ap->faction!=f) && !(gf=factionGenerates(ap->faction, f, &w)))
753 return 0;
754 if (gf == 0) {
755 *base = ap->base;
756 *bonus = ap->bonus;
757 }
758 else {
759 *base = ap->base * w;
760 *bonus = ap->bonus * w;
761 }
762 return 1;
763}
764
768static void uniedit_renderOverlay( double bx, double by, double bw, double bh, void* data )
769{
770 double x,y, mx,my, sx,sy;
771 double value, base, bonus;
772 char buf[STRMAX] = {'\0'};
773 StarSystem *sys, *cur, *mousesys;
774 SystemPresence *sp;
775 (void) data;
776
777 x = bx + uniedit_mx;
778 y = by + uniedit_my;
779
780 /* Correct coordinates. */
781 mx = uniedit_mx - bw/2. + uniedit_xpos;
782 my = uniedit_my - bh/2. + uniedit_ypos;
783 mx /= uniedit_zoom;
784 my /= uniedit_zoom;
785
786 /* Display location. */
787 gl_print( &gl_defFontMono, bx+5, by+65, &cWhite, "% 7.2f x % 7.2f", mx, my );
788
789 /* Select drag stuff. */
790 if (uniedit_dragSel) {
791 double l, r, b, t, rx, ry;
792 const glColour col = { .r = 0.2, .g = 0.2, .b = 0.8, .a = 0.5 };
793
794 l = MIN( uniedit_dragSelX, mx );
795 r = MAX( uniedit_dragSelX, mx );
796 b = MIN( uniedit_dragSelY, my );
797 t = MAX( uniedit_dragSelY, my );
798
799 /* Project back to screen space. */
800 rx = (l * uniedit_zoom) + bw/2. - uniedit_xpos;
801 ry = (b * uniedit_zoom) + bh/2. - uniedit_ypos;
802
803 gl_renderRect( rx, ry, (r-l)*uniedit_zoom, (t-b)*uniedit_zoom, &col );
804 }
805
806 /* Don't cover up stuff if possible. */
807 if ((x > SCREEN_W-130) || (y < 60))
808 return;
809
811 toolkit_drawAltText( x, y, _("Click to add a new system"));
812 return;
813 }
814 else if (uniedit_mode == UNIEDIT_JUMP) {
815 toolkit_drawAltText( x, y, _("Click to toggle jump route"));
816 return;
817 }
818 else if (uniedit_viewmode == UNIEDIT_VIEW_DEFAULT)
819 return;
820
821 /* Find mouse over system. */
822 mousesys = NULL;
823 for (int i=0; i<array_size(systems_stack); i++) {
824 sys = system_getIndex(i);
825 sx = sys->pos.x;
826 sy = sys->pos.y;
827 if ((pow2(sx-mx)+pow2(sy-my)) > pow2(UNIEDIT_CLICK_THRESHOLD))
828 continue;
829 mousesys = sys;
830 break;
831 }
832 if (mousesys == NULL)
833 return;
834 sys = mousesys;
835 sx = sys->pos.x;
836 sy = sys->pos.y;
837
838 /* Handle virtual spob viewer. */
839 if (uniedit_viewmode == UNIEDIT_VIEW_VIRTUALSPOBS) {
840 int l;
841
842 if (array_size(sys->spobs_virtual)==0)
843 return;
844
845 /* Count spobs. */
846 l = 0;
847 for (int j=0; j<array_size(sys->spobs_virtual); j++) {
848 VirtualSpob *va = sys->spobs_virtual[j];
849 l += scnprintf( &buf[l], sizeof(buf)-l, "%s%s", (l>0)?"\n":"", va->name );
850 }
851
852 toolkit_drawAltText( x, y, buf);
853 return;
854 }
855
856 /* Handle radius view. */
857 else if (uniedit_viewmode == UNIEDIT_VIEW_RADIUS) {
858 scnprintf( &buf[0], sizeof(buf), _("System Radius: %s"), num2strU( sys->radius, 0 ));
859 toolkit_drawAltText( x, y, buf);
860 return;
861 }
862
863 /* Handle background. */
864 else if (uniedit_viewmode == UNIEDIT_VIEW_BACKGROUND) {
865 if (sys->background != NULL) {
866 scnprintf( &buf[0], sizeof(buf), _("Background: %s"), sys->background );
867 toolkit_drawAltText( x, y, buf);
868 }
869 return;
870 }
871
872 /* Handle background. */
873 else if (uniedit_viewmode == UNIEDIT_VIEW_ASTEROIDS) {
874 if (array_size(sys->asteroids) > 0) {
875 int l = 0;
876 l = scnprintf( &buf[l], sizeof(buf)-l, _("Density: %g"), sys->asteroid_density );
877 for (int i=0; i<array_size(sys->asteroids); i++) {
878 AsteroidAnchor *ast = &sys->asteroids[i];
879 for (int j=0; j<array_size(ast->groups); j++)
880 l += scnprintf( &buf[l], sizeof(buf)-l, "%s%s", (l>0)?"\n":"", ast->groups[j]->name );
881 }
882 toolkit_drawAltText( x, y, buf);
883 }
884 return;
885 }
886
887 /* Handle tech radius. */
888 else if (uniedit_viewmode == UNIEDIT_VIEW_TECH) {
889 char *techlist[256];
890 int ntechs = 0;
891 const int len = sizeof(techlist) / sizeof(char*);
892 int l;
893
894 if (array_size(sys->spobs)==0)
895 return;
896
897 /* Count spobs. */
898 l = 0;
899 for (int j=0; j<array_size(sys->spobs); j++) {
900 Spob *spob = sys->spobs[j];
901 int n;
902 char **techs;
903 if (spob->tech==NULL)
904 continue;
905 techs = tech_getItemNames( spob->tech, &n );
906 for (int k=0; (k<n) && (ntechs<len-1) ; k++)
907 techlist[ ntechs++ ] = techs[k];
908 free( techs );
909 }
910 qsort( techlist, ntechs, sizeof(char*), strsort );
911 for (int k=0; k<ntechs; k++) {
912 if ((k>0) && (strcmp(techlist[k-1],techlist[k])==0))
913 continue;
914 l += scnprintf( &buf[l], sizeof(buf)-l, "%s%s", (l>0)?"\n":"", techlist[k] );
915 }
916 for (int k=0; k<ntechs; k++)
917 free( techlist[k] );
918
919 toolkit_drawAltText( x, y, buf);
920 return;
921 }
922
923 /* Handle presence sum. */
924 else if (uniedit_viewmode == UNIEDIT_VIEW_PRESENCE_SUM) {
925 int l;
926
927 if (array_size(sys->presence)==0)
928 return;
929
930 value = 0.;
931 for (int j=0; j<array_size(sys->presence); j++)
932 value += MAX( sys->presence[j].value, 0. );
933
934 /* Count spobs. */
935 l = scnprintf( buf, sizeof(buf), _("Total: %.0f"), value );
936 for (int j=0; j<array_size(sys->presence); j++) {
937 sp = &sys->presence[j];
938 if (sp->value<=0.)
939 continue;
940 l += scnprintf( &buf[l], sizeof(buf)-l, "\n%s: %.0f = %.0f + %.0f", faction_name(sp->faction), sp->value, sp->base, sp->bonus);
941 }
942 toolkit_drawAltText( x, y, buf);
943 return;
944 }
945
946 /* Handle presence mode. */
947 else if (uniedit_viewmode == UNIEDIT_VIEW_PRESENCE) {
948 int l;
949 int f = uniedit_view_faction;
950 if (f < 0)
951 return;
952
953 /* Total presence. */
954 value = system_getPresenceFull( sys, f, &base, &bonus );
955 l = scnprintf( buf, sizeof(buf), "#%c%.0f#0 = #%c%.0f#0 + #%c%.0f#0 [%s - %s]",
956 getValCol(value), value, getValCol(base), base, getValCol(bonus), bonus,
957 _(sys->name), faction_name(f) );
958
959 /* Local presence sources. */
960 for (int j=0; j<array_size(sys->spobs); j++) {
961 Spob *spob = sys->spobs[j];
962 if (!getPresenceVal( f, &spob->presence, &base, &bonus ))
963 continue;
964 l += scnprintf( &buf[l], sizeof(buf)-l, "\n#%c%.0f#0 (#%c%+.0f#0) [%s]",
965 getValCol(base), base, getValCol(bonus), bonus, spob_name(spob) );
966 }
967 for (int j=0; j<array_size(sys->spobs_virtual); j++) {
968 VirtualSpob *va = sys->spobs_virtual[j];
969 for (int p=0; p<array_size(va->presences); p++) {
970 if (!getPresenceVal( f, &va->presences[p], &base, &bonus ))
971 continue;
972 l += scnprintf( &buf[l], sizeof(buf)-l, "\n#%c%.0f#0 (#%c%+.0f#0) [%s]",
973 getValCol(base), base, getValCol(bonus), bonus, _(va->name) );
974 }
975 }
976
977 /* Find neighbours if possible. */
978 for (int k=0; k<array_size(sys->jumps); k++) {
979 cur = sys->jumps[k].target;
980 for (int j=0; j<array_size(cur->spobs); j++) {
981 Spob *spob = cur->spobs[j];
982 if (!getPresenceVal( f, &spob->presence, &base, &bonus ))
983 continue;
984 l += scnprintf( &buf[l], sizeof(buf)-l, "\n#%c%.0f#0 (#%c%+.0f#0) [%s (%s)]",
985 getValCol(base), base*0.5, getValCol(bonus), bonus*0.5, spob_name(spob), _(cur->name) );
986 }
987 for (int j=0; j<array_size(cur->spobs_virtual); j++) {
988 VirtualSpob *va = cur->spobs_virtual[j];
989 for (int p=0; p<array_size(va->presences); p++) {
990 if (!getPresenceVal( f, &va->presences[p], &base, &bonus ))
991 continue;
992 l += scnprintf( &buf[l], sizeof(buf)-l, "\n#%c%.0f#0 (#%c%+.0f#0) [%s (%s)]",
993 getValCol(base), base*0.5, getValCol(bonus), bonus*0.5, _(va->name), _(cur->name) );
994 }
995 }
996 }
997
998 toolkit_drawAltText( x, y, buf);
999 return;
1000 }
1001}
1002
1006static void uniedit_focusLose( unsigned int wid, const char* wgtname )
1007{
1008 (void) wid;
1009 (void) wgtname;
1011}
1012
1016static int uniedit_mouse( unsigned int wid, SDL_Event* event, double mx, double my,
1017 double w, double h, double rx, double ry, void *data )
1018{
1019 (void) data;
1020 unsigned int lastClick;
1021 StarSystem *clickedsys;
1022 int inselection;
1023 SDL_Keymod mod;
1024
1025 /* Handle modifiers. */
1026 mod = SDL_GetModState();
1027
1028 switch (event->type) {
1029
1030 case SDL_MOUSEWHEEL:
1031 /* Must be in bounds. */
1032 if ((mx < 0.) || (mx > w) || (my < 0.) || (my > h))
1033 return 0;
1034
1035 if (event->wheel.y > 0)
1036 uniedit_buttonZoom( 0, "btnZoomIn" );
1037 else if (event->wheel.y < 0)
1038 uniedit_buttonZoom( 0, "btnZoomOut" );
1039
1040 return 1;
1041
1042 case SDL_MOUSEBUTTONDOWN:
1043 /* Must be in bounds. */
1044 if ((mx < 60.) || (mx > w) || (my < 0.) || (my > h-130))
1045 return 0;
1046 window_setFocus( wid, "cstSysEdit" );
1047 lastClick = uniedit_lastClick;
1048 uniedit_lastClick = SDL_GetTicks();
1049
1050 /* Selecting star system */
1051 mx -= w/2. - uniedit_xpos;
1052 my -= h/2. - uniedit_ypos;
1053 mx /= uniedit_zoom;
1054 my /= uniedit_zoom;
1055
1056 /* Create new system if applicable. */
1058 uniedit_newSys( mx, my );
1060 return 1;
1061 }
1062
1063 /* Find clicked system. */
1064 clickedsys = NULL;
1065 for (int i=0; i<array_size(systems_stack); i++) {
1066 StarSystem *sys = system_getIndex(i);
1067 if ((pow2(mx-sys->pos.x)+pow2(my-sys->pos.y)) > pow2(UNIEDIT_CLICK_THRESHOLD))
1068 continue;
1069 clickedsys = sys;
1070 break;
1071 }
1072
1073 /* Set jump if applicable. */
1074 if (clickedsys!=NULL && uniedit_mode==UNIEDIT_JUMP) {
1075 uniedit_toggleJump( clickedsys );
1077 return 1;
1078 }
1079
1080 /* See if it is selected. */
1081 inselection = 0;
1082 if (clickedsys != NULL) {
1083 for (int i=0; i<array_size(uniedit_sys); i++) {
1084 if (uniedit_sys[i] != clickedsys)
1085 continue;
1086 inselection = 1;
1087 break;
1088 }
1089 }
1090
1091 /* Handle double click. */
1092 if (clickedsys!=NULL && inselection && array_size(uniedit_sys)==1) {
1093 if ((SDL_GetTicks()-lastClick < UNIEDIT_DOUBLECLICK_THRESHOLD)
1096 uniedit_drag = 0;
1097 uniedit_dragSys = 0;
1098 uniedit_dragSel = 0;
1099 return 1;
1100 }
1101 }
1102
1103 /* Clicked on selected system. */
1104 if ((clickedsys != NULL) && inselection) {
1105 uniedit_dragSys = 1;
1106 uniedit_tsys = clickedsys;
1107 /* Check modifier. */
1108 if (mod & (KMOD_LCTRL | KMOD_RCTRL))
1109 uniedit_tadd = 0;
1110 else
1111 uniedit_tadd = -1;
1112 uniedit_moved = 0;
1113 return 1;
1114 }
1115
1116 /* Clicked on non-selected system. */
1117 if (clickedsys != NULL) {
1118 /* Add the system if not selected. */
1119 if (!(mod & (KMOD_LCTRL | KMOD_RCTRL)))
1121 uniedit_selectAdd( clickedsys );
1122 uniedit_tsys = NULL;
1123 return 1;
1124 }
1125
1126 /* Start dragging. */
1127 uniedit_moved = 0;
1128 uniedit_tsys = NULL;
1129 if (mod & (KMOD_LCTRL | KMOD_RCTRL | KMOD_LSHIFT | KMOD_RSHIFT)) {
1130 if (mod & (KMOD_LSHIFT | KMOD_RSHIFT))
1132 uniedit_dragSel = 1;
1133 uniedit_dragSelX = mx;
1134 uniedit_dragSelY = my;
1135 return 1;
1136 }
1137 else {
1138 uniedit_drag = 1;
1139 return 1;
1140 }
1141 break;
1142
1143 case SDL_MOUSEBUTTONUP:
1144 if (uniedit_drag) {
1146 if (uniedit_tsys == NULL)
1148 else
1150 }
1151 uniedit_drag = 0;
1152 }
1153 if (uniedit_dragSys) {
1154 if ((SDL_GetTicks()-uniedit_lastClick < UNIEDIT_DRAG_THRESHOLD) &&
1156 if (uniedit_tadd == 0)
1158 else {
1161 }
1162 }
1163 uniedit_dragSys = 0;
1164 if (conf.devautosave)
1165 for (int i=0; i<array_size(uniedit_sys); i++)
1167 }
1168 if (uniedit_dragSel) {
1169 double l, r, b, t;
1170
1171 /* Selecting star system */
1172 mx -= w/2. - uniedit_xpos;
1173 my -= h/2. - uniedit_ypos;
1174 mx /= uniedit_zoom;
1175 my /= uniedit_zoom;
1176
1177 /* Get bounds. */
1178 l = MIN( uniedit_dragSelX, mx );
1179 r = MAX( uniedit_dragSelX, mx );
1180 b = MIN( uniedit_dragSelY, my );
1181 t = MAX( uniedit_dragSelY, my );
1182
1183 for (int i=0; i<array_size(systems_stack); i++) {
1184 StarSystem *sys = &systems_stack[i];
1185 double x = sys->pos.x;
1186 double y = sys->pos.y;
1187 if ((x >= l) && (x <= r) && (y >= b) && (y <= t))
1188 uniedit_selectAdd( sys );
1189 }
1190
1191 uniedit_dragSel = 0;
1192 }
1193 break;
1194
1195 case SDL_MOUSEMOTION:
1196 /* Update mouse positions. */
1197 uniedit_mx = mx;
1198 uniedit_my = my;
1199
1200 /* Handle dragging. */
1201 if (uniedit_drag) {
1202 /* axis is inverted */
1203 uniedit_xpos -= rx;
1204 uniedit_ypos += ry;
1205
1206 /* Update mouse movement. */
1207 uniedit_moved += ABS(rx) + ABS(ry);
1208 }
1209 else if (uniedit_dragSys && (array_size(uniedit_sys) > 0)) {
1211 for (int i=0; i<array_size(uniedit_sys); i++) {
1212 uniedit_sys[i]->pos.x += rx / uniedit_zoom;
1213 uniedit_sys[i]->pos.y -= ry / uniedit_zoom;
1214 }
1215 }
1216
1217 /* Update mouse movement. */
1218 uniedit_moved += ABS(rx) + ABS(ry);
1219 }
1220 break;
1221 }
1222
1223 return 0;
1224}
1225
1231static int uniedit_checkName( const char *name )
1232{
1233 /* Avoid name collisions. */
1234 for (int i=0; i<array_size(systems_stack); i++) {
1235 if (strcmp(name, system_getIndex(i)->name)==0) {
1236 dialogue_alert( _("The Star System '%s' already exists!"), name );
1237 return 1;
1238 }
1239 }
1240 return 0;
1241}
1242
1243char *uniedit_nameFilter( const char *name )
1244{
1245 char *out = calloc( 1, (strlen(name)+1) );
1246 int pos = 0;
1247 for (int i=0; i<(int)strlen(name); i++) {
1248 if (!ispunct(name[i])) {
1249 if (name[i] == ' ')
1250 out[pos] = '_';
1251 else
1252 out[pos] = tolower(name[i]);
1253 pos++;
1254 }
1255 }
1256
1257 return out;
1258}
1259
1263static void uniedit_renameSys (void)
1264{
1265 for (int i=0; i<array_size(uniedit_sys); i++) {
1266 char *name, *oldName, *newName, *filtered;
1267 StarSystem *sys = uniedit_sys[i];
1268
1269 /* Get name. */
1270 name = dialogue_input( _("Rename Star System"), 1, 32, _("What do you want to rename #r%s#0?"), sys->name );
1271
1272 /* Keep current name. */
1273 if (name == NULL)
1274 continue;
1275
1276 /* Try again. */
1277 if (uniedit_checkName( name )) {
1278 free(name);
1279 i--;
1280 continue;
1281 }
1282
1283 /* Change the name. */
1284 filtered = uniedit_nameFilter(sys->name);
1285 asprintf(&oldName, "dat/ssys/%s.xml", filtered);
1286 free(filtered);
1287
1288 filtered = uniedit_nameFilter(name);
1289 asprintf(&newName, "dat/ssys/%s.xml", filtered);
1290 free(filtered);
1291
1292 rename(oldName, newName);
1293
1294 free(oldName);
1295 free(newName);
1296 free(sys->name);
1297
1298 sys->name = name;
1299 dsys_saveSystem(sys);
1300
1301 /* Re-save adjacent systems. */
1302 for (int j=0; j<array_size(sys->jumps); j++)
1303 dsys_saveSystem( sys->jumps[j].target );
1304 }
1305}
1306
1310static void uniedit_newSys( double x, double y )
1311{
1312 char *name;
1313 StarSystem *sys;
1314
1315 /* Get name. */
1316 name = dialogue_inputRaw( _("New Star System Creation"), 1, 32, _("What do you want to name the new system?") );
1317
1318 /* Abort. */
1319 if (name == NULL) {
1320 dialogue_alert( _("Star System creation aborted!") );
1321 return;
1322 }
1323
1324 /* Make sure there is no collision. */
1325 if (uniedit_checkName( name )) {
1326 free(name);
1327 uniedit_newSys( x, y );
1328 return;
1329 }
1330
1331 /* Create the system. */
1332 sys = system_new();
1333 sys->name = name;
1334 sys->pos.x = x;
1335 sys->pos.y = y;
1336 sys->stars = STARS_DENSITY_DEFAULT;
1337 sys->radius = RADIUS_DEFAULT;
1338
1339 /* Select new system. */
1341 uniedit_selectAdd( sys );
1342
1343 if (conf.devautosave)
1344 dsys_saveSystem( sys );
1345}
1346
1350static void uniedit_toggleJump( StarSystem *sys )
1351{
1352 StarSystem *isys = NULL;
1353 for (int i=0; i<array_size(uniedit_sys); i++) {
1354 int rm = 0;
1355 isys = uniedit_sys[i];
1356 for (int j=0; j<array_size(isys->jumps); j++) {
1357 StarSystem *target = isys->jumps[j].target;
1358 /* Target already exists, remove. */
1359 if (target == sys) {
1360 uniedit_jumpRm( isys, sys );
1361 uniedit_jumpRm( sys, isys );
1362 rm = 1;
1363 break;
1364 }
1365 }
1366 /* Target doesn't exist, add. */
1367 if (!rm) {
1368 uniedit_jumpAdd( isys, sys );
1369 uniedit_jumpAdd( sys, isys );
1370 }
1371 }
1372
1373 /* Reconstruct jumps just in case. */
1375
1376 /* Reconstruct universe presences. */
1379
1380 if (conf.devautosave) {
1381 dsys_saveSystem( sys );
1382 if (isys != NULL)
1383 dsys_saveSystem( isys );
1384 }
1385
1386 /* Update sidebar text. */
1388}
1389
1393static void uniedit_jumpAdd( StarSystem *sys, StarSystem *targ )
1394{
1395 /* Add the jump. */
1396 JumpPoint *jp = &array_grow( &sys->jumps );
1397 memset( jp, 0, sizeof(JumpPoint) );
1398
1399 /* Fill it out with basics. */
1400 jp->target = targ;
1401 jp->targetid = targ->id;
1402 jp->radius = 200.;
1403 jp->flags = JP_AUTOPOS; /* Will automatically create position. */
1404 jp->hide = HIDE_DEFAULT_JUMP;
1405}
1406
1410static void uniedit_jumpRm( StarSystem *sys, StarSystem *targ )
1411{
1412 int i;
1413
1414 /* Find associated jump. */
1415 for (i=0; i<array_size(sys->jumps); i++)
1416 if (sys->jumps[i].target == targ)
1417 break;
1418
1419 /* Not found. */
1420 if (i >= array_size(sys->jumps)) {
1421 WARN(_("Jump for system '%s' not found in system '%s' for removal."), targ->name, sys->name);
1422 return;
1423 }
1424
1425 /* Remove the jump. */
1426 array_erase( &sys->jumps, &sys->jumps[i], &sys->jumps[i+1] );
1427}
1428
1432static void uniedit_deselect (void)
1433{
1435 uniedit_sys = NULL;
1436
1437 /* Change window stuff. */
1438 window_disableButton( uniedit_wid, "btnJump" );
1439 window_disableButton( uniedit_wid, "btnRename" );
1440 window_disableButton( uniedit_wid, "btnEdit" );
1441 window_disableButton( uniedit_wid, "btnOpen" );
1442 window_modifyText( uniedit_wid, "txtSelected", _("No selection") );
1443 window_modifyText( uniedit_wid, "txtNebula", _("N/A") );
1444 window_modifyText( uniedit_wid, "txtPresence", _("N/A") );
1445}
1446
1450static void uniedit_selectAdd( StarSystem *sys )
1451{
1452 if (uniedit_sys == NULL)
1453 uniedit_sys = array_create( StarSystem* );
1454
1456
1457 /* Set text again. */
1459
1460 /* Enable buttons again. */
1461 window_enableButton( uniedit_wid, "btnJump" );
1462 window_enableButton( uniedit_wid, "btnRename" );
1463 window_enableButton( uniedit_wid, "btnEdit" );
1464 if (array_size(uniedit_sys) == 1)
1465 window_enableButton( uniedit_wid, "btnOpen" );
1466 else
1467 window_disableButton( uniedit_wid, "btnOpen" );
1468}
1469
1473static void uniedit_selectRm( StarSystem *sys )
1474{
1475 for (int i=0; i<array_size(uniedit_sys); i++) {
1476 if (uniedit_sys[i] == sys) {
1479 if (array_size(uniedit_sys) == 1)
1480 window_enableButton( uniedit_wid, "btnOpen" );
1481 else
1482 window_disableButton( uniedit_wid, "btnOpen" );
1483 return;
1484 }
1485 }
1486 WARN(_("Trying to remove system '%s' from selection when not selected."), sys->name);
1487}
1488
1493{
1494 int l;
1495 char buf[STRMAX];
1496
1497 l = 0;
1498 for (int i=0; i<array_size(uniedit_sys); i++) {
1499 l += scnprintf( &buf[l], sizeof(buf)-l, "%s%s", uniedit_sys[i]->name,
1500 (i == array_size(uniedit_sys)-1) ? "" : ", " );
1501 }
1502 if (l == 0)
1504 else {
1505 window_modifyText( uniedit_wid, "txtSelected", buf );
1506
1507 /* Presence text. */
1508 if (array_size(uniedit_sys) == 1) {
1509 StarSystem *sys = uniedit_sys[0];
1510 map_updateFactionPresence( uniedit_wid, "txtPresence", sys, 1 );
1511
1512 if (sys->nebu_density<=0.)
1513 snprintf( buf, sizeof(buf), _("None") );
1514 else
1515 snprintf( buf, sizeof(buf), _("%.0f Density\n%.1f Volatility"), sys->nebu_density, sys->nebu_volatility);
1516 window_modifyText( uniedit_wid, "txtNebula", buf );
1517 }
1518 else {
1519 window_modifyText( uniedit_wid, "txtNebula", _("Multiple selected") );
1520 window_modifyText( uniedit_wid, "txtPresence", _("Multiple selected") );
1521 }
1522 }
1523}
1524
1531static void uniedit_buttonZoom( unsigned int wid, const char* str )
1532{
1533 (void) wid;
1534 /* Transform coords to normal. */
1537
1538 /* Apply zoom. */
1539 if (strcmp(str,"btnZoomIn")==0) {
1542 }
1543 else if (strcmp(str,"btnZoomOut")==0) {
1546 }
1547
1548 /* Transform coords back. */
1551}
1552
1556static void uniedit_findSys (void)
1557{
1558 unsigned int wid;
1559 int x, y;
1560
1561 x = 40;
1562
1563 /* Create the window. */
1564 wid = window_create( "wdwFindSystemsandSpobs", _("Find Systems and Spobs"), x, -1, UNIEDIT_FIND_WIDTH, UNIEDIT_FIND_HEIGHT );
1565 uniedit_widFind = wid;
1566
1567 x = 20;
1568
1569 /* Close button. */
1570 window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
1571 "btnClose", _("Close"), uniedit_findSysClose );
1572
1573 /* Find input widget. */
1574 y = -45;
1575 window_addInput( wid, x, y, UNIEDIT_FIND_WIDTH - 40, 20,
1576 "inpFind", 32, 1, NULL );
1577 window_setInputCallback( wid, "inpFind", uniedit_findSearch );
1578
1579 /* Close when escape is pressed. */
1581
1582 /* Generate the list. */
1583 uniedit_findSearch( wid, NULL );
1584
1585 /* Focus the input widget. */
1586 window_setFocus( wid, "inpFind" );
1587}
1588
1592static void uniedit_findSearch( unsigned int wid, const char *str )
1593{
1594 (void) str;
1595 int n, nspobs, nsystems;
1596 const char *name;
1597 char **spobs, **systems;
1598 map_find_t *found;
1599
1600 name = window_getInput( wid, "inpFind" );
1601
1602 /* Search for names. */
1603 spobs = spob_searchFuzzyCase( name, &nspobs );
1604 systems = system_searchFuzzyCase( name, &nsystems );
1605
1606 free(found_cur);
1607 found_cur = NULL;
1608
1609 /* Construct found table. */
1610 found = malloc( sizeof(map_find_t) * (nspobs + nsystems) );
1611 n = 0;
1612
1613 /* Add spobs to the found table. */
1614 for (int i=0; i<nspobs; i++) {
1615 /* Spob must be real. */
1616 Spob *spob = spob_get( spobs[i] );
1617 if (spob == NULL)
1618 continue;
1619
1620 char *sysname = spob_getSystem( spobs[i] );
1621 if (sysname == NULL)
1622 continue;
1623
1624 StarSystem *sys = system_get( sysname );
1625 if (sys == NULL)
1626 continue;
1627
1628 /* Set some values. */
1629 found[n].spob = spob;
1630 found[n].sys = sys;
1631
1632 /* Set fancy name. */
1633 snprintf( found[n].display, sizeof(found[n].display),
1634 _("%s (%s system)"), spobs[i], sys->name );
1635 n++;
1636 }
1637 free(spobs);
1638
1639 /* Add systems to the found table. */
1640 for (int i=0; i<nsystems; i++) {
1641 StarSystem *sys = system_get( systems[i] );
1642
1643 /* Set some values. */
1644 found[n].spob = NULL;
1645 found[n].sys = sys;
1646
1647 strncpy(found[n].display, sys->name, sizeof(found[n].display)-1);
1648 n++;
1649 }
1650 free(systems);
1651
1652 /* Globals. */
1653 found_cur = found;
1654 found_ncur = n;
1655
1656 /* Display results. */
1657 uniedit_findShowResults( wid, found, n );
1658}
1659
1663static void uniedit_findShowResults( unsigned int wid, map_find_t *found, int n )
1664{
1665 int y, h;
1666 char **str;
1667
1668 /* Destroy if exists. */
1669 if (widget_exists( wid, "lstResults" ))
1670 window_destroyWidget( wid, "lstResults" );
1671
1672 y = -45 - BUTTON_HEIGHT - 20;
1673
1674 if (n == 0) {
1675 str = malloc( sizeof(char*) );
1676 str[0] = strdup(_("None"));
1677 n = 1;
1678 }
1679 else {
1680 qsort( found, n, sizeof(map_find_t), uniedit_sortCompare );
1681
1682 str = malloc( sizeof(char*) * n );
1683 for (int i=0; i<n; i++)
1684 str[i] = strdup( found[i].display );
1685 }
1686
1687 /* Add list. */
1688 h = UNIEDIT_FIND_HEIGHT + y - BUTTON_HEIGHT - 30;
1689 window_addList( wid, 20, y, UNIEDIT_FIND_WIDTH-40, h,
1690 "lstResults", str, n, 0, uniedit_centerSystem, NULL );
1691}
1692
1696static void uniedit_findSysClose( unsigned int wid, const char *name )
1697{
1698 /* Clean up if necessary. */
1699 free( found_cur );
1700 found_cur = NULL;
1701
1702 /* Close the window. */
1703 window_close( wid, name );
1704}
1705
1709static void uniedit_centerSystem( unsigned int wid, const char *unused )
1710{
1711 (void) unused;
1712 StarSystem *sys;
1713 int pos;
1714
1715 /* Make sure it's valid. */
1716 if (found_ncur == 0 || found_cur == NULL)
1717 return;
1718
1719 pos = toolkit_getListPos( wid, "lstResults" );
1720 sys = found_cur[ pos ].sys;
1721
1722 if (sys == NULL)
1723 return;
1724
1725 /* Center. */
1726 uniedit_xpos = sys->pos.x * uniedit_zoom;
1727 uniedit_ypos = sys->pos.y * uniedit_zoom;
1728}
1729
1733static int uniedit_sortCompare( const void *p1, const void *p2 )
1734{
1735 map_find_t *f1, *f2;
1736
1737 /* Convert pointer. */
1738 f1 = (map_find_t*) p1;
1739 f2 = (map_find_t*) p2;
1740
1741 /* Sort by name, nothing more. */
1742 return strcasecmp( f1->sys->name, f2->sys->name );
1743}
1744
1748static void uniedit_editSys (void)
1749{
1750 unsigned int wid;
1751 int x, y, l;
1752 char buf[STRMAX_SHORT];
1753 const char *s;
1754 StarSystem *sys;
1755
1756 /* Must have a system. */
1757 if (array_size(uniedit_sys)==0)
1758 return;
1759 sys = uniedit_sys[0];
1760
1761 /* Create the window. */
1762 wid = window_create( "wdwStarSystemPropertyEditor", _("Star System Property Editor"), -1, -1, UNIEDIT_EDIT_WIDTH, UNIEDIT_EDIT_HEIGHT );
1763 uniedit_widEdit = wid;
1765
1766 x = 20;
1767
1768 /* Close button. */
1769 window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
1770 "btnClose", _("Close"), uniedit_editSysClose );
1771
1772 /* Rename button. */
1773 y = -45;
1774 snprintf( buf, sizeof(buf), "%s #n%s", _("Name:"), (array_size(uniedit_sys) > 1) ? _("#rvarious") : uniedit_sys[0]->name );
1775 window_addText( wid, x, y, 180, 15, 0, "txtName", &gl_smallFont, NULL, buf );
1776 window_addButton( wid, 200, y+3, BUTTON_WIDTH, 21, "btnRename", _("Rename"), uniedit_btnEditRename );
1777
1778 /* New row. */
1779 y -= gl_defFont.h + 15;
1780
1781 /* Add general stats */
1782 s = _("Radius");
1783 l = gl_printWidthRaw( NULL, s );
1784 window_addText( wid, x, y, l, 20, 1, "txtRadius",
1785 NULL, NULL, s );
1786 window_addInput( wid, x += l + 7, y, 80, 20, "inpRadius", 10, 1, NULL );
1787 window_setInputFilter( wid, "inpRadius", INPUT_FILTER_NUMBER );
1788 x += 80 + 12;
1789 s = _("(Scales spob positions)");
1790 l = gl_printWidthRaw( NULL, s );
1791 window_addText( wid, x, y, l, 20, 1, "txtRadiusComment",
1792 NULL, NULL, s );
1793
1794 /* New row. */
1795 x = 20;
1796 y -= gl_defFont.h + 15;
1797
1798 s = _("Stars");
1799 l = gl_printWidthRaw( NULL, s );
1800 window_addText( wid, x, y, l, 20, 1, "txtStars",
1801 NULL, NULL, s );
1802 window_addInput( wid, x += l + 7, y, 50, 20, "inpStars", 4, 1, NULL );
1803 window_setInputFilter( wid, "inpStars", INPUT_FILTER_NUMBER );
1804 x += 50 + 12;
1805
1806 s = _("Interference");
1807 l = gl_printWidthRaw( NULL, s );
1808 window_addText( wid, x, y, l, 20, 1, "txtInterference",
1809 NULL, NULL, s );
1810 window_addInput( wid, x += l + 7, y, 55, 20, "inpInterference", 5, 1, NULL );
1811 window_setInputFilter( wid, "inpInterference", INPUT_FILTER_NUMBER );
1812
1813 /* New row. */
1814 x = 20;
1815 y -= gl_defFont.h + 15;
1816
1817 s = _("Nebula");
1818 l = gl_printWidthRaw( NULL, s );
1819 window_addText( wid, x, y, l, 20, 1, "txtNebula",
1820 NULL, NULL, s );
1821 window_addInput( wid, x += l + 7, y, 50, 20, "inpNebula", 4, 1, NULL );
1822 window_setInputFilter( wid, "inpNebula", INPUT_FILTER_NUMBER );
1823 x += 50 + 12;
1824
1825 s = _("Volatility");
1826 l = gl_printWidthRaw( NULL, s );
1827 window_addText( wid, x, y, l, 20, 1, "txtVolatility",
1828 NULL, NULL, s );
1829 window_addInput( wid, x += l + 7, y, 50, 20, "inpVolatility", 4, 1, NULL );
1830 window_setInputFilter( wid, "inpVolatility", INPUT_FILTER_NUMBER );
1831 x += 50 + 12;
1832
1833 s = _("Hue");
1834 l = gl_printWidthRaw( NULL, s );
1835 window_addText( wid, x, y, l, 20, 1, "txtHue",
1836 NULL, NULL, s );
1837 window_addInput( wid, x += l + 7, y, 50, 20, "inpHue", 4, 1, NULL );
1838 window_setInputFilter( wid, "inpHue", INPUT_FILTER_NUMBER );
1839 x += 50 + 12;
1840
1841 /* Load values */
1842 snprintf( buf, sizeof(buf), "%g", sys->radius );
1843 window_setInput( wid, "inpRadius", buf );
1844 snprintf( buf, sizeof(buf), "%d", sys->stars );
1845 window_setInput( wid, "inpStars", buf );
1846 snprintf( buf, sizeof(buf), "%g", sys->interference );
1847 window_setInput( wid, "inpInterference", buf );
1848 snprintf( buf, sizeof(buf), "%g", sys->nebu_density );
1849 window_setInput( wid, "inpNebula", buf );
1850 snprintf( buf, sizeof(buf), "%g", sys->nebu_volatility );
1851 window_setInput( wid, "inpVolatility", buf );
1852 snprintf( buf, sizeof(buf), "%g", sys->nebu_hue*360. );
1853 window_setInput( wid, "inpHue", buf );
1854
1855 /* Generate the list. */
1856 uniedit_editGenList( wid );
1857}
1858
1862static void uniedit_editGenList( unsigned int wid )
1863{
1864 int j, n;
1865 StarSystem *sys;
1866 const VirtualSpob *va;
1867 char **str;
1868 int y, h, has_spobs;
1869
1870 /* Destroy if exists. */
1871 if (widget_exists( wid, "lstSpobs" ))
1872 window_destroyWidget( wid, "lstSpobs" );
1873
1874 y = -175;
1875
1876 /* Check to see if it actually has virtual spobs. */
1877 sys = uniedit_sys[0];
1878 n = array_size( sys->spobs_virtual );
1879 has_spobs = !!n;
1880
1881 /* Generate list. */
1882 j = 0;
1883 str = malloc( sizeof(char*) * (n+1) );
1884 if (has_spobs) {
1885 /* Virtual spob button. */
1886 for (int i=0; i<n; i++) {
1887 va = sys->spobs_virtual[i];
1888 str[j++] = strdup( va->name );
1889 }
1890 }
1891 else
1892 str[j++] = strdup(_("None"));
1893
1894 /* Add list. */
1895 h = UNIEDIT_EDIT_HEIGHT+y-20 - 2*(BUTTON_HEIGHT+20);
1896 window_addList( wid, 20, y, UNIEDIT_EDIT_WIDTH-40, h,
1897 "lstSpobs", str, j, 0, NULL, NULL );
1898 y -= h + 20;
1899
1900 /* Add buttons if needed. */
1901 if (!widget_exists( wid, "btnRmSpob" ))
1902 window_addButton( wid, -20, y+3, BUTTON_WIDTH, BUTTON_HEIGHT,
1903 "btnRmSpob", _("Remove"), uniedit_btnEditRmSpob );
1904 if (!widget_exists( wid, "btnAddSpob" ))
1905 window_addButton( wid, -40-BUTTON_WIDTH, y+3, BUTTON_WIDTH, BUTTON_HEIGHT,
1906 "btnAddSpob", _("Add"), uniedit_btnEditAddSpob );
1907}
1908
1912static void uniedit_editSysClose( unsigned int wid, const char *name )
1913{
1914 StarSystem *sys;
1915 double scale;
1916
1917 /* We already know the system exists because we checked when opening the dialog. */
1918 sys = uniedit_sys[0];
1919
1920 /* Changes in radius need to scale the system spob positions. */
1921 scale = atof(window_getInput( wid, "inpRadius" )) / sys->radius;
1922 sysedit_sysScale(sys, scale);
1923
1924 sys->stars = atoi(window_getInput( wid, "inpStars" ));
1925 sys->interference = atof(window_getInput( wid, "inpInterference" ));
1926 sys->nebu_density = atof(window_getInput( wid, "inpNebula" ));
1927 sys->nebu_volatility = atof(window_getInput( wid, "inpVolatility" ));
1928 sys->nebu_hue = atof(window_getInput( wid, "inpHue" )) / 360.;
1929
1930 /* Reconstruct universe presences. */
1933
1934 /* Text might need changing. */
1936
1937 if (conf.devautosave)
1939
1940 /* Close the window. */
1941 window_close( wid, name );
1942}
1943
1947static void uniedit_btnEditRmSpob( unsigned int wid, const char *unused )
1948{
1949 (void) unused;
1950 const char *selected;
1951 int ret;
1952
1953 /* Get selection. */
1954 selected = toolkit_getList( wid, "lstSpobs" );
1955
1956 /* Make sure it's valid. */
1957 if ((selected==NULL) || (strcmp(selected,_("None"))==0))
1958 return;
1959
1960 /* Remove the spob. */
1961 ret = system_rmVirtualSpob( uniedit_sys[0], selected );
1962 if (ret != 0) {
1963 dialogue_alert( _("Failed to remove virtual spob '%s'!"), selected );
1964 return;
1965 }
1966
1967 /* Update economy due to galaxy modification. */
1969
1970 uniedit_editGenList( wid );
1971}
1972
1976static void uniedit_btnEditAddSpob( unsigned int parent, const char *unused )
1977{
1978 (void) parent;
1979 (void) unused;
1980 unsigned int wid;
1981 const VirtualSpob *va;
1982 char **str;
1983 int h;
1984
1985 /* Get all spobs. */
1986 va = virtualspob_getAll();
1987 if (array_size(va)==0) {
1988 dialogue_alert( _("No virtual spobs to add! Please add virtual spobs to the '%s' directory first."), VIRTUALSPOB_DATA_PATH );
1989 return;
1990 }
1991
1992 /* Create the window. */
1993 wid = window_create( "wdwAddaVirtualSpob", _("Add a Virtual Spob"), -1, -1, UNIEDIT_EDIT_WIDTH, UNIEDIT_EDIT_HEIGHT );
1995
1996 /* Add virtual spob list. */
1997 str = malloc( sizeof(char*) * array_size(va) );
1998 for (int i=0; i<array_size(va); i++)
1999 str[i] = strdup( va[i].name );
2001 window_addList( wid, 20, -40, UNIEDIT_EDIT_WIDTH-40, h,
2002 "lstSpobs", str, array_size(va), 0, NULL, NULL );
2003
2004 /* Close button. */
2005 window_addButton( wid, -20, 20, BUTTON_WIDTH, BUTTON_HEIGHT,
2006 "btnClose", _("Close"), window_close );
2007
2008 /* Add button. */
2009 window_addButton( wid, -20-(BUTTON_WIDTH+20), 20, BUTTON_WIDTH, BUTTON_HEIGHT,
2010 "btnAdd", _("Add"), uniedit_btnEditAddSpobAdd );
2011}
2012
2016static void uniedit_btnEditAddSpobAdd( unsigned int wid, const char *unused )
2017{
2018 const char *selected;
2019 int ret;
2020
2021 /* Get selection. */
2022 selected = toolkit_getList( wid, "lstSpobs" );
2023 if (selected == NULL)
2024 return;
2025
2026 /* Add virtual presence. */
2027 ret = system_addVirtualSpob( uniedit_sys[0], selected );
2028 if (ret != 0) {
2029 dialogue_alert( _("Failed to add virtual spob '%s'!"), selected );
2030 return;
2031 }
2032
2033 /* Update economy due to galaxy modification. */
2035
2036 /* Regenerate the list. */
2038
2039 if (conf.devautosave)
2041
2042 /* Close the window. */
2043 window_close( wid, unused );
2044}
2045
2049static void uniedit_btnEditRename( unsigned int wid, const char *unused )
2050{
2051 (void) unused;
2052 char buf[STRMAX_SHORT];
2053
2054 /* Rename systems. */
2056
2057 /* Update text. */
2058 snprintf( buf, sizeof(buf), "%s #n%s", _("Name:"), (array_size(uniedit_sys) > 1) ? _("#rvarious") : uniedit_sys[0]->name );
2059 window_modifyText( wid, "txtName", buf );
2060}
2061
2065static void uniedit_btnViewModeSet( unsigned int wid, const char *unused )
2066{
2067 const char *selected;
2068 int pos;
2069
2070 /* Check default. */
2071 pos = toolkit_getListPos( wid, "lstViewModes" );
2073 if (pos==0) {
2074 uniedit_viewmode = UNIEDIT_VIEW_DEFAULT;
2075 window_close( wid, unused );
2076 return;
2077 }
2078 else if (pos==1) {
2079 uniedit_viewmode = UNIEDIT_VIEW_VIRTUALSPOBS;
2080 window_close( wid, unused );
2081 return;
2082 }
2083 else if (pos==2) {
2084 uniedit_viewmode = UNIEDIT_VIEW_RADIUS;
2085 window_close( wid, unused );
2086 return;
2087 }
2088 else if (pos==3) {
2089 uniedit_viewmode = UNIEDIT_VIEW_BACKGROUND;
2090 window_close( wid, unused );
2091 return;
2092 }
2093 else if (pos==4) {
2094 uniedit_viewmode = UNIEDIT_VIEW_ASTEROIDS;
2095 window_close( wid, unused );
2096 return;
2097 }
2098 else if (pos==5) {
2099 uniedit_viewmode = UNIEDIT_VIEW_TECH;
2100 window_close( wid, unused );
2101 return;
2102 }
2103 else if (pos==6) {
2104 uniedit_viewmode = UNIEDIT_VIEW_PRESENCE_SUM;
2105 window_close( wid, unused );
2106 return;
2107 }
2108
2109 /* Get selection. */
2110 selected = toolkit_getList( wid, "lstViewModes" );
2111 if (selected == NULL)
2112 return;
2113
2114 uniedit_viewmode = UNIEDIT_VIEW_PRESENCE;
2115 uniedit_view_faction = faction_get( selected );
2116
2117 /* Close the window. */
2118 window_close( wid, unused );
2119}
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:171
void sysedit_open(StarSystem *sys)
Opens the system editor interface.
Definition: dev_sysedit.c:169
void sysedit_sysScale(StarSystem *sys, double factor)
Scales a system.
Definition: dev_sysedit.c:604
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:274
static UniEditMode uniedit_mode
Definition: dev_uniedit.c:76
static void uniedit_btnOpen(unsigned int wid_unused, const char *unused)
Opens up a system.
Definition: dev_uniedit.c:460
static double uniedit_my
Definition: dev_uniedit.c:96
static void uniedit_btnEditRename(unsigned int wid, const char *unused)
Renames the systems in the system editor.
Definition: dev_uniedit.c:2049
static double uniedit_dt
Definition: dev_uniedit.c:97
static int uniedit_checkName(const char *name)
Checks to see if a system name is already in use.
Definition: dev_uniedit.c:1231
static void uniedit_renderOverlay(double bx, double by, double bw, double bh, void *data)
Renders the overlay.
Definition: dev_uniedit.c:768
static double uniedit_xpos
Definition: dev_uniedit.c:82
void uniedit_open(unsigned int wid_unused, const char *unused)
Opens the system editor interface.
Definition: dev_uniedit.c:159
static int uniedit_tadd
Definition: dev_uniedit.c:94
static void uniedit_close(unsigned int wid, const char *wgt)
Closes the system editor widget.
Definition: dev_uniedit.c:297
#define UNIEDIT_CLICK_THRESHOLD
Definition: dev_uniedit.c:47
static double uniedit_dragSelX
Definition: dev_uniedit.c:90
static unsigned int uniedit_widFind
Definition: dev_uniedit.c:81
#define UNIEDIT_DOUBLECLICK_THRESHOLD
Definition: dev_uniedit.c:48
static map_find_t * found_cur
Definition: dev_uniedit.c:99
static void uniedit_btnEditAddSpobAdd(unsigned int wid, const char *unused)
Actually adds the virtual spob.
Definition: dev_uniedit.c:2016
static void uniedit_deselect(void)
Deselects selected targets.
Definition: dev_uniedit.c:1432
static void uniedit_editSys(void)
Edits an individual system or group of systems.
Definition: dev_uniedit.c:1748
#define UNIEDIT_FIND_WIDTH
Definition: dev_uniedit.c:42
static void uniedit_newSys(double x, double y)
Creates a new system.
Definition: dev_uniedit.c:1310
static double uniedit_ypos
Definition: dev_uniedit.c:83
static int uniedit_drag
Definition: dev_uniedit.c:87
static void uniedit_btnNew(unsigned int wid_unused, const char *unused)
Enters the editor in new system mode.
Definition: dev_uniedit.c:449
static int uniedit_mouse(unsigned int wid, SDL_Event *event, double mx, double my, double w, double h, double rx, double ry, void *data)
System editor custom widget mouse handling.
Definition: dev_uniedit.c:1016
#define UNIEDIT_ZOOM_STEP
Definition: dev_uniedit.c:50
static StarSystem ** uniedit_sys
Definition: dev_uniedit.c:92
#define UNIEDIT_EDIT_HEIGHT
Definition: dev_uniedit.c:40
static void uniedit_toggleJump(StarSystem *sys)
Toggles the jump point for the selected systems.
Definition: dev_uniedit.c:1350
static void uniedit_editGenList(unsigned int wid)
Generates the virtual spob list.
Definition: dev_uniedit.c:1862
static int uniedit_keys(unsigned int wid, SDL_Keycode key, SDL_Keymod mod)
Handles keybindings.
Definition: dev_uniedit.c:278
static int uniedit_moved
Definition: dev_uniedit.c:85
static unsigned int uniedit_widEdit
Definition: dev_uniedit.c:80
static void uniedit_buttonZoom(unsigned int wid, const char *str)
Handles the button zoom clicks.
Definition: dev_uniedit.c:1531
static void uniedit_renameSys(void)
Renames all the currently selected systems.
Definition: dev_uniedit.c:1263
static void uniedit_findSys(void)
Finds systems and spobs.
Definition: dev_uniedit.c:1556
static void uniedit_jumpAdd(StarSystem *sys, StarSystem *targ)
Adds a new Star System jump.
Definition: dev_uniedit.c:1393
static void uniedit_btnFind(unsigned int wid_unused, const char *unused)
Opens the system property editor.
Definition: dev_uniedit.c:474
static int uniedit_dragSys
Definition: dev_uniedit.c:88
#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.
Definition: dev_uniedit.c:1663
#define BUTTON_HEIGHT
Definition: dev_uniedit.c:37
static double uniedit_zoom
Definition: dev_uniedit.c:84
static unsigned int uniedit_lastClick
Definition: dev_uniedit.c:86
static double uniedit_dragSelY
Definition: dev_uniedit.c:91
static int uniedit_dragSel
Definition: dev_uniedit.c:89
static void uniedit_btnJump(unsigned int wid_unused, const char *unused)
Enters the editor in new jump mode.
Definition: dev_uniedit.c:427
static void uniedit_btnEdit(unsigned int wid_unused, const char *unused)
Opens the system property editor.
Definition: dev_uniedit.c:485
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.
Definition: dev_uniedit.c:1410
static void uniedit_editSysClose(unsigned int wid, const char *name)
Closes the system property editor, saving the changes made.
Definition: dev_uniedit.c:1912
static int uniedit_sortCompare(const void *p1, const void *p2)
qsort compare function for map finds.
Definition: dev_uniedit.c:1733
static void uniedit_btnEditAddSpob(unsigned int wid, const char *unused)
Adds a new virtual spob.
Definition: dev_uniedit.c:1976
static void uniedit_btnViewModeSet(unsigned int wid, const char *unused)
Actually adds the virtual spob.
Definition: dev_uniedit.c:2065
static int found_ncur
Definition: dev_uniedit.c:100
UniEditMode
Definition: dev_uniedit.c:57
@ 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.
Definition: dev_uniedit.c:359
static double uniedit_mx
Definition: dev_uniedit.c:95
static void uniedit_selectAdd(StarSystem *sys)
Adds a system to the selection.
Definition: dev_uniedit.c:1450
#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.
Definition: dev_uniedit.c:1709
static void uniedit_findSysClose(unsigned int wid, const char *name)
Closes the search dialogue.
Definition: dev_uniedit.c:1696
static UniEditViewMode uniedit_viewmode
Definition: dev_uniedit.c:77
static unsigned int uniedit_wid
Definition: dev_uniedit.c:79
static void uniedit_findSearch(unsigned int wid, const char *str)
Searches for spobs and systems.
Definition: dev_uniedit.c:1592
#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:78
#define UNIEDIT_MOVE_THRESHOLD
Definition: dev_uniedit.c:46
void uniedit_selectText(void)
Sets the selected system text.
Definition: dev_uniedit.c:1492
static void uniedit_btnRename(unsigned int wid_unused, const char *unused)
Renames selected systems.
Definition: dev_uniedit.c:438
static void uniedit_selectRm(StarSystem *sys)
Removes a system from the selection.
Definition: dev_uniedit.c:1473
static void uniedit_focusLose(unsigned int wid, const char *wgtname)
Called when it's de-focused.
Definition: dev_uniedit.c:1006
static void uniedit_btnEditRmSpob(unsigned int wid, const char *unused)
Removes a selected spob.
Definition: dev_uniedit.c:1947
static void uniedit_render(double bx, double by, double w, double h, void *data)
System editor custom widget rendering.
Definition: dev_uniedit.c:717
static StarSystem * uniedit_tsys
Definition: dev_uniedit.c:93
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:465
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:436
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:304
const FactionGenerator * faction_generators(int f)
Gets the faction's generators.
Definition: faction.c:1848
const glColour * faction_colour(int f)
Gets the colour of the faction.
Definition: faction.c:467
int * faction_getAll(void)
Returns all faction IDs in an array (array.h).
Definition: faction.c:193
int faction_get(const char *name)
Gets a faction ID by name.
Definition: faction.c:182
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:960
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:690
glFont gl_defFontMono
Definition: font.c:155
double naev_getrealdt(void)
Gets the last delta-tick.
Definition: naev.c:1122
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 asprintf(char **strp, const char *fmt,...)
Like sprintf(), but it allocates a large-enough string and returns the pointer in the first argument....
Definition: nstring.c:161
int strsort(const void *p1, const void *p2)
Sort function for sorting strings with qsort().
Definition: nstring.c:108
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:178
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:230
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.
Definition: opengl_render.c:90
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
static const double b[]
Definition: rng.c:256
void safelanes_recalculate(void)
Update the safe lane locations in response to the universe changing (e.g., diff applied).
Definition: safelanes.c:249
void space_reconstructPresences(void)
Reset the presence of all systems.
Definition: space.c:4220
void systems_reconstructJumps(void)
Reconstructs the jumps.
Definition: space.c:2671
double system_getPresenceFull(const StarSystem *sys, int faction, double *base, double *bonus)
Get the presence of a faction in a system.
Definition: space.c:4167
Spob * spob_getAll(void)
Gets an array (array.h) of all spobs.
Definition: space.c:1063
Spob * spob_get(const char *spobname)
Gets a spob based on its name.
Definition: space.c:1006
int system_addVirtualSpob(StarSystem *sys, const char *spobname)
Adds a virtual spob to a system.
Definition: space.c:2466
StarSystem * system_getIndex(int id)
Get the system by its index.
Definition: space.c:944
StarSystem * system_new(void)
Creates a new star system.
Definition: space.c:2601
char ** spob_searchFuzzyCase(const char *spobname, int *n)
Does a fuzzy case matching. Searches spob_name() but returns internal names.
Definition: space.c:1107
char ** system_searchFuzzyCase(const char *sysname, int *n)
Does a fuzzy case matching. Searches translated names but returns internal names.
Definition: space.c:869
StarSystem * system_get(const char *sysname)
Get the system from its name.
Definition: space.c:914
char * spob_getSystem(const char *spobname)
Get the name of a system from a spobname.
Definition: space.c:980
double system_getPresence(const StarSystem *sys, int faction)
Get the presence of a faction in a system.
Definition: space.c:4138
int system_rmVirtualSpob(StarSystem *sys, const char *spobname)
Removes a virtual spob from a system.
Definition: space.c:2490
VirtualSpob * virtualspob_getAll(void)
Gets all the virtual spobs.
Definition: space.c:1138
const char * spob_name(const Spob *p)
Gets the translated name of a spob.
Definition: space.c:1705
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:159
Represents the presence of a spob.
Definition: space.h:65
double bonus
Definition: space.h:68
double base
Definition: space.h:67
int faction
Definition: space.h:66
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...
Definition: space.h:88
tech_group_t * tech
Definition: space.h:116
SpobPresence presence
Definition: space.h:102
Represents presence in a system.
Definition: space.h:169
double value
Definition: space.h:173
double base
Definition: space.h:171
double bonus
Definition: space.h:172
int faction
Definition: space.h:170
Basically modifies system parameters without creating any real objects.
Definition: space.h:77
SpobPresence * presences
Definition: space.h:79
char * name
Definition: space.h:78
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:683
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:696
void window_setFocus(unsigned int wid, const char *wgtname)
Sets the focused widget in a window.
Definition: toolkit.c:2460
void window_setCancel(unsigned int wid, void(*cancel)(unsigned int, const char *))
Sets the default cancel function of the window.
Definition: toolkit.c:900
void toolkit_drawAltText(int bx, int by, const char *alt)
Draws an alt text.
Definition: toolkit.c:1426
void window_handleKeys(unsigned int wid, int(*keyhandler)(unsigned int, SDL_Keycode, SDL_Keymod))
Sets the key handler for the window.
Definition: toolkit.c:972
void window_destroyWidget(unsigned int wid, const char *wgtname)
Destroys a widget in a window.
Definition: toolkit.c:1162
void window_setBorder(unsigned int wid, int enable)
Sets or removes the border of a window.
Definition: toolkit.c:953
int widget_exists(unsigned int wid, const char *wgtname)
Checks to see if a widget exists.
Definition: toolkit.c:1139
void window_close(unsigned int wid, const char *str)
Helper function to automatically close the window calling it.
Definition: toolkit.c:1031
void diff_clear(void)
Removes all active diffs. (Call before economy_destroy().)
Definition: unidiff.c:1472