/// <summary> /// Adds the provided point. Overwrites any existing point with the same key. /// </summary> /// <param name="point">PointIcon to add.</param> public void AddPoint(PointIcon point) { if (this.m_points.ContainsKey(point.Name)) { this.m_points.Remove(point.Name); } this.m_points.Add(point.Name, point); }
public PointSettings() { UserPoints = new UserPointCollection(); ExchangeProportions = new PointExchangeProportionCollection(); ExchangeProportions.Add(UserPointType.Point1, 10); ExchangeProportions.Add(UserPointType.Point2, 1); ExchangeProportions.Add(UserPointType.Point3, 1); ExchangeProportions.Add(UserPointType.Point4, 1); ExchangeProportions.Add(UserPointType.Point5, 1); ExchangeProportions.Add(UserPointType.Point6, 1); ExchangeProportions.Add(UserPointType.Point7, 1); ExchangeProportions.Add(UserPointType.Point8, 1); EnablePointExchange = false; EnablePointTransfer = false; PointRechargeRules = new PointRechargeRuleCollection(); PointExchangeRules = new PointExchangeRuleCollection(); PointExchangeRule rule = new PointExchangeRule(); rule.PointType = UserPointType.Point2; rule.TargetPointType = UserPointType.Point1; rule.TaxRate = 2; PointExchangeRules.Add(rule); GeneralPointName = "总积分"; GeneralPointExpression = "p1+p2*10"; DisplayGeneralPoint = true; TradeRate = 2; PointTransferRules = new PointTransferRuleCollection(); PointTransferRule tRule = new PointTransferRule(); tRule.CanTransfer = true; tRule.PointType = UserPointType.Point1; tRule.TaxRate = 2; PointTransferRules.Add(tRule); PointIcons = new PointIconCollection(); PointIcon icon = new PointIcon(); icon.IconCount = 4; icon.IconsString = "fortune_3.gif|fortune_2.gif|fortune_1.gif"; icon.PointType = UserPointType.Point1; icon.PointValue = 1000; PointIcons.Add(icon); }
public override bool PerformSelectionAction(DrawArgs drawArgs) { int closestIconDistanceSquared = int.MaxValue; PointIcon closestIcon = null; foreach (PointIcon point in this.m_points.Values) { // don't check if we aren't even in view if (drawArgs.WorldCamera.ViewFrustum.ContainsPoint(point.Position)) { // check if inside the icons bounding box Vector3 referenceCenter = new Vector3( (float)drawArgs.WorldCamera.ReferenceCenter.X, (float)drawArgs.WorldCamera.ReferenceCenter.Y, (float)drawArgs.WorldCamera.ReferenceCenter.Z); Vector3 projectedPoint = drawArgs.WorldCamera.Project(point.Position - referenceCenter); int dx = DrawArgs.LastMousePosition.X - (int)projectedPoint.X; int dy = DrawArgs.LastMousePosition.Y - (int)projectedPoint.Y; if (this.SelectionRectangle.Contains(dx, dy)) { // Mouse is over, check whether this icon is closest int distanceSquared = dx * dx + dy * dy; if (distanceSquared < closestIconDistanceSquared) { closestIconDistanceSquared = distanceSquared; closestIcon = point; } } } } // if no other object has handled the selection let the closest icon try if (closestIcon != null) { return(closestIcon.PerformSelectionAction(drawArgs)); } return(false); }
public override void Render(DrawArgs drawArgs) { if (!this.isOn) { return; } if (!this.isInitialized) { this.Initialize(drawArgs); } this.m_pointSprites.Clear(); int closestIconDistanceSquared = int.MaxValue; PointIcon closestIcon = null; // build list of all points in view foreach (PointIcon point in this.m_points.Values) { try { // don't bother to do anything else if we aren't even in view if (drawArgs.WorldCamera.ViewFrustum.ContainsPoint(point.Position)) { Vector3 translationVector = new Vector3( (float)(point.PositionD.X - drawArgs.WorldCamera.ReferenceCenter.X), (float)(point.PositionD.Y - drawArgs.WorldCamera.ReferenceCenter.Y), (float)(point.PositionD.Z - drawArgs.WorldCamera.ReferenceCenter.Z)); Vector3 projectedPoint = drawArgs.WorldCamera.Project(translationVector); // check if inside bounding box of icon int dx = DrawArgs.LastMousePosition.X - (int)projectedPoint.X; int dy = DrawArgs.LastMousePosition.Y - (int)projectedPoint.Y; if (this.SelectionRectangle.Contains(dx, dy)) { // Mouse is over, check whether this icon is closest int distanceSquared = dx * dx + dy * dy; if (distanceSquared < closestIconDistanceSquared) { closestIconDistanceSquared = distanceSquared; closestIcon = point; } } PointSpriteVertex pv = new PointSpriteVertex(translationVector.X, translationVector.Y, translationVector.Z, point.Size, point.Color.ToArgb()); this.m_pointSprites.Add(pv); } } catch { } finally { } } // render point sprites if any in the list try { if (this.m_pointSprites.Count > 0) { // save device state BaseTexture origTexture = drawArgs.device.GetTexture(0); VertexFormat origVertexFormat = drawArgs.device.VertexFormat; float origPointScaleA = drawArgs.device.GetRenderState <float>(RenderState.PointScaleA); float origPointScaleB = drawArgs.device.GetRenderState <float>(RenderState.PointScaleB); float origPointScaleC = drawArgs.device.GetRenderState <float>(RenderState.PointScaleC); bool origPointSpriteEnable = drawArgs.device.GetRenderState <bool>(RenderState.PointSpriteEnable); bool origPointScaleEnable = drawArgs.device.GetRenderState <bool>(RenderState.PointScaleEnable); Blend origSourceBlend = drawArgs.device.GetRenderState <Blend>(RenderState.SourceBlend); Blend origDestBlend = drawArgs.device.GetRenderState <Blend>(RenderState.DestinationBlend); // set device to do point sprites drawArgs.device.SetTexture(0, this.m_pointTexture.Texture); drawArgs.device.VertexFormat = VertexFormat.Position | VertexFormat.PointSize | VertexFormat.Diffuse; drawArgs.device.SetRenderState(RenderState.PointScaleA, 1f); drawArgs.device.SetRenderState(RenderState.PointScaleB, 0f); drawArgs.device.SetRenderState(RenderState.PointScaleC, 0f); drawArgs.device.SetRenderState(RenderState.PointSpriteEnable, true); drawArgs.device.SetRenderState(RenderState.PointScaleEnable, true); drawArgs.device.SetTextureStageState(0, TextureStage.ColorOperation, (int)TextureOperation.Modulate); drawArgs.device.SetTextureStageState(0, TextureStage.ColorArg1, (int)TextureArgument.Texture); drawArgs.device.SetTextureStageState(0, TextureStage.ColorArg2, (int)TextureArgument.Diffuse); // Draw all visible points drawArgs.device.DrawUserPrimitives(PrimitiveType.PointList, this.m_pointSprites.Count, this.m_pointSprites.ToArray()); // Draw label and description of mouseover point if (closestIcon != null) { } // restore device state drawArgs.device.SetTexture(0, origTexture); drawArgs.device.VertexFormat = origVertexFormat; drawArgs.device.SetRenderState(RenderState.PointScaleA, origPointScaleA); drawArgs.device.SetRenderState(RenderState.PointScaleB, origPointScaleB); drawArgs.device.SetRenderState(RenderState.PointScaleC, origPointScaleC); drawArgs.device.SetRenderState(RenderState.PointSpriteEnable, origPointSpriteEnable); drawArgs.device.SetRenderState(RenderState.PointScaleEnable, origPointScaleEnable); drawArgs.device.SetRenderState(RenderState.SourceBlend, origSourceBlend); drawArgs.device.SetRenderState(RenderState.DestinationBlend, origDestBlend); } } catch { } }
public Point(int x, int y, PointIcon icon) { _icon = icon; _y = y; _x = x; }
/// <summary> /// 更新积分等级图标 /// </summary> /// <param name="pointType"></param> /// <param name="pointValue">初级图标 所需积分</param> /// <param name="iconCount"> 升上一级图标 所需当前图标个数</param> /// <param name="icons"></param> /// <returns></returns> public static bool UpdatePointIcon(UserPointType pointType, int pointValue, int iconCount, IEnumerable <string> icons) { if (pointValue < 1) { Context.ThrowError <UserPointIconValueError>(new UserPointIconValueError("pointValue", AllSettings.Current.PointSettings.GetUserPoint(pointType).Name)); } if (iconCount < 1) { Context.ThrowError <UserPointUpgradeIconCountError>(new UserPointUpgradeIconCountError("iconCount")); } List <string> tempIcons = new List <string>(); foreach (string icon in icons) { string tempIcon = icon.Trim(); if (tempIcons.Contains(icon)) { Context.ThrowError <UserPointIconIsExistsError>(new UserPointIconIsExistsError("icons")); return(false); } if (tempIcon != string.Empty && !tempIcons.Contains(icon)) { tempIcons.Add(icon); } } if (tempIcons.Count == 0) { Context.ThrowError <UserPointIconEmptyError>(new UserPointIconEmptyError("icons")); } if (HasUnCatchedError) { return(false); } string iconsString = StringUtil.Join(tempIcons, "|"); PointIcon pointIcon = new PointIcon(); pointIcon.PointType = pointType; pointIcon.PointValue = pointValue; pointIcon.IconCount = iconCount; pointIcon.IconsString = iconsString; lock (AllSettings.Current.PointSettings) { PointSettings setting = SettingManager.CloneSetttings <PointSettings>(AllSettings.Current.PointSettings); bool hasAdd = false; for (int i = 0; i < setting.PointIcons.Count; i++) { if (setting.PointIcons[i].PointType == pointType) { setting.PointIcons[i] = pointIcon; hasAdd = true; } } if (!hasAdd) { setting.PointIcons.Add(pointIcon); } bool success = SettingManager.SaveSettings(setting); //if (success) // AllSettings.Current.PointSettings = setting; return(success); } }