///scr_Book_StepEvent_Mouse
//Place this script within the obj_Book's (or equivalent) Step Event.
//This script takes no arguments.

var RandomPageTurningSound;
var Random = irandom_range(1,3);
if (Random = 1) {RandomPageTurningSound = PageTurnAudio1;}
if (Random = 2) {RandomPageTurningSound = PageTurnAudio2;}
if (Random = 3) {RandomPageTurningSound = PageTurnAudio3;}

//If clicked the page forward button...
if (p < (TotalPages-2)) and (mouse_check_button_released(mb_left)) and (mouse_x >= PageForward_X) and (mouse_y >= PageForward_Y) and (mouse_x <= PageForward_XX) and (mouse_y <= PageForward_YY) {
        PreviousPage = p; //Keep at beginning
        p += 2; 
        if sound_isplaying(Narration[PreviousPage]){ sound_stop(Narration[PreviousPage]); }
        HeardIt = false;
        sound_play(RandomPageTurningSound);
}

//If clicked the page backward button...
if (p > 0) and (mouse_x >= PageBackward_X) and (mouse_y >= PageBackward_Y) and (mouse_x <= PageBackward_XX) and (mouse_y <= PageBackward_YY) and (mouse_check_button_released(mb_left)){
    PreviousPage = p;
    p -= 2;
    if sound_isplaying(Narration[PreviousPage]){ sound_stop(Narration[PreviousPage]); }
    HeardIt = false;
    sound_play(RandomPageTurningSound);
}

//If clicked the bookmark button...
if (mouse_x >= Bookmark_X) and (mouse_y >= Bookmark_Y) and (mouse_x <= Bookmark_XX) and (mouse_y <= Bookmark_YY) and (mouse_check_button_released(mb_left)){
    ini_open(Book);
        ini_write_real("Settings","Bookmark",p);
    ini_close();
    sound_play(BookmarkAudio);
    Bookmark = p;
}

//If clicked the background audio on/off button...
//And yes, it is weird to have to treat true/false like strings.
if (mouse_x >= BgAudioOff_X) and (mouse_y >= BgAudioOff_Y) and (mouse_x <= BgAudioOff_XX) and (mouse_y <= BgAudioOff_YY) and (mouse_check_button_released(mb_left)){
    if (BackgroundAudioOn = "false"){ BackgroundAudioOn = "true"; }
    else{ BackgroundAudioOn = "false"; }
    ini_open(working_directory+"Settings/Audio.ini");
        ini_write_string("Books","BackgroundAudioOn",string(BackgroundAudioOn));
    ini_close();
    mouse_clear(mb_left); //Need because Step Event is too fast; sleep() won't work
}

//If clicked the narration audio on/off button...
//And yes, it is weird to have to treat true/false like strings.
if (mouse_x >= NarrationOff_X) and (mouse_y >= NarrationOff_Y) and (mouse_x <= NarrationOff_XX) and (mouse_y <= NarrationOff_YY) and (mouse_check_button_released(mb_left)){
    if (NarrationOn = "false"){ NarrationOn = "true" }
    else{ NarrationOn = "false"; }
    ini_open(working_directory+"Settings/Audio.ini");
        ini_write_string("Books","NarrationOn",string(NarrationOn));
    ini_close();
    mouse_clear(mb_left); //Need because Step Event is too fast; sleep() won't work
}

//If clicked the book close button on title page...
if (p != TotalPages ) and (mouse_x >= CloseBook_X) and (mouse_y >= CloseBook_Y) and (mouse_x <= CloseBook_XX) and (mouse_y <= CloseBook_YY) and (mouse_check_button_released(mb_left)){
    script_execute(scr_Book_CloseBook);
}
//If clicked the book close button on last page...
if (p >= (TotalPages-2)) and (mouse_x >= CloseBook_LastPageX) and (mouse_y >= CloseBook_LastPageY) and (mouse_x <= CloseBook_LastPageXX) and (mouse_y <= CloseBook_LastPageYY) and (mouse_check_button_pressed(mb_left)){
    script_execute(scr_Book_CloseBook);
}
