import { Color, NodeEventType } from "cc";
import { config } from "../script/config";

export class attributes_data{
    public zIndex = config.Zindex_type.Zindex_scene;
    public img_dir = config.widget_scale_dir.normal;
    public id:number = 1;
    public name:string = "";
    public remark:string = "";
    public type:number = 0;
    public widget_type:number = 0;
    public x:number = 0;
    public y:number =0;
    public z:number = 0;
    public width:number = 0;
    public height:number = 0;
    public anchor_x:number = 0.5;
    public anchor_y:number = 0.5;
    public rotation:number = 0;
    public src:string = "";
    public src_name:string = "";
    public ani:string = "";
    public scene_rule_tips_data:scene_tips_rule_data = new scene_tips_rule_data; //场景的规则和提示
    public edit_active:boolean = true;  //是否激活
    public is_interaction:boolean = true;  //开启交互
    public is_show:boolean = true; //默认显示
    public drag_data:att_drag_data = null;
    public slide_data:att_slide_data = null;
    public click_data:att_click_data = null;
    public top_data:att_top_data = null; //弹窗数据
    public animation_list:att_ani_data[] = []; //动画组
    public text_sound_data:att_text_sound_data = null; //文本及语音
    public question_select:att_question_select = null; //问题选择
    public count_down:att_count_down = null; //倒计时
}

export class att_count_down{
    public ProgressBar_Bg:ui_att_item = null;
    public ProgressBar_Bar:ui_att_item = null;
    public img_text:ui_att_item = null;
    public time_count:number = 0;
    public is_show_time:boolean = false;
    public start_event_id:number = -1;
    public finish_event_id:number = -1;
    public fail_event_id:number = -1;
    public font_info:font_info = new font_info;
}

export class att_question_select{
    btn_question_list:ui_att_item[] = []
}

export class att_ani_data{ //动画属性
    public ani_id:number = 0; //动画id
    public ani_name:string = ""; //动画名字
    public isLoop:boolean = false;//是否循环
    public isMove:boolean = true; //是否移動
    public binding_widget_id:number =0; //哪个控件
    public ani_frame_list:ani_frame[] = [];//动画帧
}

export class ani_frame{ //动画帧
    public next_time:number = 1//下一帧的时间
    public pos_x:number=0; //位置
    public pos_y:number = 0;
    public size_width:number = 100; //宽高
    public size_height:number = 100; 
    public rotation:number = 0; //旋转
    public anchor_point_x:number = 0.5; //锚点x
    public anchor_point_y:number = 0.5; //锚点y
    public color:string = "#FFFFFF"; //颜色
    public transparent:number = 255; //透明度
    public url:string = "";//资源
    public url_name:string = "";
}


export class att_drag_data{
    public drag_size_width:number = 0;
    public drag_size_height:number = 0;
    public drag_pos_x:number = 0;
    public drag_pos_y:number = 0;
    public other_event_id:number = -1; //其他拖拽的完成事件
    public is_err_drag_back:boolean = true; //拖拽错误是否回归原位
    public other_drag_list:att_drag_data[] = [];
    public other_widget_finish_listen_list:other_widget_finish_listen_item[] = [];
    public remark:string = ''; //备注
    public is_show_inTheEditor:boolean = true; //在编辑器中,是否显示
}

export class other_widget_finish_listen_item{
    public event_id:number = -1;
    public widget_id:number = -1;
}

export class att_slide_data{
    public slide_dir:number = config.slide_type.down; //滑动方向
    public slide_distance:number = 100; //滑动的距离
    public slide_num:number = 1; //滑动次数
    public other_widget_finish_listen_list:other_widget_finish_listen_item[] = [];
}

export class att_click_data{
    public click_type:number = config.clcik_type.click; //点击的类型
    public  hold_time:number = 5; //按下按钮的事件s单位
    public multiple_check_num:number = 2;
    public other_widget_finish_listen_list:other_widget_finish_listen_item[] = [];
}

export class att_text_sound_data{
    public sound_data:bag_item_data = null;
    public text:string = '';
    public pos_y:number = 0;
    public is_open_click_close:boolean = true;
}

export class scene_tips_rule_data{
    public tips_data:scene_tips_data = new scene_tips_data;
    public rule_list:ui_att_item[] = []
    public rule_find_tips:ui_att_item = new ui_att_item;  
    public scene_des:string = "";  
}

export class scene_tips_data{
    public tips_answer:ui_att_item = new ui_att_item;
    public tips_tips:ui_att_item = new ui_att_item;
}

export class att_top_data{
    public top_ui_type:number = config.top_view_type.__null //ui类型
    public is_open_jump:boolean = false; //是否开启跳过
    public is_open_close:boolean = true; //是否开启关闭
    public close_info:ui_att_item = null; //关闭按钮的属性
    public jump_info:ui_att_item = null; //跳过按钮
    public _not_have_interact_data:not_have_interact_data = null;
    public _interact_input_data:interact_input_data = null;
    public _interact_page_data:interact_page_data = null;
    public _interact_puzzle_data:interact_puzzle_data = null;
    public _interact_scene_data:interact_scene_data = null;
    public _pointer_ding_wei_data:pointer_ding_wei_data = null;
    public _wei_chi_pointer_data:wei_chi_pointer_data = null;
    public _boss_info_data:boss_info_data = null;
    public close_event_id:number = -1;
    public finish_event_id:number = -1;
    public fail_event_id:number = -1;
    public clearAll(){
        this._not_have_interact_data = null;
        this._interact_input_data = null;
        this._interact_page_data = null;
        this._interact_puzzle_data = null;
        this._interact_scene_data = null;
        this._pointer_ding_wei_data = null;
        this._wei_chi_pointer_data = null;
    }
}

export class font_color_info{
    public r:number = 255;
    public g:number = 255;
    public b:number = 255;

    public info(r:number,g:number,b:number):font_color_info{
        this.r = r;
        this.g = g;
        this.b = b;
        return this;
    }
    public infoColor(color:Color):font_color_info{
        this.r = color.r;
        this.g = color.g;
        this.b = color.b;
        return this;
    }
}

export class font_info{
    public font_color:font_color_info = new font_color_info;
    public font_size:number = 20;
}

export class ui_att_item{
    public x:number = 0;
    public y:number = 0;
    public width:number = 0;
    public height:number = 0;
    public res:string = ""; //资源
    public res_name:string = "";
}
export class not_have_interact_data{
    public bg:ui_att_item = null;
}
export class interact_input_data{
    public bg:ui_att_item = null;
    public image_1:ui_att_item = null;
    public image_2:ui_att_item = null;
    public image_3:ui_att_item = null;
    public image_4:ui_att_item = null;
    public image_5:ui_att_item = null;
    public image_6:ui_att_item = null;
    public image_7:ui_att_item = null;
    public image_8:ui_att_item = null;
    public image_9:ui_att_item = null;
    public image_0:ui_att_item = null;

    public image_xing:ui_att_item = null;
    public image_jing:ui_att_item = null;

    public att_1:ui_att_item = null;
    public att_2:ui_att_item = null;
    public att_3:ui_att_item = null;
    public att_4:ui_att_item = null;
    public att_5:ui_att_item = null;
    public att_6:ui_att_item = null;
    public att_7:ui_att_item = null;
    public att_8:ui_att_item = null;
    public att_9:ui_att_item = null;
    public att_0:ui_att_item = null;
    public att_xing:ui_att_item = null;
    public att_jing:ui_att_item = null;

    public input_fail:ui_att_item = null;
    public input_default:ui_att_item = null;
    public input_right:ui_att_item = null;
    public font:ui_att_item = null;
    public answer:string = "0";
}
export class interact_page_data{
    public bg:ui_att_item = null;
    public btn_interact_left:ui_att_item = null;
    public btn_interact_right:ui_att_item = null;
    public img_item_interact_bg:ui_att_item = null;
    public btn_sure:ui_att_item = null;
    public img_item_interact_list:ui_att_item[] = [];
    public answer:number = 0;
}
export class interact_puzzle_data{
    public bg:ui_att_item = null;
    public content:ui_att_item = null;
    public puzzle1:ui_att_item = null;
    public puzzle2:ui_att_item = null;
    public puzzle3:ui_att_item = null;
    public puzzle4:ui_att_item = null;
    public puzzle5:ui_att_item = null;
    public puzzle6:ui_att_item = null;
    public answer:string = "0";
}
export class interact_scene_data{
    public scene:scene_item_data = null;
}
export class boss_info_data{
    public bg:ui_att_item = null;
    public bg_bar:ui_att_item = null;
    public bar:ui_att_item = null;
    public head:ui_att_item = null;
    public hp:number = 0;
}
export class pointer_ding_wei_data{
    public bg:ui_att_item = null;
    public pointer_bar:ui_att_item = null;
    public pointer_bar_point:ui_att_item =null;
    public img_text:ui_att_item = null;
    public img_eye_1:ui_att_item = null;
    public img_eye_2:ui_att_item = null;
    public btn_pointer_ding_wei_sure:ui_att_item = null;
    public rightLength:number = 200; //以进度条的中心点向左右个延长长度的一半
}
export class wei_chi_pointer_data{
    public bg:ui_att_item = null;
    public img_hand:ui_att_item = null;
    public img_bar:ui_att_item = null;
    public img_pointer:ui_att_item = null;
    public img_text_bing_zhu_hu_xi:ui_att_item = null;
    public btn_bingxi:ui_att_item = null;
    public rightLength:number = 200; //以进度条的中心点向左右个延长长度的一半
    public time:number = 3; //总时长
}
export class level_list_data {
    public zujian_id:number = 0;
    public level_list:bag_data[] = [] //关卡列表
}

export class widget_item_data  {
    constructor(n:string,t:number){
        this.name = n;
        this.type = t;
    }
    public name:string = "";
    public type:number =0;
    public att:attributes_data = null;
}

export class scene_item_data  {
    constructor(n:string,t:number,full:boolean=false){
        this.name = n;
        this.type = t;
        this.is_full_screen = full;
    }
    public index:number = 0;
    public name:string = "";
    public scene_diy_name:string = "";
    public type:number =0;  //0:单页 1:多页-上下 2:多页-左右
    public is_child_scene:boolean = false;
    public is_check_mask:boolean = false; //是否是遮罩
    public is_full_screen:boolean = false; //是否是铺满
    public page:number = 0;
    public page_list:scene_item_data[] = [];
    public _task_data:task_data = null; //一个场景有一个玩法（任务）
    public page_widget_list:widget_item_data[] = [];
    public att:attributes_data = null;
}

export class bag_item_data  {
    public name:string = "";
    public url:string = "";
}

export class bag_data  {
    public id:number = 0;
    public name:string = "";
    public is_edit:number = 0;
    public item_list:bag_item_data[] = []; //道具列表
    public bg_list:bag_item_data[] = []; //背景列表
    public component_list:bag_item_data[] = []; //组件列表
    public sound_list:bag_item_data[] = []; //音效列表
    public content:scene_item_data[] = null; //保存的数据
    public static initBagData(data:bag_data){   
        let t_data = new bag_data
        for (const key in data) {
            if (Object.prototype.hasOwnProperty.call(data, key)) {
                const element = data[key];
                t_data[key] = element;
            }
        }
        if(t_data.content.length>0){
            let  list:scene_item_data[] = JSON.parse(t_data.content.toString())
            t_data.content = list;
        }
        return t_data
    }
}


export class level_list_item_data {
    public id:number = 0;
    public name:string = "";
    public is_edit:number =0;
}

export class task_data{  //玩法===任务
    public type:number = config.task_type.da_guai;
    public event_list:event_item[] = [];
    public _zhao_xi_jie_data:zhao_xi_jie_data = null;
    public _guo_ju_qing:guo_ju_qing_data = null;
    public _da_guai:da_guai_data = null;
    public _guo_ju_qing_not_rule_data:guo_ju_qing_not_rule_data = null;
    public _guo_ju_qing_dai_dao_ju:guo_ju_qing_dai_dao_ju = null;
}

export class dai_dao_ju_item{
    public widget_id:number = -1; //控件id
    public is_in_bag:boolean = true; //是否默认在背包里
    public info_res:bag_item_data = new bag_item_data; 
}

export class guo_ju_qing_dai_dao_ju{
    public widget_list:dai_dao_ju_item[] = []
    public binding_count_time_widget:number = -1;
    public add_time_number:number = 0;
    public finish_event_id:number = -1;
}

export class da_guai_data{
    public widget_id_list:da_guai_item_data[] = []
}
export class guo_ju_qing_data{
    public binding_event_id:number = -1;
}
export class da_guai_item_data{
    public widget_id:number = -1; //控件id
    public hurt:number = 1; //伤害
}
export class zhao_xi_jie_item_data{
    public widget_id:number = -1; //控件id
    public res:string = ""; //资源
    public res_name:string = "";
    public tips_res:string = "";
    public tips_res_name:string = "";
}
export class zhao_xi_jie_data{
    public tip_type:number = config.zhao_xi_jie_tip_type.select_tips;
    public widget_id_list:zhao_xi_jie_item_data[] = []
    public finish_event_id:number = -1; //全部找到之后执行的事件
    static finish_widget_hidden_delay_time = 0; // 全部找到后组件隐藏延迟时间(无服务器返回,自主添加)
}
export class guo_ju_qing_not_rule_data { //先创建数据模型,目前没有属性
}

export class event_item{
    public event_id:number = 0;
    public event_name:string = "";
    public type:number = config.event_type.play_ani;
    public is_progress_event:boolean = true; //是否是进度事件
    public fail:event_item_fail = new event_item_fail;
    public success:event_item_success = new event_item_success;
    public event_item_play_ani_data:event_item_play_ani = null; //播放动画
    public event_item_top_view_data:event_item_top_view = null; //弹窗
    public event_item_text_sound_data:event_item_text_sound = null; //出现文字及语音
    public event_item_change_one_item_status_data:event_item_change_one_item_status = null; //改变指定道具资源
    public event_item_show_new_item_data:event_item_show_new_item = null; //出现新道具
    public event_item_hide_data:event_item_hide = null; //隐藏某个道具
    public event_item_delay_exe_data:event_item_delay_exe_event = null; //延迟执行一个事件
    public event_item_show_question_select_data:event_item_show_question_select = null; // 出现问题选择
    public event_item_countdown_over_data:event_item_countdown_over = null; //倒计时结束
    public event_item_be_event_data:event_item_be_event = null; //被动事件

    public event_item_start_event_data:event_start_event_item = null; //
    public event_item_collect_event_data:event_collect_event_item = null; // 
    public event_item_active_event_data:event_active_event_item = null; //
    public event_item_stop_active_event_data:event_stop_active_event_item = null; //

    public event_item_fail_event_data:event_item_fail_event = null; //失败事件
    public event_item_play_sound_data:event_item_play_sound = null; //播放一个音效

    public event_item_show_scene_title_data:event_item_show_scene_title = null; //场景标签
    public event_item_scene_ani:event_item_scene_ani = null; //场景动画
    public event_item_delete_drag_other_data:event_item_delete_drag_other = null; //删除其他拖拽的目标
    public event_item_stop_play_loop_sound_data:event_item_stop_play_loop_sound = null; //停止播放一个音效资源

    public event_item_switch_scene_event_data:event_item_switch_scene_event = null; // 切换场景事件
    public event_item_more_scene_is_show_arrow_event_data:event_item_more_scene_is_show_arrow_event = null;//多场景-是否显示箭头事件
    public event_item_more_scene_jump_assigned_page_event_data:event_item_more_scene_jump_assigned_page_event = null;//多场景-跳转指定页数事件

    public event_item_event_group_data:event_group_event_item = null;// 事件组
}
export class base_event_item{

}

export class event_item_fail_event { //失败事件
    public is_relife:boolean = false; //是否可以复活
    public is_show_animation:boolean = true; //是否显示动画,默认显示
}

export class event_item_show_scene_title {
    public title:string = "";
}

export class event_item_scene_ani {
    public ani_id:number = -1;
}
export class event_item_stop_play_loop_sound{
    public res:string = "";
}
export class event_item_delete_drag_other {
    public widget_id:number = -1;
    public widget_remark:string = '';//备注
    public delete_drag_other_index:number = -1; //废弃
    public widget_list:event_item_delete_drag_other[] = [] //列表
}

export class event_item_play_sound { //播放一个音效
    public sound_res:bag_item_data =  new bag_item_data;
    public isLoop:boolean = false;
    public volume:number = 1; //音量
}

export class event_item_success { //成功
    public is_finish_game:boolean = false; //全部通关完成
    public is_next_scene:boolean = false; //执行下一个场景
    public trigger_event_id:number = -1; //触发某个事件
}
export class event_item_fail { //失败
    public is_restart:boolean = false; //是否重新开始
    public is_relife:boolean = false; //是否复活
    public trigger_event_id:number = -1; //触发某个事件
}

export class event_item_play_ani extends base_event_item{ // 播放动画
    public binding_widget_id:number = -1; //绑定某一个控件进行播放动画
    public ani_id:number = -1; //该控件下选中的某个动画id
}
export class event_item_top_view extends base_event_item{ // 弹窗
    public binding_ui_id:number = -1; //绑定某一个UI
}
export class event_item_text_sound extends base_event_item{ //出现文字及语音
    public binding_widget_id:number = -1; //绑定某一个UI
}
export class event_item_change_one_item_status extends base_event_item{ //改变指定道具资源
    public binding_widget_id:number = -1; //绑定某一个UI
    public att:ui_att_item = new ui_att_item;
}
export class event_item_show_new_item extends base_event_item{ // 出现新道具
    public binding_widget_id:number = -1; //绑定某一个UI
}
export class event_item_hide extends base_event_item{ // 隐藏
    public binding_widget_id:number = -1; //绑定某一个UI
    public binding_widget_list:event_widget_more_event_item[] = [] //绑定事件列表
}

export class event_item_delay_exe_event extends base_event_item{ // 延迟多久执行一个事件
    public binding_event_id:number = -1; //绑定某一个事件
    public delay_time:number = 0;
}
export class event_item_show_question_select_item {
    public binding_event_id:number = -1; 
    public isRight:boolean = false;
}
export class event_item_show_question_select extends base_event_item{ // 出现问题选择
    public binding_widget_id:number = -1; //绑定某一个UI
    public question_list:event_item_show_question_select_item[] = []
}
export class event_start_event_item extends base_event_item{ // 开始的事件
    public binding_event_id:number = -1; //绑定事件
}
export class event_active_event_item extends base_event_item{ // 激活控件的事件
    public binding_widget_id:number = -1; //绑定事件
    public binding_widget_list:event_widget_more_event_item[] = [] //绑定事件列表
}
export class event_stop_active_event_item extends base_event_item{ // 不激活控件的事件,停用交互
    public binding_widget_id:number = -1; //绑定事件
    public binding_widget_list:event_widget_more_event_item[] = [] //绑定事件列表
}
export class event_collect_event_item extends base_event_item{ // 收集多个事件完成
    public event_id_list:number[] = []
}
export class event_item_countdown_over extends base_event_item{ //倒计时结束
    public binding_widget_id:number = -1; //绑定某一个UI
    public binding_fail_event_id:number = -1; //失败事件
    public binding_win_event_id:number = -1; //成功事件
}

export class event_item_be_event extends base_event_item{ // 被动事件
    public binding_widget_id:number = -1; //绑定某一个UI
}

export class event_item_switch_scene_event extends base_event_item { // 切换场景事件
    public binding_page_index:number = -1; //多场景-绑定页码索引(真实页数+1)
    public direction:number = config.switch_scene_page_direction.unknown;
    public executeOnlyOnce:boolean = true; //只执行一次
    public delay_time:number = 0;
}

export class event_item_more_scene_is_show_arrow_event extends base_event_item {
    public is_show:boolean = false;
}

export class event_item_more_scene_jump_assigned_page_event extends base_event_item {
    public page_number:number = -1;
    public interval_time:number = event_item_more_scene_jump_assigned_page_event.defaultIntervalTime(); //默认0.7
    static defaultIntervalTime():number{ return 0.7 }
}

export class event_group_event_item extends base_event_item{ // 事件组
    public list:event_group_event_item_event_item[] = []
}

export class event_widget_more_event_item extends base_event_item {
    public binding_widget_id:number = -1; //绑定事件
    public binding_widget_remark:string = ''; //备注
}

export class event_group_event_item_event_item extends base_event_item{
    public event_item:event_item = new event_item
    public delay_time:number = 0;
}

export class UserData {
    public user_id:string = null; //用户id
    public token:string = "";
    public select_page:number = 1; //用户当前选中的页数
    public isOpenYinXiao:boolean = true; //是否开启音效
    public isOpenYinYue:boolean = true; //是否开启音乐
    public isOpenPeiYin:boolean = true; //是否开启配音
    public unlock_levels:number[] = []; //解锁关卡
}
export class Message{
    public code:number = 0;
    public status:string = "";
    public message:string = "";
}

export class LevelMessage extends Message{
    public content :LevelListData = null;
}

export class LevelInfoMessage extends Message{
    public content :LevelInfo = null;
}

export class LevelInfo {
    public id:number = 0;
    public cover:string = "";
    public name:string = "";
    public content:scene_item_data[] = null;
}

export class LevelListData{
    public tool_number:number = 0;
    public list:LevelItemData[] = [];
}
export class LevelItemData{
    public id:number = 0; //关卡ID
    public cover:string = ""; //图片
    public complete_img:string = ""; //通关图片
    public name:string = "";//名称
    public piped_music:string = "";//背景音乐
    public ads_unlock:number = 0;//解锁广告数量
    public category_id:number = 0;//"0=>"无","1"=>"恐怖","2"=>"剧情","3"=>"怀旧","4"=>"脑洞","5"=>"推理"
    public label_id:number = 0; // "0"=>"无","1"=>"新","2"=>"热"
}
export class sysMessage extends Message{
    public content :sys_config = null;
}
export class sys_config {
    public sys_piped_music:string = null; //系统背景音乐
    public unlock_time:number = 0; //全部解锁时长 单位秒
    public unlock_ads:number = 0; //	全部解锁 广告数量
    public sys_click_button_music:string = null; //	点击按钮音效
    public sys_fail_scary_music:string = null; //		失败吓人音效
    public sys_fail_attack_music:string = null; //		失败后攻击音效
    public sys_fail_prompt_music:string = null; //		失败提示音效
    public sys_success_complete_music:string = null; //		正确通关音效
    public sys_click_correct_detail_music:string = null; //		点击正确细节音效
}