summaryrefslogtreecommitdiff
path: root/src/interface.c
diff options
context:
space:
mode:
authorPhilip <philip@philip-linuxlaptop.(none)>2010-10-28 23:18:06 (GMT)
committer Philip <philip@philip-linuxlaptop.(none)>2010-10-28 23:18:06 (GMT)
commitbff5961d602531b224821da54a874a09f1dba317 (patch)
tree5663de4f3f51edb932e19acfd20b42cd6622e30d /src/interface.c
parente4f9f77de906d65264c7d09635761dd05940e1aa (diff)
downloadpowder-bff5961d602531b224821da54a874a09f1dba317.zip
powder-bff5961d602531b224821da54a874a09f1dba317.tar.gz
updating
Diffstat (limited to 'src/interface.c')
-rw-r--r--src/interface.c708
1 files changed, 661 insertions, 47 deletions
diff --git a/src/interface.c b/src/interface.c
index bdec111..4ab7bf4 100644
--- a/src/interface.c
+++ b/src/interface.c
@@ -1,3 +1,6 @@
+#ifdef MACOSX
+#include <CoreFoundation/CFString.h>
+#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -46,6 +49,7 @@ void *search_thumbs[GRID_X*GRID_Y];
int search_thsizes[GRID_X*GRID_Y];
int search_own = 0;
+int search_fav = 0;
int search_date = 0;
int search_page = 0;
char search_expr[256] = "";
@@ -207,7 +211,7 @@ void add_sign_ui(pixel *vid_buf, int mx, int my)
strcpy(signs[i].text, ed.str);
signs[i].ju = ju;
}
-
+//TODO: Finish text wrapping in text edits
void ui_edit_draw(pixel *vid_buf, ui_edit *ed)
{
int cx, i;
@@ -225,8 +229,13 @@ void ui_edit_draw(pixel *vid_buf, ui_edit *ed)
if(ed->str[0])
{
- drawtext(vid_buf, ed->x, ed->y, str, 255, 255, 255, 255);
- drawtext(vid_buf, ed->x+ed->w-11, ed->y-1, "\xAA", 128, 128, 128, 255);
+ if(ed->multiline){
+ drawtextwrap(vid_buf, ed->x, ed->y, ed->w-14, str, 255, 255, 255, 255);
+ drawtext(vid_buf, ed->x+ed->w-11, ed->y-1, "\xAA", 128, 128, 128, 255);
+ } else {
+ drawtext(vid_buf, ed->x, ed->y, str, 255, 255, 255, 255);
+ drawtext(vid_buf, ed->x+ed->w-11, ed->y-1, "\xAA", 128, 128, 128, 255);
+ }
}
else if(!ed->focus)
drawtext(vid_buf, ed->x, ed->y, ed->def, 128, 128, 128, 255);
@@ -258,19 +267,35 @@ void ui_edit_process(int mx, int my, int mb, ui_edit *ed)
else
str = ed->str;
- if(mx>=ed->x+ed->w-11 && mx<ed->x+ed->w && my>=ed->y-5 && my<ed->y+11)
- {
- ed->focus = 1;
- ed->cursor = 0;
- ed->str[0] = 0;
- }
- else if(mx>=ed->x-ed->nx && mx<ed->x+ed->w && my>=ed->y-5 && my<ed->y+11)
- {
- ed->focus = 1;
- ed->cursor = textwidthx(str, mx-ed->x);
- }
- else
- ed->focus = 0;
+ if(ed->multiline){
+ if(mx>=ed->x+ed->w-11 && mx<ed->x+ed->w && my>=ed->y-5 && my<ed->y+11)
+ {
+ ed->focus = 1;
+ ed->cursor = 0;
+ ed->str[0] = 0;
+ }
+ else if(mx>=ed->x-ed->nx && mx<ed->x+ed->w && my>=ed->y-5 && my<ed->y+ed->h)
+ {
+ ed->focus = 1;
+ ed->cursor = textwidthx(str, mx-ed->x);
+ }
+ else
+ ed->focus = 0;
+ } else {
+ if(mx>=ed->x+ed->w-11 && mx<ed->x+ed->w && my>=ed->y-5 && my<ed->y+11)
+ {
+ ed->focus = 1;
+ ed->cursor = 0;
+ ed->str[0] = 0;
+ }
+ else if(mx>=ed->x-ed->nx && mx<ed->x+ed->w && my>=ed->y-5 && my<ed->y+11)
+ {
+ ed->focus = 1;
+ ed->cursor = textwidthx(str, mx-ed->x);
+ }
+ else
+ ed->focus = 0;
+ }
}
if(ed->focus && sdl_key)
{
@@ -335,19 +360,19 @@ void ui_edit_process(int mx, int my, int mb, ui_edit *ed)
}
ts[0]=ed->hide?0x8D:ch;
ts[1]=0;
- if(textwidth(str)+textwidth(ts) > ed->w-14)
+ if((textwidth(str)+textwidth(ts) > ed->w-14 && !ed->multiline) || (float)(((textwidth(str)+textwidth(ts))/(ed->w-14)*12) > ed->h && ed->multiline))
break;
memmove(ed->str+ed->cursor+1, ed->str+ed->cursor, l+1-ed->cursor);
ed->str[ed->cursor] = ch;
ed->cursor++;
}
#else
- if(sdl_ascii>=' ' && sdl_ascii<127)
+ if(sdl_ascii>=' ' && sdl_ascii<127 && l<255)
{
ch = sdl_ascii;
ts[0]=ed->hide?0x8D:ch;
ts[1]=0;
- if(textwidth(str)+textwidth(ts) > ed->w-14)
+ if((textwidth(str)+textwidth(ts) > ed->w-14 && !ed->multiline) || (float)(((textwidth(str)+textwidth(ts))/(ed->w-14)*12) > ed->h && ed->multiline))
break;
memmove(ed->str+ed->cursor+1, ed->str+ed->cursor, l+1-ed->cursor);
ed->str[ed->cursor] = ch;
@@ -1121,6 +1146,7 @@ int save_name_ui(pixel *vid_buf)
ed.focus = 1;
ed.hide = 0;
ed.cursor = strlen(svf_name);
+ ed.multiline = 0;
strcpy(ed.str, svf_name);
cb.x = x0+10;
@@ -1759,7 +1785,7 @@ corrupt:
int search_ui(pixel *vid_buf)
{
- int uih=0,nyu,nyd,b=1,bq,mx=0,my=0,mxq=0,myq=0,mmt=0,gi,gj,gx,gy,pos,i,mp,dp,dap,own,last_own=search_own,page_count=0,last_page=0,last_date=0,j,w,h,st=0,lv;
+ int uih=0,nyu,nyd,b=1,bq,mx=0,my=0,mxq=0,myq=0,mmt=0,gi,gj,gx,gy,pos,i,mp,dp,dap,own,last_own=search_own,last_fav=search_fav,page_count=0,last_page=0,last_date=0,j,w,h,st=0,lv;
int is_p1=0, exp_res=GRID_X*GRID_Y, tp, view_own=0;
int thumb_drawn[GRID_X*GRID_Y];
pixel *v_buf = (pixel *)malloc(((YRES+MENUSIZE)*(XRES+BARSIZE))*PIXELSIZE);
@@ -1817,6 +1843,7 @@ int search_ui(pixel *vid_buf)
ed.focus = 1;
ed.hide = 0;
ed.cursor = strlen(search_expr);
+ ed.multiline = 0;
strcpy(ed.str, search_expr);
sdl_wheel = 0;
@@ -1851,39 +1878,50 @@ int search_ui(pixel *vid_buf)
if(!svf_login)
{
search_own = 0;
- drawrect(vid_buf, XRES-64, 8, 56, 16, 96, 96, 96, 255);
- drawtext(vid_buf, XRES-61, 11, "\x94", 96, 80, 16, 255);
- drawtext(vid_buf, XRES-61, 11, "\x93", 128, 128, 128, 255);
- drawtext(vid_buf, XRES-46, 13, "My Own", 128, 128, 128, 255);
+ drawrect(vid_buf, XRES-64+16, 8, 56, 16, 96, 96, 96, 255);
+ drawtext(vid_buf, XRES-61+16, 11, "\x94", 96, 80, 16, 255);
+ drawtext(vid_buf, XRES-61+16, 11, "\x93", 128, 128, 128, 255);
+ drawtext(vid_buf, XRES-46+16, 13, "My Own", 128, 128, 128, 255);
}
else if(search_own)
{
- fillrect(vid_buf, XRES-65, 7, 58, 18, 255, 255, 255, 255);
- drawtext(vid_buf, XRES-61, 11, "\x94", 192, 160, 64, 255);
- drawtext(vid_buf, XRES-61, 11, "\x93", 32, 32, 32, 255);
- drawtext(vid_buf, XRES-46, 13, "My Own", 0, 0, 0, 255);
+ fillrect(vid_buf, XRES-65+16, 7, 58, 18, 255, 255, 255, 255);
+ drawtext(vid_buf, XRES-61+16, 11, "\x94", 192, 160, 64, 255);
+ drawtext(vid_buf, XRES-61+16, 11, "\x93", 32, 32, 32, 255);
+ drawtext(vid_buf, XRES-46+16, 13, "My Own", 0, 0, 0, 255);
}
else
{
- drawrect(vid_buf, XRES-64, 8, 56, 16, 192, 192, 192, 255);
- drawtext(vid_buf, XRES-61, 11, "\x94", 192, 160, 32, 255);
- drawtext(vid_buf, XRES-61, 11, "\x93", 255, 255, 255, 255);
- drawtext(vid_buf, XRES-46, 13, "My Own", 255, 255, 255, 255);
+ drawrect(vid_buf, XRES-64+16, 8, 56, 16, 192, 192, 192, 255);
+ drawtext(vid_buf, XRES-61+16, 11, "\x94", 192, 160, 32, 255);
+ drawtext(vid_buf, XRES-61+16, 11, "\x93", 255, 255, 255, 255);
+ drawtext(vid_buf, XRES-46+16, 13, "My Own", 255, 255, 255, 255);
+ }
+
+ if(search_fav)
+ {
+ fillrect(vid_buf, XRES-134, 7, 18, 18, 255, 255, 255, 255);
+ drawtext(vid_buf, XRES-130, 11, "\xCC", 192, 160, 64, 255);
+ }
+ else
+ {
+ drawrect(vid_buf, XRES-134, 8, 16, 16, 192, 192, 192, 255);
+ drawtext(vid_buf, XRES-130, 11, "\xCC", 192, 160, 32, 255);
}
if(search_date)
{
- fillrect(vid_buf, XRES-130, 7, 62, 18, 255, 255, 255, 255);
- drawtext(vid_buf, XRES-126, 11, "\xA6", 32, 32, 32, 255);
- drawtext(vid_buf, XRES-111, 13, "By date", 0, 0, 0, 255);
+ fillrect(vid_buf, XRES-130+16, 7, 62, 18, 255, 255, 255, 255);
+ drawtext(vid_buf, XRES-126+16, 11, "\xA6", 32, 32, 32, 255);
+ drawtext(vid_buf, XRES-111+16, 13, "By date", 0, 0, 0, 255);
}
else
{
- drawrect(vid_buf, XRES-129, 8, 60, 16, 192, 192, 192, 255);
- drawtext(vid_buf, XRES-126, 11, "\xA9", 144, 48, 32, 255);
- drawtext(vid_buf, XRES-126, 11, "\xA8", 32, 144, 32, 255);
- drawtext(vid_buf, XRES-126, 11, "\xA7", 255, 255, 255, 255);
- drawtext(vid_buf, XRES-111, 13, "By votes", 255, 255, 255, 255);
+ drawrect(vid_buf, XRES-129+16, 8, 60, 16, 192, 192, 192, 255);
+ drawtext(vid_buf, XRES-126+16, 11, "\xA9", 144, 48, 32, 255);
+ drawtext(vid_buf, XRES-126+16, 11, "\xA8", 32, 144, 32, 255);
+ drawtext(vid_buf, XRES-126+16, 11, "\xA7", 255, 255, 255, 255);
+ drawtext(vid_buf, XRES-111+16, 13, "By votes", 255, 255, 255, 255);
}
if(search_page)
@@ -2133,16 +2171,21 @@ int search_ui(pixel *vid_buf)
if(sdl_key==SDLK_ESCAPE)
goto finish;
- if(b && !bq && mx>=XRES-64 && mx<=XRES-8 && my>=8 && my<=24 && svf_login)
+ if(b && !bq && mx>=XRES-64+16 && mx<=XRES-8+16 && my>=8 && my<=24 && svf_login)
{
search_own = !search_own;
lasttime = TIMEOUT;
}
- if(b && !bq && mx>=XRES-129 && mx<=XRES-65 && my>=8 && my<=24)
+ if(b && !bq && mx>=XRES-129+16 && mx<=XRES-65+16 && my>=8 && my<=24)
{
search_date = !search_date;
lasttime = TIMEOUT;
}
+ if(b && !bq && mx>=XRES-134 && mx<=XRES-134+16 && my>=8 && my<=24)
+ {
+ search_fav = !search_fav;
+ lasttime = TIMEOUT;
+ }
if(b && !bq && dp!=-1)
if(confirm_ui(vid_buf, "Do you want to delete?", search_names[dp], "Delete"))
@@ -2180,6 +2223,10 @@ int search_ui(pixel *vid_buf)
if((b && !bq && mp!=-1 && !st && !uih) || do_open==1)
{
+ if(open_ui(vid_buf, search_ids[mp], search_dates[mp]?search_dates[mp]:NULL)==1) {
+ goto finish;
+ }
+ /*
fillrect(vid_buf, 0, 0, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 255);
info_box(vid_buf, "Loading...");
@@ -2300,17 +2347,17 @@ int search_ui(pixel *vid_buf)
if(data)
free(data);
- goto finish;
+ goto finish;*/
}
if(!last)
{
search = 1;
}
- else if(!active && (strcmp(last, ed.str) || last_own!=search_own || last_date!=search_date || last_page!=search_page))
+ else if(!active && (strcmp(last, ed.str) || last_own!=search_own || last_date!=search_date || last_page!=search_page || last_fav!=search_fav))
{
search = 1;
- if(strcmp(last, ed.str) || last_own!=search_own || last_date!=search_date)
+ if(strcmp(last, ed.str) || last_own!=search_own || last_fav!=search_fav || last_date!=search_date)
{
search_page = 0;
page_count = 0;
@@ -2328,8 +2375,10 @@ int search_ui(pixel *vid_buf)
last_own = search_own;
last_date = search_date;
last_page = search_page;
+ last_fav = search_fav;
active = 1;
- uri = malloc(strlen(last)*3+80+strlen(SERVER)+strlen(svf_user));
+ // TODO: Create a better fix for this bug
+ uri = malloc(strlen(last)*3+180+strlen(SERVER)+strlen(svf_user)+20); //Increase "padding" from 80 to 180 to fix the search memory corruption bug
if(search_own || svf_admin || svf_mod)
tmp = "&ShowVotes=true";
else
@@ -2358,6 +2407,10 @@ int search_ui(pixel *vid_buf)
strcaturl(uri, " user:");
strcaturl(uri, svf_user);
}
+ if(search_fav)
+ {
+ strcaturl(uri, " cat:favs");
+ }
if(search_date)
strcaturl(uri, " sort:date");
@@ -2495,6 +2548,449 @@ finish:
return 0;
}
+int open_ui(pixel *vid_buf, char *save_id, char *save_date)
+{
+ int b=1,bq,mx,my,ca=0,thumb_w,thumb_h,active=0,active_2=0,cc=0,ccy=0,cix=0,hasdrawninfo=0,hasdrawnthumb=0,authoritah=0,myown=0,queue_open=0,data_size=0,retval=0,bc=255,openable=1;
+ char *uri, *uri_2, *o_uri;
+ void *data, *info_data;
+ save_info *info = malloc(sizeof(save_info));
+ void *http = NULL, *http_2 = NULL;
+ int lasttime = TIMEOUT;
+ int status, status_2, info_ready = 0, data_ready = 0;
+ time_t http_last_use = HTTP_TIMEOUT, http_last_use_2 = HTTP_TIMEOUT;
+ pixel *save_pic;// = malloc((XRES/2)*(YRES/2));
+ ui_edit ed;
+
+ pixel *old_vid=(pixel *)calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE);
+ fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
+
+ fillrect(vid_buf, 50, 50, XRES+BARSIZE-100, YRES+MENUSIZE-100, 0, 0, 0, 255);
+ drawrect(vid_buf, 50, 50, XRES+BARSIZE-100, YRES+MENUSIZE-100, 255, 255, 255, 255);
+ drawrect(vid_buf, 50, 50, (XRES/2)+1, (YRES/2)+1, 255, 255, 255, 155);
+ drawrect(vid_buf, 50+(XRES/2)+1, 50, XRES+BARSIZE-100-((XRES/2)+1), YRES+MENUSIZE-100, 155, 155, 155, 255);
+ drawtext(vid_buf, 50+(XRES/4)-textwidth("Loading...")/2, 50+(YRES/4), "Loading...", 255, 255, 255, 128);
+
+ ed.x = 57+(XRES/2)+1;
+ ed.y = YRES+MENUSIZE-118;
+ ed.w = XRES+BARSIZE-114-((XRES/2)+1);
+ ed.h = 48;
+ ed.nx = 1;
+ ed.def = "Add comment";
+ ed.focus = 1;
+ ed.hide = 0;
+ ed.multiline = 1;
+ ed.cursor = 0;
+ strcpy(ed.str, "");
+
+ memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
+
+ while(!sdl_poll())
+ {
+ b = SDL_GetMouseState(&mx, &my);
+ if(!b)
+ break;
+ }
+
+ //Begin Async loading of data
+ if(save_date) {
+ // We're loading an historical save
+ uri = malloc(strlen(save_id)*3+strlen(save_date)*3+strlen(SERVER)+71);
+ strcpy(uri, "http://" SERVER "/Get.api?Op=save&ID=");
+ strcaturl(uri, save_id);
+ strappend(uri, "&Date=");
+ strcaturl(uri, save_date);
+
+ uri_2 = malloc(strlen(save_id)*3+strlen(save_date)*3+strlen(SERVER)+71);
+ strcpy(uri_2, "http://" SERVER "/Info.api?ID=");
+ strcaturl(uri_2, save_id);
+ strappend(uri_2, "&Date=");
+ strcaturl(uri_2, save_date);
+ } else {
+ //We're loading a normal save
+ uri = malloc(strlen(save_id)*3+strlen(SERVER)+64);
+ strcpy(uri, "http://" SERVER "/Get.api?Op=save&ID=");
+ strcaturl(uri, save_id);
+
+ uri_2 = malloc(strlen(save_id)*3+strlen(SERVER)+64);
+ strcpy(uri_2, "http://" SERVER "/Info.api?ID=");
+ strcaturl(uri_2, save_id);
+ }
+ http = http_async_req_start(http, uri, NULL, 0, 1);
+ http_2 = http_async_req_start(http_2, uri_2, NULL, 0, 1);
+ if(svf_login)
+ {
+ http_auth_headers(http, svf_user, svf_pass);
+ http_auth_headers(http_2, svf_user, svf_pass);
+ }
+ http_last_use = time(NULL);
+ http_last_use_2 = time(NULL);
+ free(uri);
+ free(uri_2);
+ active = 1;
+ active_2 = 1;
+ while(!sdl_poll())
+ {
+ bq = b;
+ b = SDL_GetMouseState(&mx, &my);
+ mx /= sdl_scale;
+ my /= sdl_scale;
+
+ if(active && http_async_req_status(http))
+ {
+ int imgh, imgw, nimgh, nimgw;
+ http_last_use = time(NULL);
+ data = http_async_req_stop(http, &status, &data_size);
+ if(status == 200)
+ {
+ pixel *full_save = prerender_save(data, data_size, &imgw, &imgh);
+ save_pic = rescale_img(full_save, imgw, imgh, &thumb_w, &thumb_h, 2);
+ data_ready = 1;
+ free(full_save);
+ }
+ active = 0;
+ free(http);
+ http = NULL;
+ }
+ if(active_2 && http_async_req_status(http_2))
+ {
+ http_last_use_2 = time(NULL);
+ info_data = http_async_req_stop(http_2, &status_2, NULL);
+ if(status_2 == 200)
+ {
+ info_ready = info_parse(info_data, info);
+ if(info_ready==-1) {
+ error_ui(vid_buf, 0, "Not found");
+ break;
+ }
+ }
+ free(info_data);
+ active_2 = 0;
+ free(http_2);
+ http_2 = NULL;
+ }
+
+ if(data_ready && !hasdrawnthumb) {
+ draw_image(vid_buf, save_pic, 51, 51, thumb_w, thumb_h, 255);
+ hasdrawnthumb = 1;
+ memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
+ }
+ if(info_ready && !hasdrawninfo) {
+ //drawtext(vid_buf, 2, 2, info->name, 255, 255, 255, 255);
+ cix = drawtext(vid_buf, 60, (YRES/2)+60, info->name, 255, 255, 255, 255);
+ cix = drawtext(vid_buf, 60, (YRES/2)+72, "Author:", 255, 255, 255, 155);
+ cix = drawtext(vid_buf, cix+4, (YRES/2)+72, info->author, 255, 255, 255, 255);
+ cix = drawtext(vid_buf, cix+4, (YRES/2)+72, "Date:", 255, 255, 255, 155);
+ cix = drawtext(vid_buf, cix+4, (YRES/2)+72, info->date, 255, 255, 255, 255);
+ drawtextwrap(vid_buf, 62, (YRES/2)+86, (XRES/2)-24, info->description, 255, 255, 255, 200);
+
+ ccy = 0;
+ for(cc=0; cc<info->comment_count; cc++) {
+ drawtext(vid_buf, 60+(XRES/2)+1, ccy+60, info->commentauthors[cc], 255, 255, 255, 255);
+ ccy += 12;
+ ccy += drawtextwrap(vid_buf, 60+(XRES/2)+1, ccy+60, XRES+BARSIZE-100-((XRES/2)+1)-20, info->comments[cc], 255, 255, 255, 185);
+ ccy += 10;
+ draw_line(vid_buf, 50+(XRES/2)+2, ccy+52, XRES+BARSIZE-50, ccy+52, 100, 100, 100, XRES+BARSIZE);
+ }
+ hasdrawninfo = 1;
+ myown = svf_login && !strcmp(info->author, svf_user);
+ authoritah = svf_login && (!strcmp(info->author, svf_user) || svf_admin || svf_mod);
+ memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
+ }
+ if(info_ready && svf_login){
+
+ fillrect(vid_buf, 50+(XRES/2)+1, YRES+MENUSIZE-125, XRES+BARSIZE-100-((XRES/2)+1), 75, 0, 0, 0, 255);
+ drawrect(vid_buf, 50+(XRES/2)+1, YRES+MENUSIZE-125, XRES+BARSIZE-100-((XRES/2)+1), 75, 200, 200, 200, 255);
+
+ drawrect(vid_buf, 54+(XRES/2)+1, YRES+MENUSIZE-121, XRES+BARSIZE-108-((XRES/2)+1), 48, 255, 255, 255, 200);
+
+ ui_edit_draw(vid_buf, &ed);
+
+ drawrect(vid_buf, XRES+BARSIZE-100, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 255);
+ drawtext(vid_buf, XRES+BARSIZE-90, YRES+MENUSIZE-63, "Submit", 255, 255, 255, 255);
+ }
+
+ if(queue_open) {
+ if(info_ready && data_ready) {
+ // Do Open!
+ status = parse_save(data, data_size, 1, 0, 0);
+ if(!status) {
+ //if(svf_last)
+ //free(svf_last);
+ svf_last = data;
+ svf_lsize = data_size;
+
+ svf_open = 1;
+ svf_own = svf_login && !strcmp(info->author, svf_user);
+ svf_publish = info->publish && svf_login && !strcmp(info->author, svf_user);
+
+ strcpy(svf_id, save_id);
+ strcpy(svf_name, info->name);
+ if(info->tags)
+ {
+ strncpy(svf_tags, info->tags, 255);
+ svf_tags[255] = 0;
+ } else {
+ svf_tags[0] = 0;
+ }
+ svf_myvote = info->myvote;
+ retval = 1;
+ break;
+ } else {
+ queue_open = 0;
+
+ svf_open = 0;
+ svf_publish = 0;
+ svf_own = 0;
+ svf_myvote = 0;
+ svf_id[0] = 0;
+ svf_name[0] = 0;
+ svf_tags[0] = 0;
+ if(svf_last)
+ free(svf_last);
+ svf_last = NULL;
+ error_ui(vid_buf, 0, "An Error Occurred");
+ }
+ } else {
+ fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 190);
+ drawtext(vid_buf, XRES+BARSIZE/2, XRES+MENUSIZE, "Loading...", 0, 0, 0, 200);
+ }
+ }
+
+ //Open Button
+ bc = openable?255:150;
+ drawrect(vid_buf, 50, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, bc);
+ drawtext(vid_buf, 73, YRES+MENUSIZE-63, "Open", 255, 255, 255, bc);
+ drawtext(vid_buf, 58, YRES+MENUSIZE-64, "\x81", 255, 255, 255, bc);
+ //Fav Button
+ bc = svf_login?255:150;
+ drawrect(vid_buf, 100, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, bc);
+ drawtext(vid_buf, 122, YRES+MENUSIZE-63, "Fav.", 255, 255, 255, bc);
+ drawtext(vid_buf, 107, YRES+MENUSIZE-64, "\xCC", 255, 255, 255, bc);
+ //Report Button
+ bc = (svf_login && info_ready)?255:150;
+ drawrect(vid_buf, 150, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, bc);
+ drawtext(vid_buf, 168, YRES+MENUSIZE-63, "Report", 255, 255, 255, bc);
+ drawtext(vid_buf, 158, YRES+MENUSIZE-63, "!", 255, 255, 255, bc);
+ //Delete Button
+ bc = authoritah?255:150;
+ drawrect(vid_buf, 200, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, bc);
+ drawtext(vid_buf, 218, YRES+MENUSIZE-63, "Delete", 255, 255, 255, bc);
+ drawtext(vid_buf, 206, YRES+MENUSIZE-64, "\xAA", 255, 255, 255, bc);
+ //Open in browser button
+ bc = 255;
+ drawrect(vid_buf, 250, YRES+MENUSIZE-68, 107, 18, 255, 255, 255, bc);
+ drawtext(vid_buf, 273, YRES+MENUSIZE-63, "Open in Browser", 255, 255, 255, bc);
+ drawtext(vid_buf, 258, YRES+MENUSIZE-64, "\x81", 255, 255, 255, bc);
+
+ //Open Button
+ if(sdl_key==SDLK_RETURN && openable) {
+ queue_open = 1;
+ }
+ if(mx > 50 && mx < 50+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && openable) {
+ fillrect(vid_buf, 50, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
+ if(b && !bq) {
+ //Button Clicked
+ queue_open = 1;
+ }
+ }
+ //Fav Button
+ if(mx > 100 && mx < 100+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && svf_login) {
+ fillrect(vid_buf, 100, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
+ if(b && !bq) {
+ //Button Clicked
+ fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
+ info_box(vid_buf, "Adding to favourites...");
+ execute_fav(vid_buf, save_id);
+ }
+ }
+ //Report Button
+ if(mx > 150 && mx < 150+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && svf_login && info_ready) {
+ fillrect(vid_buf, 150, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
+ if(b && !bq) {
+ //Button Clicked
+ if(confirm_ui(vid_buf, "Are you sure?", "Are you sure you wish to report this save?", "Report")){
+ fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
+ info_box(vid_buf, "Reporting...");
+ if(execute_report(vid_buf, save_id)){
+ info_ui(vid_buf, "Success", "This save has been reported");
+ retval = 0;
+ break;
+ }
+ }
+ }
+ }
+ //Delete Button
+ if(mx > 200 && mx < 200+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && (authoritah || myown)) {
+ fillrect(vid_buf, 200, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
+ if(b && !bq) {
+ //Button Clicked
+ if(myown || !info->publish){
+ if(confirm_ui(vid_buf, "Are you sure you wish to delete this?", "You will not be able recover it.", "Delete")){
+ fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
+ info_box(vid_buf, "Deleting...");
+ if(execute_delete(vid_buf, save_id)){
+ retval = 0;
+ break;
+ }
+ }
+ } else {
+ if(confirm_ui(vid_buf, "Are you sure?", "This save will be removed from the search index.", "Remove")){
+ fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
+ info_box(vid_buf, "Removing...");
+ if(execute_delete(vid_buf, save_id)){
+ retval = 0;
+ break;
+ }
+ }
+ }
+ }
+ }
+ //Open in browser button
+ if(mx > 250 && mx < 250+107 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50) {
+ fillrect(vid_buf, 250, YRES+MENUSIZE-68, 107, 18, 255, 255, 255, 40);
+ if(b && !bq) {
+ //Button Clicked
+ //TODO: Open link
+ o_uri = malloc(7+strlen(SERVER)+41+strlen(save_id)*3);
+ strcpy(o_uri, "http://" SERVER "/Browse/View.html?ID=");
+ strcaturl(o_uri, save_id);
+ open_link(o_uri);
+ free(o_uri);
+ }
+ }
+ //Submit Button
+ if(mx > XRES+BARSIZE-100 && mx < XRES+BARSIZE-100+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && svf_login && info_ready) {
+ fillrect(vid_buf, XRES+BARSIZE-100, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
+ if(b && !bq) {
+ //Button Clicked
+ fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
+ info_box(vid_buf, "Submitting Comment...");
+ execute_submit(vid_buf, save_id, ed.str);
+ }
+ }
+
+ sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
+ memcpy(vid_buf, old_vid, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
+ if(info_ready && svf_login){
+ ui_edit_process(mx, my, b, &ed);
+ }
+
+ if(sdl_key==SDLK_ESCAPE)
+ break;
+
+ if(lasttime<TIMEOUT)
+ lasttime++;
+ }
+ return retval;
+}
+
+int info_parse(char *info_data, save_info *info)
+{
+ int i,j;
+ char *p,*q,*r,*s,*vu,*vd,*pu,*sd;
+
+ memset(info, 0, sizeof(save_info));
+
+ if(!info_data || !*info_data)
+ return 0;
+
+ i = 0;
+ j = 0;
+ s = NULL;
+ do_open = 0;
+ while(1)
+ {
+ if(!*info_data)
+ break;
+ p = strchr(info_data, '\n');
+ if(!p)
+ p = info_data + strlen(info_data);
+ else
+ *(p++) = 0;
+
+ if(!strncmp(info_data, "TITLE ", 6))
+ {
+ info->title = mystrdup(info_data+6);
+ j++;
+ }
+ else if(!strncmp(info_data, "NAME ", 5))
+ {
+ info->name = mystrdup(info_data+5);
+ j++;
+ }
+ else if(!strncmp(info_data, "AUTHOR ", 7))
+ {
+ info->author = mystrdup(info_data+7);
+ j++;
+ }
+ else if(!strncmp(info_data, "DATE ", 5))
+ {
+ info->date = mystrdup(info_data+5);
+ j++;
+ }
+ else if(!strncmp(info_data, "DESCRIPTION ", 12))
+ {
+ info->description = mystrdup(info_data+12);
+ j++;
+ }
+ else if(!strncmp(info_data, "VOTEUP ", 7))
+ {
+ info->voteup = atoi(info_data+7);
+ j++;
+ }
+ else if(!strncmp(info_data, "VOTEDOWN ", 9))
+ {
+ info->votedown = atoi(info_data+9);
+ j++;
+ }
+ else if(!strncmp(info_data, "VOTE ", 5))
+ {
+ info->vote = atoi(info_data+5);
+ j++;
+ }
+ else if(!strncmp(info_data, "MYVOTE ", 7))
+ {
+ info->myvote = atoi(info_data+7);
+ j++;
+ }
+ else if(!strncmp(info_data, "MYFAV ", 6))
+ {
+ info->myfav = atoi(info_data+6);
+ j++;
+ }
+ else if(!strncmp(info_data, "PUBLISH ", 8))
+ {
+ info->publish = atoi(info_data+8);
+ j++;
+ }
+ else if(!strncmp(info_data, "TAGS ", 5))
+ {
+ info->tags = mystrdup(info_data+5);
+ j++;
+ }
+ else if(!strncmp(info_data, "COMMENT ", 8))
+ {
+ if(info->comment_count>=6) {
+ info_data = p;
+ continue;
+ } else {
+ q = strchr(info_data+8, ' ');
+ *(q++) = 0;
+ info->commentauthors[info->comment_count] = mystrdup(info_data+8);
+ info->comments[info->comment_count] = mystrdup(q);
+ info->comment_count++;
+ }
+ j++;
+ }
+ info_data = p;
+ }
+ if(j>=8) {
+ return 1;
+ } else {
+ return -1;
+ }
+}
+
int search_results(char *str, int votes)
{
int i,j;
@@ -2890,7 +3386,7 @@ void execute_save(pixel *vid_buf)
free(result);
}
-void execute_delete(pixel *vid_buf, char *id)
+int execute_delete(pixel *vid_buf, char *id)
{
int status;
char *result;
@@ -2911,6 +3407,111 @@ void execute_delete(pixel *vid_buf, char *id)
error_ui(vid_buf, status, http_ret_text(status));
if(result)
free(result);
+ return 0;
+ }
+ if(result && strncmp(result, "OK", 2))
+ {
+ error_ui(vid_buf, 0, result);
+ free(result);
+ return 0;
+ }
+
+ if(result)
+ free(result);
+ return 1;
+}
+
+void execute_submit(pixel *vid_buf, char *id, char *message)
+{
+ int status;
+ char *result;
+
+ char *names[] = {"ID", "Message", NULL};
+ char *parts[2];
+
+ parts[0] = id;
+ parts[1] = message;
+
+ result = http_multipart_post(
+ "http://" SERVER "/Comment.api",
+ names, parts, NULL,
+ svf_user, svf_pass,
+ &status, NULL);
+
+ if(status!=200)
+ {
+ error_ui(vid_buf, status, http_ret_text(status));
+ if(result)
+ free(result);
+ return;
+ }
+ if(result && strncmp(result, "OK", 2))
+ {
+ error_ui(vid_buf, 0, result);
+ free(result);
+ return;
+ }
+
+ if(result)
+ free(result);
+}
+
+int execute_report(pixel *vid_buf, char *id)
+{
+ int status;
+ char *result;
+
+ char *names[] = {"ID", NULL};
+ char *parts[1];
+
+ parts[0] = id;
+
+ result = http_multipart_post(
+ "http://" SERVER "/Report.api",
+ names, parts, NULL,
+ svf_user, svf_pass,
+ &status, NULL);
+
+ if(status!=200)
+ {
+ error_ui(vid_buf, status, http_ret_text(status));
+ if(result)
+ free(result);
+ return 0;
+ }
+ if(result && strncmp(result, "OK", 2))
+ {
+ error_ui(vid_buf, 0, result);
+ free(result);
+ return 0;
+ }
+
+ if(result)
+ free(result);
+ return 1;
+}
+
+void execute_fav(pixel *vid_buf, char *id)
+{
+ int status;
+ char *result;
+
+ char *names[] = {"ID", NULL};
+ char *parts[1];
+
+ parts[0] = id;
+
+ result = http_multipart_post(
+ "http://" SERVER "/Favourite.api",
+ names, parts, NULL,
+ svf_user, svf_pass,
+ &status, NULL);
+
+ if(status!=200)
+ {
+ error_ui(vid_buf, status, http_ret_text(status));
+ if(result)
+ free(result);
return;
}
if(result && strncmp(result, "OK", 2))
@@ -2959,3 +3560,16 @@ int execute_vote(pixel *vid_buf, char *id, char *action)
free(result);
return 1;
}
+void open_link(char *uri){
+#ifdef WIN32
+ ShellExecute(0, "OPEN", uri, NULL, NULL, 0)
+#elif MACOSX
+ //LSOpenCFURLRef(CFURLCreateWithString(NULL, CFStringCreateWithCString(NULL, uri, 0) ,NULL), NULL); //TODO: Get this crap working
+#elif LIN32
+ execvp("xdg-open", uri);
+#elif LIN64
+ execvp("xdg-open", uri);
+#else
+ printf("Cannot open browser\n");
+#endif
+}