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
63#define MAPEDIT_FILENAME_MAX 128
64#define MAPEDIT_NAME_MAX 128
65#define MAPEDIT_DESCRIPTION_MAX 1024
67typedef struct mapOutfitsList_s {
104static void mapedit_render(
double bx,
double by,
double w,
double h,
void *data );
106static int mapedit_mouse(
unsigned int wid, SDL_Event* event,
double mx,
double my,
107 double w,
double h,
double xr,
double yr,
void *data );
109static void mapedit_close(
unsigned int wid,
const char *wgt );
110static void mapedit_btnOpen(
unsigned int wid_unused,
const char *unused );
112static void mapedit_clear(
unsigned int wid_unused,
const char *unused );
114static int mapedit_keys(
unsigned int wid, SDL_Keycode key, SDL_Keymod mod );
158 wid =
window_create(
"wdwMapOutfitEditor", _(
"Map Outfit Editor"), -1, -1, -1, -1 );
163 window_addCust( wid, 20, -40, SCREEN_W - 350, SCREEN_H - 100,
188 window_addText( wid, -200, -40-textPos*parHeight-linesPos*lineHeight, 100, lineHeight, 0,
"txtSFileName",
190 window_addInput( wid, -30, -40-textPos*parHeight-linesPos*lineHeight, 170, lineHeight,
"inpFileName",
196 window_addText( wid, -200, -40-textPos*parHeight-linesPos*lineHeight, 100, lineHeight, 0,
"txtSMapName",
198 window_addInput( wid, -30, -40-textPos*parHeight-(linesPos+1)*lineHeight, 170, lineHeight,
"inpMapName",
205 window_addText( wid, -20, -40-textPos*parHeight-linesPos*lineHeight, 300-20, lineHeight, 0,
"txtSDescription",
207 window_addInput( wid, -20, -40-textPos*parHeight-(linesPos+1)*lineHeight, 300-20, curLines*lineHeight,
"inpDescription",
210 linesPos+=(curLines+1);
214 window_addText( wid, -20, -40-textPos*parHeight-linesPos*lineHeight, 300-20, 20, 0,
"txtSCurrentNumSystems",
215 &
gl_smallFont, NULL,
"Number of Systems (up to 100):" );
216 window_addText( wid, -20, -40-textPos*parHeight-linesPos*lineHeight, 60, curLines*lineHeight, 0,
"txtCurrentNumSystems",
223 window_addText( wid, -20, -40-textPos*parHeight-linesPos*lineHeight, 300-20, 20, 0,
"txtSPresence",
225 window_addText( wid, -20, -40-textPos*parHeight-(linesPos+1)*lineHeight, 300-20, curLines*lineHeight, 0,
"txtPresence",
228 linesPos+=curLines+1;
232 window_addText( wid, -200, -40-textPos*parHeight-linesPos*lineHeight, 100, 20, 0,
"txtSPrice",
234 window_addInput( wid, -30, -40-textPos*parHeight-linesPos*lineHeight, 170, lineHeight,
"inpPrice",
236 window_setInputFilter( wid,
"inpPrice", INPUT_FILTER_NUMBER );
238 linesPos+=curLines+1;
241 window_addText( wid, -200, -40-textPos*parHeight-linesPos*lineHeight, 100, 20, 0,
"txtSRarity",
243 window_addInput( wid, -30, -40-textPos*parHeight-linesPos*lineHeight, 170, lineHeight,
"inpRarity",
245 window_setInputFilter( wid,
"inpRarity", INPUT_FILTER_NUMBER );
247 linesPos+=curLines+1;
250 window_addText( wid, -20, -40-textPos*parHeight-linesPos*lineHeight, 300-20, curLines*lineHeight, 0,
"txtSWarning",
252 "Warning: Editor can't (yet) manage which details are mapped within a system. Review its changes before committing." );
254 linesPos+=curLines+1;
257 window_addButtonKey( wid, 40, 20, 30, 30,
"btnZoomIn",
"+",
mapedit_buttonZoom, SDLK_EQUALS );
258 window_addButtonKey( wid, 80, 20, 30, 30,
"btnZoomOut",
"-",
mapedit_buttonZoom, SDLK_MINUS );
261 window_addText( wid, 140, 10, SCREEN_W - 350 - 30 - 30 -
BUTTON_WIDTH - 20, 30, 0,
271static int mapedit_keys(
unsigned int wid, SDL_Keycode key, SDL_Keymod mod )
332static void mapedit_render(
double bx,
double by,
double w,
double h,
void *data )
340 uniedit_renderMap( bx, by, w, h, x, y,
mapedit_zoom, r );
376static int mapedit_mouse(
unsigned int wid, SDL_Event* event,
double mx,
double my,
377 double w,
double h,
double xr,
double yr,
void *data )
380 const double t = 15.*15.;
382 switch (event->type) {
385 if ((mx < 0.) || (mx > w) || (my < 0.) || (my > h))
387 if (event->wheel.y > 0)
389 else if (event->wheel.y < 0)
393 case SDL_MOUSEBUTTONDOWN:
395 if ((mx < 0.) || (mx > w) || (my < 0.) || (my > h))
400 if (event->button.button == SDL_BUTTON_X1) {
404 else if (event->button.button == SDL_BUTTON_X2) {
454 case SDL_MOUSEBUTTONUP:
459 case SDL_MOUSEMOTION:
491 window_modifyText(
mapedit_wid,
"txtSelected",
"No selection" );
492 window_modifyText(
mapedit_wid,
"txtCurrentNumSystems",
"0" );
541 char buf[STRMAX_SHORT];
555 window_modifyText(
mapedit_wid,
"txtSelected", buf );
559 window_modifyText(
mapedit_wid,
"txtCurrentNumSystems", buf );
564 map_updateFactionPresence(
mapedit_wid,
"txtPresence", sys, 1 );
565 snprintf( &buf[0],
sizeof(buf),
"Presence (%s)", sys->name );
566 window_modifyText(
mapedit_wid,
"txtSPresence", buf );
568 window_modifyText(
mapedit_wid,
"txtSPresence",
"Presence" );
569 window_modifyText(
mapedit_wid,
"txtPresence",
"No system yet clicked" );
588 if (strcmp(str,
"btnZoomIn")==0) {
592 else if (strcmp(str,
"btnZoomOut")==0) {
626 names = malloc(
sizeof(
char*)*n );
627 for (
int i=0; i<n; i++) {
629 names[i] = strdup(ns->mapName);
634 names = malloc(
sizeof(
char*));
635 names[0] = strdup(
"None");
641 0,
"txtMapInfo", NULL, NULL, NULL );
667 char buf[STRMAX_SHORT];
670 save = toolkit_getList( wdw,
"lstMapOutfits" );
671 if (strcmp(save,
"None") == 0)
675 pos = toolkit_getListPos( wdw,
"lstMapOutfits" );
679 snprintf( buf,
sizeof(buf),
688 ns->fileName, ns->mapName, ns->description, ns->numSystems
691 window_modifyText( wdw,
"txtMapInfo", buf );
711 int pos, len, compareLimit, i, found;
714 char *file, *name, *systemName;
722 save = toolkit_getList( wdw,
"lstMapOutfits" );
723 if (strcmp(save,
"None") == 0)
727 pos = toolkit_getListPos( wdw,
"lstMapOutfits" );
731 len = strlen(MAP_DATA_PATH)+strlen(ns->fileName)+2;
732 file = malloc( len );
733 snprintf( file, len,
"%s%s", MAP_DATA_PATH, ns->fileName );
738 node = doc->xmlChildrenNode;
745 if (!xml_isNode(node,
"outfit")) {
752 xmlr_attr_strd(node,
"name", name);
753 if (strcmp(ns->mapName, name)!=0) {
764 node = node->xmlChildrenNode;
768 if (!xml_isNode(node,
"specific"))
773 }
while (xml_nextNode(node));
778 node = node->xmlChildrenNode;
782 if (!xml_isNode(node,
"sys"))
786 xmlr_attr_strd(node,
"name", systemName);
792 compareLimit = strlen(systemName);
793 if (strncmp(systemName, sys->name, compareLimit)==0) {
804 }
while (xml_nextNode(node));
822 ns.fileName = strdup( window_getInput( wdw,
"inpFileName" ) );
823 ns.mapName = strdup( window_getInput( wdw,
"inpMapName" ) );
824 ns.description = strdup( window_getInput( wdw,
"inpDescription" ) );
826 ns.price = atoll(window_getInput( wdw,
"inpPrice" ));
827 ns.rarity = atoi(window_getInput( wdw,
"inpRarity" ));
833 free( ns.description );
844 window_setInput(
mapedit_wid,
"inpFileName", ns->fileName );
845 window_setInput(
mapedit_wid,
"inpMapName", ns->mapName );
846 window_setInput(
mapedit_wid,
"inpDescription", ns->description );
847 snprintf( buf,
sizeof(buf),
"%i", ns->numSystems );
848 window_modifyText(
mapedit_wid,
"txtCurrentNumSystems", buf );
849 snprintf( buf,
sizeof(buf),
"%"CREDITS_PRI, ns->price );
851 snprintf( buf,
sizeof(buf),
"%i", ns->rarity );
866 int is_map, nSystems;
867 xmlNodePtr node, cur;
870 char *file, *name, *outfitType;
876 map_files = PHYSFS_enumerateFiles( MAP_DATA_PATH );
878 for (
size_t i=0; map_files[i]!=NULL; i++) {
879 char *description = NULL;
880 credits_t price = 1000;
883 asprintf( &file,
"%s%s", MAP_DATA_PATH, map_files[i] );
892 node = doc->xmlChildrenNode;
899 if (!xml_isNode(node,
"outfit")) {
906 xmlr_attr_strd( node,
"name", name );
909 node = node->xmlChildrenNode;
914 if (!xml_isNode(node,
"specific")) {
915 if (xml_isNode(node,
"general")) {
916 cur = node->children;
919 xmlr_str(cur,
"description",description);
920 xmlr_long(cur,
"price",price);
921 xmlr_int(cur,
"rarity",rarity);
922 }
while (xml_nextNode(cur));
928 xmlr_attr_strd( node,
"type", outfitType );
929 is_map = outfitType == NULL ? 0 : !strncmp(outfitType,
"map", 3);
934 }
while (xml_nextNode(node));
946 node = node->xmlChildrenNode;
949 if (!xml_isNode(node,
"sys"))
954 }
while (xml_nextNode(node));
959 newMapItem->numSystems = nSystems;
960 newMapItem->fileName = strdup( map_files[ i ] );
961 newMapItem->mapName = strdup( name );
962 newMapItem->description = strdup( description != NULL ? description :
"" );
963 newMapItem->price = price;
964 newMapItem->rarity = rarity;
973 PHYSFS_freeList( map_files );
984 for (
unsigned int i=0; i<n; i++) {
985 free( mapList[i].fileName );
986 free( mapList[i].mapName );
987 free( mapList[i].description );
1004 xmlTextWriterPtr writer;
1008 writer = xmlNewTextWriterDoc(&doc, 0);
1009 if (writer == NULL) {
1010 WARN(_(
"testXmlwriterDoc: Error creating the xml writer"));
1019 xmlw_startElem( writer,
"outfit" );
1022 xmlw_attr( writer,
"name",
"%s", ns->mapName );
1025 xmlw_startElem( writer,
"general" );
1026 xmlw_elem( writer,
"rarity",
"%d", ns->rarity );
1027 xmlw_elem( writer,
"mass",
"%d", 0 );
1028 xmlw_elem( writer,
"price",
"%"CREDITS_PRI, ns->price );
1029 xmlw_elem( writer,
"description",
"%s", ns->description );
1030 xmlw_elem( writer,
"gfx_store",
"%s",
"map.webp" );
1031 xmlw_endElem( writer );
1033 xmlw_startElem( writer,
"specific" );
1034 xmlw_attr( writer,
"type",
"map" );
1037 for (
int i=0; i < ns->numSystems; i++) {
1039 xmlw_startElem( writer,
"sys" );
1040 xmlw_attr( writer,
"name",
"%s", s->name );
1043 for (
int j=0; j <
array_size(s->jumps); j++) {
1045 if (jp_isFlag(&s->jumps[j], JP_EXITONLY ))
1047 if (jp_isFlag(&s->jumps[j], JP_HIDDEN))
1050 for (
int k=0; k < ns->numSystems; k++) {
1052 xmlw_elem( writer,
"jump",
"%s",
uniedit_sys[k]->name );
1060 xmlw_elem( writer,
"spob",
"%s", s->spobs[j]->name );
1062 xmlw_endElem( writer );
1065 xmlw_endElem( writer );
1066 xmlw_endElem( writer );
1070 xmlFreeTextWriter(writer);
1074 if (xmlSaveFileEnc( file, doc,
"UTF-8" ) < 0)
1075 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 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 int mapedit_keys(unsigned int wid, SDL_Keycode key, SDL_Keymod mod)
Handles keybindings.
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 void mapedit_loadMapMenu_load(unsigned int wdw, const char *str)
Load the selected Map.
static double mapedit_zoom
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 int mapedit_mouse(unsigned int wid, SDL_Event *event, double mx, double my, double w, double h, double xr, double yr, void *data)
System editor custom widget mouse handling.
static void 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 asprintf(char **strp, const char *fmt,...)
Like sprintf(), but it allocates a large-enough string and returns the pointer in the first argument....
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().)