16#include "dev_mapedit.h"
22#include "dev_uniedit.h"
23#include "dev_sysedit.h"
24#include "dev_system.h"
36#include "tk/toolkit_priv.h"
42#define BUTTON_WIDTH 80
43#define BUTTON_HEIGHT 30
45#define MAPEDIT_EDIT_WIDTH 400
46#define MAPEDIT_EDIT_HEIGHT 450
48#define MAPEDIT_DRAG_THRESHOLD 300
49#define MAPEDIT_MOVE_THRESHOLD 10
51#define MAPEDIT_ZOOM_STEP 1.2
52#define MAPEDIT_ZOOM_MAX 5
53#define MAPEDIT_ZOOM_MIN -5
55#define MAPEDIT_OPEN_WIDTH 800
56#define MAPEDIT_OPEN_HEIGHT 500
57#define MAPEDIT_OPEN_TXT_WIDTH 300
59#define MAPEDIT_SAVE_WIDTH 800
60#define MAPEDIT_SAVE_HEIGHT 500
61#define MAPEDIT_SAVE_TXT_WIDTH 300
63typedef struct mapOutfitsList_s {
103static void mapedit_render(
double bx,
double by,
double w,
double h,
void *data );
105static int mapedit_mouse(
unsigned int wid,
const SDL_Event* event,
double mx,
double my,
106 double w,
double h,
double xr,
double yr,
void *data );
108static void mapedit_close(
unsigned int wid,
const char *wgt );
109static void mapedit_btnOpen(
unsigned int wid_unused,
const char *unused );
111static void mapedit_clear(
unsigned int wid_unused,
const char *unused );
112static void mapedit_chkSpob(
unsigned int wid,
const char *wgtname );
113static void mapedit_chkHidden(
unsigned int wid,
const char *wgtname );
115static int mapedit_keys(
unsigned int wid, SDL_Keycode key, SDL_Keymod mod,
int isrepeat );
159 wid =
window_create(
"wdwMapOutfitEditor", _(
"Map Outfit Editor"), -1, -1, -1, -1 );
164 window_addCust( wid, 20, -40, SCREEN_W - 350, SCREEN_H - 100,
189 window_addText( wid, -200, -40-textPos*parHeight-linesPos*lineHeight, 100, lineHeight, 0,
"txtSFileName",
191 window_addInput( wid, -30, -40-textPos*parHeight-linesPos*lineHeight, 170, lineHeight,
"inpFileName",
197 window_addText( wid, -200, -40-textPos*parHeight-linesPos*lineHeight, 100, lineHeight, 0,
"txtSMapName",
199 window_addInput( wid, -30, -40-textPos*parHeight-linesPos*lineHeight, 170, lineHeight,
"inpMapName",
206 window_addText( wid, -20, -40-textPos*parHeight-linesPos*lineHeight, 300-20, lineHeight, 0,
"txtSDescription",
208 window_addInput( wid, -20, -40-textPos*parHeight-(linesPos+1)*lineHeight, 300-20, curLines*lineHeight,
"inpDescription",
211 linesPos+=(curLines+1);
215 window_addText( wid, -20, -40-textPos*parHeight-linesPos*lineHeight, 300-20, 20, 0,
"txtSCurrentNumSystems",
216 &
gl_smallFont, NULL, _(
"Number of Systems (up to 100):") );
217 window_addText( wid, -20, -40-textPos*parHeight-linesPos*lineHeight, 60, curLines*lineHeight, 0,
"txtCurrentNumSystems",
224 window_addText( wid, -20, -40-textPos*parHeight-linesPos*lineHeight, 300-20, 20, 0,
"txtSPresence",
226 window_addText( wid, -20, -40-textPos*parHeight-(linesPos+1)*lineHeight, 300-20, curLines*lineHeight, 0,
"txtPresence",
229 linesPos+=curLines+1;
233 window_addText( wid, -200, -40-textPos*parHeight-linesPos*lineHeight, 100, 20, 0,
"txtSPrice",
235 window_addInput( wid, -30, -40-textPos*parHeight-linesPos*lineHeight, 170, lineHeight,
"inpPrice",
237 window_setInputFilter( wid,
"inpPrice", INPUT_FILTER_NUMBER );
242 window_addText( wid, -200, -40-textPos*parHeight-linesPos*lineHeight, 100, 20, 0,
"txtSGFX",
244 window_addInput( wid, -30, -40-textPos*parHeight-linesPos*lineHeight, 170, lineHeight,
"inpGFX",
250 window_addText( wid, -200, -40-textPos*parHeight-linesPos*lineHeight, 100, 20, 0,
"txtSRarity",
252 window_addInput( wid, -30, -40-textPos*parHeight-linesPos*lineHeight, 170, lineHeight,
"inpRarity",
254 window_setInputFilter( wid,
"inpRarity", INPUT_FILTER_NUMBER );
256 linesPos+=curLines+1;
260 window_addCheckbox( wid, -30, -40-textPos*parHeight-linesPos*lineHeight, 170, lineHeight,
"chkSpob", _(
"Ignore Spobs"), mapedit_chkSpob,
mapedit_nospob );
262 linesPos+=curLines+1;
266 window_addCheckbox( wid, -30, -40-textPos*parHeight-linesPos*lineHeight, 170, lineHeight,
"chkHidden", _(
"Set Hidden Jumps"), mapedit_chkHidden,
mapedit_nospob );
268 linesPos+=curLines+1;
271 window_addText( wid, -20, -40-textPos*parHeight-linesPos*lineHeight, 300-20, curLines*lineHeight, 0,
"txtSWarning",
273 _(
"Warning: Editor can't (yet) manage which details are mapped within a system. Review its changes before committing.") );
275 linesPos+=curLines+1;
278 window_addButtonKey( wid, 40, 20, 30, 30,
"btnZoomIn",
"+",
mapedit_buttonZoom, SDLK_EQUALS );
279 window_addButtonKey( wid, 80, 20, 30, 30,
"btnZoomOut",
"-",
mapedit_buttonZoom, SDLK_MINUS );
282 window_addText( wid, 140, 10, SCREEN_W - 350 - 30 - 30 -
BUTTON_WIDTH - 20, 30, 0,
292static int mapedit_keys(
unsigned int wid, SDL_Keycode key, SDL_Keymod mod,
int isrepeat )
339static void mapedit_chkSpob(
unsigned int wid,
const char *wgtname )
344static void mapedit_chkHidden(
unsigned int wid,
const char *wgtname )
364static void mapedit_render(
double bx,
double by,
double w,
double h,
void *data )
372 uniedit_renderMap( bx, by, w, h, x, y,
mapedit_zoom, r );
408static int mapedit_mouse(
unsigned int wid,
const SDL_Event* event,
double mx,
double my,
409 double w,
double h,
double xr,
double yr,
void *data )
412 const double t = 15.*15.;
414 switch (event->type) {
417 if ((mx < 0.) || (mx > w) || (my < 0.) || (my > h))
419 if (event->wheel.y > 0)
421 else if (event->wheel.y < 0)
425 case SDL_MOUSEBUTTONDOWN:
427 if ((mx < 0.) || (mx > w) || (my < 0.) || (my > h))
432 if (event->button.button == SDL_BUTTON_X1) {
436 else if (event->button.button == SDL_BUTTON_X2) {
486 case SDL_MOUSEBUTTONUP:
491 case SDL_MOUSEMOTION:
523 window_modifyText(
mapedit_wid,
"txtSelected", _(
"No selection") );
524 window_modifyText(
mapedit_wid,
"txtCurrentNumSystems",
"0" );
573 char buf[STRMAX_SHORT];
587 window_modifyText(
mapedit_wid,
"txtSelected", buf );
591 window_modifyText(
mapedit_wid,
"txtCurrentNumSystems", buf );
596 map_updateFactionPresence(
mapedit_wid,
"txtPresence", sys, 1 );
597 snprintf( &buf[0],
sizeof(buf), _(
"Presence (%s)"), sys->name );
598 window_modifyText(
mapedit_wid,
"txtSPresence", buf );
600 window_modifyText(
mapedit_wid,
"txtSPresence", _(
"Presence") );
601 window_modifyText(
mapedit_wid,
"txtPresence", _(
"No system yet clicked") );
620 if (strcmp(str,
"btnZoomIn")==0) {
624 else if (strcmp(str,
"btnZoomOut")==0) {
658 names = malloc(
sizeof(
char*)*n );
659 for (
int i=0; i<n; i++) {
661 names[i] = strdup(ns->mapName);
666 names = malloc(
sizeof(
char*));
667 names[0] = strdup(
"None");
673 0,
"txtMapInfo", NULL, NULL, NULL );
699 char buf[STRMAX_SHORT];
702 save = toolkit_getList( wdw,
"lstMapOutfits" );
703 if (strcmp(save,
"None") == 0)
707 pos = toolkit_getListPos( wdw,
"lstMapOutfits" );
711 snprintf( buf,
sizeof(buf),
720 ns->fileName, ns->mapName, ns->description, ns->numSystems
723 window_modifyText( wdw,
"txtMapInfo", buf );
743 int pos, len, compareLimit, i, found;
746 char *file, *name, *systemName;
754 save = toolkit_getList( wdw,
"lstMapOutfits" );
755 if (strcmp(save,
"None") == 0)
763 pos = toolkit_getListPos( wdw,
"lstMapOutfits" );
767 len = strlen(MAP_DATA_PATH)+strlen(ns->fileName)+2;
768 file = malloc( len );
769 snprintf( file, len,
"%s%s", MAP_DATA_PATH, ns->fileName );
774 node = doc->xmlChildrenNode;
781 if (!xml_isNode(node,
"outfit")) {
788 xmlr_attr_strd(node,
"name", name);
789 if (strcmp(ns->mapName, name)!=0) {
800 node = node->xmlChildrenNode;
804 if (!xml_isNode(node,
"specific"))
809 }
while (xml_nextNode(node));
814 node = node->xmlChildrenNode;
818 if (!xml_isNode(node,
"sys"))
822 xmlr_attr_strd(node,
"name", systemName);
828 compareLimit = strlen(systemName);
829 if (strncmp(systemName, sys->name, compareLimit)==0) {
840 }
while (xml_nextNode(node));
858 ns.fileName = strdup( window_getInput( wdw,
"inpFileName" ) );
859 ns.mapName = strdup( window_getInput( wdw,
"inpMapName" ) );
860 ns.description = strdup( window_getInput( wdw,
"inpDescription" ) );
861 ns.gfx_store = strdup( window_getInput( wdw,
"inpGFX" ) );
863 ns.price = atoll(window_getInput( wdw,
"inpPrice" ));
864 ns.rarity = atoi(window_getInput( wdw,
"inpRarity" ));
870 free( ns.description );
871 free( ns.gfx_store );
882 window_setInput(
mapedit_wid,
"inpFileName", ns->fileName );
883 window_setInput(
mapedit_wid,
"inpMapName", ns->mapName );
884 window_setInput(
mapedit_wid,
"inpDescription", ns->description );
885 window_setInput(
mapedit_wid,
"inpGFX", ns->gfx_store );
886 snprintf( buf,
sizeof(buf),
"%i", ns->numSystems );
887 window_modifyText(
mapedit_wid,
"txtCurrentNumSystems", buf );
888 snprintf( buf,
sizeof(buf),
"%"CREDITS_PRI, ns->price );
890 snprintf( buf,
sizeof(buf),
"%i", ns->rarity );
905 int is_map, nSystems;
906 xmlNodePtr node, cur;
909 char *file, *name, *outfitType;
915 map_files = PHYSFS_enumerateFiles( MAP_DATA_PATH );
917 for (
size_t i=0; map_files[i]!=NULL; i++) {
918 char *description = NULL;
919 char *gfx_store = NULL;
920 credits_t price = 1000;
923 SDL_asprintf( &file,
"%s%s", MAP_DATA_PATH, map_files[i] );
932 node = doc->xmlChildrenNode;
939 if (!xml_isNode(node,
"outfit")) {
946 xmlr_attr_strd( node,
"name", name );
949 node = node->xmlChildrenNode;
954 if (!xml_isNode(node,
"specific")) {
955 if (xml_isNode(node,
"general")) {
956 cur = node->children;
959 xmlr_str(cur,
"description",description);
960 xmlr_long(cur,
"price",price);
961 xmlr_int(cur,
"rarity",rarity);
962 xmlr_str(cur,
"gfx_store",gfx_store);
963 }
while (xml_nextNode(cur));
969 xmlr_attr_strd( node,
"type", outfitType );
970 is_map = outfitType == NULL ? 0 : !strncmp(outfitType,
"map", 3);
975 }
while (xml_nextNode(node));
987 node = node->xmlChildrenNode;
990 if (!xml_isNode(node,
"sys"))
995 }
while (xml_nextNode(node));
1000 newMapItem->numSystems = nSystems;
1001 newMapItem->fileName = strdup( map_files[ i ] );
1002 newMapItem->mapName = strdup( name );
1003 newMapItem->description = strdup( (description != NULL) ? description :
"" );
1004 newMapItem->gfx_store = strdup( (gfx_store != NULL) ? gfx_store :
"" );
1005 newMapItem->price = price;
1006 newMapItem->rarity = rarity;
1017 PHYSFS_freeList( map_files );
1028 for (
unsigned int i=0; i<n; i++) {
1029 free( mapList[i].fileName );
1030 free( mapList[i].mapName );
1031 free( mapList[i].description );
1032 free( mapList[i].gfx_store );
1049 xmlTextWriterPtr writer;
1053 writer = xmlNewTextWriterDoc(&doc, 0);
1054 if (writer == NULL) {
1055 WARN(_(
"testXmlwriterDoc: Error creating the xml writer"));
1064 xmlw_startElem( writer,
"outfit" );
1067 xmlw_attr( writer,
"name",
"%s", ns->mapName );
1070 xmlw_startElem( writer,
"general" );
1071 xmlw_elem( writer,
"rarity",
"%d", ns->rarity );
1072 xmlw_elem( writer,
"mass",
"%d", 0 );
1073 xmlw_elem( writer,
"price",
"%"CREDITS_PRI, ns->price );
1074 xmlw_elem( writer,
"description",
"%s", ns->description );
1075 xmlw_elem( writer,
"gfx_store",
"%s", ns->gfx_store );
1076 xmlw_endElem( writer );
1078 xmlw_startElem( writer,
"specific" );
1079 xmlw_attr( writer,
"type",
"map" );
1082 for (
int i=0; i < ns->numSystems; i++) {
1084 xmlw_startElem( writer,
"sys" );
1085 xmlw_attr( writer,
"name",
"%s", s->name );
1088 for (
int j=0; j <
array_size(s->jumps); j++) {
1090 if (jp_isFlag(&s->jumps[j], JP_EXITONLY ))
1095 for (
int k=0; k < ns->numSystems; k++) {
1097 xmlw_elem( writer,
"jump",
"%s",
uniedit_sys[k]->name );
1106 xmlw_elem( writer,
"spob",
"%s", s->spobs[j]->name );
1108 xmlw_endElem( writer );
1111 xmlw_endElem( writer );
1112 xmlw_endElem( writer );
1116 xmlFreeTextWriter(writer);
1119 SDL_asprintf( &file,
"%s/%s", conf.
dev_save_map, ns->fileName );
1120 if (xmlSaveFileEnc( file, doc,
"UTF-8" ) < 0)
1121 WARN(_(
"Failed writing '%s'!"), file);
Provides macros to work with dynamic arrays.
#define array_free(ptr_array)
Frees memory allocated and sets array to NULL.
static ALWAYS_INLINE int array_size(const void *array)
Returns number of elements in the array.
#define array_grow(ptr_array)
Increases the number of elements by one and returns the last element.
#define array_create(basic_type)
Creates a new dynamic array of ‘basic_type’.
static int mapedit_mapsList_refresh(void)
Gets the list of all the maps names. from outfit_mapParse()
static void mapedit_focusLose(unsigned int wid, const char *wgtname)
Called when it's de-focused.
static int mapedit_keys(unsigned int wid, SDL_Keycode key, SDL_Keymod mod, int isrepeat)
Handles keybindings.
static void mapedit_buttonZoom(unsigned int wid, const char *str)
Handles the button zoom clicks.
static void mapedit_selectRm(StarSystem *sys)
Removes a system from the selection.
static void mapedit_btnOpen(unsigned int wid_unused, const char *unused)
Opens up a map file.
void mapedit_open(unsigned int wid_unused, const char *unused)
Opens the system editor interface.
static unsigned int mapedit_wid
static char * mapedit_sLoadMapName
#define MAPEDIT_OPEN_WIDTH
static StarSystem ** mapedit_sys
static void mapedit_loadMapMenu_update(unsigned int wdw, const char *str)
Updates the load menu.
static int mapedit_nospob
static void mapedit_loadMapMenu_load(unsigned int wdw, const char *str)
Load the selected Map.
static int mapedit_hidden
static double mapedit_zoom
static int mapedit_mouse(unsigned int wid, const SDL_Event *event, double mx, double my, double w, double h, double xr, double yr, void *data)
System editor custom widget mouse handling.
static int mapedit_saveMap(StarSystem **uniedit_sys, mapOutfitsList_t *ns)
Saves selected systems as a map outfit file.
static unsigned int mapedit_widLoad
static void mapedit_btnSaveMapAs(unsigned int wid_unused, const char *unused)
Save the current Map to selected file.
#define MAPEDIT_OPEN_TXT_WIDTH
void mapedit_selectText(void)
Sets the selected system text.
static double mapedit_xpos
static void mapedit_loadMapMenu_close(unsigned int wdw, const char *str)
Closes the load map outfit menu.
StarSystem * systems_stack
static void mapedit_selectAdd(StarSystem *sys)
Adds a system to the selection.
static void mapsList_free(void)
Frees the loaded map.
void mapedit_setGlobalLoadedInfos(mapOutfitsList_t *ns)
Set and display the global variables describing last loaded/saved file.
static void mapedit_loadMapMenu_open(void)
Opens the load map outfit menu.
static unsigned int mapedit_dragTime
static int mapedit_iLastClickedSystem
static void mapedit_clear(unsigned int wid_unused, const char *unused)
Closes the system editor widget.
#define MAPEDIT_OPEN_HEIGHT
static void mapedit_deselect(void)
Deselects selected targets.
static double mapedit_ypos
static void mapedit_render(double bx, double by, double w, double h, void *data)
System editor custom widget rendering.
#define MAPEDIT_ZOOM_STEP
static void mapedit_close(unsigned int wid, const char *wgt)
Closes the system editor widget.
static StarSystem ** uniedit_sys
Header file with generic functions and naev-specifics.
int scnprintf(char *text, size_t maxlen, const char *fmt,...)
Like snprintf(), but returns the number of characters ACTUALLY "printed" into the buffer....
void xmlw_setParams(xmlTextWriterPtr writer)
Sets up the standard xml write parameters.
xmlDocPtr xml_parsePhysFS(const char *filename)
Analogous to xmlParseMemory/xmlParseFile.
void gl_renderCircle(double cx, double cy, double r, const glColour *c, int filled)
Draws a circle.
void pause_game(void)
Pauses the game.
void unpause_game(void)
Unpauses the game.
void systems_reconstructJumps(void)
Reconstructs the jumps.
StarSystem * system_getIndex(int id)
Get the system by its index.
void diff_clear(void)
Removes all active diffs. (Call before economy_destroy().)