diff --git a/ToDo b/ToDo index 16e5fe3..12cfa0f 100644 --- a/ToDo +++ b/ToDo @@ -1,4 +1,3 @@ * Mouse support * In game lobby - * In network lobby * In game ;) diff --git a/about.c b/about.c index ac80c60..c1f4a52 100644 --- a/about.c +++ b/about.c @@ -62,9 +62,9 @@ void help_draw(void) help_button[2].h = help_font->maxheight; help_button[2].x = 2+spGetWindowSurface()->w*5/6; help_button[2].y = spGetWindowSurface()->h-2-2*help_font->maxheight; - int width = help_button[2].w + B4; - int height = help_font->maxheight + B4; - draw_edgy_rectangle(help_button[2].x,help_button[2].y,width,height,B0,B1,B2); + int width = help_button[2].w; + int height = help_font->maxheight; + draw_edgy_rectangle(help_button[2].x,help_button[2].y,&width,&height,B0,B1,B2,B4); spFontDraw( help_button[2].x, help_button[2].y, 0, button_text, help_font ); } else @@ -81,9 +81,9 @@ void help_draw(void) help_button[1].h = help_font->maxheight; help_button[1].x = 2+spGetWindowSurface()->w*5/6; help_button[1].y = 2+ help_font->maxheight; - int width = help_button[1].w + B4; - int height = help_font->maxheight + B4; - draw_edgy_rectangle(help_button[1].x,help_button[1].y,width,height,B0,B1,B2); + int width = help_button[1].w; + int height = help_font->maxheight; + draw_edgy_rectangle(help_button[1].x,help_button[1].y,&width,&height,B0,B1,B2,B4); spFontDraw( help_button[1].x, help_button[1].y, 0, button_text, help_font ); } else @@ -98,9 +98,9 @@ void help_draw(void) help_button[0].h = help_font->maxheight; help_button[0].x = spGetWindowSurface()->w/2 - help_button[0].w/2; help_button[0].y = spGetWindowSurface()->h-B4-help_font->maxheight; - int width = help_button[0].w + B4; - int height = help_font->maxheight + B4; - draw_edgy_rectangle(help_button[0].x,help_button[0].y,width,height,B0,B1,B2); + int width = help_button[0].w; + int height = help_font->maxheight; + draw_edgy_rectangle(help_button[0].x,help_button[0].y,&width,&height,B0,B1,B2,B4); spFontDraw( help_button[0].x, help_button[0].y, 0, button_text, help_font ); spFlip(); } diff --git a/lobbyGame.c b/lobbyGame.c index 4ab8c3f..da9babc 100644 --- a/lobbyGame.c +++ b/lobbyGame.c @@ -1,7 +1,6 @@ #include "lobbyGame.h" #include "level.h" #include -#include "window.h" #include "options.h" #include "client.h" @@ -35,8 +34,102 @@ int level_mode; int use_chat; int after_start; +tLobbyButton lg_button[ SP_MAPPING_MAX + 4 ]; + #define CHAT_LINES 8 +void lobby_draw_buttons(window_text_positon position, int x, int y, char const * const text__,spFontPointer font,pLobbyButton button) +{ + int l = strlen(text__); + char text_buffer[l+1]; + memcpy(text_buffer,text__,(l+1)*sizeof(char)); + char* text = text_buffer; + int width = spFontWidth( text, font ); + switch (position) + { + case LEFT: + break; + case MIDDLE: + x -= width/2; + break; + case RIGHT: + x -= width; + break; + } + int i = -1; + int in_button = 0; + do + { + ++i; + int draw_text = 0; + if (!in_button && (text[i] == '{' || text[i] == '[')) + { + in_button = 1; + draw_text = i > 0; + } + if (in_button && ((text[i] == ' ' && text[i+1] == ' ') || text[i] == 0)) + { + in_button = 0; + draw_text = i > 0; + } + else + if (text[i] == 0) + { + in_button = 1; + draw_text = i > 0; + } + if (draw_text) + { + char temp = text[i]; + text[i] = 0; + if (!in_button) + { + int B0 = spMax(spGetSizeFactor()>>17,1); + int B1 = spMax(spGetSizeFactor()>>16,1); + int B2 = spMax(spGetSizeFactor()>>15,1); + int B4 = spMax(spGetSizeFactor()>>14,1); + width = spFontWidth( text, font ) + B4; + int height = font->maxheight; + draw_edgy_rectangle(x,y,&width,&height,B0,B1,B2,B4); + int j = 0; + for (; text[j] && text[j] != '}' && text[j] != ']';j++); + if (text[j]) + { + char temp2 = text[j]; + text[j] = 0; + int id = -1; + if (temp2 == '}') + id = spMapIDByName( &(text[1]) ); + else // ] + { + switch (text[j-1]) + { + case '<': id = SP_MAPPING_MAX+0; break; + case '^': id = SP_MAPPING_MAX+1; break; + case '>': id = SP_MAPPING_MAX+2; break; + case 'v': id = SP_MAPPING_MAX+3; break; + } + } + if ( id >= 0 ) + { + button[id].x = x; + button[id].y = y; + button[id].w = width; + button[id].h = height; + } + text[j] = temp2; + } + } + spFontDraw( x, y, 0, text, font ); + x += spFontWidth( text, font ); + text[i] = temp; + text = &(text[i]); + i = -1; + } + } + while (text[i]); +} + void lg_draw(void) { SDL_Surface* screen = spGetWindowSurface(); @@ -1228,6 +1321,14 @@ int game_options(Uint32 *game_opt,int* game_seconds,int* game_hares,spFontPointe int start_lobby_game(spFontPointer font, void ( *resize )( Uint16 w, Uint16 h ), pGame game,int spectate) { + int i = SP_MAPPING_MAX+4; + while (i --> 0 ) + { + lg_button[i].x = -1; + lg_button[i].y = -1; + lg_button[i].w = -1; + lg_button[i].h = -1; + } int result = 0; level_mode = 0; level_filename[0] = 0; diff --git a/lobbyGame.h b/lobbyGame.h index 967a524..7d64056 100644 --- a/lobbyGame.h +++ b/lobbyGame.h @@ -4,7 +4,18 @@ #include #include "lobbyList.h" #include "client.h" +#include "window.h" +typedef struct sLobbyButton *pLobbyButton; +typedef struct sLobbyButton +{ + int x; + int y; + int w; + int h; +} tLobbyButton; + +void lobby_draw_buttons(window_text_positon position, int x, int y, char const * const text__,spFontPointer font,pLobbyButton button); int game_options(Uint32 *game_opt,int* game_seconds,int* game_hares,spFontPointer font, void ( *resize )( Uint16 w, Uint16 h )); void save_level(char* level_string); int start_lobby_game(spFontPointer font, void ( *resize )( Uint16 w, Uint16 h ),pGame game,int spectate); diff --git a/lobbyList.c b/lobbyList.c index 7e80571..6dff8f0 100644 --- a/lobbyList.c +++ b/lobbyList.c @@ -25,6 +25,8 @@ int use_chat; pGame mom_game; +tLobbyButton ll_button[ SP_MAPPING_MAX ]; + #define LL_SURFACE_DIV 16 #define LL_MOM_PLAYER 11 #define LL_STATUS 13 @@ -90,14 +92,25 @@ void ll_draw(void) spClearTarget(LL_BG); char buffer[256]; + int i = SP_MAPPING_MAX; + while (i --> 0 ) + { + ll_button[i].x = -1; + ll_button[i].y = -1; + ll_button[i].w = -1; + ll_button[i].h = -1; + } + + int button_pos = spMax(spGetSizeFactor()>>15,1); + sprintf(buffer,"%i Games on Server (Version %i):\n",ll_game_count,CLIENT_VERSION); - spFontDrawMiddle( screen->w/3+2, 0*ll_font->maxheight, 0, buffer, ll_font ); - spBlitSurface(screen->w/3,ll_font->maxheight*1+ll_surface->h/2,0,ll_surface); + spFontDrawMiddle( screen->w/3+2, 0*ll_font->maxheight-2, 0, buffer, ll_font ); + spBlitSurface(screen->w/3,ll_font->maxheight*1+ll_surface->h/2-1,0,ll_surface); - spFontDrawMiddle(5*screen->w/6+4, 0*ll_font->maxheight, 0, "Preview & Players", ll_font ); - spRectangle(5*screen->w/6, 1*ll_font->maxheight+screen->w/6-4, 0,screen->w/3-6,screen->w/3-6,LL_FG); + spFontDrawMiddle(5*screen->w/6, 0*ll_font->maxheight-2, 0, "Preview & Players", ll_font ); + spRectangle(5*screen->w/6, ll_font->maxheight+screen->w/6-5, 0,screen->w/3-6,screen->w/3-6,LL_FG); if (ll_level) - spBlitSurface(5*screen->w/6, 1*ll_font->maxheight+screen->w/6-4, 0,ll_level); + spBlitSurface(5*screen->w/6, 1*ll_font->maxheight+screen->w/6-5, 0,ll_level); int h = screen->h-(screen->w/3+3*ll_font->maxheight-6); @@ -108,29 +121,31 @@ void ll_draw(void) spFontDrawMiddle(screen->w/2, screen->h-2*ll_font->maxheight-h/2, 0, "Connecting to IRC Server...", ll_font ); else { - spFontDrawMiddle(screen->w/2, 1*ll_font->maxheight+screen->w/3-6, 0, "{chat}Chat {power_down}/{power_up}scroll", ll_font ); - int rh = (h+3)/ll_font->maxheight*ll_font->maxheight; - spRectangle(screen->w/2, screen->h-1*ll_font->maxheight-h/2, 0,screen->w-4,rh,LL_FG); + int rh = (h+3)/ll_font->maxheight*ll_font->maxheight-button_pos*5 + (spGetSizeFactor()>>17)*3; + spRectangle(screen->w/2, screen->h-1*ll_font->maxheight-h/2-1, 0,screen->w-4,rh,LL_FG); if (ll_chat_block) spFontDrawTextBlock(left,2, screen->h-1*ll_font->maxheight-h-2+(h-rh)/2, 0,ll_chat_block,rh,ll_chat_scroll,ll_font); + const int button_y = ( + screen->h-1*ll_font->maxheight-h/2-1 - rh/2 + //chat window top + ll_font->maxheight+screen->w/6-5 + (screen->w/3-6) / 2 // preview window bottom + ) / 2 - ll_font->maxheight/2; + lobby_draw_buttons( MIDDLE, screen->w/2, button_y, "{chat}Chat {power_down}scroll up {power_up}scroll down", ll_font, ll_button ); } if (ll_game_count > 0 && mom_game && ll_block) { - //spFontDrawMiddle(5*screen->w/6+4, 2*ll_font->maxheight+screen->w/3-6, 0, "Players", ll_font ); - //spRectangle(5*screen->w/6, screen->h-1*ll_font->maxheight-h/2, 0,screen->w/3-6,h,LL_FG); - spFontDrawTextBlock(middle,4*screen->w/6+5, 1*ll_font->maxheight + 5 /*+ screen->w/6 - ll_block->line_count*ll_font->maxheight/2*/, 0,ll_block,screen->w/3-6,0,ll_font); + spFontDrawTextBlock(middle,4*screen->w/6+5, 1*ll_font->maxheight + 5, 0,ll_block,screen->w/3-6,0,ll_font); } - + if (ll_reload_now == 0) { if (mom_game && mom_game->status != 0) - spFontDraw( 2, screen->h-ll_font->maxheight, 0, "{jump}/{view}Show {weapon}Create {menu}Back", ll_font ); + lobby_draw_buttons( LEFT, 2, screen->h-ll_font->maxheight-button_pos, "{jump}/{view}Show {weapon}Create {menu}Back", ll_font, ll_button ); else - spFontDraw( 2, screen->h-ll_font->maxheight, 0, "{jump}Join {weapon}Create {view}Spectate {menu}Back", ll_font ); + lobby_draw_buttons( LEFT, 2, screen->h-ll_font->maxheight-button_pos, "{jump}Join {weapon}Create {view}Spectate {menu}Back", ll_font, ll_button); } else - spFontDraw( 2, screen->h-ll_font->maxheight, 0, "{menu}Back", ll_font ); + lobby_draw_buttons( LEFT, 2, screen->h-ll_font->maxheight-button_pos, "{menu}Back", ll_font, ll_button); if (ll_reload_now == 1) ll_reload_now = 2; @@ -138,7 +153,7 @@ void ll_draw(void) sprintf(buffer,"Reloading..."); else sprintf(buffer,"Next update: %is",(10000-ll_counter)/1000); - spFontDrawRight( screen->w-2, screen->h-ll_font->maxheight, 0, buffer, ll_font ); + spFontDrawRight( screen->w-2, screen->h-ll_font->maxheight-2, 0, buffer, ll_font ); spFlip(); } @@ -166,6 +181,24 @@ int create_game_feedback( pWindow window, pWindowElement elem, int action ) int ll_calc(Uint32 steps) { + if ( spGetInput()->touchscreen.pressed ) + { + int mx = spGetInput()->touchscreen.x; + int my = spGetInput()->touchscreen.y; + int i = SP_MAPPING_MAX; + while (i --> 0 ) + { + if ( ll_button[i].x + ll_button[i].w >= mx && + ll_button[i].x <= mx && + ll_button[i].y + ll_button[i].h >= my && + ll_button[i].y <= my ) + { + spMapSetByID( i, 1 ); + spGetInput()->touchscreen.pressed = 0; + break; + } + } + } try_to_join(); int CHAT_LINES = (spGetWindowSurface()->h-(spGetWindowSurface()->w/3+4*ll_font->maxheight-4))/ll_font->maxheight; if (ll_chat_block) @@ -480,6 +513,14 @@ int ll_reload(void* dummy) void start_lobby(spFontPointer font, void ( *resize )( Uint16 w, Uint16 h ), int start_chat) { + int i = SP_MAPPING_MAX; + while (i --> 0 ) + { + ll_button[i].x = -1; + ll_button[i].y = -1; + ll_button[i].w = -1; + ll_button[i].h = -1; + } use_chat = start_chat; char time_buffer[128]; time_t t = time(NULL); diff --git a/window.c b/window.c index 7a13f1a..9458468 100644 --- a/window.c +++ b/window.c @@ -69,7 +69,7 @@ pWindow create_window(int ( *feedback )( pWindow window, pWindowElement elem, in window->cancel_to_no = 0; window->zig_zag = 1; window->sizeFactor = spGetSizeFactor(); - int i = SP_MAPPING_MAX; + int i = SP_MAPPING_MAX+4; while (i --> 0 ) { window->button[i].x = -1; @@ -121,23 +121,18 @@ pWindowElement add_window_element(pWindow window,int type,int reference) pWindow recent_window = NULL; -typedef enum +void draw_edgy_rectangle(int x, int y, int * width, int * height, int B0, int B1, int B2,int B4) { - LEFT, - MIDDLE, - RIGHT -} window_text_positon; - -void draw_edgy_rectangle(int x, int y, int width, int height, int B0, int B1, int B2) -{ - int X = x + width/2 - B2; - int Y = y + height/2 - B2; - spRectangle ( X, Y, 0, width + B2 , height + B2, LL_BG); - spRectangleBorder( X, Y, 0, width , height , B1, B1, LL_FG); - spRectangle( x - B2, y - B2, 0, B0, B0, LL_BG ); - spRectangle( x + width - B2, y - B2, 0, B0, B0, LL_BG ); - spRectangle( x - B2, y + height - B2, 0, B0, B0, LL_BG ); - spRectangle( x + width - B2, y + height - B2, 0, B0, B0, LL_BG ); +// *height += 2*B1; + *width += 2*B2; + int Y; + for (Y = y; Y <= y + *height; ++Y) + { + int add = 0; + if (Y < y + B1 || Y > y + *height - B1) + add = B2; + spLine( x - B1 + add, Y, 0, x - B1 + *width - add, Y, 0, LL_FG ); + } } static void window_draw_buttons(window_text_positon position, int x, int y, char const * const text__) @@ -190,9 +185,9 @@ static void window_draw_buttons(window_text_positon position, int x, int y, char int B1 = spMax(spGetSizeFactor()>>16,1); int B2 = spMax(spGetSizeFactor()>>15,1); int B4 = spMax(spGetSizeFactor()>>14,1); - width = spFontWidth( text, recent_window->font ) + B4; - int height = recent_window->font->maxheight + B4; - draw_edgy_rectangle(x,y,width,height,B0,B1,B2); + width = spFontWidth( text, recent_window->font ); + int height = recent_window->font->maxheight; + draw_edgy_rectangle(x,y,&width,&height,B0,B1,B2,B4); int j = 0; for (; text[j] && text[j] != '}' && text[j] != ']';j++); if (text[j]) @@ -332,8 +327,8 @@ void window_draw(void) spFontDrawRight( t_r, y, 0, elem->text, window->font ); if (nr == window->selection && (elem->type == 0 || elem->type == 2)) { - window_draw_buttons( LEFT, t_r, y, " [>]" ); - window_draw_buttons( RIGHT, t_r - t_w, y, "[<] " ); + window_draw_buttons( LEFT, t_r, y+SMALL_HACK/2, " [>]" ); + window_draw_buttons( RIGHT, t_r - t_w, y+SMALL_HACK/2, "[<] " ); } elem->button.type = 0; } @@ -381,8 +376,7 @@ void window_draw(void) spFontDrawMiddle( screen->w/2, y, 0, buffer, window->font); } - - y = (screen->h + window->height) / 2 - meow - 3*window->font->maxheight/2-SMALL_HACK/2 + extra_y; + y = (screen->h + window->height) / 2 - meow - 3*window->font->maxheight/2-SMALL_HACK/2 + extra_y + 1; if (selElem) { switch (selElem->type) diff --git a/window.h b/window.h index 39160f4..c9bede9 100644 --- a/window.h +++ b/window.h @@ -54,6 +54,13 @@ typedef struct sWindow int was_pressed; } tWindow; +typedef enum +{ + LEFT, + MIDDLE, + RIGHT +} window_text_positon; + #define WN_ACT_UPDATE 0 #define WN_ACT_LEFT 1 #define WN_ACT_RIGHT 2 @@ -67,7 +74,7 @@ int modal_window(pWindow window, void ( *resize )( Uint16 w, Uint16 h )); pWindow create_text_box(spFontPointer font, void ( *resize )( Uint16 w, Uint16 h ), char* caption, char* text,int len,int show_selection,int* sprite_count,int insult_button); void delete_window(pWindow window); -void draw_edgy_rectangle(int x, int y, int width, int height, int B0, int B1, int B2); +void draw_edgy_rectangle(int x, int y, int * width, int * height, int B0, int B1, int B2,int B4); int message_box(spFontPointer font, void ( *resize )( Uint16 w, Uint16 h ), char* caption); int text_box(spFontPointer font, void ( *resize )( Uint16 w, Uint16 h ), char* caption, char* text,int len,int show_selection,int* sprite_count,int insult_button);