protected void TestSpeechBubbles(Vector2 touch) { if (_bubble!=null) { FSpeechBubbleManager.TransitionFadeOut(_bubble,0f); } FPseudoHtmlText text=new FPseudoHtmlText(Config.fontFile,"<style text-color='#111111'><style text-scale='0.5'>FSpeechBubble</style><br/><style text-scale='0.3'>Combined with a FPseudoHtmlText. How cool is that? <style text-color='#FF99FF'><br/><fsprite width='50' src='Monkey_0'/> With FSprites and FButtons inside, that's pretty cool! <fbutton src='YellowButton_normal' label='FButtons' scale='0.5' label-scale='0.5' color-down='#FF0000' action='MyMethodNameWithData' data='mybutttonid'/></style></style>",Config.textParams,200f,PseudoHtmlTextAlign.left,1f,this); //_bubble=FSpeechBubbleManager.Instance.Show(text,touch,10f); FSpeechBubbleManager.Instance.defaultContainer=this; _bubble=FSpeechBubbleManager.Instance.Show(text,touch,10f); FSpeechBubbleManager.TransitionPop(_bubble); //_back.MoveToFront(); }
public void TempMessage(string text,float duration) { FLabel label=new FLabel(Config.fontFile,text,Config.textParams); label.color=Color.black; label.scale=0.5f; FSpeechBubble bubble=new FSpeechBubble(); bubble.backgroundColor=Color.white; AddChild(bubble); label.y+=3f; bubble.AddChild(label); bubble.SetSizeAndPointer(label.textRect.width*label.scaleX+20f,label.textRect.height*label.scaleY+20f,new Vector2(0,0),0f); FSpeechBubbleManager.TransitionPop(bubble); FSpeechBubbleManager.TransitionFadeOut(bubble,duration); }
public override void Start() { FLabel label=new FLabel(Config.fontFile,"Click anywhere\noutside of the box",Config.textParams); label.color=Color.black; _bubble=new FSpeechBubble(); _bubble.backgroundColor=Color.white; AddChild(_bubble); label.y+=3f; _bubble.AddChild(label); _bubble.SetSizeAndPointer(label.textRect.width+10f,label.textRect.height+40f,new Vector2(0,0),0f); base.Start(); }
public FSpeechBubble Show(FNode node, float width, float height, float contentMarginX, float contentMarginY, Vector2 point, float pointerLength, float pointerMargin, Color backgroundColor, FContainer container, Rect visibleArea) { FSpeechBubble bubble=new FSpeechBubble(); bubble.backgroundColor=backgroundColor; if (node!=null) { if (node.container!=null) node.RemoveFromContainer(); bubble.AddChild(node); } container.AddChild(bubble); //size fo the bubble with content margin taken into account float totalWidth=width+contentMarginX*2; float totalHeight=height+contentMarginY*2; float totalPointerLength=pointerLength+pointerMargin; float verticalFreeWidth=0,verticalFreeHeight=0; float horizontalFreeWidth=0,horizontalFreeHeight=0; //Try first the space on top/bottom or left/right //Determine which space is best suited if (point.x<visibleArea.center.x) { //more space on the right verticalFreeWidth=visibleArea.xMax-point.x-totalPointerLength; verticalFreeHeight=visibleArea.height; } else { //more space on the left verticalFreeWidth=point.x-visibleArea.xMin-totalPointerLength; verticalFreeHeight=visibleArea.height; } if (point.y<visibleArea.center.y) { //more space on the top horizontalFreeWidth=visibleArea.width; horizontalFreeHeight=visibleArea.yMax-point.y-totalPointerLength; } else { //more space on the bottom horizontalFreeWidth=visibleArea.width; horizontalFreeHeight=point.y-visibleArea.yMin-totalPointerLength; } float verticalRemainingSurface=-1,horizontalRemainingSurface=-1; float verticalHiddenSurface=0,horizontalHiddenSurface=0; bool verticalFit=false,horizontalFit=false; if ((totalWidth<=verticalFreeWidth)&&(totalHeight<=verticalFreeHeight)) { verticalFit=true; } else { if (totalWidth>verticalFreeWidth) { verticalHiddenSurface+=(totalWidth-verticalFreeWidth)*totalHeight; } if (totalHeight>verticalFreeHeight) { verticalHiddenSurface+=(totalHeight-verticalFreeHeight)*totalWidth; } } verticalRemainingSurface=verticalFreeWidth*verticalFreeHeight-totalWidth*totalHeight; if ((totalWidth<=horizontalFreeWidth)&&(totalHeight<=horizontalFreeHeight)) { horizontalFit=true; } else { if (totalWidth>horizontalFreeWidth) { horizontalHiddenSurface+=(totalWidth-horizontalFreeWidth)*totalHeight; } if (totalHeight>horizontalFreeHeight) { horizontalHiddenSurface+=(totalHeight-horizontalFreeHeight)*totalWidth; } } horizontalRemainingSurface=horizontalFreeWidth*horizontalFreeHeight-totalWidth*totalHeight; bool chooseHorizontal; if (verticalFit && horizontalFit) { if (verticalRemainingSurface>horizontalRemainingSurface) { //choose vertical chooseHorizontal=false; } else { //choose horizontal chooseHorizontal=true; } } else if (horizontalFit) { //choose horizontal chooseHorizontal=true; } else if (verticalFit) { //choose vertical chooseHorizontal=false; } else { if (verticalHiddenSurface<horizontalHiddenSurface) { //choose vertical chooseHorizontal=false; } else { //choose horizontal chooseHorizontal=true; } } if (chooseHorizontal) { //horizontal if (point.y<visibleArea.center.y) { //more space on the top bubble.y=point.y+totalPointerLength+totalHeight*0.5f; } else { //more space on the bottom bubble.y=point.y-totalPointerLength-totalHeight*0.5f; } bubble.x=point.x; if (bubble.x+totalWidth*0.5f>visibleArea.xMax) { bubble.x=visibleArea.xMax-totalWidth*0.5f; } else if (bubble.x-totalWidth*0.5f<visibleArea.xMin) { bubble.x=visibleArea.xMin+totalWidth*0.5f; } } else { //vertical if (point.x<visibleArea.center.x) { //more space on the right bubble.x=point.x+totalPointerLength+totalWidth*0.5f; } else { //more space on the left bubble.x=point.x-totalPointerLength-totalWidth*0.5f; } bubble.y=point.y; if (bubble.y+totalHeight*0.5f>visibleArea.yMax) { bubble.y=visibleArea.yMax-totalHeight*0.5f; } else if (bubble.y-totalHeight*0.5f<visibleArea.yMin) { bubble.y=visibleArea.yMin+totalHeight*0.5f; } } bubble.SetSizeAndPointer(totalWidth,totalHeight,point-bubble.GetPosition(),pointerMargin); //bubble.alpha=0.25f; return bubble; }