private void LoadFromText()
 {
     Global.mapobj_config_mgr.ReloadDataFromFile(textResourcesPath, EditionType.ALL, false);
     Global.mapobj_config_mgr.ForEach(delegate(MapObjectConfigReference moc)
     {
         if (moc.map == curMap.ID)
         {
             MPObject mp;
             if (moc.isRole)
             {
                 mp = new MPRole();
             }
             else
             {
                 mp = new MPItem();
             }
             try {
                 mp.LoadFromText(moc);
                 //mp.CreateGameObject();
                 mapObjs_.Add(mp.sn, mp);
             }
             catch (System.Exception exp) {
                 errorCaught_ = true;
                 Debug.Log(exp.Message);
                 Debug.Log(exp.StackTrace);
             }
         }
     }
                                      );
 }
        protected void itemDetailsView_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
        {
            // Because ObjectDataSource loses all the non-displayed values, as well as composite values,
            // we need to reload them here from the object.
            log.Debug(String.Format("Updating item {0}", e.Keys["Id"]));

            MPRSession session = MPRController.StartSession();
            MPItem     item    = MPRController.RetrieveById <MPItem>(session, (Int64)e.Keys["Id"]);

            item.Name              = (string)e.NewValues["Name"];
            item.Description       = (string)e.NewValues["Description"];
            item.DescriptionShort  = (string)e.NewValues["DescriptionShort"];
            item.Author            = (string)e.NewValues["Author"];
            item.Homepage          = (string)e.NewValues["Homepage"];
            item.License           = (string)e.NewValues["License"];
            item.LicenseMustAccept = (bool)e.NewValues["LicenseMustAccept"];
            item.Tags              = MPRController.GetTags(session, ((TextBox)itemDetailsView.FindControl("tagsTextBox")).Text);
            MPRController.Save <MPItem>(session, item);
            MPRController.EndSession(session, true);

            log.Info(String.Format("Updated item {0} ({1})", e.Keys["Id"], e.NewValues["Name"]));

            // Manually reset the form to view format
            e.Cancel = true;
            itemDetailsView.ChangeMode(DetailsViewMode.ReadOnly);
        }
    MPObject CreateObject(Vector3 pos)
    {
        int refid;

        int.TryParse(editTargetID_, out refid);
        MPObject mapobj = null;

        //暂时使用同一个reference
        RoleReference reference = Global.role_mgr.GetReference(refid);

        if (reference == null)
        {
            Debug.Log("无此ID" + refid);
            return(null);
        }
        if (objectType_ == 2)
        {
            if (mapObjectResLoadPathStrFormat.Length <= 0)
            {
                Debug.Log("待添加物件资源路径");
                return(null);
            }
            mapobj = new MPItem();
            ((MPItem)mapobj).reference = reference;
        }
        else
        {
            mapobj = new MPRole();
            ((MPRole)mapobj).reference = reference;
        }
        if (objectType_ == 0)
        {
            mapobj.ObjectType = "Monster";
        }
        if (objectType_ == 1)
        {
            mapobj.ObjectType = "Npc";
        }
        if (objectType_ == 2)
        {
            mapobj.ObjectType = "Object";
        }
        mapobj.map    = curMap.ID;
        mapobj.refid  = refid;
        mapobj.apprId = reference.Apprid;
        mapobj.sn     = GetUseableSN();
        mapobj.ID     = reference.ID;
        mapobj.CreateGameObject((a) => { mapObjs_[a.sn] = a; a.position = pos; });
        return(mapobj);
    }
        protected void versionDetailsView_ItemInserting(object sender, DetailsViewInsertEventArgs e)
        {
            log.Debug(String.Format("Inserting version to item {0}", itemDetailsView.SelectedValue));

            FileUpload fileUpload = (FileUpload)versionDetailsView.FindControl("fileUpload");

            if ((fileUpload.PostedFile == null) || (fileUpload.PostedFile.ContentLength == 0))
            {
                statusLabel.Text    = "Please upload a file for the new version";
                statusLabel.Visible = true;
                e.Cancel            = true;
                return;
            }

            // Save the file
            string targetFilename = FileManager.GetSaveLocation(fileUpload.PostedFile.FileName);

            try
            {
                fileUpload.PostedFile.SaveAs(targetFilename);
            }
            catch (Exception ex)
            {
                log.Error("Unable to save file to local system: " + ex.ToString());
                statusLabel.Text    = "Error while trying to save file";
                statusLabel.Visible = true;
                e.Cancel            = true;
                return;
            }

            // TODO: Persist target filename somewhere
            ViewState["TargetFileName"]     = System.IO.Path.GetFileName(fileUpload.PostedFile.FileName);
            ViewState["TargetFileLocation"] = targetFilename;

            MPRSession session = MPRController.StartSession();
            MPItem     item    = MPRController.RetrieveById <MPItem>(session, (Int64)itemDetailsView.SelectedValue);

            e.Values["Item"]       = item;
            e.Values["Uploader"]   = SessionUtils.GetCurrentUser();
            e.Values["UpdateDate"] = DateTime.Now;

            MPRController.EndSession(session, true);

            log.Info(String.Format("Added new version to item {0}", itemDetailsView.SelectedValue));

            statusLabel.Text    = "Version added";
            statusLabel.Visible = true;
        }
예제 #5
0
        protected void itemsGridView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (itemsGridView.SelectedRow != null)
            {
                MPRSession session = MPRController.StartSession();

                MPItem item = MPRController.RetrieveById <MPItem>(session, (Int64)itemsGridView.SelectedValue);

                if (item == null)
                {
                    throw new InvalidFormDataException("Asked to provide details for invalid item id");
                }

                // TODO: clean up binding to a single object
                List <MPItem> items = new List <MPItem>();
                items.Add(item);
                itemDetailsView.DataSource = items;
                itemDetailsView.DataBind();

                versionDetailsView.DataSource = item.Versions;
                versionDetailsView.DataBind();

                commentsRepeater.DataSource = item.Comments;
                commentsRepeater.DataBind();

                // TODO: Only if submitter or has permission
                singleItemHyperLink.NavigateUrl = "~/single_item.aspx?itemid=" + item.Id.ToString();
                singleItemHyperLink.Visible     = true;

                commentAddTextBox.Text    = "";
                commentAddTextBox.Visible = true;
                commentAddButton.Visible  = true;

                MPRController.EndSession(session, true);
            }
            else
            {
                singleItemHyperLink.NavigateUrl = "";
                singleItemHyperLink.Visible     = false;
                commentAddTextBox.Visible       = false;
                commentAddButton.Visible        = false;
                commentAddLabel.Visible         = false;
            }
        }
    private void LoadFromXml(string filePath)
    {
        try {
            XmlDocument doc = new XmlDocument();
            doc.Load(filePath);
            XmlNodeList xnList = doc.DocumentElement.ChildNodes;
            foreach (XmlNode node in xnList)
            {
                XmlElement ele = node as XmlElement;
                MPObject   mp;
                //Debug.Log( string.Format( "{0},{1}", ele.LocalName, ele.Name ) );
                if (ele.Name == "Role")
                {
                    mp = new MPRole();
                }
                else if (ele.Name == "Item")
                {
                    mp = new MPItem();
                }
                else
                {
                    mp = new MPObject();
                }

                try{
                    mp.LoadFromXml(ele);
                    //mp.CreateGameObject();
                    mapObjs_.Add(mp.sn, mp);
                }
                catch (System.Exception exp) {
                    errorCaught_ = true;
                    Debug.Log(exp.Message);
                    Debug.Log(exp.StackTrace);
                }
            }

            lastSaveTime_ = Time.time;
        }
        catch (System.Exception exp) {
            Debug.Log(exp.ToString());
            Debug.Log(exp.StackTrace);
        }
    }
    private List <TemplateMapObjectConfig> PrepareSaveJson()
    {
        List <TemplateMapObjectConfig> objs = new List <TemplateMapObjectConfig>();

        foreach (MPObject mpo in mapObjs_.Values)
        {
            TemplateMapObjectConfig tempConfig = new TemplateMapObjectConfig();
            tempConfig.objType = mpo.ObjectType;
            tempConfig.refId   = mpo.mocReference_.refid;
            tempConfig.pos     = MyVector3.GetMyVector3(GameUtility.StrToVector3(mpo.mocReference_.position));
            tempConfig.dir     = MyVector3.GetMyVector3(GameUtility.StrToVector3(mpo.mocReference_.direction));
            tempConfig.visible = mpo.available;
            tempConfig.sn      = mpo.sn;
            tempConfig.isVisibleInMiddleMap = mpo.IsShowInMiddleMap;
            if (mpo.ObjectType != "Object")
            {
                MPRole mpoRole = mpo as MPRole;
                tempConfig.patrolType = mpoRole.patrolType.ToString();
                tempConfig.patrolPath = new List <MyVector3>();
                foreach (MPRole.RoutePoint point in mpoRole.routeList)
                {
                    tempConfig.patrolPath.Add(MyVector3.GetMyVector3(point.position));
                }
                tempConfig.camp    = (int)mpoRole.camp;
                tempConfig.aiRefId = mpoRole.aiRefid;
                tempConfig.team    = mpoRole.teamID;
            }
            else
            {
                MPItem mpItem = mpo as MPItem;
                tempConfig.team = mpItem.teamID;
            }
            objs.Add(tempConfig);
            //if (!Physics.Raycast(new Vector3(mpo.position.x, 10, mpo.position.z), Vector3.down, 200))
            //{
            //    Debug.Log("物体坐标非法  sn:" + mpo.sn);
            //}
        }
        return(objs);
    }
예제 #8
0
        protected void commentAddButton_Click(object sender, EventArgs e)
        {
            if (commentAddTextBox.Text.Length == 0)
            {
                commentAddLabel.Text    = "Please enter a comment";
                commentAddLabel.Visible = true;
                return;
            }

            if (itemsGridView.SelectedRow == null)
            {
                throw new InvalidFormDataException("Comment can only be added to a selected item");
            }

            MPRSession session = MPRController.StartSession();

            MPItem item = MPRController.RetrieveById <MPItem>(session, (Int64)itemsGridView.SelectedValue);

            if (item == null)
            {
                throw new InvalidFormDataException("Asked to provide details for invalid item id");
            }

            MPItemComment comment = new MPItemComment();

            comment.User = SessionUtils.GetCurrentUser();
            comment.Text = commentAddTextBox.Text;
            item.Comments.Add(comment);
            MPRController.Save <MPItem>(session, item);

            MPRController.EndSession(session, true);

            commentAddTextBox.Text  = "";
            commentAddLabel.Text    = "Comment added. Thank you!";
            commentAddLabel.Visible = true;
        }
예제 #9
0
    /// <summary>
    /// Handle the actual creation of the entity
    /// </summary>
    /// <param name="filename">the name of the local file</param>
    /// <returns>success or failure</returns>
    protected bool AddFileToRepository(string filename)
    {
      MPRSession session = MPRController.StartSession();
      MPUser user = SessionUtils.GetCurrentUser();

      MPItem item = new MPItem();
      item.Name = titleTextBox.Text;

      Int64 typeId;
      if (!Int64.TryParse(typesList.SelectedValue, out typeId))
      {
        return UploadFail(String.Format("Invalid item type {0}", typesList.SelectedValue));
      }

      item.Type = MPRController.RetrieveById<MPItemType>(session, typeId);
      if (item.Type == null)
      {
        return UploadFail(String.Format("Unable to find item type {0} ({1})", typesList.SelectedItem, typeId));
      }

      List<Int64> categoryIds = new List<Int64>();
      foreach (ListItem categoryItem in categoriesList.Items)
      {
        if (categoryItem.Selected)
        {
          Int64 id;
          if (Int64.TryParse(categoryItem.Value, out id))
          {
            categoryIds.Add(id);
          }
        }
      }
      IList<MPCategory> categories = MPRController.RetrieveByIdList<MPCategory>(session, categoryIds);
      foreach (MPCategory category in categories)
      {
        item.Categories.Add(category);
      }

      item.Description = descriptionTextBox.Text;
      item.DescriptionShort = descriptionShortTextBox.Text;
      item.License = licenseTextBox.Text;
      item.LicenseMustAccept = licenseMustAccessCheckBox.Checked;
      item.Author = authorTextBox.Text;
      item.Homepage = homepageTextbox.Text;

      item.Tags = MPRController.GetTags(session, tagsTextBox.Text);

      // create ItemVersion
      MPItemVersion itemVersion = new MPItemVersion();
      itemVersion.Item = item;
      itemVersion.Uploader = user;
      itemVersion.DevelopmentStatus = (MPItemVersion.MPDevelopmentStatus) Enum.Parse(typeof(MPItemVersion.MPDevelopmentStatus), developmentStatusDropDownList.SelectedValue);
      itemVersion.MPVersionMin = mpVersionMinTextBox.Text;
      itemVersion.MPVersionMax = mpVersionMaxTextBox.Text;
      itemVersion.Version = versionTextBox.Text;

      MPFile mpfile = new MPFile();
      mpfile.ItemVersion = itemVersion;
      mpfile.Filename = System.IO.Path.GetFileName(fileUpload.PostedFile.FileName);
      mpfile.Location = filename;

      itemVersion.Files.Add(mpfile);

      item.Versions.Add(itemVersion);

      // Save item (and sub-items) to database
      try
      {
        MPRController.Save<MPItem>(session, item);
        MPRController.EndSession(session, true);
      }
      catch (Exception ex)
      {
        MPRController.EndSession(session, false);
        return UploadFail("Unable to save item: " + ex.ToString());
      }

      return true;

    }
예제 #10
0
        /// <summary>
        /// Handle the actual creation of the entity
        /// </summary>
        /// <param name="filename">the name of the local file</param>
        /// <returns>success or failure</returns>
        protected bool AddFileToRepository(string filename)
        {
            MPRSession session = MPRController.StartSession();
            MPUser     user    = SessionUtils.GetCurrentUser();

            MPItem item = new MPItem();

            item.Name = titleTextBox.Text;

            Int64 typeId;

            if (!Int64.TryParse(typesList.SelectedValue, out typeId))
            {
                return(UploadFail(String.Format("Invalid item type {0}", typesList.SelectedValue)));
            }

            item.Type = MPRController.RetrieveById <MPItemType>(session, typeId);
            if (item.Type == null)
            {
                return(UploadFail(String.Format("Unable to find item type {0} ({1})", typesList.SelectedItem, typeId)));
            }

            List <Int64> categoryIds = new List <Int64>();

            foreach (ListItem categoryItem in categoriesList.Items)
            {
                if (categoryItem.Selected)
                {
                    Int64 id;
                    if (Int64.TryParse(categoryItem.Value, out id))
                    {
                        categoryIds.Add(id);
                    }
                }
            }
            IList <MPCategory> categories = MPRController.RetrieveByIdList <MPCategory>(session, categoryIds);

            foreach (MPCategory category in categories)
            {
                item.Categories.Add(category);
            }

            item.Description       = descriptionTextBox.Text;
            item.DescriptionShort  = descriptionShortTextBox.Text;
            item.License           = licenseTextBox.Text;
            item.LicenseMustAccept = licenseMustAccessCheckBox.Checked;
            item.Author            = authorTextBox.Text;
            item.Homepage          = homepageTextbox.Text;

            item.Tags = MPRController.GetTags(session, tagsTextBox.Text);

            // create ItemVersion
            MPItemVersion itemVersion = new MPItemVersion();

            itemVersion.Item              = item;
            itemVersion.Uploader          = user;
            itemVersion.DevelopmentStatus = (MPItemVersion.MPDevelopmentStatus)Enum.Parse(typeof(MPItemVersion.MPDevelopmentStatus), developmentStatusDropDownList.SelectedValue);
            itemVersion.MPVersionMin      = mpVersionMinTextBox.Text;
            itemVersion.MPVersionMax      = mpVersionMaxTextBox.Text;
            itemVersion.Version           = versionTextBox.Text;

            MPFile mpfile = new MPFile();

            mpfile.ItemVersion = itemVersion;
            mpfile.Filename    = System.IO.Path.GetFileName(fileUpload.PostedFile.FileName);
            mpfile.Location    = filename;

            itemVersion.Files.Add(mpfile);

            item.Versions.Add(itemVersion);

            // Save item (and sub-items) to database
            try
            {
                MPRController.Save <MPItem>(session, item);
                MPRController.EndSession(session, true);
            }
            catch (Exception ex)
            {
                MPRController.EndSession(session, false);
                return(UploadFail("Unable to save item: " + ex.ToString()));
            }

            return(true);
        }
    private IEnumerator LoadFromJson(string filePath)
    {
        if (!File.Exists(filePath))
        {
            yield break;
        }
        StreamReader sr   = File.OpenText(filePath);
        string       json = sr.ReadToEnd();

        sr.Close();
        List <TemplateMapObjectConfig> objsRead = JsonMapper.ToObject <List <TemplateMapObjectConfig> >(json);

        if (objsRead == null)
        {
            yield break;
        }
        for (int i = 0; i < objsRead.Count; i++)
        {
            yield return(null);//每一个都延迟一帧执行,以免加载角色出错

            MPObject mapObj    = null;
            Vector3  positon   = objsRead[i].pos.GetVector3();
            Vector3  direction = objsRead[i].dir.GetVector3();

            if (objsRead[i].objType != "Object")
            {
                mapObj = new MPRole();
            }
            else
            {
                mapObj = new MPItem();
            }
            mapObj.refid      = objsRead[i].refId;
            mapObj.ObjectType = objsRead[i].objType;
            RoleReference reference = Global.role_mgr.GetReference(mapObj.refid);
            if (reference == null)
            {
                Debug.LogError(string.Format("无此role表Id:{0}", mapObj.refid));
            }
            else
            {
                mapObj.apprId = reference.Apprid;
            }
            mapObj.map               = curMap.ID;
            mapObj.sn                = objsRead[i].sn;
            mapObj.ID                = curMap.ID * 10000 + mapObj.sn;
            mapObjs_[mapObj.sn]      = mapObj;
            mapObj.available         = objsRead[i].visible;
            mapObj.camp              = (MPObject.ObjectCamp)objsRead[i].camp;
            mapObj.IsShowInMiddleMap = objsRead[i].isVisibleInMiddleMap;
            if (mapObj.ObjectType != "Object")
            {
                MPRole mpRole = mapObj as MPRole;
                mpRole.reference  = Global.role_mgr.GetReference(mpRole.refid);
                mpRole.teamID     = objsRead[i].team;
                mpRole.patrolType = (MPRole.PatrolType)Enum.Parse(typeof(MPRole.PatrolType), objsRead[i].patrolType);
                foreach (MyVector3 myVec in objsRead[i].patrolPath)
                {
                    mpRole.routeList.Add(new MPRole.RoutePoint(myVec.GetVector3(), 0));
                }
                mpRole.aiRefid = objsRead[i].aiRefId;
            }
            else
            {
                MPItem item = mapObj as MPItem;
                item.reference = Global.role_mgr.GetReference(item.refid);
                item.teamID    = objsRead[i].team;
            }

            //if (!Physics.Raycast(new Vector3(positon.x, 10, positon.z), Vector3.down, 200))
            //{
            //    Debug.Log("物体坐标非法  sn:" + mapObj.sn);
            //}
            mapObj.CreateGameObject((a) =>
            {
                mapObj.position  = positon;
                mapObj.direction = direction;
            });
        }
    }