From: terencehill Date: Sun, 7 Feb 2016 18:33:06 +0000 (+0100) Subject: Load csqc cursor attributes from the current menu skin file rather than using constan... X-Git-Tag: xonotic-v0.8.2~1195^2 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=a685802e37c3d93737d62224bc84f950cc086b4c;p=xonotic%2Fxonotic-data.pk3dir.git Load csqc cursor attributes from the current menu skin file rather than using constant values (fixes incorrect cursor offset) --- diff --git a/qcsrc/client/hud/hud_config.qc b/qcsrc/client/hud/hud_config.qc index 9ca2a0ab5..2ba78f798 100644 --- a/qcsrc/client/hud/hud_config.qc +++ b/qcsrc/client/hud/hud_config.qc @@ -1192,17 +1192,16 @@ void HUD_Panel_Mouse() drawfill(panel_pos - '1 1 0' * panel_bg_border, panel_size + '2 2 0' * panel_bg_border, '1 1 1', .1, DRAWFLAG_NORMAL); } // draw cursor after performing move/resize to have the panel pos/size updated before mouse_over_panel - const vector cursorsize = '32 32 0'; float cursor_alpha = 1 - autocvar__menu_alpha; if(!mouse_over_panel) - drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', cursor_alpha, DRAWFLAG_NORMAL); + draw_cursor_normal(mousepos, '1 1 1', cursor_alpha); else if(mouse_over_panel == 1) - drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_move.tga"), cursorsize, '1 1 1', cursor_alpha, DRAWFLAG_NORMAL); + draw_cursor(mousepos, '0.5 0.5 0', "/cursor_move", '1 1 1', cursor_alpha); else if(mouse_over_panel == 2) - drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize.tga"), cursorsize, '1 1 1', cursor_alpha, DRAWFLAG_NORMAL); + draw_cursor(mousepos, '0.5 0.5 0', "/cursor_resize", '1 1 1', cursor_alpha); else - drawpic(mousepos - cursorsize * 0.5, strcat("gfx/menu/", autocvar_menu_skin, "/cursor_resize2.tga"), cursorsize, '1 1 1', cursor_alpha, DRAWFLAG_NORMAL); + draw_cursor(mousepos, '0.5 0.5 0', "/cursor_resize2", '1 1 1', cursor_alpha); prevMouseClicked = mouseClicked; } diff --git a/qcsrc/client/hud/panel/radar.qc b/qcsrc/client/hud/panel/radar.qc index 2082f70b1..07677fcc4 100644 --- a/qcsrc/client/hud/panel/radar.qc +++ b/qcsrc/client/hud/panel/radar.qc @@ -156,8 +156,7 @@ void HUD_Radar_Mouse() } - const vector cursor_size = '32 32 0'; - drawpic(mousepos-'8 4 0', strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursor_size, '1 1 1', 0.8, DRAWFLAG_NORMAL); + draw_cursor_normal(mousepos, '1 1 1', 0.8); } void HUD_Radar() diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index 0dcf6811d..aa490aa50 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -28,6 +28,58 @@ #define DP_CSQC_ENTITY_REMOVE_IS_B0RKED +void draw_cursor(vector pos, vector ofs, string img, vector col, float a) +{ + ofs = eX * (ofs.x * SIZE_CURSOR.x) + eY * (ofs.y * SIZE_CURSOR.y); + drawpic(pos - ofs, strcat(draw_currentSkin, img), SIZE_CURSOR, col, a, DRAWFLAG_NORMAL); +} + +void draw_cursor_normal(vector pos, vector col, float a) +{ + draw_cursor(pos, OFFSET_CURSOR, "/cursor", col, a); +} + +void LoadMenuSkinValues() +{ + int fh = -1; + if(cvar_string("menu_skin") != "") + { + draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin")); + fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ); + } + if(fh < 0 && cvar_defstring("menu_skin") != "") + { + cvar_set("menu_skin", cvar_defstring("menu_skin")); + draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin")); + fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ); + } + if(fh < 0) + { + draw_currentSkin = "gfx/menu/default"; + fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ); + } + + draw_currentSkin = strzone(draw_currentSkin); + + if(fh >= 0) + { + string s; + while((s = fgets(fh))) + { + int n = tokenize_console(s); + if (n < 2) + continue; + if(substring(argv(0), 0, 2) == "//") + continue; + if(argv(0) == "SIZE_CURSOR") + SIZE_CURSOR = stov(substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1))); + else if(argv(0) == "OFFSET_CURSOR") + OFFSET_CURSOR = stov(substring(s, argv_start_index(1), argv_end_index(-1) - argv_start_index(1))); + } + fclose(fh); + } +} + // CSQC_Init : Called every time the CSQC code is initialized (essentially at map load) // Useful for precaching things @@ -125,26 +177,7 @@ void CSQC_Init() } hud_skin_path = strzone(strcat("gfx/hud/", autocvar_hud_skin)); - - int fh = -1; - if(cvar_string("menu_skin") != "") - { - draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin")); - fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ); - } - if(fh < 0 && cvar_defstring("menu_skin") != "") - { - cvar_set("menu_skin", cvar_defstring("menu_skin")); - draw_currentSkin = strcat("gfx/menu/", cvar_string("menu_skin")); - fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ); - } - if(fh < 0) - { - draw_currentSkin = "gfx/menu/default"; - fh = fopen(strcat(draw_currentSkin, "/skinvalues.txt"), FILE_READ); - } - - draw_currentSkin = strzone(draw_currentSkin); + LoadMenuSkinValues(); } // CSQC_Shutdown : Called every time the CSQC code is shutdown (changing maps, quitting, etc) diff --git a/qcsrc/client/main.qh b/qcsrc/client/main.qh index bed4daa26..084dfba2f 100644 --- a/qcsrc/client/main.qh +++ b/qcsrc/client/main.qh @@ -40,6 +40,13 @@ float gametype; float FONT_USER = 8; + +vector OFFSET_CURSOR = '0 0 0'; +vector SIZE_CURSOR = '32 32 0'; +void draw_cursor(vector pos, vector ofs, string img, vector col, float a); +void draw_cursor_normal(vector pos, vector col, float a); +void LoadMenuSkinValues(); + // -------------------------------------------------------------------------- // Scoreboard stuff diff --git a/qcsrc/client/mapvoting.qc b/qcsrc/client/mapvoting.qc index 30c938aa3..707123165 100644 --- a/qcsrc/client/mapvoting.qc +++ b/qcsrc/client/mapvoting.qc @@ -482,7 +482,7 @@ void MapVote_Draw() MapVote_DrawAbstain(pos, dist.x, xmax - xmin, tmp, i); } - drawpic(mv_mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), '32 32 0', '1 1 1', 1 - autocvar__menu_alpha, DRAWFLAG_NORMAL); + draw_cursor_normal(mv_mousepos, '1 1 1', 1 - autocvar__menu_alpha); } void Cmd_MapVote_MapDownload(float argc) diff --git a/qcsrc/client/quickmenu.qc b/qcsrc/client/quickmenu.qc index 90f6c171c..63416f2b0 100644 --- a/qcsrc/client/quickmenu.qc +++ b/qcsrc/client/quickmenu.qc @@ -531,8 +531,7 @@ void QuickMenu_Mouse() } } - vector cursorsize = '32 32 0'; - drawpic(mousepos, strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursorsize, '1 1 1', 0.8, DRAWFLAG_NORMAL); + draw_cursor_normal(mousepos, '1 1 1', 0.8); prevMouseClicked = mouseClicked; }