コード例 #1
0
    void AddLibraries()
    {
        int countLib = ctGameManager.Singleton.m_Libraries.Count;

        TxtLibCount.text = string.Format("({0}) libraries", countLib);
        if (countLib <= 0)
        {
            return;
        }

        LibraryList.GetComponent <ToggleGroup>().allowSwitchOff = true;

        curLibIdx = Mathf.Clamp(curLibIdx, 0, countLib - 1);
        for (int i = 0; i < ctGameManager.Singleton.m_Libraries.Count; i++)
        {
            ctLibrary lib = ctGameManager.Singleton.m_Libraries[i];

            GameObject childObj = GameObject.Instantiate(LibraryListCell);
            //childObj.transform.parent = LibraryList.transform;
            childObj.transform.SetParent(LibraryList.transform, false);

            string text = string.Format("{0} ({1})", lib.name, lib.lines.Count);

            childObj.GetComponent <LibraryCell>().Init(i, text, ScrollRect, CallbackTouchCell);
            //childObj.GetComponent<Toggle>().group = LibraryList.GetComponent<ToggleGroup>();
            childObj.GetComponent <Toggle>().isOn = curLibIdx == i ? true : false;
            childObj.GetComponent <Toggle>().onValueChanged.AddListener(OnLibCellChanged);

            cells.Add(childObj);
        }

        //LibraryList.GetComponent<ToggleGroup>().allowSwitchOff = false;
    }
コード例 #2
0
ファイル: ctGameManager.cs プロジェクト: older007/ChsBernard
    public void saveData()
    {
        PlayerPrefs.SetInt(LIBRARY_COUNT_KEY, m_Libraries.Count);
        if (m_Libraries.Count > 0)
        {
            for (int idxLib = 0; idxLib < m_Libraries.Count; idxLib++)
            {
                ctLibrary lib = m_Libraries[idxLib];
                PlayerPrefs.SetString(LIBRARY_NAME_KEY + idxLib.ToString(), lib.name);
                PlayerPrefs.SetInt(LINE_COUNT_KEY + idxLib.ToString(), lib.lines.Count);

                for (int idxLine = 0; idxLine < lib.lines.Count; idxLine++)
                {
                    ctLine line = lib.lines[idxLine];
                    PlayerPrefs.SetString(LINE_NAME_KEY + idxLib.ToString() + "_" + idxLine.ToString(), line.name);
                    PlayerPrefs.SetString(LINE_ORDER_KEY + idxLib.ToString() + "_" + idxLine.ToString(), line.moves);
                }
            }
        }

        PlayerPrefs.SetString(TRAINER_NAME, m_Trainer.name);
        PlayerPrefs.SetFloat(TRAINER_SCORE, m_Trainer.score);

        PlayerPrefs.Save();
    }
コード例 #3
0
ファイル: ctLibrary.cs プロジェクト: older007/ChsBernard
    public void Clone(ctLibrary _lib)
    {
        this.name = _lib.name;

        for (int i = 0; i < _lib.lines.Count; i++)
        {
            ctLine line = new ctLine(this, _lib.lines[i].name, _lib.lines[i].moves);
            AddLine(line);
        }
    }
コード例 #4
0
ファイル: ctGameManager.cs プロジェクト: older007/ChsBernard
    public void RemoveLibrary(string _name)
    {
        ctLibrary lib = GetLibrary(_name);

        if (lib == null)
        {
            return;
        }

        m_Libraries.Remove(lib);
    }
コード例 #5
0
ファイル: ctGameManager.cs プロジェクト: older007/ChsBernard
    public ctLine GetLine(string _libName, string _lineName)
    {
        ctLibrary lib = GetLibrary(_libName);

        if (lib != null)
        {
            return(lib.GetLine(_lineName));
        }

        return(null);
    }
コード例 #6
0
ファイル: ctGameManager.cs プロジェクト: older007/ChsBernard
    void _createDefaultLibrary()
    {
        ctLibrary lib = new ctLibrary();

        lib.name = "Spanish Openings";

        ctLine line = new ctLine(lib, "Morphy Defense", "1. e4 e5 2. Nf3 Nc6 3. Bb5 a6 ");

        lib.AddLine(line);

        AddLibrary(lib);
    }
コード例 #7
0
ファイル: ctGameManager.cs プロジェクト: older007/ChsBernard
    public void loadData()
    {
        m_Libraries.Clear();

        int libCount = PlayerPrefs.GetInt(LIBRARY_COUNT_KEY, 0);

        if (libCount > 0)
        {
            for (int idxLib = 0; idxLib < libCount; idxLib++)
            {
                ctLibrary lib = new ctLibrary();
                lib.name = PlayerPrefs.GetString(LIBRARY_NAME_KEY + idxLib.ToString(), "");
                int lineCount = PlayerPrefs.GetInt(LINE_COUNT_KEY + idxLib.ToString(), 0);

                for (int idxLine = 0; idxLine < lineCount; idxLine++)
                {
                    string lineName  = PlayerPrefs.GetString(LINE_NAME_KEY + idxLib.ToString() + "_" + idxLine.ToString(), "");
                    string lineMoves = PlayerPrefs.GetString(LINE_ORDER_KEY + idxLib.ToString() + "_" + idxLine.ToString(), "");

                    ctLine line = new ctLine(lib, lineName, lineMoves);

                    if (lib.GetLineIdx(line.name) > -1)
                    {
                        Debug.Log("Duplicated line name found, cannot add line");
                    }
                    else
                    {
                        lib.AddLine(line);
                    }
                }

                if (GetLibrary(lib.name) != null)
                {
                    //
                    Debug.Log("Duplicated library name found, cannot add library");
                }
                else
                {
                    AddLibrary(lib);
                }
            }
        }
        else
        {
            _createDefaultLibrary();
        }

        m_Trainer.name  = PlayerPrefs.GetString(TRAINER_NAME, "Michael");
        m_Trainer.score = PlayerPrefs.GetFloat(TRAINER_SCORE, 0);
    }
コード例 #8
0
    void AddLines()
    {
        int i = 0;

        for (i = 0; i < List_Lines.transform.childCount; i++)
        {
            Destroy(List_Lines.transform.GetChild(i).gameObject);
        }

        LineCellObjs.Clear();
        LineList.Clear();

        i = 0;
        for (int idxLib = 0; idxLib < LibraryList.Count; idxLib++)
        {
            ctLibrary lib = ctGameManager.Singleton.GetLibrary(LibraryList[idxLib]);

            for (int idxLine = 0; idxLine < lib.lines.Count; idxLine++)
            {
                if (lib.lines[idxLine].moveList.Count < 1)
                {
                    continue;
                }

                LineList.Add(lib.lines[idxLine]);

                GameObject childObj = GameObject.Instantiate(LineListCellPrefab);

                childObj.transform.SetParent(List_Lines.transform, false);

                string text = string.Format("{0} ({1})", lib.lines[idxLine].fullName, lib.lines[idxLine].moveList.Count);

                childObj.GetComponent <LibraryCell>().Init(i, text, ScrollViewLineList);
                childObj.GetComponent <LibraryCell>().SetToggleMode(true);
                //childObj.GetComponent<Toggle>().group = LibraryList.GetComponent<ToggleGroup>();
                childObj.GetComponent <Toggle>().isOn = true;
                childObj.GetComponent <Toggle>().onValueChanged.AddListener(OnListLineSellChange);

                if (Tgl_AllLines.isOn)
                {
                    childObj.GetComponent <Toggle>().enabled = false;
                }

                LineCellObjs.Add(childObj);
                i++;
            }
        }
    }
コード例 #9
0
ファイル: ctGameManager.cs プロジェクト: older007/ChsBernard
    public bool RenameLibrary(string _oldName, string _newName)
    {
        ctLibrary lib = GetLibrary(_oldName);

        if (lib == null)
        {
            return(false);
        }

        if (GetLibrary(_newName) != null)
        {
            return(false);
        }

        lib.name = _newName;
        return(true);
    }
コード例 #10
0
    public void Init(string _libName)
    {
        libName         = _libName;
        TxtLibName.text = libName;
        library         = ctGameManager.Singleton.GetLibrary(libName);

        if (library == null)
        {
            library = null;

            Debug.Log("Cannot find library, name = " + libName);
            return;
        }

        curLineIdx = 0;
        UpdateWnd();
        SetToggleMode(false);
    }
コード例 #11
0
ファイル: ctGameManager.cs プロジェクト: older007/ChsBernard
    public bool AddLibrary(ctLibrary _lib, bool _sort = false)
    {
        if (GetLibrary(_lib.name) != null)
        {
            return(false);
        }

        m_Libraries.Add(_lib);

        if (_sort)
        {
            m_Libraries.Sort(delegate(ctLibrary p1, ctLibrary p2)
            {
                return(p1.name.CompareTo(p2.name));
            });
        }

        return(true);
    }
コード例 #12
0
    public bool CallbackTouchCell(int _id, bool _longTouch, PointerEventData _eventData)
    {
        ctLibrary lib = ctGameManager.Singleton.GetLibrary(_id);

        if (lib == null)
        {
            return(true);
        }

        curLibIdx = _id;
        if (_longTouch)
        {
            SetToggleMode(true);
        }
        else
        {
            WndManager.Singleton.OpenLibraryPage(lib.name);
        }

        return(true);
    }
コード例 #13
0
    bool CallBackAdd(string _name)
    {
        if (_name.Equals(""))
        {
            WndManager.Singleton.OpenMsgBox("The name cannot be empty.");
            return(false);
        }

        if (ctGameManager.Singleton.GetLibrary(_name) != null)
        {
            WndManager.Singleton.OpenMsgBox("Duplicated name.");
            return(false);
        }

        ctLibrary lib = new ctLibrary();

        lib.name = _name;
        ctGameManager.Singleton.AddLibrary(lib, true);

        UpdateWnd();
        return(true);
    }
コード例 #14
0
ファイル: ctLine.cs プロジェクト: older007/ChsBernard
 public ctLine(ctLibrary _parent, string _name, string _moves = "")
 {
     parent = _parent;
     name   = _name;
     moves  = _moves;
 }