using System;
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.SocialPlatforms.Impl;
using UnityEngine.UI;

public class Powersupplytest : MonoBehaviour
{
    public static Powersupplytest Instance;
    /// <summary>
    /// 下一题按钮
    /// </summary>
    public Button nextquestion1, nextquestion2;
    /// <summary>
    /// 上一题按钮
    /// </summary>
    public Button previousquestion1, previousquestion2;
    /// <summary>
    /// 每题切换页面
    /// </summary>
    public GameObject Powersupplybaseplate1, Powersupplybaseplate2, Powersupplybaseplate3;
    /// <summary>
    /// 填空题答案
    /// </summary>
    public InputField topiicinput1, topiicinput2, topiicinput3, topiicinput4, topiicinput5, topiicinput6, topiicinput7;
    /// <summary>
    /// 选择题答案
    /// </summary>
    public InputField selectinput1, selectinput2;
    /// <summary>
    /// 判断题答案
    /// </summary>
    public InputField judgmentinput1, judgmentinput2, judgmentinput3;
    void Start()
    {
        Instance = this;    
        Topicswitching();//题目切换
    }
    /// <summary>
    /// 每个题目之间切换
    /// </summary>
    private void Topicswitching()
    {
        nextquestion1.onClick.AddListener(() =>
        {
            Powersupplybaseplate1.SetActive(false);
            nextquestion1.gameObject.SetActive(false);
            nextquestion2.gameObject.SetActive(true);
            previousquestion1.gameObject.SetActive(true);
            Powersupplybaseplate2.SetActive(true);
        });
        nextquestion2.onClick.AddListener(() =>
        {
            Powersupplybaseplate2.SetActive(false);
            nextquestion2.gameObject.SetActive(false);
            previousquestion1.gameObject.SetActive(false);
            previousquestion2.gameObject.SetActive(true);
            Powersupplybaseplate3.SetActive(true);
        });
        previousquestion1.onClick.AddListener(() =>
        {
            Powersupplybaseplate2.SetActive(false);
            nextquestion2.gameObject.SetActive(false);
            previousquestion1.gameObject.SetActive(false);
            nextquestion1.gameObject.SetActive(true);
            Powersupplybaseplate1.SetActive(true);
        });
        previousquestion2.onClick.AddListener(() =>
        {
            Powersupplybaseplate3.SetActive(false);
            previousquestion2.gameObject.SetActive(false);
            nextquestion2.gameObject.SetActive(true);
            previousquestion1.gameObject.SetActive(true);
            Powersupplybaseplate2.SetActive(true);

        });
    }
    /// <summary>
    /// 供电交卷判断得分
    /// </summary>
    public void Powersupplyhandover()
    {
        float Supplyfraction = 0f;
        string str;
        float scoring = 0f;
        Supplyfraction = (float.Parse(ScoreManager.Instance.totalpoints[0]) / 7);//判断填空题得分
        if ((Supplyfraction - Mathf.Floor(Supplyfraction)) < 0.001f)
        {
            str = Supplyfraction.ToString();
        }
        else
        {
            str = Supplyfraction.ToString("f2");
        }
        if (topiicinput1.text == "电力")
        {
            scoring += (float.Parse(str));
        }
        if (topiicinput2.text == "格式")
        {
            scoring += (float.Parse(str));
        }
        if (topiicinput3.text == "连续")
        {
            scoring += (float.Parse(str));
        }
        if (topiicinput4.text == "抢修义务")
        {
            scoring += (float.Parse(str));
        }
        if (topiicinput5.text == "缴纳电费")
        {
            scoring += (float.Parse(str));
        }
        if (topiicinput6.text == "±5%")
        {
            scoring += (float.Parse(str));
        }
        if (topiicinput7.text == "四")
        {
            scoring += (float.Parse(str));
        }
        ScoreManager.Instance.Powersupplytests[0] = scoring;//第一答题得分
        float select1 = 0f;
        string str2;
        float select2 = 0f;
        select1 = (float.Parse(ScoreManager.Instance.totalpoints[1]) / 2);
        if ((select1 - Mathf.Floor(select1)) < 0.001f)
        {
            str2 = select1.ToString();
        }
        else
        {
            str2 = select1.ToString("f2");
        }
        if (selectinput1.text == "C")
        {
            select2 += float.Parse(str2);
        }
        if (selectinput2.text == "D")
        {
            select2 += float.Parse(str2);
        }
        ScoreManager.Instance.Powersupplytests[1] = select2;
        float select3 = 0f;
        string str3;
        float select4 = 0f;
        select3= (float.Parse(ScoreManager.Instance.totalpoints[2]) / 3);
        if ((select3 - Mathf.Floor(select3)) < 0.001f)
        {
            str3 = select3.ToString();
        }
        else
        {
            str3 = select3.ToString("f2");
        }
        if (judgmentinput1.text=="对")
        {
            select4 += float.Parse(str3);
        }
        if (judgmentinput2.text == "错")
        {
            select4 += float.Parse(str3);
        }
        if (judgmentinput3.text == "错")
        {
            select4 += float.Parse(str3);
        }
        ScoreManager.Instance.Powersupplytests[2] = select4;
    }

    void Update()
    {

    }
}