Esempio n. 1
0
        private void save()
        {
            string sImage = UploadImage(HD_Image.Value);

            if (sImage != "")
            {
                HD_Image.Value = sImage;
            }

            int        id   = UntilityFunction.IntegerForNull(HD_ID.Value);
            SliderInfo info = new SliderInfo();

            info.id    = id;
            info.name  = TB_Name.Text;
            info.image = HD_Image.Value;
            info.alt   = TB_Alt.Text;
            info.link  = TB_Link.Text;
            if (id > 0)
            {
                SliderImpl.Instance.Update(info);
                MessageBox.Show("Cập nhật thành công");
            }
            else
            {
                HD_ID.Value = SliderImpl.Instance.Add(info).ToString();
                MessageBox.Show("Thêm mới thành công");
                LB_Messenger.Text = "Sửa thông tin slideshow";
            }

            Image1.ImageUrl = info.image != ""
                                      ? Config.GetPathSlideshow + info.image
                                      : Config.GetPathNoImage;
        }
Esempio n. 2
0
        public SliderInfo GetInfo(int id)
        {
            SliderInfo info = null;

            SqlParameter[] param =
            {
                new SqlParameter("@id", id)
            };
            var r = DataHelper.ExecuteReader(Config.ConnectString, "usp_Slider_GetById", param);

            if (r != null)
            {
                info = new SliderInfo();
                while (r.Read())
                {
                    info.id    = Int32.Parse(r["id"].ToString());
                    info.name  = r["name"].ToString();
                    info.image = r["image"].ToString();
                    info.alt   = r["alt"].ToString();
                    info.link  = r["link"].ToString();
                }
                r.Close();
                r.Dispose();
            }
            return(info);
        }
Esempio n. 3
0
        public ActionResult Update(SlidersModel model)
        {
            if (!ModelState.IsValid)
            {
                return(new AjaxResult().Alert(T(Constants.Messages.InvalidModel)));
            }

            var service    = WorkContext.Resolve <ISlidersService>();
            var listDelete = service.GetRecords(x => x.Type == model.Type);

            service.DeleteMany(listDelete);

            foreach (var image in model.UploadPhotos)
            {
                var row = new SliderInfo
                {
                    Id           = 0,
                    LanguageCode = "",
                    CategoryId   = 0,
                    Type         = model.Type,
                    ImageUrl     = image.ImageUrl,
                    Caption      = image.Caption,
                    SortOrder    = image.SortOrder,
                    Url          = image.Url,
                    IsDeleted    = false
                };
                service.Save(row);
            }

            return(new AjaxResult().NotifyMessage("UPDATE_ENTITY_COMPLETE").Alert(T("Đã cập nhật thành công.")).Redirect(Url.Action("Index")));
        }
Esempio n. 4
0
    public void UpdateServerWithNewSliderInfo(SliderInfo sliderInfo)
    {
        // send message
        ISFSObject strategyUpdateObj = new SFSObject();

        strategyUpdateObj.PutUtfString("type", "ss");         // strategy screen
        strategyUpdateObj.PutUtfString("sv", sliderInfo.val); // slider value
        strategyUpdateObj.PutInt("id", sliderInfo.id);        // type
        CommunicationManager.SendObjectMsg(strategyUpdateObj);
    }
Esempio n. 5
0
 public int Add(SliderInfo info)
 {
     SqlParameter[] param =
     {
         new SqlParameter("@name",  info.name),
         new SqlParameter("@image", info.image),
         new SqlParameter("@alt",   info.alt),
         new SqlParameter("@link",  info.link)
     };
     return(int.Parse(DataHelper.ExecuteScalar(Config.ConnectString, "usp_Slider_Add", param).ToString()));
 }
Esempio n. 6
0
    private string UpdateSliderVal(SliderInfo sliderInfo)
    {
        string cmd    = GetSliderPositionCmd(sliderInfo.divName);
        string newVal = GetCmdStrResult(cmd);

        if (sliderInfo.val != newVal)
        {
            dirtyFlags |= sliderInfo.id;
        }
        return(newVal);
    }
Esempio n. 7
0
 public int Update(SliderInfo info)
 {
     SqlParameter[] param =
     {
         new SqlParameter("@id",    info.id)
         ,                          new SqlParameter("@name",info.name),
         new SqlParameter("@image", info.image),
         new SqlParameter("@alt",   info.alt),
         new SqlParameter("@link",  info.link)
     };
     return(DataHelper.ExecuteNonQuery(Config.ConnectString, "usp_Slider_Update", param));
 }
        private void BindObject(int objID)
        {
            SliderInfo obj = SliderManager.Select(objID);

            if (obj != null)
            {
                txtName.Text              = obj.SliderName;
                txtDetailText.Value       = obj.SliderContent;
                txtLink.Text              = obj.SliderLink;
                img1.DescriptionUrl       = "/Upload/" + obj.SliderImage;
                img1.ImageUrl             = "/Upload/" + obj.SliderImage;
                imageName                 = obj.SliderImage;
                lblImg1.Text              = this.imageName;
                ddlCategory.SelectedValue = obj.SliderClass;
            }
        }
Esempio n. 9
0
        public List <SliderInfo> GetList(int pageIndex, int pageSize, out int total)
        {
            List <SliderInfo> list = null;
            var t = 0;

            SqlParameter[] param =
            {
                new SqlParameter("@pageIndex", pageIndex),
                new SqlParameter("@pageSize",  pageSize),
                new SqlParameter("@totalrow",  DbType.Int32)
                {
                    Direction = ParameterDirection.Output
                }
            };
            SqlCommand comx;
            var        r = DataHelper.ExecuteReader(Config.ConnectString, "usp_Slider_GetList", param, out comx);

            if (r != null)
            {
                list = new List <SliderInfo>();
                while (r.Read())
                {
                    var info = new SliderInfo();
                    info.id    = Int32.Parse(r["id"].ToString());
                    info.name  = r["name"].ToString();
                    info.image = r["image"].ToString();
                    info.alt   = r["alt"].ToString();
                    info.link  = r["link"].ToString();


                    list.Add(info);
                }
                r.Close();
                r.Dispose();
                t = int.Parse(comx.Parameters[2].Value.ToString());
            }

            total = t;
            return(list);
        }
        protected void SaveData()
        {
            if (this.ddlCategory.SelectedValue == "0")
            {
                this.lblError.Text = "Hãy chọn kiểu";
                return;
            }
            try
            {
                if (id > 0)
                {
                    SliderInfo info = new SliderInfo();
                    info.SliderName    = txtName.Text.Trim();
                    info.SliderContent = txtDetailText.Value;
                    info.SliderImage   = imageName;
                    info.SliderLink    = txtLink.Text.Trim();
                    info.SliderClass   = ddlCategory.SelectedValue.ToString();
                    info.SliderID      = id;
                    SliderManager.Update(info);
                }
                else
                {
                    //this is a new object.
                    SliderInfo info = new SliderInfo();
                    info.SliderName    = txtName.Text.Trim();
                    info.SliderContent = txtDetailText.Value;
                    info.SliderImage   = imageName;
                    info.SliderLink    = txtLink.Text.Trim();
                    info.SliderClass   = ddlCategory.SelectedValue.ToString();
                    SliderManager.Insert(info);
                }

                this.lblError.Text = "Đã lưu dữ liệu thành công";
            }
            catch (Exception ex)
            {
                this.lblError.Text = ex.Message;
            }
        }
Esempio n. 11
0
        public Slider Slider(int x, int y,
                             int sizeX, int sizeY,
                             int sliderSizeX, int sliderSizeY,
                             SliderInfo sliderInfo,
                             IColorPattern background,
                             IColorPattern slider,
                             IColorPattern filling,
                             IColorPattern border,
                             ARenderStyle style)
        {
            int offSet = 3;

            return(controlFactory.CreateSlider(sliderInfo,
                                               GetTexture(sizeX, sizeY + offSet * 2, background),
                                               GetTexture(sliderSizeX, sliderSizeY, slider),
                                               GetTexture(1, 1, filling),
                                               GetTexture(sizeX, sizeY, border),
                                               new Region(x, y - offSet, sizeX, sizeY + offSet * 2),
                                               new Region(x, y, sizeX, sizeY),
                                               new Region(x, y, sliderSizeX, sliderSizeY),
                                               style));
        }
Esempio n. 12
0
        public Slider Slider(int x, int y,
                             int sizeX, int sizeY,
                             int sliderSizeX, int sliderSizeY,
                             SliderInfo sliderInfo,
                             Texture2D backgroundTexture,
                             Texture2D slider,
                             Texture2D filling,
                             Texture2D border,
                             ARenderStyle style)
        {
            float offSet = 3.0f;

            return(controlFactory.CreateSlider(sliderInfo,
                                               backgroundTexture,
                                               slider,
                                               filling,
                                               border,
                                               new Region(x - offSet, y - offSet, sizeX + offSet * 2, sizeY + offSet * 2),
                                               new Region(x, y, sizeX, sizeY),
                                               new Region(x, y, sliderSizeX, sliderSizeY),
                                               style));
        }
Esempio n. 13
0
 public Slider CreateSlider(SliderInfo sliderInfo,
                            Texture2D backgroundTexture,
                            Texture2D slider,
                            Texture2D filling,
                            Texture2D border,
                            Region region,
                            Region borderRegion,
                            Region sliderRegion,
                            ARenderStyle style)
 {
     return(new Slider(sliderInfo,
                       new SliderDrawable(slider,
                                          border,
                                          filling,
                                          borderRegion,
                                          new AlignmentContext(HorizontalAlignment.Left,
                                                               VerticalAlignment.Center,
                                                               AlignmentTransition.Instant),
                                          sliderInfo.PercentageStep),
                       backgroundTexture,
                       region,
                       style));
 }
Esempio n. 14
0
        public List <SliderInfo> GetAll()
        {
            List <SliderInfo> list = null;
            var r = DataHelper.ExecuteReader(Config.ConnectString, "usp_slider_GetAll", null);

            if (r != null)
            {
                list = new List <SliderInfo>();
                while (r.Read())
                {
                    var info = new SliderInfo();
                    info.id    = Int32.Parse(r["id"].ToString());
                    info.name  = r["name"].ToString();
                    info.image = r["image"].ToString();
                    info.alt   = r["alt"].ToString();
                    info.link  = r["link"].ToString();

                    list.Add(info);
                }
                r.Close();
                r.Dispose();
            }
            return(list);
        }
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public static void CalculateSegments(SliderInfo pInfo, List<SegmentInfo> pSegments)
        {
            pSegments.Clear();

            int mult = (pInfo.TrackStartPosition < pInfo.TrackEndPosition ? 1 : -1);
            float half = 0.5f*mult;
            float handleMinPos = pInfo.TrackStartPosition + pInfo.HandleSize*half;
            float handleMaxPos = pInfo.TrackEndPosition - pInfo.HandleSize*half;
            float handlePos = Mathf.Lerp(handleMinPos, handleMaxPos, pInfo.HandleValue);
            float jumpPos = Mathf.Lerp(handleMinPos, handleMaxPos, pInfo.JumpValue);
            float zeroPos = Mathf.Lerp(handleMinPos, handleMaxPos, pInfo.ZeroValue);
            bool hasJump = (pInfo.JumpSize > 0);
            bool isJumpTooNear = (Mathf.Abs(handlePos-jumpPos) <
                (pInfo.HandleSize+pInfo.JumpSize)*0.6f);

            var handleSeg = new SegmentInfo {
                Type = SegmentType.Handle,
                StartPositionType = PositionType.HandleStart,
                EndPositionType = PositionType.HandleEnd,
                StartPosition = handlePos-pInfo.HandleSize*half,
                EndPosition = handlePos+pInfo.HandleSize*half
            };

            pSegments.Add(handleSeg);

            if ( hasJump && !isJumpTooNear && pInfo.JumpValue >= 0 ) {
                var jumpSeg = new SegmentInfo {
                    Type = SegmentType.Jump,
                    StartPositionType = PositionType.JumpStart,
                    EndPositionType = PositionType.JumpEnd,
                    StartPosition = jumpPos-pInfo.JumpSize*half,
                    EndPosition = jumpPos+pInfo.JumpSize*half
                };

                pSegments.Insert((handlePos*mult < jumpPos*mult ? 1 : 0), jumpSeg);
            }

            ////

            if ( pInfo.FillType == SliderFillType.Zero ) {
                var zeroSeg = new SegmentInfo {
                    Type = SegmentType.Zero,
                    StartPositionType = PositionType.Zero,
                    EndPositionType = PositionType.Zero,
                    StartPosition = zeroPos,
                    EndPosition = zeroPos
                };

                int zeroI;

                if ( zeroPos*mult < pSegments[0].StartPosition*mult ) {
                    zeroI = 0;
                    pSegments.Insert(zeroI, zeroSeg);
                }
                else if ( pSegments.Count > 1 && zeroPos*mult < pSegments[1].StartPosition*mult ) {
                    zeroI = 1;
                    pSegments.Insert(zeroI, zeroSeg);
                }
                else {
                    zeroI = pSegments.Count;
                    pSegments.Add(zeroSeg);
                }

                if ( zeroI > 0 ) {
                    SegmentInfo beforeZeroSeg = pSegments[zeroI-1];

                    if ( zeroSeg.StartPosition*mult < beforeZeroSeg.EndPosition*mult ) {
                        zeroSeg.StartPosition = beforeZeroSeg.EndPosition;
                        zeroSeg.EndPosition = beforeZeroSeg.EndPosition;
                        zeroSeg.StartPositionType = beforeZeroSeg.EndPositionType;
                        zeroSeg.EndPositionType = beforeZeroSeg.EndPositionType;
                        pSegments[zeroI] = zeroSeg;
                    }
                }
            }

            ////

            var startSeg = new SegmentInfo {
                Type = SegmentType.Start,
                StartPositionType = PositionType.TrackStart,
                EndPositionType = PositionType.TrackStart,
                StartPosition = pInfo.TrackStartPosition,
                EndPosition = pInfo.TrackStartPosition
            };

            var endSeg = new SegmentInfo {
                Type = SegmentType.End,
                StartPositionType = PositionType.TrackEnd,
                EndPositionType = PositionType.TrackEnd,
                StartPosition = pInfo.TrackEndPosition,
                EndPosition = pInfo.TrackEndPosition
            };

            pSegments.Insert(0, startSeg);
            pSegments.Add(endSeg);

            ////

            bool isFilling = false;
            SegmentType fillToSegType;

            switch ( pInfo.FillType ) {
                case SliderFillType.Zero:
                    fillToSegType = SegmentType.Zero;
                    break;

                case SliderFillType.MinimumValue:
                    fillToSegType = SegmentType.Start;
                    break;

                case SliderFillType.MaximumValue:
                    fillToSegType = SegmentType.End;
                    break;

                default:
                    throw new Exception("Unhandled fill type: "+pInfo.FillType);
            }

            ////

            for ( int i = 1 ; i < pSegments.Count ; i++ ) {
                SegmentInfo prevSeg = pSegments[i-1];
                SegmentInfo nextSeg = pSegments[i];

                if ( prevSeg.Type == SegmentType.Handle || prevSeg.Type == fillToSegType ) {
                    isFilling = !isFilling;
                }

                var trackSeg = new SegmentInfo {
                    Type = SegmentType.Track,
                    StartPositionType = prevSeg.EndPositionType,
                    EndPositionType = nextSeg.StartPositionType,
                    StartPosition = prevSeg.EndPosition,
                    EndPosition = nextSeg.StartPosition,
                    IsFill = isFilling
                };

                pSegments.Insert(i, trackSeg);
                i++;
            }
        }
        /*--------------------------------------------------------------------------------------------*/
        public static void CalculateTicks(SliderInfo pInfo, List<SegmentInfo> pSliderSegments,
																			List<SegmentInfo> pTicks)
        {
            pTicks.Clear();

            if ( pInfo.TickCount <= 1 ) {
                return;
            }

            ////

            float handStart = -1;
            float handEnd = -1;
            float jumpStart = -1;
            float jumpEnd = -1;

            for ( int i = 0 ; i < pSliderSegments.Count ; i++ ) {
                SegmentInfo seg = pSliderSegments[i];

                if ( seg.Type == SegmentType.Handle ) {
                    handStart = seg.StartPosition;
                    handEnd = seg.EndPosition;
                }

                if ( seg.Type == SegmentType.Jump ) {
                    jumpStart = seg.StartPosition;
                    jumpEnd = seg.EndPosition;
                }
            }

            ////

            int mult = (pInfo.TrackStartPosition < pInfo.TrackEndPosition ? 1 : -1);
            float half = 0.5f*mult;
            float handleMinPos = pInfo.TrackStartPosition + pInfo.HandleSize*half;
            float handleMaxPos = pInfo.TrackEndPosition - pInfo.HandleSize*half;

            for ( int i = 0 ; i < pInfo.TickCount ; i++ ) {
                float prog = i/(pInfo.TickCount-1f);
                float tickCenterPos = Mathf.Lerp(handleMinPos, handleMaxPos, prog);

                var tick = new SegmentInfo {
                    Type = SegmentType.Tick,
                    StartPositionType = PositionType.TickStart,
                    EndPositionType = PositionType.TickEnd,
                    StartPosition = tickCenterPos-pInfo.TickSize*half,
                    EndPosition = tickCenterPos+pInfo.TickSize*half
                };

                float startMult = tick.StartPosition*mult;
                float endMult = tick.EndPosition*mult;
                bool startsInHand = (startMult >= handStart*mult && startMult <= handEnd*mult);
                bool endsInHand   = (endMult   >= handStart*mult && endMult   <= handEnd*mult);
                bool startsInJump = (startMult >= jumpStart*mult && startMult <= jumpEnd*mult);
                bool endsInJump   = (endMult   >= jumpStart*mult && endMult   <= jumpEnd*mult);

                tick.IsHidden = ((startsInHand && endsInHand) || (startsInJump && endsInJump));

                if ( startsInHand ) {
                    tick.StartPosition = handEnd;
                }

                if ( endsInHand ) {
                    tick.EndPosition = handStart;
                }

                if ( startsInJump ) {
                    tick.StartPosition = jumpEnd;
                }

                if ( endsInJump ) {
                    tick.EndPosition = jumpStart;
                }

                pTicks.Add(tick);
            }
        }
Esempio n. 17
0
        ////////////////////////////////////////////////////////////////////////////////////////////////
        /*--------------------------------------------------------------------------------------------*/
        public static void CalculateSegments(SliderInfo pInfo, List <SegmentInfo> pSegments)
        {
            pSegments.Clear();

            int   mult          = (pInfo.TrackStartPosition < pInfo.TrackEndPosition ? 1 : -1);
            float half          = 0.5f * mult;
            float handleMinPos  = pInfo.TrackStartPosition + pInfo.HandleSize * half;
            float handleMaxPos  = pInfo.TrackEndPosition - pInfo.HandleSize * half;
            float handlePos     = Mathf.Lerp(handleMinPos, handleMaxPos, pInfo.HandleValue);
            float jumpPos       = Mathf.Lerp(handleMinPos, handleMaxPos, pInfo.JumpValue);
            float zeroPos       = Mathf.Lerp(handleMinPos, handleMaxPos, pInfo.ZeroValue);
            bool  hasJump       = (pInfo.JumpSize > 0);
            bool  isJumpTooNear = (Mathf.Abs(handlePos - jumpPos) <
                                   (pInfo.HandleSize + pInfo.JumpSize) * 0.6f);

            var handleSeg = new SegmentInfo {
                Type = SegmentType.Handle,
                StartPositionType = PositionType.HandleStart,
                EndPositionType   = PositionType.HandleEnd,
                StartPosition     = handlePos - pInfo.HandleSize * half,
                EndPosition       = handlePos + pInfo.HandleSize * half
            };

            pSegments.Add(handleSeg);

            if (hasJump && !isJumpTooNear && pInfo.JumpValue >= 0)
            {
                var jumpSeg = new SegmentInfo {
                    Type = SegmentType.Jump,
                    StartPositionType = PositionType.JumpStart,
                    EndPositionType   = PositionType.JumpEnd,
                    StartPosition     = jumpPos - pInfo.JumpSize * half,
                    EndPosition       = jumpPos + pInfo.JumpSize * half
                };

                pSegments.Insert((handlePos * mult < jumpPos * mult ? 1 : 0), jumpSeg);
            }

            ////

            if (pInfo.FillType == SliderFillType.Zero)
            {
                var zeroSeg = new SegmentInfo {
                    Type = SegmentType.Zero,
                    StartPositionType = PositionType.Zero,
                    EndPositionType   = PositionType.Zero,
                    StartPosition     = zeroPos,
                    EndPosition       = zeroPos
                };

                int zeroI;

                if (zeroPos * mult < pSegments[0].StartPosition * mult)
                {
                    zeroI = 0;
                    pSegments.Insert(zeroI, zeroSeg);
                }
                else if (pSegments.Count > 1 && zeroPos * mult < pSegments[1].StartPosition * mult)
                {
                    zeroI = 1;
                    pSegments.Insert(zeroI, zeroSeg);
                }
                else
                {
                    zeroI = pSegments.Count;
                    pSegments.Add(zeroSeg);
                }

                if (zeroI > 0)
                {
                    SegmentInfo beforeZeroSeg = pSegments[zeroI - 1];

                    if (zeroSeg.StartPosition * mult < beforeZeroSeg.EndPosition * mult)
                    {
                        zeroSeg.StartPosition     = beforeZeroSeg.EndPosition;
                        zeroSeg.EndPosition       = beforeZeroSeg.EndPosition;
                        zeroSeg.StartPositionType = beforeZeroSeg.EndPositionType;
                        zeroSeg.EndPositionType   = beforeZeroSeg.EndPositionType;
                        pSegments[zeroI]          = zeroSeg;
                    }
                }
            }

            ////

            var startSeg = new SegmentInfo {
                Type = SegmentType.Start,
                StartPositionType = PositionType.TrackStart,
                EndPositionType   = PositionType.TrackStart,
                StartPosition     = pInfo.TrackStartPosition,
                EndPosition       = pInfo.TrackStartPosition
            };

            var endSeg = new SegmentInfo {
                Type = SegmentType.End,
                StartPositionType = PositionType.TrackEnd,
                EndPositionType   = PositionType.TrackEnd,
                StartPosition     = pInfo.TrackEndPosition,
                EndPosition       = pInfo.TrackEndPosition
            };

            pSegments.Insert(0, startSeg);
            pSegments.Add(endSeg);

            ////

            bool        isFilling = false;
            SegmentType fillToSegType;

            switch (pInfo.FillType)
            {
            case SliderFillType.Zero:
                fillToSegType = SegmentType.Zero;
                break;

            case SliderFillType.MinimumValue:
                fillToSegType = SegmentType.Start;
                break;

            case SliderFillType.MaximumValue:
                fillToSegType = SegmentType.End;
                break;

            default:
                throw new Exception("Unhandled fill type: " + pInfo.FillType);
            }

            ////

            for (int i = 1; i < pSegments.Count; i++)
            {
                SegmentInfo prevSeg = pSegments[i - 1];
                SegmentInfo nextSeg = pSegments[i];

                if (prevSeg.Type == SegmentType.Handle || prevSeg.Type == fillToSegType)
                {
                    isFilling = !isFilling;
                }

                var trackSeg = new SegmentInfo {
                    Type = SegmentType.Track,
                    StartPositionType = prevSeg.EndPositionType,
                    EndPositionType   = nextSeg.StartPositionType,
                    StartPosition     = prevSeg.EndPosition,
                    EndPosition       = nextSeg.StartPosition,
                    IsFill            = isFilling
                };

                pSegments.Insert(i, trackSeg);
                i++;
            }
        }
Esempio n. 18
0
        /*--------------------------------------------------------------------------------------------*/
        public static void CalculateTicks(SliderInfo pInfo, List <SegmentInfo> pSliderSegments,
                                          List <SegmentInfo> pTicks)
        {
            pTicks.Clear();

            if (pInfo.TickCount <= 1)
            {
                return;
            }

            ////

            float handStart = -1;
            float handEnd   = -1;
            float jumpStart = -1;
            float jumpEnd   = -1;

            for (int i = 0; i < pSliderSegments.Count; i++)
            {
                SegmentInfo seg = pSliderSegments[i];

                if (seg.Type == SegmentType.Handle)
                {
                    handStart = seg.StartPosition;
                    handEnd   = seg.EndPosition;
                }

                if (seg.Type == SegmentType.Jump)
                {
                    jumpStart = seg.StartPosition;
                    jumpEnd   = seg.EndPosition;
                }
            }

            ////

            int   mult         = (pInfo.TrackStartPosition < pInfo.TrackEndPosition ? 1 : -1);
            float half         = 0.5f * mult;
            float handleMinPos = pInfo.TrackStartPosition + pInfo.HandleSize * half;
            float handleMaxPos = pInfo.TrackEndPosition - pInfo.HandleSize * half;

            for (int i = 0; i < pInfo.TickCount; i++)
            {
                float prog          = i / (pInfo.TickCount - 1f);
                float tickCenterPos = Mathf.Lerp(handleMinPos, handleMaxPos, prog);

                var tick = new SegmentInfo {
                    Type = SegmentType.Tick,
                    StartPositionType = PositionType.TickStart,
                    EndPositionType   = PositionType.TickEnd,
                    StartPosition     = tickCenterPos - pInfo.TickSize * half,
                    EndPosition       = tickCenterPos + pInfo.TickSize * half
                };

                float startMult    = tick.StartPosition * mult;
                float endMult      = tick.EndPosition * mult;
                bool  startsInHand = (startMult >= handStart * mult && startMult <= handEnd * mult);
                bool  endsInHand   = (endMult >= handStart * mult && endMult <= handEnd * mult);
                bool  startsInJump = (startMult >= jumpStart * mult && startMult <= jumpEnd * mult);
                bool  endsInJump   = (endMult >= jumpStart * mult && endMult <= jumpEnd * mult);

                tick.IsHidden = ((startsInHand && endsInHand) || (startsInJump && endsInJump));

                if (startsInHand)
                {
                    tick.StartPosition = handEnd;
                }

                if (endsInHand)
                {
                    tick.EndPosition = handStart;
                }

                if (startsInJump)
                {
                    tick.StartPosition = jumpEnd;
                }

                if (endsInJump)
                {
                    tick.EndPosition = jumpStart;
                }

                pTicks.Add(tick);
            }
        }
Esempio n. 19
0
        private void Parse(string bm)
        {
            Info.Filename = bm;
            Info.BeatmapHash = MD5FromFile(bm);
            using (StreamReader sR = new StreamReader(bm))
            {
                string currentSection = "";

                while (sR.Peek() != -1)
                {
                    string line = sR.ReadLine();

                    //Check for blank lines
                    if ((line == "") || (line.Length < 2))
                        continue;

                    //Check for section tag
                    if (line.Substring(0, 1) == "[")
                    {
                        currentSection = line;
                        continue;
                    }

                    //Check for commented-out line
                    if (line.Substring(0, 2) == "//")
                        continue;

                    //Check for version string
                    if (line.Length > 17)
                    {
                        if (line.Substring(0, 17) == "osu file format v")
                        {
                            Info.Format = Convert.ToInt32(line.Substring(17).Replace(Environment.NewLine, "").Replace(" ", ""));
                        }
                    }

                    //Do work for [General], [Metadata], [Difficulty] and [Editor] sections
                    if ((currentSection == "[General]") || (currentSection == "[Metadata]") || (currentSection == "[Difficulty]") || (currentSection == "[Editor]"))
                    {
                        string[] reSplit = line.Split(':');
                        string cProperty = reSplit[0];

                        //Check for blank value
                        string cValue = line.Length == reSplit[0].Length ? "" : reSplit[1].Trim();

                        //Import properties into Info
                        switch (cProperty)
                        {
                            case "EditorBookmarks":
                            {
                                string[] marks = cValue.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (string m in marks.Where(m => m != ""))
                                {
                                    Info.EditorBookmarks.Add(Convert.ToInt32(m));
                                }
                            }
                                break;
                            case "Bookmarks":
                            {
                                string[] marks = cValue.Split(new[] { "," }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (string m in marks.Where(m => m != ""))
                                {
                                    Info.Bookmarks.Add(Convert.ToInt32(m));
                                }
                            }
                                break;
                            case "Tags":
                                string[] tags = cValue.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries);
                                foreach (string t in tags)
                                    Info.Tags.Add(t);
                                break;
                            case "Mode":
                                Info.Mode = (GameMode)Convert.ToInt32(cValue);
                                break;
                            case "OverlayPosition":
                                Info.OverlayPosition = (OverlayOptions)Convert.ToInt32(cValue);
                                break;
                            case "AlwaysShowPlayfield":
                                Info.AlwaysShowPlayfield = Convert.ToBoolean(Convert.ToInt32(cValue));
                                break;
                            default:
                                FieldInfo fi = Info.GetType().GetField(cProperty);
                                PropertyInfo pi = Info.GetType().GetProperty(cProperty);
                                if (fi != null)
                                {
                                    if ((fi.FieldType == typeof(double?)) || (fi.FieldType == typeof(double)))
                                        fi.SetValue(Info, Convert.ToDouble(cValue));
                                    else if ((fi.FieldType == typeof(int?)) || (fi.FieldType == typeof(int)))
                                        fi.SetValue(Info, Convert.ToInt32(cValue));
                                    else if (fi.FieldType == typeof(string))
                                        fi.SetValue(Info, cValue);
                                    break;
                                }
                                if ((pi.PropertyType == typeof(double?)) || (pi.PropertyType == typeof(double)))
                                    pi.SetValue(Info, Convert.ToDouble(cValue), null);
                                else if ((pi.PropertyType == typeof(int?)) || (pi.PropertyType == typeof(int)))
                                    pi.SetValue(Info, Convert.ToInt32(cValue), null);
                                else if (pi.PropertyType == typeof(string))
                                    pi.SetValue(Info, cValue, null);
                                break;
                        }
                        continue;
                    }

                    //The following are version-dependent, the version is stored as a numeric value inside Info.Format
                    //Do work for [Events] section
                    if (currentSection == "[Events]")
                    {
                        switch (Info.Format)
                        {
                            case 3: case 4: case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13:
                                string[] reSplit = line.Split(',');
                                if (reSplit[0] == "0")
                                {
                                    BackgroundInfo tempEvent = new BackgroundInfo();
                                    tempEvent.StartTime = Convert.ToInt32(reSplit[1]);
                                    tempEvent.Filename = reSplit[2].Replace("\"", "");
                                    Info.Events.Add(tempEvent);
                                }
                                else if ((reSplit[0] == "1") || (reSplit[0].ToLower() == "video"))
                                {
                                    VideoInfo tempEvent = new VideoInfo();
                                    tempEvent.StartTime = Convert.ToInt32(reSplit[1]);
                                    tempEvent.Filename = reSplit[2];
                                    Info.Events.Add(tempEvent);
                                }
                                else if (reSplit[0] == "2")
                                {
                                    BreakInfo tempEvent = new BreakInfo();
                                    tempEvent.StartTime = Convert.ToInt32(reSplit[1]);
                                    tempEvent.EndTime = Convert.ToInt32(reSplit[2]);
                                    Info.Events.Add(tempEvent);
                                }
                                else if (reSplit[0] == "3")
                                {
                                    ColourInfo tempEvent = new ColourInfo();
                                    tempEvent.StartTime = Convert.ToInt32(reSplit[1]);
                                    tempEvent.R = Convert.ToInt32(reSplit[2]);
                                    tempEvent.G = Convert.ToInt32(reSplit[3]);
                                    tempEvent.B = Convert.ToInt32(reSplit[4]);
                                    Info.Events.Add(tempEvent);
                                }
                                break;
                        }

                    }

                    //Do work for [TimingPoints] section
                    if (currentSection == "[TimingPoints]")
                    {
                        TimingPointInfo tempTimingPoint = new TimingPointInfo();

                        double[] values = { 0, 0, 4, 0, 0, 100, 0, 0, 0 };
                        string[] reSplit = line.Split(',');
                        for (int i = 0; i < reSplit.Length; i++)
                        {
                            values[i] += Convert.ToDouble(reSplit[i]);
                        }
                        tempTimingPoint.Time = Convert.ToDouble(values[0]);
                        tempTimingPoint.BpmDelay = Convert.ToDouble(values[1]);
                        tempTimingPoint.TimeSignature = Convert.ToInt32(values[2]);
                        tempTimingPoint.SampleSet = Convert.ToInt32(values[3]);
                        tempTimingPoint.CustomSampleSet = Convert.ToInt32(values[4]);
                        tempTimingPoint.VolumePercentage = Convert.ToInt32(values[5]);
                        tempTimingPoint.InheritsBPM = !Convert.ToBoolean(Convert.ToInt32(values[6]));
                        tempTimingPoint.VisualOptions = (TimingPointOptions)Convert.ToInt32(values[7]);
                        Info.TimingPoints.Add(tempTimingPoint);
                    }

                    //Do work for [Colours] section
                    if (currentSection == "[Colours]")
                    {
                        switch (Info.Format)
                        {
                            case 5: case 6: case 7: case 8: case 9: case 10: case 11: case 12: case 13:
                                if (line.Substring(0, line.IndexOf(':', 1)).Trim() == "SliderBorder")
                                {
                                    string value = line.Substring(line.IndexOf(':', 1) + 1).Trim();
                                    string[] reSplit = value.Split(',');
                                    Info.SliderBorder = new ColourInfo();
                                    Info.SliderBorder.R = Convert.ToInt32(reSplit[0]);
                                    Info.SliderBorder.G = Convert.ToInt32(reSplit[1]);
                                    Info.SliderBorder.B = Convert.ToInt32(reSplit[2]);
                                }
                                else if (line.Substring(0, 5) == "Combo")
                                {
                                    string value = line.Substring(line.IndexOf(':', 1) + 1).Trim();
                                    string[] reSplit = value.Split(',');
                                    ComboInfo tempCombo = new ComboInfo();
                                    tempCombo.ComboNumber = Convert.ToInt32(line.Substring(5, 1));
                                    tempCombo.Colour.R = Convert.ToInt32(reSplit[0]);
                                    tempCombo.Colour.G = Convert.ToInt32(reSplit[1]);
                                    tempCombo.Colour.B = Convert.ToInt32(reSplit[2]);
                                    Info.ComboColours.Add(tempCombo);
                                }
                                break;
                        }
                    }

                    //Do work for [HitObjects] section
                    if (currentSection == "[HitObjects]")
                    {
                        string[] reSplit = line.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                        BaseCircle newObject = new BaseCircle
                        {
                            Radius = 40 - 4 * (Info.CircleSize - 2),
                            Location = new PointInfo(Convert.ToInt32(reSplit[0]), Convert.ToInt32(reSplit[1])),
                            StartTime = Convert.ToInt32(reSplit[2]),
                            Type = (HitObjectType)Convert.ToInt32(reSplit[3]),
                            Effect = (EffectType)Convert.ToInt32(reSplit[4])
                        };
                        if ((newObject.Type & HitObjectType.Slider) > 0)
                        {
                            newObject = new SliderInfo(newObject);
                            ((SliderInfo)newObject).Velocity = Info.SliderMultiplier;
                            switch (reSplit[5].Substring(0, 1))
                            {
                                case "B":
                                    ((SliderInfo)newObject).Type = SliderType.Bezier;
                                    break;
                                case "C":
                                    ((SliderInfo)newObject).Type = SliderType.CSpline;
                                    break;
                                case "L":
                                    ((SliderInfo)newObject).Type = SliderType.Linear;
                                    break;
                                case "P":
                                    ((SliderInfo)newObject).Type = SliderType.PSpline;
                                    break;
                            }
                            string[] pts = reSplit[5].Split(new[] { "|" }, StringSplitOptions.None);

                            //Always add the location as a point
                            ((SliderInfo)newObject).Points.Add(newObject.Location);

                            //Always exclude index 1, this will contain the type
                            for (int i = 1; i <= pts.Length - 1; i++)
                            {
                                PointInfo p = new PointInfo(Convert.ToDouble(pts[i].Substring(0, pts[i].IndexOf(":", StringComparison.InvariantCulture))),
                                                            Convert.ToDouble(pts[i].Substring(pts[i].IndexOf(":", StringComparison.InvariantCulture) + 1)));
                                ((SliderInfo)newObject).Points.Add(p);
                            }
                            ((SliderInfo)newObject).RepeatCount = Convert.ToInt32(reSplit[6]);
                            double tempDbl;
                            if (double.TryParse(reSplit[7], out tempDbl))
                            {
                                ((SliderInfo)newObject).MaxPoints = tempDbl;
                            }
                        }
                        if ((newObject.Type & HitObjectType.Spinner) > 0)
                        {
                            newObject = new SpinnerInfo(newObject);
                            ((SpinnerInfo)newObject).EndTime = Convert.ToInt32(reSplit[5]);
                        }
                        Info.HitObjects.Add(newObject);
                    }
                }
            }
            foreach (FieldInfo fi in Info.GetType().GetFields())
            {
                FieldInfo ff = GetType().GetField(fi.Name);
                ff.SetValue(this, fi.GetValue(Info));
            }
            foreach (PropertyInfo pi in Info.GetType().GetProperties())
            {
                PropertyInfo ff = GetType().GetProperty(pi.Name);
                ff.SetValue(this, pi.GetValue(Info, null), null);
            }
        }