void BtnLineTitleRightOnClick()
 {
     if (isConnectLine == false)
     {
         return;
     }
     mSelectedLineIndex++;
     if (mSelectedLineIndex >= 0 && mSelectedLineIndex < mRailLineList.Count)
     {
         UIRailLine line = mRailLineList[mSelectedLineIndex];
         if (line.mRoute.pointCount > 0)
         {
             OnSeletedLine(true, line.mRoute.id, line.mRoute.GetPointByIndex(0).id);
         }
     }
     else
     {
         if (mRailLineList.Count > 0)
         {
             mSelectedLineIndex = 0;
             UIRailLine line = mRailLineList[mSelectedLineIndex];
             if (line.mRoute.pointCount > 0)
             {
                 OnSeletedLine(true, line.mRoute.id, line.mRoute.GetPointByIndex(0).id);
             }
         }
     }
 }
    void OnLineNameChange(string text)
    {
        if ("" != text.Trim() && isConnectLine)
        {
            UIRailLine line = mRailLineList.Find(
                delegate(UIRailLine li)
            {
                return(li.mRoute.id == mSelectedLineId);
            });

            if (line != null && line.mRoute.name != text)
            {
                if (!Railway.Manager.Instance.IsRouteNameExist(text))
                {
                    line.mRoute.name    = text;
                    mTitleLineName.text = text;
                    if (null != e_ResetRouteName)
                    {
                        e_ResetRouteName(line.mRoute.id, text);
                    }
                }
                else
                {
                    MessageBox_N.ShowOkBox(UIMsgBoxInfo.ReNameNotice.GetString());
                }
                mLineName.text = line.mRoute.name;
            }
        }
    }
    void DeleteUIRailLine(Railway.Route _rail)
    {
        UIRailLine line = mRailLineList.Find(
            delegate(UIRailLine li)
        {
            return(li.mRoute == _rail);
        });

        if (line != null)
        {
            GameObject.Destroy(line.gameObject);
            mRailLineList.Remove(line);
        }
    }
    void AddUIRailLine(Railway.Route _rail)
    {
        GameObject line = GameObject.Instantiate(mLinePrefab) as GameObject;

        line.transform.parent        = mLinesContent.transform;
        line.transform.localPosition = new Vector3(0, 0, 0);
        line.transform.localScale    = new Vector3(1, 1, 1);

        UIRailLine uiLine = line.GetComponent <UIRailLine>();

        uiLine.Init(_rail);
        uiLine.CreateLine();
        uiLine.ResetLinePos(mMapCtrl);

        uiLine.mSelectedLine += OnSeletedLine;

        mRailLineList.Add(uiLine);
    }
    void BtnStationTitleRightOnClick()
    {
        if (mSelectedStation == null)
        {
            return;
        }

        if (isConnectLine)
        {
            UIRailLine Line = mRailLineList.Find(
                delegate(UIRailLine li)
            {
                return(li.mRoute.id == mSelectedLineId);
            });

            if (Line == null || Line.mRoute.pointCount == 0)
            {
                return;
            }

            int index = Line.FindStationIndex(mSelectedStation.mRailPointData.id);
            do
            {
                index++;
                if (index < 0 || index >= Line.mRoute.pointCount)
                {
                    break;
                }
            }while(Line.mRoute.GetPointByIndex(index).pointType == Railway.Point.EType.Joint);

            if (index < 0 || index >= Line.mRoute.pointCount)
            {
                index = 0;
            }

            if (Line.mRoute.pointCount > 0)
            {
                OnSeletedLine(true, Line.mRoute.id, Line.mRoute.GetPointByIndex(index).id);
            }
        }
        else
        {
            UIDisconnectionLine Line = mDisRailLineList.Find(
                delegate(UIDisconnectionLine li)
            {
                return(li.mIndex == mSelectedLineId);
            });

            if (Line == null || Line.mPointList.Count == 0)
            {
                return;
            }

            int index = Line.FindStationIndex(mSelectedStation.mRailPointData.id);
            do
            {
                index++;
                if (index < 0 || index >= Line.mPointList.Count)
                {
                    break;
                }
            }while(Line.mPointList[index].pointType == Railway.Point.EType.Joint);

            if (index < 0 || index >= Line.mPointList.Count)
            {
                index = 0;
            }

            if (Line.mPointList.Count > 0)
            {
                OnSeletedLine(false, Line.mIndex, Line.mPointList[index].id);
            }
        }
    }
    void OnSeletedLine(bool isConnect, int routeID, int stationID)
    {
        isConnectLine = isConnect;

        ChangeUILineInfo(isConnect);

        if (mSelectedLineId != -1)
        {
            UIRailLine lineOld = mRailLineList.Find(
                delegate(UIRailLine li)
            {
                return(li.mRoute.id == mSelectedLineId);
            });
            if (lineOld != null)
            {
                lineOld.SetSelected(false);
            }

            UIDisconnectionLine disLineOld = mDisRailLineList.Find(
                delegate(UIDisconnectionLine li)
            {
                return(li.mIndex == mSelectedLineId);
            });
            if (disLineOld != null)
            {
                disLineOld.SetSelected(false);
            }
        }


        if (isConnect)
        {
            UIRailLine line = mRailLineList.Find(
                delegate(UIRailLine li)
            {
                return(li.mRoute.id == routeID);
            });
            if (line == null)
            {
                ClearLineInfo();
                return;
            }

            mSelectedLineIndex = mRailLineList.FindIndex(
                delegate(UIRailLine li)
            {
                return(li == line);
            });


            line.SetSelected(true);
            mSelectedLineId = routeID;
            SetLineInfo(line.mRoute);

            if (mSelectedStation != null)
            {
                mSelectedStation.SetSelected(false);
            }

            UIRailStation station = line.FindStation(stationID);
            if (station != null)
            {
                station.SetSelected(true);
                mSelectedStation = station;
            }
            SetSatationInfo(station.mRailPointData);
            EnableBtn(mBtnStop, true);
        }

        else
        {
            int index = routeID;

            UIDisconnectionLine disLine = mDisRailLineList.Find(
                delegate(UIDisconnectionLine li)
            {
                return(li.mIndex == index);
            });

            if (disLine == null)
            {
                ClearLineInfo();
                return;
            }

            disLine.SetSelected(true);
            mSelectedLineId = index;

            if (mSelectedStation != null)
            {
                mSelectedStation.SetSelected(false);
            }

            UIRailStation station = disLine.FindStation(stationID);
            if (station != null)
            {
                station.SetSelected(true);
                mSelectedStation = station;
            }
            SetSatationInfo(station.mRailPointData);
            bool ok = PERailwayCtrl.CheckRoute(station.mRailPointData);
            EnableBtn(mBtnStop, ok);
        }
    }