Skip to content

Commit 0de954d

Browse files
committed
Fix zc mouse showing during gameplay, setup for fancy mouse stuff.
1 parent 3353e3c commit 0de954d

File tree

7 files changed

+134
-44
lines changed

7 files changed

+134
-44
lines changed

src/base/render.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,8 @@ namespace MouseSprite
290290
}
291291
void assign(int index, BITMAP* spr, int xf, int yf)
292292
{
293+
if(index < 0 || index >= MAX_MOUSESPRITE)
294+
return;
293295
ALLEGRO_MOUSE_CURSOR* old_cursor = zc_mouse_sprites[index];
294296
all_set_transparent_palette_index(0);
295297
ALLEGRO_BITMAP* a5_mouse_sprite = all_get_a5_bitmap(spr);
@@ -302,20 +304,31 @@ namespace MouseSprite
302304
if(old_cursor)
303305
al_destroy_mouse_cursor(old_cursor);
304306
}
305-
void set(int index)
307+
bool set(int index)
306308
{
307309
if(index < 0 || index >= MAX_MOUSESPRITE)
308310
{
309311
active_mouse_sprite = -1;
310312
set_nullmouse();
313+
return true;
311314
}
312-
if(index == active_mouse_sprite) return;
315+
if(index == active_mouse_sprite) return true;
313316
if(zc_mouse_sprites[index])
314317
{
315318
active_mouse_sprite = index;
316319
al_show_mouse_cursor(all_get_display());
317320
al_set_mouse_cursor(all_get_display(), zc_mouse_sprites[index]);
321+
return true;
318322
}
323+
return false;
324+
}
325+
void clear(int index)
326+
{
327+
if(index < 0 || index >= MAX_MOUSESPRITE)
328+
return;
329+
if(zc_mouse_sprites[index])
330+
al_destroy_mouse_cursor(zc_mouse_sprites[index]);
331+
zc_mouse_sprites[index] = nullptr;
319332
}
320333
}
321334

src/base/render.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ namespace MouseSprite
5252
{
5353
#define MAX_MOUSESPRITE 35
5454
void assign(int index, BITMAP* spr, int xf = 1, int yf = 1);
55-
void set(int index);
55+
bool set(int index);
56+
void clear(int index);
5657
};
5758

5859
extern RenderTreeItem rti_dialogs;

src/zc/title.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4014,6 +4014,7 @@ int32_t custom_game(int32_t file)
40144014
gamemode_dlg[2].d1 = gamemode_dlg[4].d1 = 0;
40154015
gamemode_dlg[2].d2 = gamemode_dlg[4].d2 = 0;
40164016
system_pal();
4017+
sys_mouse();
40174018

40184019
clear_keybuf();
40194020

@@ -4061,6 +4062,7 @@ int32_t custom_game(int32_t file)
40614062
}
40624063
if(!customized) strcpy(qstpath, relpath);
40634064

4065+
game_mouse();
40644066
game_pal();
40654067
key[KEY_ESC]=0;
40664068
chosecustomquest = (ret==5) && customized;
@@ -4419,7 +4421,10 @@ if ( FFCore.coreflags&FFCORE_SCRIPTED_MIDI_VOLUME )
44194421
cont_game();
44204422
return;
44214423
}
4422-
4424+
4425+
game_mouse_index = ZCM_BLANK; //Force game mouse to blank
4426+
MouseSprite::clear(ZCM_CUSTOM); //Delete any custom cursor between quests
4427+
44234428
if (replay_get_mode() == ReplayMode::Record)
44244429
{
44254430
replay_save();

src/zc/zc_sys.cpp

Lines changed: 95 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -680,58 +680,113 @@ void dump_pal(BITMAP *dest)
680680

681681
//----------------------------------------------------------------
682682

683+
int game_mouse_index = ZCM_BLANK;
684+
static bool system_mouse = false;
685+
bool sys_mouse()
686+
{
687+
system_mouse = true;
688+
return MouseSprite::set(ZCM_NORMAL);
689+
}
690+
bool game_mouse()
691+
{
692+
system_mouse = false;
693+
return MouseSprite::set(game_mouse_index);
694+
}
695+
void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale)
696+
{
697+
if(!bmp)
698+
return;
699+
float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
700+
int scaledw = bmp->w*scale, scaledh = bmp->h*scale;
701+
if(bmp->w == scaledw && bmp->h == scaledh)
702+
user_scale = false;
703+
if(user_scale || sys_recolor)
704+
{
705+
if(!user_scale) scale = 1;
706+
BITMAP* tmpbmp = create_bitmap_ex(8,bmp->w*scale,bmp->h*scale);
707+
if(user_scale)
708+
stretch_blit(bmp, tmpbmp, 0, 0, bmp->w, bmp->h, 0, 0, tmpbmp->w, tmpbmp->h);
709+
else
710+
blit(bmp, tmpbmp, 0, 0, 0, 0, bmp->w, bmp->h);
711+
if(sys_recolor)
712+
recolor_mouse(tmpbmp);
713+
MouseSprite::assign(ZCM_CUSTOM, tmpbmp, fx*scale, fy*scale);
714+
destroy_bitmap(tmpbmp);
715+
}
716+
else
717+
{
718+
MouseSprite::assign(ZCM_CUSTOM, bmp, fx, fy);
719+
}
720+
if(!system_mouse && game_mouse_index == ZCM_CUSTOM)
721+
MouseSprite::set(ZCM_CUSTOM); //Reload the new sprite
722+
}
723+
683724
//Handles converting the mouse sprite from the .dat file
725+
void recolor_mouse(BITMAP* bmp)
726+
{
727+
for(int32_t x = 0; x < bmp->w; ++x)
728+
{
729+
for(int32_t y = 0; y < bmp->h; ++y)
730+
{
731+
int32_t color = getpixel(bmp, x, y);
732+
switch(color)
733+
{
734+
case dvc(1):
735+
color = jwin_pal[jcCURSORMISC];
736+
break;
737+
case dvc(2):
738+
color = jwin_pal[jcCURSOROUTLINE];
739+
break;
740+
case dvc(3):
741+
color = jwin_pal[jcCURSORLIGHT];
742+
break;
743+
case dvc(5):
744+
color = jwin_pal[jcCURSORDARK];
745+
break;
746+
default:
747+
continue;
748+
}
749+
putpixel(bmp, x, y, color);
750+
}
751+
}
752+
}
684753
void load_mouse()
685754
{
686755
system_pal();
687756
MouseSprite::set(-1);
688-
int32_t sz = vbound(int32_t(16*(zc_get_config("zeldadx","cursor_scale_large",1.5))),16,80);
689-
for(int32_t j = 0; j < 4; ++j)
757+
float scale = vbound(zc_get_config("zeldadx","cursor_scale_large",1.5),1.0,5.0);
758+
int32_t sz = 16*scale;
759+
for(int32_t j = 0; j < 1; ++j)
690760
{
691761
BITMAP* tmpbmp = create_bitmap_ex(8,16,16);
692-
BITMAP* subbmp = create_bitmap_ex(8,16,16);
693762
if(zcmouse[j])
694763
destroy_bitmap(zcmouse[j]);
695764
zcmouse[j] = create_bitmap_ex(8,sz,sz);
696765
clear_bitmap(zcmouse[j]);
697766
clear_bitmap(tmpbmp);
698-
clear_bitmap(subbmp);
699767
blit((BITMAP*)datafile[BMP_MOUSE].dat,tmpbmp,1,j*17+1,0,0,16,16);
700-
for(int32_t x = 0; x < 16; ++x)
701-
{
702-
for(int32_t y = 0; y < 16; ++y)
703-
{
704-
int32_t color = getpixel(tmpbmp, x, y);
705-
switch(color)
706-
{
707-
case dvc(1):
708-
color = jwin_pal[jcCURSORMISC];
709-
break;
710-
case dvc(2):
711-
color = jwin_pal[jcCURSOROUTLINE];
712-
break;
713-
case dvc(3):
714-
color = jwin_pal[jcCURSORLIGHT];
715-
break;
716-
case dvc(5):
717-
color = jwin_pal[jcCURSORDARK];
718-
break;
719-
}
720-
putpixel(subbmp, x, y, color);
721-
}
722-
}
768+
recolor_mouse(tmpbmp);
723769
if(sz!=16)
724-
stretch_blit(subbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
770+
stretch_blit(tmpbmp, zcmouse[j], 0, 0, 16, 16, 0, 0, sz, sz);
725771
else
726-
blit(subbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
772+
blit(tmpbmp, zcmouse[j], 0, 0, 0, 0, 16, 16);
727773
destroy_bitmap(tmpbmp);
728-
destroy_bitmap(subbmp);
729774
}
730775
zc_set_palette(*hw_palette);
731776

732-
MouseSprite::assign(0, zcmouse[0]);
733-
MouseSprite::set(0);
777+
BITMAP* blankmouse = create_bitmap_ex(8,16,16);
778+
clear_bitmap(blankmouse);
779+
780+
MouseSprite::assign(ZCM_NORMAL, zcmouse[0], 1*scale, 1*scale);
781+
MouseSprite::assign(ZCM_BLANK, blankmouse);
782+
//Don't assign ZCM_CUSTOM. That'll be handled by scripts.
783+
784+
//Reload the mouse
785+
if(system_mouse)
786+
sys_mouse();
787+
else game_mouse();
734788

789+
destroy_bitmap(blankmouse);
735790
game_pal();
736791
}
737792

@@ -745,7 +800,7 @@ bool game_vid_mode(int32_t mode,int32_t wait)
745800

746801
scrx = (resx-320)>>1;
747802
scry = (resy-240)>>1;
748-
for(int32_t q = 0; q < 4; ++q)
803+
for(int32_t q = 0; q < NUM_ZCMOUSE; ++q)
749804
zcmouse[q] = NULL;
750805
load_mouse();
751806

@@ -4248,6 +4303,7 @@ void f_Quit(int32_t type)
42484303
{
42494304
music_pause();
42504305
pause_all_sfx();
4306+
sys_mouse();
42514307
}
42524308
enter_sys_pal();
42534309
clear_keybuf();
@@ -4291,6 +4347,7 @@ void f_Quit(int32_t type)
42914347
}
42924348

42934349
if(!from_menu)
4350+
game_mouse();
42944351
eat_buttons();
42954352

42964353
zc_readrawkey(KEY_ESC);
@@ -6342,11 +6399,13 @@ int32_t onGoToComplete()
63426399
system_pal();
63436400
music_pause();
63446401
pause_all_sfx();
6402+
sys_mouse();
63456403
onGoTo();
63466404
eat_buttons();
63476405

63486406
zc_readrawkey(KEY_ESC);
6349-
6407+
6408+
game_mouse();
63506409
game_pal();
63516410
music_resume();
63526411
resume_all_sfx();
@@ -8332,6 +8391,7 @@ void System()
83328391
misc_menu[5].flags = Playing ? 0 : D_DISABLED;
83338392
misc_menu[7].flags = !Playing ? 0 : D_DISABLED;
83348393
clear_keybuf();
8394+
sys_mouse();
83358395

83368396
DIALOG_PLAYER *p;
83378397

@@ -8467,6 +8527,7 @@ void System()
84678527
// font=oldfont;
84688528
mouse_down=gui_mouse_b();
84698529
shutdown_dialog(p);
8530+
game_mouse();
84708531
MenuOpen = false;
84718532
if(Quit)
84728533
{

src/zc/zc_sys.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ bool flash_reduction_enabled(bool check_qr = true);
2626
void large_dialog(DIALOG *d);
2727
void large_dialog(DIALOG *d, float RESIZE_AMT);
2828

29-
bool game_vid_mode(int32_t mode,int32_t wait);
3029
int32_t Z_init_timers();
3130
void Z_remove_timers();
3231
void Z_init_sound();
@@ -194,6 +193,11 @@ enum {bosCIRCLE=0, bosOVAL, bosTRIANGLE, bosSMAS, bosFADEBLACK, bosMAX};
194193
void go();
195194
void comeback();
196195
void dump_pal(BITMAP *dest);
196+
extern int game_mouse_index;
197+
bool sys_mouse();
198+
bool game_mouse();
199+
void custom_mouse(BITMAP* bmp, int fx, int fy, bool sys_recolor, bool user_scale);
200+
void recolor_mouse(BITMAP* bmp);
197201
bool game_vid_mode(int32_t mode,int32_t wait);
198202
void init_NES_mode();
199203

src/zc/zelda.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ BITMAP *framebuf, *menu_bmp, *gui_bmp, *scrollbuf, *tmp_bmp, *tmp_scr, *scre
333333
*msg_portrait_display_buf, *msg_txt_display_buf, *msg_bg_display_buf,
334334
*pricesdisplaybuf, *tb_page[3], *temp_buf, *prim_bmp,
335335
*script_menu_buf, *f6_menu_buf;
336-
BITMAP *zcmouse[4];
336+
BITMAP *zcmouse[NUM_ZCMOUSE];
337337
DATAFILE *datafile, *sfxdata, *fontsdata, *mididata;
338338
PALETTE RAMpal;
339339
byte *colordata, *trashbuf;
@@ -5763,9 +5763,6 @@ void quit_game()
57635763
set_clip_state(pricesdisplaybuf, 1);
57645764
destroy_bitmap(pricesdisplaybuf);
57655765
destroy_bitmap(zcmouse[0]);
5766-
destroy_bitmap(zcmouse[1]);
5767-
destroy_bitmap(zcmouse[2]);
5768-
destroy_bitmap(zcmouse[3]);
57695766
destroy_bitmap(script_menu_buf);
57705767
destroy_bitmap(f6_menu_buf);
57715768
destroy_bitmap(darkscr_bmp_curscr);

src/zc/zelda.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,8 @@ extern BITMAP *darkscr_bmp_curscr, *darkscr_bmp_scrollscr,
312312
*darkscr_bmp_curscr_trans, *darkscr_bmp_scrollscr_trans;
313313
extern BITMAP *lightbeam_bmp;
314314
extern bool lightbeam_present;
315-
extern BITMAP *zcmouse[4];
315+
#define NUM_ZCMOUSE 1
316+
extern BITMAP *zcmouse[NUM_ZCMOUSE];
316317
extern DATAFILE *datafile, *sfxdata, *fontsdata, *mididata;
317318
extern SAMPLE wav_refill;
318319
extern PALETTE RAMpal;
@@ -542,6 +543,14 @@ extern zctune tunes[MAXMIDIS];
542543
//extern zcmidi_ tunes[MAXMIDIS];
543544
//extern emusic enhancedMusic[MAXMUSIC];
544545

546+
//Mouse stuff
547+
enum
548+
{
549+
ZCM_NORMAL,
550+
ZCM_BLANK,
551+
ZCM_CUSTOM
552+
};
553+
545554
#endif
546555

547556
/*** end of zelda.h ***/

0 commit comments

Comments
 (0)