Skip to content

Commit

Permalink
patch #3167, forum #55346: Show marks on all tab maps, not just curre…
Browse files Browse the repository at this point in the history
…nt map. Thanks sir_odie.
  • Loading branch information
pjbroad committed May 31, 2011
1 parent 6b68c2f commit 2b29b9d
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 100 deletions.
175 changes: 100 additions & 75 deletions interface.c
Expand Up @@ -693,14 +693,105 @@ CHECK_GL_ERRORS();
#endif /* NEW_TEXTURES */
}

static void draw_mark_filter(void)
{
int screen_x=0;
int screen_y=0;

// display the Mark filter title
glColor3f(1.0f,1.0f,0.0f);
screen_x = 25 - 1.5*strlen(label_mark_filter);
screen_y = 150 + 22;
draw_string_zoomed(screen_x, screen_y, (unsigned char*)label_mark_filter, 1, 0.3);

// if filtering marks, display the label and the current filter text
if (mark_filter_active) {
char * show_mark_filter_text;
int max_show_len = 15;
if (strlen(mark_filter_text) > max_show_len)
show_mark_filter_text = &mark_filter_text[strlen(mark_filter_text)-max_show_len];
else if (strlen(mark_filter_text) == 0)
show_mark_filter_text = "_";
else
show_mark_filter_text = mark_filter_text;
screen_x = 25 - 1.5*strlen(show_mark_filter_text);
screen_y = 150 + 29;
draw_string_zoomed(screen_x, screen_y, (unsigned char*)show_mark_filter_text, 1, 0.3);
}
// display which key to activate the filter
else
{
char buf[20];
get_key_string(K_MARKFILTER, buf, sizeof(buf));
draw_string_zoomed(25 - 1.5*strlen(buf), 150 + 29, (const unsigned char *)buf, 1, 0.3);
}
}

static void draw_marks(marking *the_marks, int the_max_mark, int the_tile_map_size_x, int the_tile_map_size_y)
{
size_t i;
int screen_x=0;
int screen_y=0;

// crave the markings
for(i=0;i<the_max_mark;i++)
{
int x = the_marks[i].x;
int y = the_marks[i].y;
if ( x > 0 ) {

// if filtering marks, don't display if it doesn't match the current filter
if (mark_filter_active
&& (get_string_occurance(mark_filter_text, the_marks[i].text, strlen(the_marks[i].text), 1) == -1))
continue;

screen_x=(51+200*x/(the_tile_map_size_x*6));
screen_y=201-200*y/(the_tile_map_size_y*6);

if(!the_marks[i].server_side) glColor3f((float)the_marks[i].r/255,(float)the_marks[i].g/255,(float)the_marks[i].b/255);//glColor3f(0.4f,1.0f,0.0f);
else glColor3f(0.33f,0.6f,1.0f);
glDisable(GL_TEXTURE_2D);
glBegin(GL_LINES);
glVertex2i(screen_x-9*mapmark_zoom,screen_y-9*mapmark_zoom);
glVertex2i(screen_x+6*mapmark_zoom,screen_y+6*mapmark_zoom);

glVertex2i(screen_x+6*mapmark_zoom,screen_y-9*mapmark_zoom);
glVertex2i(screen_x-9*mapmark_zoom,screen_y+6*mapmark_zoom);
glEnd();
glEnable(GL_TEXTURE_2D);
if(!the_marks[i].server_side) glColor3f((float)the_marks[i].r/255,(float)the_marks[i].g/255,(float)the_marks[i].b/255);//glColor3f(0.2f,1.0f,0.0f);
else glColor3f(0.33f,0.6f,1.0f);
draw_string_zoomed(screen_x, screen_y, (unsigned char*)the_marks[i].text, 1, mapmark_zoom);
}
}
}

void draw_coordinates(int the_tile_map_size_x, int the_tile_map_size_y)
{
int screen_x=0;
int screen_y=0;
int map_x, map_y;

// draw coordinates
if (pf_get_mouse_position_extended(mouse_x, mouse_y, &map_x, &map_y, the_tile_map_size_x, the_tile_map_size_y)) {
// we're pointing on the map, display position
char buf[10];
safe_snprintf(buf, sizeof(buf), "%d,%d", map_x, map_y);
glColor3f(1.0f,1.0f,0.0f);
screen_x = 25 - 1.5*strlen(buf);
screen_y = 150 + 8;
draw_string_zoomed(screen_x, screen_y, (unsigned char*)buf, 1, 0.3);
screen_x = 25 - 1.5*strlen(label_cursor_coords);
screen_y = 150 + 1;
draw_string_zoomed(screen_x, screen_y, (unsigned char*)label_cursor_coords, 1, 0.3);
}
}

void draw_game_map (int map, int mouse_mini)
{
int screen_x=0;
int screen_y=0;
int map_x, map_y;
int x=-1,y=-1;
int i;
float x_size=0,y_size=0;
GLuint map_small, map_large;
actor *me;
Expand Down Expand Up @@ -888,80 +979,14 @@ void draw_game_map (int map, int mouse_mini)
draw_string_zoomed (screen_x, screen_y, (unsigned char*)input_text_line.data, 1, mapmark_zoom);
}

draw_mark_filter();
if(inspect_map_text == 0) {
// display the Mark filter title
glColor3f(1.0f,1.0f,0.0f);
screen_x = 25 - 1.5*strlen(label_mark_filter);
screen_y = 150 + 22;
draw_string_zoomed(screen_x, screen_y, (unsigned char*)label_mark_filter, 1, 0.3);

// if filtering marks, display the label and the current filter text
if (mark_filter_active) {
char * show_mark_filter_text;
int max_show_len = 15;
if (strlen(mark_filter_text) > max_show_len)
show_mark_filter_text = &mark_filter_text[strlen(mark_filter_text)-max_show_len];
else if (strlen(mark_filter_text) == 0)
show_mark_filter_text = "_";
else
show_mark_filter_text = mark_filter_text;
screen_x = 25 - 1.5*strlen(show_mark_filter_text);
screen_y = 150 + 29;
draw_string_zoomed(screen_x, screen_y, (unsigned char*)show_mark_filter_text, 1, 0.3);
}
// display which key to activate the filter
else
{
char buf[20];
get_key_string(K_MARKFILTER, buf, sizeof(buf));
draw_string_zoomed(25 - 1.5*strlen(buf), 150 + 29, (const unsigned char *)buf, 1, 0.3);
}

// crave the markings
for(i=0;i<max_mark;i++)
{
int x = marks[i].x;
int y = marks[i].y;
if ( x > 0 ) {

// if filtering marks, don't display if it doesn't match the current filter
if (mark_filter_active
&& (get_string_occurance(mark_filter_text, marks[i].text, strlen(marks[i].text), 1) == -1))
continue;

screen_x=(51+200*x/(tile_map_size_x*6));
screen_y=201-200*y/(tile_map_size_y*6);

if(!marks[i].server_side) glColor3f((float)marks[i].r/255,(float)marks[i].g/255,(float)marks[i].b/255);//glColor3f(0.4f,1.0f,0.0f);
else glColor3f(0.33f,0.6f,1.0f);
glDisable(GL_TEXTURE_2D);
glBegin(GL_LINES);
glVertex2i(screen_x-9*mapmark_zoom,screen_y-9*mapmark_zoom);
glVertex2i(screen_x+6*mapmark_zoom,screen_y+6*mapmark_zoom);

glVertex2i(screen_x+6*mapmark_zoom,screen_y-9*mapmark_zoom);
glVertex2i(screen_x-9*mapmark_zoom,screen_y+6*mapmark_zoom);
glEnd();
glEnable(GL_TEXTURE_2D);
if(!marks[i].server_side) glColor3f((float)marks[i].r/255,(float)marks[i].g/255,(float)marks[i].b/255);//glColor3f(0.2f,1.0f,0.0f);
else glColor3f(0.33f,0.6f,1.0f);
draw_string_zoomed(screen_x, screen_y, (unsigned char*)marks[i].text, 1, mapmark_zoom);
}
}

// draw coordinates
if (pf_get_mouse_position(mouse_x, mouse_y, &map_x, &map_y)) {
// we're pointing on the map, display position
char buf[10];
safe_snprintf(buf, sizeof(buf), "%d,%d", map_x, map_y);
glColor3f(1.0f,1.0f,0.0f);
screen_x = 25 - 1.5*strlen(buf);
screen_y = 150 + 8;
draw_string_zoomed(screen_x, screen_y, (unsigned char*)buf, 1, 0.3);
screen_x = 25 - 1.5*strlen(label_cursor_coords);
screen_y = 150 + 1;
draw_string_zoomed(screen_x, screen_y, (unsigned char*)label_cursor_coords, 1, 0.3);
}
draw_marks(marks, max_mark, tile_map_size_x, tile_map_size_y);
draw_coordinates(tile_map_size_x, tile_map_size_y);
}
else {
draw_marks(temp_marks, max_temp_mark, temp_tile_map_size_x, temp_tile_map_size_y);
draw_coordinates(temp_tile_map_size_x, temp_tile_map_size_y);
}
}

Expand Down
22 changes: 22 additions & 0 deletions io/map_io.c
Expand Up @@ -24,6 +24,28 @@ float offset_2d = (1.0f / 32768.0f);
const float offset_2d_max = 0.01f;
#endif

int get_tile_map_sizes(const char *file_name, int *x, int *y)
{
map_header cur_map_header;
char* file_mem;
el_file_ptr file;

file = el_open(file_name);

if (!file)
{
return 0;
}

file_mem = el_get_pointer(file);

memcpy(&cur_map_header, file_mem, sizeof(cur_map_header));
*x = SDL_SwapLE32(cur_map_header.tile_map_x_len);
*y = SDL_SwapLE32(cur_map_header.tile_map_y_len);
el_close(file);
return 1;
}

static int do_load_map(const char *file_name, update_func *update_function)
{
int i;
Expand Down
14 changes: 14 additions & 0 deletions io/map_io.h
Expand Up @@ -250,6 +250,20 @@ typedef void (update_func) (char *str, float percent);
*/
int load_map(const char * file_name, update_func *update_function);

/**
* @ingroup maps
* @brief Reads the tilemap sizes of the map given by \a file_name
*
* Reads the tilemap sizes of the map given by \a file_name.
*
* @param file_name the filename of the map to read.
* @param x x-part of the tilemap size
* @param y y-part od the tilemap size
* @retval int 0, if the file given by \a file_name could not be opened, or if the file is invalid, i.e. has an invalid magic number, else 1 is returned.
* @callgraph
*/
int get_tile_map_sizes(const char * file_name, int *x, int *y);

#ifdef __cplusplus
} // extern "C"
#endif
Expand Down
39 changes: 19 additions & 20 deletions map.c
Expand Up @@ -379,51 +379,43 @@ void add_server_markers(){
}
}


void load_map_marks()
void load_marks_to_buffer(char* mapname, marking* buffer, int* max)
{
FILE * fp = NULL;
char marks_file[256] = {0}, text[600] = {0};
char *mapname = strrchr (map_file_name,'/');

if(mapname == NULL) {
//Oops
return;
}
safe_snprintf (marks_file, sizeof (marks_file), "maps/%s.txt", mapname + 1);
safe_snprintf (marks_file, sizeof (marks_file), "%s.txt", mapname + 1);
fp = open_file_config(marks_file, "r");
if(fp == NULL){
//TODO: remove this after the next update. Until then, people may still have files in the old location.
safe_snprintf (marks_file, sizeof (marks_file), "%s.txt", mapname + 1);
fp = open_file_config(marks_file, "r");
}
max_mark = 0;
*max = 0;

if (fp == NULL) { add_server_markers(); return;}
if (fp == NULL) return;


//load user markers
while ( fgets(text, 600,fp) ) {
if (strlen (text) > 1) {
int r,g,b;
sscanf (text, "%d %d", &marks[max_mark].x, &marks[max_mark].y);
sscanf (text, "%d %d", &buffer[*max].x, &buffer[*max].y);
//scanning mark color. It can be optional -> default=green
if(sscanf(text,"%*d %*d|%d,%d,%d|",&r,&g,&b)<3) { //NO SPACES in RGB format string!
r=b=0;
g=255;
}
marks[max_mark].server_side=0;
buffer[*max].server_side=0;
text[strlen(text)-1] = '\0'; //remove the newline
if ((strstr(text, " ") == NULL) || (strstr(strstr(text, " ")+1, " ") == NULL)) {
LOG_ERROR("Bad map mark file=[%s] text=[%s]", marks_file, text);
}
else {
safe_strncpy(marks[max_mark].text, strstr(strstr(text, " ")+1, " ") + 1, sizeof(marks[max_mark].text));
marks[max_mark].r=r;
marks[max_mark].g=g;
marks[max_mark].b=b;
max_mark++;
if ( max_mark > MAX_USER_MARKS ) break;
safe_strncpy(buffer[*max].text, strstr(strstr(text, " ")+1, " ") + 1, sizeof(buffer[*max].text));
buffer[*max].r=r;
buffer[*max].g=g;
buffer[*max].b=b;
*max = *max + 1;
if ( *max > MAX_USER_MARKS ) break;
}
}
}
Expand All @@ -432,6 +424,13 @@ void load_map_marks()

LOG_DEBUG("Read map markings from file '%s'", marks_file);

}

void load_map_marks()
{
//load user markers
load_marks_to_buffer(map_file_name, marks, &max_mark);

//load server markers on this map
add_server_markers();

Expand Down
17 changes: 15 additions & 2 deletions map.h
Expand Up @@ -10,6 +10,7 @@
#include "io/map_io.h"

#include "hash.h"
#include "mapwin.h"

#ifdef __cplusplus
extern "C" {
Expand Down Expand Up @@ -51,9 +52,21 @@ void change_map (const char * mapname);

/**
* @ingroup maps
* @brief Loads the given map marks for the given map
* @brief Loads the map marks for the given mapname into the given buffer
*
* Loads the map marks for the given map
* Loads the map marks for the given \a mapname into the given \a buffer
*
* @param mapname filename of the map
* @param buffer buffer for the map marks
* @param max maximum number of map marks in \a buffer
*/
void load_marks_to_buffer(char* mapname, marking* buffer, int* max);

/**
* @ingroup maps
* @brief Loads the map marks for the current map
*
* Loads the map marks for the current map
*
*/
void load_map_marks(void);
Expand Down
8 changes: 8 additions & 0 deletions mapwin.c
Expand Up @@ -16,6 +16,7 @@
#include "init.h"
#include "interface.h"
#include "lights.h"
#include "map.h"
#include "missiles.h"
#include "new_character.h"
#include "pathfinder.h"
Expand All @@ -34,6 +35,11 @@ int mouse_over_minimap = 0;

int reload_tab_map = 0;

int temp_tile_map_size_x = 0;
int temp_tile_map_size_y = 0;
int max_temp_mark = 0;
marking temp_marks[MAX_USER_MARKS];

#define MARK_FILTER_MAX_LEN 40
int mark_filter_active = 0;
char mark_filter_text[MARK_FILTER_MAX_LEN] = "";
Expand Down Expand Up @@ -114,6 +120,8 @@ int click_map_handler (window_info *win, int mx, int my, Uint32 flags)
#ifdef DEBUG_MAP_SOUND
cur_tab_map = i;
#endif // DEBUG_MAP_SOUND
load_marks_to_buffer(continent_maps[i].name, temp_marks, &max_temp_mark);
get_tile_map_sizes(continent_maps[i].name, &temp_tile_map_size_x, &temp_tile_map_size_y);
showing_continent = !showing_continent;
break;
}
Expand Down
4 changes: 4 additions & 0 deletions mapwin.h
Expand Up @@ -36,7 +36,11 @@ typedef struct
extern int adding_mark; /*!< flag that indicates we are currently adding a mark to a map */
extern int mark_x, mark_y; /*!< map coordinates of the position of the mark */
extern int max_mark; /*!< max. number of marks we can handle */
extern int max_temp_mark; /*!< max. number of temporary marks we can handle */
extern int temp_tile_map_size_x; /*!< The tile map size in the x direction */
extern int temp_tile_map_size_y; /*!< The tile map size in the y direction */
extern marking marks[MAX_MARKINGS]; /*!< a global array of marks */
extern marking temp_marks[MAX_USER_MARKS]; /*!< a global array of temporary marks */
extern int curmark_r,curmark_g,curmark_b; //current mark color

extern int reload_tab_map; /*!< flag that indicates the tabmap needs to be reloaded */
Expand Down

0 comments on commit 2b29b9d

Please sign in to comment.