/* date = August 14th 2023 5:00 pm */

#ifndef VN_SCENE_VIEW_H
#define VN_SCENE_VIEW_H

struct scene_view_character_texture_info
{
	render_handle Texture;
	r32 Scale;
};

struct scene_view_character_data
{
	string Name;
	
	scene_view_character_texture_info Info;
	
	b32 Active;
	r32 ActiveT;
	
	b32 Talking;
	r32 TalkingT;
	
	r32 PctP;
};

enum scene_nav_action_kind
{
	S_NavAction_None,
	S_NavAction_Proc,
	S_NavAction_Scene,
};

struct scene_nav_action
{
	scene_nav_action_kind Kind;
	string Content;
};

struct scene_nav_item
{
	asset_id TextureID;
	r32 Scale;
	v2_r32 Origin;
	v2_r32 P;
	string HoverText;
	scene_nav_action Action;
};

typedef u8 scene_nav_item_op;
enum
{
	S_NavItemOp_None = 0,
	S_NavItemOp_TextureID,
	S_NavItemOp_Scale,
	S_NavItemOp_Origin,
	S_NavItemOp_P,
	S_NavItemOp_HoverText,
	S_NavItemOp_Action,
};

struct scene_nav
{
	scene_nav_item *Items;
	s32 ItemCount;
	s32 ItemMax;
};

enum scene_view_mode
{
    SV_Mode_Scene,
    SV_Mode_Nav,
    SV_Mode_P15,
};

struct scene_view
{
	arena *SceneArena;
    
	//- sixten: state
	scene2_runtime Runtime;
	compiled_scene2 Compiled;
    scene_view_mode Mode;
    
    //- sixten: messages
	arena *MessageArena;
    scene2_message_list Messages;
    
    //- sixten: textbox
    char TextboxData[1024];
    u64 TextboxUsed;
    r32 TextboxRevealed;
    
    //- sixten: characters
	scene_view_character_data Characters[16];
    u64 CharactersUsed;
	
	//- sixten: nav items
	scene_nav_item *NavItems;
	u64 NavItemCount;
	
	//- sixten: input per frame
	platform_event_list *EventList;
	r32 dtForFrame;
    
    //- sixten: 15-puzzle
    r32 BoardOpenT;
    u8 Board[4][4];
    u8 PrevBoard[4][4];
    b32 BoardIsComplete;
    r32 TimeSinceBoardUpdate;
    r32 TimeSinceBoardClear;
};

static void SV_SetState(scene_view *View);
static scene_view *SV_GetState();

static void SV_NewFrame(scene_view *View, platform_event_list *EventList, r32 dtForFrame);
static void SV_Reset(void);
static void SV_SetCurrentSource(compiled_scene2 *Compiled);
static void SV_Init(scene_view *View);

static b32 SV_CurrentlyInProc(void);

static scene_view_character_data *SV_FindTalkingCharacter(void);
static string SV_DisplayNameFromCharacter(scene_view_character_data *Character);

static void SV_DrawBackground(scene_view *SceneView, ui_box *Box, render_group *Group);

static ui_signal SV_BuildNavItem(scene_nav_item * Item, r32 GlobalScale, v2_r32 GlobalDim);
static void SV_BuildSceneView(vn_input *Input);

static void SV_Update(arena *FrameArena);

#endif //VN_SCENE_VIEW_H
