public int CompareTo(object obj)
        {
            int result = -1;

            try
            {
                GpsMapMonitorSpot ms = obj as GpsMapMonitorSpot;
                if (ms != null)
                {
                    result = this.Id.CompareTo(ms.Id);
                }
                else
                {
                    result = this.Id.CompareTo(obj);
                }
            }
            catch (Exception ex)
            {
                XxdwDebugger.Log(ex.Message);
            }
            return(result);
        }
Exemple #2
0
        private void Zoom()
        {
            if (this.gpsMap == null)
            {
                return;
            }

            float orthographicSize = this.gpsMap.GetZoomOrthographicSize(this.zoomLevel);

            // this.camera.orthographicSize 为相机视口纵幅的一半
            // this.camera.orthographicSize * this.camera.aspect 为相机视口横幅的一半
            this.cameraRange.xMin = orthographicSize * this.GetComponent <Camera>().aspect + this.gpsMap.MapRange.xMin;
            this.cameraRange.xMax = -orthographicSize *this.GetComponent <Camera>().aspect + this.gpsMap.MapRange.xMax;

            this.cameraRange.yMin = orthographicSize + this.gpsMap.MapRange.yMin;
            this.cameraRange.yMax = -orthographicSize + this.gpsMap.MapRange.yMax;
            XxdwDebugger.Log("cameraRange:(" + this.cameraRange.xMin + "," + this.cameraRange.yMin + "),(" + this.cameraRange.xMax + "," + this.cameraRange.yMax + ")");

            Vector3 v = LimitRange(this.GetComponent <Camera>().transform.position);

            this.GetComponent <Camera>().orthographicSize = orthographicSize;
            this.cameraTarget = v;
            MoveCamera();
        }
        public void AddObserver(Component observer, string name, int priority, object sender)
        {
            // If the name isn't good, then throw an error and return.
            if (name == null || name == "")
            {
                XxdwDebugger.Log("Null name specified for notification in AddObserver."); return;
            }
            // If this specific notification doens't exist yet, then create it.
            if (!notifications.ContainsKey(name))
            {
                notifications[name] = new List <Observer>();
            }

            List <Observer> notifyList = (List <Observer>)notifications[name];

            // If the list of observers doesn't already contain the one that's registering, then add it.
            Observer o     = new Observer(observer, priority, sender);
            int      index = notifyList.BinarySearch(o);

            if (index < 0)
            {
                notifyList.Insert(~index, o);
            }
        }
Exemple #4
0
        // 输出的顶点数和边数相同
        public bool FindCell2CrossPath(GpsMapCell from, GpsMapCell cross,
                                       out List <MapPathGraph.NavigateVertexNode> listNavigateVertexNode, out List <MapPathGraph.Edge> listEdge)
        {
            listNavigateVertexNode = null;
            listEdge = null;

            from = FindNearestCellOf(from, GpsMapCell.EType.EN_ROAD);
            if (from == null)
            {
                XxdwDebugger.Log("Road nearby not found. Strange!");
                return(false);
            }

            int crossVertexIndex = this.pathGraph.FindVertex(cross.Index);

            if (crossVertexIndex < 0)
            {
                XxdwDebugger.Log("Target cross not found. Strange!");
                return(false);
            }
            MapPathGraph.VertexNode vnTo = this.pathGraph.VertexList[crossVertexIndex];

            MapPathGraph.VertexNode vn1, vn2;
            MapPathGraph.Edge       e;
            int spotIndex = FindEdgeOfRoadCell(from.Index, out vn1, out vn2, out e);

            if (spotIndex < 0)
            {
                XxdwDebugger.Log("Cross of road not found. Strange!");
                return(false);
            }
            float w1 = CalcDetailWeight(e.Spots, 0, spotIndex + 1);
            float w2 = CalcDetailWeight(e.Spots, spotIndex, e.Spots.Length);

            int[] spots1 = new int[spotIndex + 1];
            Array.Copy(e.Spots, 0, spots1, 0, spotIndex + 1);
            int[] spots2 = new int[e.Spots.Length - spotIndex];
            Array.Copy(e.Spots, spotIndex, spots2, 0, e.Spots.Length - spotIndex);

            MapPathGraph.Edge e1, e2;
            if (e.Spots[0] == vn1.Cell)
            {
                e1 = new MapPathGraph.Edge(vn1.Cell, e.Spots[spotIndex], w1, spots1, "");
                e1.ReverseSpots();
                e2 = new MapPathGraph.Edge(vn2.Cell, e.Spots[spotIndex], w2, spots2, "");
            }
            else
            {
                e1 = new MapPathGraph.Edge(vn1.Cell, e.Spots[spotIndex], w2, spots2, "");
                e2 = new MapPathGraph.Edge(vn2.Cell, e.Spots[spotIndex], w1, spots1, "");
                e2.ReverseSpots();
            }


            List <MapPathGraph.NavigateVertexNode> listNavigateVertexNode1 = new List <MapPathGraph.NavigateVertexNode>();
            List <MapPathGraph.NavigateVertexNode> listNavigateVertexNode2 = new List <MapPathGraph.NavigateVertexNode>();
            AStarHelper ash = new AStarHelper(this.CalcDistanceWeight);

            ash.Clear();
            float weight1 = this.pathGraph.FindShortestPaths(ash, vn1, vnTo, listNavigateVertexNode1);

            weight1 += weight1 >= 0 ? w1 : Parameters.MAX_EDGE_WEIGHT;
            ash.Clear();
            float weight2 = this.pathGraph.FindShortestPaths(ash, vn2, vnTo, listNavigateVertexNode2);

            weight2 += weight2 >= 0 ? w2 : Parameters.MAX_EDGE_WEIGHT;
            if (listNavigateVertexNode1.Count == 0 && listNavigateVertexNode2.Count == 0)
            {
                return(false);
            }

            listEdge = new List <MapPathGraph.Edge>();
            if (weight1 < weight2)
            {
                listNavigateVertexNode1[0].SelectedEdgeIndex = this.pathGraph.GetEdgeNumber(vn1, e);
                listNavigateVertexNode = listNavigateVertexNode1;
                this.pathGraph.NormalizeVertexAndSpotsOrder(listNavigateVertexNode, listEdge);
                listEdge.Insert(0, e1);
            }
            else
            {
                listNavigateVertexNode2[0].SelectedEdgeIndex = this.pathGraph.GetEdgeNumber(vn2, e);
                listNavigateVertexNode = listNavigateVertexNode2;
                this.pathGraph.NormalizeVertexAndSpotsOrder(listNavigateVertexNode, listEdge);
                listEdge.Insert(0, e2);
            }

            return(true);
        }
Exemple #5
0
        private void DataThreadFunc()
        {
            XxdwDebugger.Log("GpsMap: DataThreadFunc() entering...");
            try
            {
                this.LoadingStatus = SafeStatus.LS_NULL;

                int    pos        = this.mapXmlText.IndexOf("<cells>");
                string strMapData = this.mapXmlText.Substring(0, pos);
                strMapData += "</grid>";
                string strCellAndPathData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<grid>\n";
                strCellAndPathData += this.mapXmlText.Substring(pos);

                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(new StringReader(strMapData));

                XmlNode node = xmlDoc.SelectSingleNode("/grid/mapName");
                this.name            = (node == null ? "" : node.InnerText.Trim());
                node                 = xmlDoc.SelectSingleNode("/grid/sliceWidth");
                this.sliceWidth      = (node == null ? 0 : int.Parse(node.InnerText.Trim()));
                node                 = xmlDoc.SelectSingleNode("/grid/sliceHeight");
                this.sliceHeight     = (node == null ? 0 : int.Parse(node.InnerText.Trim()));
                node                 = xmlDoc.SelectSingleNode("/grid/triggerDistance");
                this.triggerDistance = (node == null ? 0 : int.Parse(node.InnerText.Trim()));

                node                  = xmlDoc.SelectSingleNode("/grid/pixelWidth");
                this.pixelWidth       = int.Parse(node.InnerText.Trim());
                node                  = xmlDoc.SelectSingleNode("/grid/pixelHeight");
                this.pixelHeight      = int.Parse(node.InnerText.Trim());
                node                  = xmlDoc.SelectSingleNode("/grid/gridCellPixelNum");
                this.gridCellPixelNum = int.Parse(node.InnerText.Trim());
                this.rowNum           = this.pixelHeight / this.gridCellPixelNum;
                this.colNum           = this.pixelWidth / this.gridCellPixelNum;

                this.mapRange = new Rect(-(float)this.PixelWidth / 2 / UNIT_PIXEL_NUM,
                                         -(float)this.pixelHeight / 2 / UNIT_PIXEL_NUM,
                                         (float)this.PixelWidth / UNIT_PIXEL_NUM,
                                         (float)this.PixelHeight / UNIT_PIXEL_NUM);
                XxdwDebugger.Log("rowNum=" + this.rowNum + "colNum=" + this.colNum
                                 + " mapRange:(" + this.mapRange.xMin + "," + this.mapRange.yMin + "),(" + this.mapRange.xMax + "," + this.mapRange.yMax + ")");

                node = xmlDoc.SelectSingleNode("/grid/rolePositionIndex");
                if (node != null)
                {
                    this.rolePositionIndex = int.Parse(node.InnerText.Trim());
                }

                node = xmlDoc.SelectSingleNode("/grid/gridCellLongitudeDiff");
                this.gridCellLongitudeDiff = float.Parse(node.InnerText.Trim());
                node = xmlDoc.SelectSingleNode("/grid/gridCellLatitudeDiff");
                this.gridCellLatitudeDiff = float.Parse(node.InnerText.Trim());
                node = xmlDoc.SelectSingleNode("/grid/gridCellDistance");
                this.gridCellDistance = float.Parse(node.InnerText.Trim());
                node = xmlDoc.SelectSingleNode("/grid/gridCellDiagonalDistance");
                this.gridCellDiagonalDistance = float.Parse(node.InnerText.Trim());
                node = xmlDoc.SelectSingleNode("/grid/zeroLongitude");
                this.zeroLongitude = float.Parse(node.InnerText.Trim());
                node = xmlDoc.SelectSingleNode("/grid/zeroLatitude");
                this.zeroLatitude = float.Parse(node.InnerText.Trim());

                node                     = xmlDoc.SelectSingleNode("/grid/baseIndex1");
                this.baseIndex1          = int.Parse(node.InnerText.Trim());
                node                     = xmlDoc.SelectSingleNode("/grid/baseIndex2");
                this.baseIndex2          = int.Parse(node.InnerText.Trim());
                node                     = xmlDoc.SelectSingleNode("/grid/basePoint1Longitude");
                this.basePoint1Longitude = float.Parse(node.InnerText.Trim());
                node                     = xmlDoc.SelectSingleNode("/grid/basePoint1Latitude");
                this.basePoint1Latitude  = float.Parse(node.InnerText.Trim());
                node                     = xmlDoc.SelectSingleNode("/grid/basePoint2Longitude");
                this.basePoint2Longitude = float.Parse(node.InnerText.Trim());
                node                     = xmlDoc.SelectSingleNode("/grid/basePoint2Latitude");
                this.basePoint2Latitude  = float.Parse(node.InnerText.Trim());

                this.LoadingStatus |= SafeStatus.LS_INFO_DATA;
                XxdwDebugger.Log("GpsMap: DataThreadFunc(), post NOTI_MAP_INFO_READY");
                AsyncNotification.Instance.PostNotification(this, Notification.NOTI_MAP_INFO_READY, this.LoadingStatus, this.name);

                //--------------------------------------------------------------------------------------
                xmlDoc.Load(new StringReader(strCellAndPathData));

                // read cells of the grid
                this.grid = new GpsMapCell[this.rowNum, this.colNum];

                string      xmlPathPattern = "/grid/cells/r";
                XmlNodeList rows           = xmlDoc.SelectNodes(xmlPathPattern);
                if (rows != null && rows.Count > 0)
                {
                    foreach (XmlNode xn in rows)
                    {
                        int         i    = int.Parse(xn.Attributes["v"].InnerText);
                        XmlNodeList cols = xn.SelectNodes("./c");
                        foreach (XmlNode cell in cols)
                        {
                            int j = int.Parse(cell.Attributes["v"].InnerText);
                            if (!(i >= 0 && i < this.rowNum && j >= 0 && j < this.colNum))
                            {
                                continue;
                            }

                            node = cell.SelectSingleNode("./t");
                            int type = int.Parse(node.InnerText.Trim());

                            node = cell.SelectSingleNode("./d");
                            string data = (node == null ? "" : node.InnerText.Trim());

                            int entryNumber = 0;
                            if ((type & (int)GpsMapCell.EType.EN_CROSS) != 0)
                            {
                                node = cell.SelectSingleNode("./n");
                                if (node != null)
                                {
                                    entryNumber = int.Parse(node.InnerText.Trim());
                                }
                            }

                            this.grid[i, j] = new GpsMapCell(i * this.colNum + j, i, j, (GpsMapCell.EType)type, data, entryNumber);

                            //---------------------------------------------------------------------------------
                            // 触发点,以触发点编号排序插入
                            if ((type & (int)GpsMapCell.EType.EN_MONITOR_POINT) != 0)
                            {
                                node = cell.SelectSingleNode("./d2");
                                if (node != null)
                                {
                                    string   data2       = node.InnerText.Trim();
                                    string[] ssid_number = data2.Split(new char[] { '_' });
                                    if (ssid_number.Length == 2)
                                    {
                                        GpsMapMonitorSpot ms = new GpsMapMonitorSpot(data2, ssid_number[0], i * this.colNum + j);
                                        int index            = this.listMonitorSpots.BinarySearch(ms);
                                        if (index < 0)
                                        {
                                            this.listMonitorSpots.Insert(~index, ms);
                                        }
                                    }
                                    else
                                    {
                                        XxdwDebugger.LogWarning("Invalid monitor spot data at: " + (i * this.colNum + j));
                                    }
                                }
                                else
                                {
                                    XxdwDebugger.LogWarning("Monitor spot without data at: " + (i * this.colNum + j));
                                }
                            }
                        }
                    }
                }

                this.LoadingStatus |= SafeStatus.LS_CELL_DATA;
                XxdwDebugger.Log("GpsMap: DataThreadFunc(), post NOTI_MAP_DATA_READY cell_data ok");
                AsyncNotification.Instance.PostNotification(this, Notification.NOTI_MAP_DATA_READY, this.LoadingStatus, this.name);

                //--------------------------------------------------------------------------------------
                // read the road data of the grid, which will shape a Data Structure of Graph.
                xmlPathPattern = "/grid/edges/e";
                XmlNodeList edges = xmlDoc.SelectNodes(xmlPathPattern);

                if (edges != null && edges.Count > 0)
                {
                    for (int i = 0; i < edges.Count; i++)
                    {
                        node = edges[i].SelectSingleNode("./cl1");
                        int cell1 = int.Parse(node.InnerText.Trim());
                        node = edges[i].SelectSingleNode("./cl2");
                        int cell2 = int.Parse(node.InnerText.Trim());
                        node = edges[i].SelectSingleNode("./w");
                        float weight = float.Parse(node.InnerText.Trim());
                        node = edges[i].SelectSingleNode("./ir");
                        string identifier = node.InnerText.Trim();
                        node = edges[i].SelectSingleNode("./s");
                        string   strSpots = node.InnerText.Trim();
                        string[] sSpots   = strSpots.Split(new char[] { ',' });
                        if (sSpots.Length == 0)
                        {
                            continue;
                        }
                        int[] spots = new int[sSpots.Length];
                        for (int j = 0; j < sSpots.Length; j++)
                        {
                            spots[j] = int.Parse(sSpots[j]);
                        }

                        this.pathGraph.AddEdge(cell1, cell2, weight, spots, identifier, CompareEdgeByRadian);
                    }
                }

                //--------------------------------------------------------------------------------------
                // read the scenic spot data of the grid
                xmlPathPattern = "/grid/scenic_spot/ss";
                XmlNodeList scenicSpots = xmlDoc.SelectNodes(xmlPathPattern);
                this.listScenicSpots.Clear();
                if (scenicSpots != null)
                {
                    foreach (XmlNode xn in scenicSpots)
                    {
                        node = xn.SelectSingleNode("./ir");
                        string identifier = node.InnerText.Trim();
                        node = xn.SelectSingleNode("./en");
                        string cells = node.InnerText.Trim();

                        GpsMapScenicSpot ss = new GpsMapScenicSpot(identifier, cells);
                        int index           = listScenicSpots.BinarySearch(ss);
                        if (index < 0)
                        {
                            this.listScenicSpots.Insert(~index, ss);
                        }
                    }
                }

                //------------------------------------------------------
                this.LoadingStatus |= SafeStatus.LS_PATH_DATA;
                XxdwDebugger.Log("GpsMap: DataThreadFunc(), post NOTI_MAP_DATA_READY path_data ok");
                AsyncNotification.Instance.PostNotification(this, Notification.NOTI_MAP_DATA_READY, this.LoadingStatus, this.name);
            }
            catch (System.Exception ex)
            {
                XxdwDebugger.LogError(ex.Message);
                this.LoadingStatus = SafeStatus.LS_NULL;
            }

            //this.pathGraph.TraverseAllAdjacents();
            XxdwDebugger.Log("GpsMap: DataThreadFunc() leaving...");
        }
Exemple #6
0
        /*private Rect TestBackgroundRange()
         * {
         *  float minX = TypeAndParameter.MAX_COORDINATE, minY = TypeAndParameter.MAX_COORDINATE;
         *  float maxX = TypeAndParameter.MIN_COORDINATE, maxY = TypeAndParameter.MIN_COORDINATE;
         *
         *  foreach (Transform child in transform)
         *  {
         *      string name = child.gameObject.name;
         *      Vector3 min = child.gameObject.GetComponent<Renderer>().bounds.min;
         *      Vector3 max = child.gameObject.GetComponent<Renderer>().bounds.max;
         *      XxdwDebugger.Log(name + " @ (" + min.x + "," + min.y + "),(" + max.x + "," + max.y + ")");
         *      if (min.x < minX) minX = min.x;
         *      if (min.y < minY) minY = min.y;
         *      if (max.x > maxX) maxX = max.x;
         *      if (max.y > maxY) maxY = max.y;
         *  }
         *
         *  Rect rect = new Rect(minX, minY, maxX - minX, maxY - minY);
         *  XxdwDebugger.Log("bg bounds: (" + rect.min.x + "," + rect.min.y + "),(" +
         *            rect.max.x + "," + rect.max.y + ")");
         *  return rect;
         * }*/

        public void OnNotiMapSwitched(Notification noti)
        {
            XxdwDebugger.Log("BackgroundController -> OnNotiMapSwitched()");
            this.gpsMap = (GpsMap)noti.Data;
        }
Exemple #7
0
 public void OnNotiBackgroundReady(Notification noti)
 {
     XxdwDebugger.Log("Camera: Notification noti OnBackgroundReady");
     this.zoomLevel = GpsMap.NORM_ZOOM_LEVEL;
     Zoom();
 }
Exemple #8
0
 // Use this for initialization
 void Start()
 {
     XxdwDebugger.Log("CameraController -> Start()");
     this.zoomLevel   = GpsMap.NORM_ZOOM_LEVEL;
     this.cameraRange = new Rect(0, 0, 0, 0);
 }
Exemple #9
0
 protected void FocusInPanel()
 {
     XxdwDebugger.Log("EnterPanel");
     NotificationCenter.Instance.DisableTouchUpOnce();
 }
        private void DealWithInput()
        {
            if (this.DisableInput)
            {
                return;
            }

            Notification noti = new Notification(this, Notification.NOTI_NULL);
            GameKey      gk   = new GameKey();

            GameKey.EKey key = gk.GetKeyUp();
            if (key != GameKey.EKey.K_NULL)
            {
                noti.Name = Notification.NOTI_KEY_UP;
                noti.Data = key;

                XxdwDebugger.Log(noti.Name + ":" + gk.GetKeyString(key));
                this.SendNotification(noti);
            }
            else if ((key = gk.GetKeyDown()) != GameKey.EKey.K_NULL)
            {
                noti.Name      = Notification.NOTI_KEY_DOWN;
                noti.Data      = key;
                noti.ExtraData = gk.GetModifier();

                XxdwDebugger.Log(noti.Name + ":" + gk.GetKeyString(key) + "," + gk.GetKeyString(gk.GetModifier()));
                this.SendNotification(noti);
            }

            if (Application.platform == RuntimePlatform.Android || Application.platform == RuntimePlatform.IPhonePlayer)
            {
                int touchCount = 0;
                int touch1 = 0, touch2 = 0;
                for (int i = 0; i < Input.touches.Length; i++)
                {
                    if (Input.touches[i].phase != TouchPhase.Canceled)
                    {
                        if (touchCount == 0)
                        {
                            touch1 = i;
                            touchCount++;
                        }
                        else
                        {
                            touch2 = i;
                            touchCount++;
                            break;
                        }
                    }
                }
                if (touchCount == 0)
                {
                    return;
                }

                Vector3 pos = new Vector3(Input.touches[touch1].position.x, Input.touches[touch1].position.y, 0);
                if (touchCount == 2 && Input.touches[touch1].phase == TouchPhase.Moved && Input.touches[touch2].phase == TouchPhase.Moved)
                {
                    XxdwDebugger.Log("TouchPhase.SizeChanged");
                    float   distNow = Vector2.Distance(Input.touches[touch1].position, Input.touches[touch2].position);
                    Vector2 pre1    = Input.touches[touch1].position - Input.touches[touch1].deltaPosition;
                    Vector2 pre2    = Input.touches[touch2].position - Input.touches[touch2].deltaPosition;
                    float   distPre = Vector2.Distance(pre1, pre2);
                    if (distNow > distPre)
                    {
                        XxdwDebugger.Log("Touch Zoom in");
                        noti.Name = Notification.NOTI_ZOOM_IN;
                    }
                    else
                    {
                        XxdwDebugger.Log("Touch Zoom out");
                        noti.Name = Notification.NOTI_ZOOM_OUT;
                    }
                    noti.Data = Math.Abs(distNow - distPre);

                    if ((float)noti.Data > Parameters.MIN_SIZE_TRIGGER_ZOOM)
                    {
                        this.SendNotification(noti);
                    }
                    //XxdwDebugger.DisplayMessage("dist:" + Math.Abs(distNow - distPre));
                }
                else
                {
                    switch (Input.touches[touch1].phase)
                    {
                    case TouchPhase.Began:
                        XxdwDebugger.Log("TouchPhase.Began");
                        this.touchDownTime = Time.time;
                        this.posPrevious   = pos;
                        noti.Name          = Notification.NOTI_TOUCH_DOWN;
                        noti.Data          = pos;

                        this.SendNotification(noti);
                        break;

                    case TouchPhase.Ended:
                        if (PeekDisableTouchUp() == 0)
                        {
                            XxdwDebugger.Log("TouchPhase.Ended.");
                            noti.Name = Notification.NOTI_TOUCH_UP;
                            noti.Data = pos;

                            this.SendNotification(noti);
                        }
                        break;

                    case TouchPhase.Moved:
                        if (Input.touches[touch1].deltaPosition.sqrMagnitude > Parameters.MIN_COORDINATE_OFFSET)
                        {
                            XxdwDebugger.Log("TouchPhase.Moved");
                            // 拖动
                            noti.Name      = Notification.NOTI_DRAG;
                            noti.Data      = pos;
                            noti.ExtraData = this.posPrevious;

                            this.touchDownTime = Time.time;
                            this.posPrevious   = pos;

                            this.SendNotification(noti);
                        }
                        else
                        {
                            goto STATIONARY;
                        }
                        break;

                    case TouchPhase.Stationary:
STATIONARY:
                        if (Time.time - touchDownTime > Parameters.LONG_TOUCH_INTERVAL)
                        {
                            XxdwDebugger.Log("MouseButtonUp Long.");
                            this.touchDownTime = Time.time;

                            noti.Name = Notification.NOTI_LONG_TOUCH_UP;
                            noti.Data = Input.mousePosition;

                            this.SendNotification(noti);
                        }
                        break;
                    }
                }
            }
            else if (Application.platform <= RuntimePlatform.WindowsEditor)
            {
                // 按下鼠标
                if (Input.GetMouseButtonDown((int)Parameters.MouseTypeEnum.LEFT))
                {
                    XxdwDebugger.Log("MouseButtonDown");
                    this.touchDownTime = Time.time;
                    this.posPrevious.Set(Input.mousePosition.x, Input.mousePosition.y, 0);
                    noti.Name    = Notification.NOTI_TOUCH_DOWN;
                    noti.Data    = Input.mousePosition;
                    this.touched = true;

                    this.SendNotification(noti);
                }
                // 松开鼠标
                else if (Input.GetMouseButtonUp((int)Parameters.MouseTypeEnum.LEFT))
                {
                    XxdwDebugger.Log("MouseButtonUp");
                    noti.Name = Notification.NOTI_TOUCH_UP;
                    noti.Data = Input.mousePosition;

                    this.touched = false;
                    this.SendNotification(noti);
                }
                // 松开鼠标右键
                else if (Input.GetMouseButtonUp((int)Parameters.MouseTypeEnum.RIGHT))
                {
                    XxdwDebugger.Log("MouseButtonUp");
                    noti.Name = Notification.NOTI_RIGHT_CLICK;
                    noti.Data = Input.mousePosition;

                    this.SendNotification(noti);
                }
                else if (this.touched)
                {
                    Vector3 pos  = new Vector3(Input.mousePosition.x, Input.mousePosition.y, 0);
                    Vector2 diff = new Vector2(pos.x - this.posPrevious.x, pos.y - this.posPrevious.y);
                    if (diff.sqrMagnitude > Parameters.MIN_COORDINATE_OFFSET)
                    {
                        // 拖动
                        noti.Name      = Notification.NOTI_DRAG;
                        noti.Data      = Input.mousePosition;
                        noti.ExtraData = this.posPrevious;

                        this.touchDownTime = Time.time;
                        this.posPrevious   = pos;

                        this.SendNotification(noti);
                    }
                    else if (Time.time - touchDownTime > Parameters.LONG_TOUCH_INTERVAL)
                    {
                        XxdwDebugger.Log("MouseButtonUp Long.");
                        noti.Name = Notification.NOTI_LONG_TOUCH_UP;
                        noti.Data = Input.mousePosition;

                        this.touched = false;
                        this.SendNotification(noti);
                    }
                }
                else
                {
                    // 鼠标滚轮拉近拉远
                    float mouseScroll = Input.GetAxis("Mouse ScrollWheel");
                    if (Mathf.Abs(mouseScroll) > Parameters.MIN_COORDINATE_OFFSET)
                    {
                        if (mouseScroll > 0)
                        {
                            XxdwDebugger.Log("Mouse Scroll Zoom in");
                            noti.Name = Notification.NOTI_ZOOM_IN;
                            noti.Data = mouseScroll;
                        }
                        else
                        {
                            XxdwDebugger.Log("Mouse Scroll Zoom out");
                            noti.Name = Notification.NOTI_ZOOM_OUT;
                            noti.Data = -mouseScroll;
                        }
                        this.SendNotification(noti);
                    }
                }
            }
        } // DealWithInput()
Exemple #11
0
        private void OnDownloadMapAndVoiceData(object objData, ResponseData result)
        {
            ClientSocket cs  = null;
            SslAppData   sad = new SslAppData();

            try
            {
                SimpleJson.JsonObject jsonPathData = new SimpleJson.JsonObject();
                jsonPathData.Add("op", "UPLOAD_PATH_DATA");
                jsonPathData.Add("data", (string)objData);
                //jsonPathData.Add("data", "no actual data.");
                string strJsonText = jsonPathData.ToString();

                cs = Connect();
                if (cs == null)
                {
                    result.Code = ResponseData.RESP_SERVER_UNREACHABLE;
                    result.Msg  = TypeAndParameter.STR_CONNECT_WITH_SERVER_FAILED;
                    return;
                }

                // 发送数据
                sad.SetType(SslAppData.APP_TYPE_PLAIN_JSON);
                byte[] allBytes = System.Text.Encoding.Default.GetBytes(strJsonText);
                if (allBytes.Length > SslAppData.SSL_APP_CONTENT_MAX_SIZE)
                {
                    sad.SetFirst(true);
                    sad.SetLast(false);
                    sad.SetData(allBytes, 0, SslAppData.SSL_APP_CONTENT_MAX_SIZE);
                    cs.Send(sad);

                    sad.SetFirst(false);
                    int i = SslAppData.SSL_APP_CONTENT_MAX_SIZE;
                    while (i < allBytes.Length)
                    {
                        if (allBytes.Length - i <= SslAppData.SSL_APP_CONTENT_MAX_SIZE)
                        {
                            sad.SetLast(true);
                            sad.SetData(allBytes, i);
                            i += allBytes.Length - i;
                        }
                        else
                        {
                            sad.SetData(allBytes, i, SslAppData.SSL_APP_CONTENT_MAX_SIZE);
                            i += SslAppData.SSL_APP_CONTENT_MAX_SIZE;
                        }
                        cs.Send(sad);
                    }
                }
                else
                {
                    sad.SetData(allBytes);
                    //sad.SetData(System.Text.Encoding.UTF8.GetBytes(strJsonText));
                    cs.Send(sad);
                }

                // 接收数据
                cs.Recv(sad);
                byte[] jsonData = sad.GetData();
                //strJsonText = System.Text.Encoding.Default.GetString(jsonData);
                strJsonText = System.Text.Encoding.UTF8.GetString(jsonData);

                var rsp = (IDictionary <string, object>)SimpleJson.SimpleJson.DeserializeObject(strJsonText);
                if ("AE_SUCCESS" == (rsp["err"] as string))
                {
                    result.Code = ResponseData.RESP_SUCCESS;
                    result.Msg  = TypeAndParameter.STR_UPLOAD_PATH_DATA_FINISHED;
                }
                else
                {
                    result.Msg = rsp["msg"] as string;
                }
            }
            catch (Exception e)
            {
                XxdwDebugger.LogError(e.StackTrace);
            }
            finally
            {
                if (cs != null)
                {
                    cs.Close();
                }
            }
        }
Exemple #12
0
        private void OnUploadPathData2(object objData, ResponseData result)
        {
            ClientSocket cs  = null;
            SslAppData   sad = new SslAppData();

            try
            {
                string str = (string)objData;
                cs = Connect();
                if (cs == null)
                {
                    result.Code = ResponseData.RESP_SERVER_UNREACHABLE;
                    result.Msg  = TypeAndParameter.STR_CONNECT_WITH_SERVER_FAILED;
                    return;
                }

                // 发送数据
                sad.SetType(SslAppData.APP_TYPE_FILE);
                byte[] allBytes      = System.Text.Encoding.Default.GetBytes(str);
                byte[] filenameBytes = System.Text.Encoding.Default.GetBytes("test.txt\0");
                byte[] d             = new byte[SslAppData.APP_TYPE_FILE_HEADER_SIZE + filenameBytes.Length + SslAppData.SSL_APP_CONTENT_MAX_SIZE];
                int    s             = IPAddress.HostToNetworkOrder(allBytes.Length); // 文件大小
                System.Array.Copy(BitConverter.GetBytes(s), 0, d, 0, 4);
                //System.Array.Copy(BitConverter.GetBytes(91), 0, d, 4, 4); // 偏移,为调试
                short t = IPAddress.HostToNetworkOrder((short)filenameBytes.Length);
                System.Array.Copy(BitConverter.GetBytes(t), 0, d, 8, 2);
                System.Array.Copy(filenameBytes, 0, d, SslAppData.APP_TYPE_FILE_HEADER_SIZE, filenameBytes.Length);

                if (allBytes.Length > SslAppData.SSL_APP_CONTENT_MAX_SIZE)
                {
                    sad.SetFirst(true);
                    sad.SetLast(false);

                    System.Array.Copy(allBytes, 0, d, SslAppData.APP_TYPE_FILE_HEADER_SIZE + filenameBytes.Length, SslAppData.SSL_APP_CONTENT_MAX_SIZE);
                    sad.SetData(d, 0, SslAppData.APP_TYPE_FILE_HEADER_SIZE + filenameBytes.Length + SslAppData.SSL_APP_CONTENT_MAX_SIZE);
                    cs.Send(sad);

                    sad.SetFirst(false);
                    int i = SslAppData.SSL_APP_CONTENT_MAX_SIZE;
                    while (i < allBytes.Length)
                    {
                        if (allBytes.Length - i <= SslAppData.SSL_APP_CONTENT_MAX_SIZE)
                        {
                            sad.SetLast(true);
                            sad.SetData(allBytes, i);
                            i += allBytes.Length - i;
                        }
                        else
                        {
                            sad.SetData(allBytes, i, SslAppData.SSL_APP_CONTENT_MAX_SIZE);
                            i += SslAppData.SSL_APP_CONTENT_MAX_SIZE;
                        }
                        cs.Send(sad);
                    }
                }
                else
                {
                    System.Array.Copy(allBytes, 0, d, SslAppData.APP_TYPE_FILE_HEADER_SIZE + filenameBytes.Length, allBytes.Length);
                    sad.SetData(d, 0, SslAppData.APP_TYPE_FILE_HEADER_SIZE + filenameBytes.Length + allBytes.Length);
                    cs.Send(sad);
                }

                // 接收数据
                cs.Recv(sad);
                byte[] jsonData = sad.GetData();
                //string strJsonText = System.Text.Encoding.Default.GetString(jsonData);
                string strJsonText = System.Text.Encoding.UTF8.GetString(jsonData);

                var rsp = (IDictionary <string, object>)SimpleJson.SimpleJson.DeserializeObject(strJsonText);
                if ("AE_SUCCESS" == (rsp["err"] as string))
                {
                    result.Code = ResponseData.RESP_SUCCESS;
                    result.Msg  = TypeAndParameter.STR_UPLOAD_PATH_DATA_FINISHED;
                }
                else
                {
                    // utf-8格式的消息转unicode
                    //byte[] buffer= Encoding.UTF8.GetBytes(rsp["msg"] as string);
                    //result.Msg = Encoding.Unicode.GetString(buffer);
                    result.Msg = rsp["msg"] as string;
                }
            }
            catch (Exception e)
            {
                XxdwDebugger.LogError(e.StackTrace);
            }
            finally
            {
                if (cs != null)
                {
                    cs.Close();
                }
            }
        }
Exemple #13
0
        private void DataThreadFunc()
        {
            try
            {
                StringReader sr = new StringReader(this.csvText);

                List <string> row = new List <string>();
                int           quotaNumNotMatched = 0;
                bool          previousQuota      = false;
                string        cell = "";
                string        line;
                while ((line = sr.ReadLine()) != null)  // 返回的串不包括“\r\n”
                {
                    for (int i = 0; i < line.Length; i++)
                    {
                        char ch = line[i];
                        if (ch == '\"')
                        {
                            if (previousQuota)      // 两个引号,忽略前一个,加后一个
                            {
                                cell         += ch;
                                previousQuota = false;
                                quotaNumNotMatched--;
                            }
                            else if (quotaNumNotMatched > 0 &&
                                     (i == line.Length - 1 || line[i + 1] != '\"')) // 引用结束
                            {
                                quotaNumNotMatched--;
                            }
                            else
                            {
                                previousQuota = true;
                                quotaNumNotMatched++;
                            }
                        }
                        else if (ch == ',')
                        {
                            if (quotaNumNotMatched > 0)
                            {
                                cell += ch;
                            }
                            else
                            {
                                row.Add(cell.Trim());
                                cell = "";
                            }
                            previousQuota = false;
                        }
                        else
                        {
                            cell         += ch;
                            previousQuota = false;
                        }
                    } // for

                    if (quotaNumNotMatched == 0)
                    {
                        cell = cell.Trim();
                        if (cell.Length > 0)
                        {
                            row.Add(cell);
                            cell = "";
                        }

                        bool emptyRow = true;
                        foreach (string cont in row)
                        {
                            if (cont != "")
                            {
                                emptyRow = false;
                                break;
                            }
                        }

                        if (!emptyRow)  // 排除空行
                        {
                            if (row.Count > this.colNum)
                            {
                                this.colNum = row.Count;
                            }
                            this.grid.Add(row);
                        }

                        row = new List <string>();
                    }
                    else
                    {
                        cell += "\n";   // 单元格中包含换行符
                    }
                } // while
                this.rowNum = this.grid.Count - (this.firstRowAsTitle ? 1 : 0);
                sr.Close();

                this.ready = true;
                XxdwDebugger.Log("CsvSheet: DataThreadFunc() post NOTI_MODEL_DATA_READY.");
                AsyncNotification.Instance.PostNotification(this, Notification.NOTI_MODEL_DATA_READY, this.name);
            }
            catch (System.Exception ex)
            {
                XxdwDebugger.LogError(ex.Message);
            }
        }