#include "Dialog.h"

#define EXIT_DIALOG_WIDTH_ 36
#define EXIT_DIALOG_HEIGHT_ 20
#define EXIT_DIALOG_X_ 22
#define DIALOG_Y_ 44
#define DIALOG_Y_TEXT_ 45

#define OBJECTIVE_DIALOG_X_ 29
#define OBJECTIVE_DIALOG_WIDTH_ 21
#define OBJECTIVE_DIALOG_HEIGHT_ 34

u8 exitDialog()
{
    u8* memory = cpct_getScreenPtr(CPCT_VMEM_START, EXIT_DIALOG_X_, DIALOG_Y_);
    cpct_drawSolidBox(memory, cpct_px2byteM0(0, 0) , EXIT_DIALOG_WIDTH_, EXIT_DIALOG_HEIGHT_ );   
    drawString(EXIT_DIALOG_X_ + 1, DIALOG_Y_TEXT_ + 3, "exit       y or n");

    // Break out of the loop once the user decides on their choice.
    while (1)
    {
        if (cpct_isKeyPressed(Key_Y))
        {
            return TRUE;
        }
        else if (cpct_isKeyPressed(Key_N))
        {
            return FALSE;
        }
    }
}

void objectiveDialog()
{
    static u8 objectiveText[3];

    // Draw the dialog box for objectives.
    u8* memory = cpct_getScreenPtr(CPCT_VMEM_START, OBJECTIVE_DIALOG_X_, DIALOG_Y_);
    cpct_drawSolidBox(memory, cpct_px2byteM0(0, 0), OBJECTIVE_DIALOG_WIDTH_, OBJECTIVE_DIALOG_HEIGHT_);
    drawString(OBJECTIVE_DIALOG_X_ + 1, DIALOG_Y_TEXT_, "objectives");

    // Display the number of objective actions remaining.
    convertNumberToString(objectiveActionCount, objectiveText);
    drawString(OBJECTIVE_DIALOG_X_ + 1, DIALOG_Y_TEXT_ + 18, objectiveText);

    // Display graphics related to the objective.
    if (mapObjective == OBJECTIVE_TYPE_FIX_MACHINERY)
    {
        cpct_drawSprite(G_interactable_pump_part1_broken, memory + 166, TILE_WIDTH_BYTES, TILE_HEIGHT);
        cpct_drawSprite(G_interactable_pump_part2, memory + 166 + 4, TILE_WIDTH_BYTES, TILE_HEIGHT);
        cpct_drawSprite(G_interactable_tank_broken, memory + 166 + 4 + 5, TILE_WIDTH_BYTES, TILE_HEIGHT);
    }
    else if (mapObjective == OBJECTIVE_TYPE_TURN_VALVES)
    {
        cpct_drawSprite(G_interactable_valve_off, memory + 166, TILE_WIDTH_BYTES, TILE_HEIGHT);
    }
    else if (mapObjective == OBJECTIVE_TYPE_COLLECT_PIPES)
    {
        cpct_drawSprite(G_item_pipe, memory + 166, TILE_WIDTH_BYTES, TILE_HEIGHT);
    }
    else
    {
        cpct_drawSprite(G_interactable_pipe_location, memory + 166, TILE_WIDTH_BYTES, TILE_HEIGHT);
    }

    // Wait for any previous key presses to clear first.
    while (cpct_isAnyKeyPressed());

    // Then wait for another key press.
    while (!cpct_isAnyKeyPressed());

    // Redraw map and player after finishing with objective dialog.
    mapRedraw = TRUE;
    playerRedraw = TRUE;
}
