@@ -8,7 +8,17 @@ BetterAlertLayer* BetterAlertLayer::create(FLAlertLayerProtocol* delegate, char
88{
99 auto pRet = new BetterAlertLayer ();
1010
11- if (pRet && pRet->init (delegate, title, desc, btn1, btn2, width, scroll, height, textScale))
11+ pRet->delegate = delegate;
12+ pRet->title = title;
13+ pRet->desc = desc;
14+ pRet->btn1 = btn1;
15+ pRet->btn2 = btn2;
16+ pRet->width = width;
17+ pRet->scroll = scroll;
18+ pRet->height = height;
19+ pRet->textScale = textScale;
20+
21+ if (pRet && pRet->initAnchored (0 , 0 ))
1222 {
1323 pRet->autorelease ();
1424 return pRet;
@@ -40,73 +50,54 @@ BetterAlertLayer* BetterAlertLayer::createWithLocalisation(char const* title, co
4050 return create (lm->getLocalisedString (title).c_str (), lm->getLocalisedString (desc), lm->getLocalisedString (btn).c_str ());
4151}
4252
43- bool BetterAlertLayer::init (FLAlertLayerProtocol* delegate, char const * title, gd::string desc, char const * btn1, char const * btn2, float width, bool scroll, float height, float textScale )
53+ bool BetterAlertLayer::setup ( )
4454{
4555 this ->addChild (CCBlurLayer::create (), -69 );
4656
57+ m_bgSprite->setVisible (false );
58+ m_buttonMenu->setVisible (false );
59+
4760 content = AdvLabelBMFont::createWithStruct ({}, " chatFont.fnt" );
48- content->setMaxWidth (width - 30 );
61+ content->setMaxWidth (width - 60 );
4962 content->setSplitEverySpace (true );
5063 content->setLineSpacing (3 .5f );
5164 content->setAlignment (kCCTextAlignmentCenter );
5265 content->setString (desc.c_str ());
5366
54- std::string ss;
55-
56- for (size_t i = 0 ; i < content->getLineCount (); i++)
57- {
58- ss.append (" boobs\n " );
59- }
67+ float desHeight = std::max<float >(140.0 , content->getScaledContentHeight () + 100 );
6068
61- if (!FLAlertLayer::init (delegate, title, ss, btn1, btn2, width, scroll, height, textScale))
62- return false ;
69+ m_mainLayer->setContentSize (ccp (width, desHeight));
6370
64- auto oldTitle = m_mainLayer->getChildByType <CCLabelBMFont>(0 );
65- auto area = m_mainLayer->getChildByType <TextArea>(0 );
66- auto bg = m_mainLayer->getChildByType <CCScale9Sprite>(0 );
67- auto men = m_mainLayer->getChildByType <CCMenu>(0 );
68-
69- oldTitle->setVisible (false );
70- area->setVisible (false );
71- men->setVisible (false );
71+ bg = CCScale9Sprite::create (" square01_001.png" );
72+ bg->setContentSize (ccp (width, desHeight));
7273
7374 titleLabel = AdvLabelBMFont::createWithString (title, " goldFont.fnt" );
74- titleLabel->setPosition (ccp (getContentWidth () / 2 , getContentHeight () / 2 + bg->getScaledContentHeight () / 2 + -15 ));
7575 titleLabel->setAnchorPoint (ccp (0 .5f , 1 ));
76- titleLabel->limitLabelWidth (width - 30 , 0 .9f , 0 );
77-
78- auto bg2 = EasyBG::create ();
79- bg2->setTargettingNode (titleLabel);
80- bg2->setTargettingOffset (ccp (4 , 4 ));
81- bg2->setPosition (titleLabel->getPosition () + ccp (0 , -titleLabel->getScaledContentHeight () / 2 ));
82- bg2->setVisible (titleLabel->isUsingTTFCurrently ());
83-
84- content->setPosition (ccp (getContentWidth () / 2 , getContentHeight () / 2 + 5 ));
76+ titleLabel->limitLabelWidth (width - 60 , 0 .9f , 0 );
8577
8678 auto menu = CCMenu::create ();
87- menu->setTouchPriority (-512 );
88- menu->setPosition (ccp (getContentWidth () / 2 , getContentHeight () / 2 - bg->getScaledContentHeight () / 2 + 30 ));
79+ menu->setZOrder (8 );
8980
9081 auto spr = BetterButtonSprite::create (ccp (54 .25f , 30 ), btn1, " goldFont.fnt" , " GJ_button_01.png" );
9182 auto btn = CCMenuItemSpriteExtra::create (spr, this , menu_selector (BetterAlertLayer::onButton));
9283 btn->setTag (1 );
9384 menu->addChild (btn);
9485
95- m_mainLayer->addChild (content, 6 );
96- m_mainLayer->addChild (titleLabel, 7 );
97- m_mainLayer->addChild (bg2, 5 );
98- m_mainLayer->addChild (menu, 8 );
86+ m_mainLayer->addChildAtPosition (bg, Anchor::Center );
87+ m_mainLayer->addChildAtPosition (content, Anchor::Center, ccp ( 0 , 5 ) );
88+ m_mainLayer->addChildAtPosition (titleLabel, Anchor::Top, ccp ( 0 , - 15 ) );
89+ m_mainLayer->addChildAtPosition (menu, Anchor::Bottom, ccp ( 0 , 30 ) );
9990 return true ;
10091}
10192
10293void BetterAlertLayer::onButton (CCObject* sender)
10394{
10495 if (sender->getTag () == 1 )
10596 {
106- this ->onBtn1 (m_button1-> getParent () );
97+ this ->onBtn1 (sender );
10798 }
10899 else
109100 {
110- this ->onBtn2 (m_button2-> getParent () );
101+ this ->onBtn2 (sender );
111102 }
112103}
0 commit comments