Skip to content

Commit fc4fe13

Browse files
committed
Merge commit 'c36c9824d9d53c63e7c76620ed54d1279fbfdd79' into scgamex-v3
* commit 'c36c9824d9d53c63e7c76620ed54d1279fbfdd79': Revert "fix keyback bug after opened a page (cocos2d#18153)" (cocos2d#18601) fix keyback bug after opened a page (cocos2d#18153) Fix actions with zero duration on NDK 16. (cocos2d#18596) fixed proguard-rules.pro for Android tests (cocos2d#18594) Added support for BMFont in TextField (cocos2d#18587) Fix gradlew build (cocos2d#18592) spine res name update, because files name changed before (cocos2d#18586)
2 parents 4afbd8d + c36c982 commit fc4fe13

File tree

20 files changed

+176
-57
lines changed

20 files changed

+176
-57
lines changed

cocos/2d/CCActionInterval.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ void ActionInterval::step(float dt)
126126
}
127127

128128

129-
float updateDt = MAX (0, // needed for rewind. elapsed could be negative
130-
MIN(1, _elapsed / _duration)
131-
);
129+
float updateDt = std::max(0.0f, // needed for rewind. elapsed could be negative
130+
std::min(1.0f, _elapsed / _duration)
131+
);
132132

133133
if (sendUpdateEventToScript(updateDt, this)) return;
134134

cocos/2d/CCLabel.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1781,13 +1781,15 @@ Sprite* Label::getLetter(int letterIndex)
17811781
}
17821782
else
17831783
{
1784+
this->updateBMFontScale();
17841785
letter = LabelLetter::createWithTexture(_fontAtlas->getTexture(textureID), uvRect);
17851786
letter->setTextureAtlas(_batchNodes.at(textureID)->getTextureAtlas());
17861787
letter->setAtlasIndex(letterInfo.atlasIndex);
1787-
auto px = letterInfo.positionX + uvRect.size.width / 2 + _linesOffsetX[letterInfo.lineIndex];
1788-
auto py = letterInfo.positionY - uvRect.size.height / 2 + _letterOffsetY;
1788+
auto px = letterInfo.positionX + _bmfontScale * uvRect.size.width / 2 + _linesOffsetX[letterInfo.lineIndex];
1789+
auto py = letterInfo.positionY - _bmfontScale * uvRect.size.height / 2 + _letterOffsetY;
17891790
letter->setPosition(px,py);
17901791
letter->setOpacity(_realOpacity);
1792+
this->updateLetterSpriteScale(letter);
17911793
}
17921794

17931795
addChild(letter);

cocos/2d/CCTextFieldTTF.cpp

Lines changed: 42 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,8 @@ bool TextFieldTTF::initWithPlaceHolder(const std::string& placeholder, const std
170170
setSystemFontSize(fontSize);
171171

172172
} while (false);
173-
174-
175-
Label::setTextColor(_colorSpaceHolder);
173+
174+
setTextColorInternally(_colorSpaceHolder);
176175
Label::setString(_placeHolder);
177176

178177
#if (CC_TARGET_PLATFORM == CC_PLATFORM_MAC || CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_LINUX)
@@ -270,7 +269,7 @@ void TextFieldTTF::insertText(const char * text, size_t len)
270269
stringUTF8.replace(_inputText);
271270
stringUTF8.insert(_cursorPosition, insert);
272271

273-
setCursorPosition(_cursorPosition + countInsertChar);
272+
setCursorPosition(_cursorPosition + countInsertChar);
274273

275274
setString(stringUTF8.getAsCharSequence());
276275
}
@@ -452,12 +451,22 @@ void TextFieldTTF::setAttachWithIME(bool isAttachWithIME)
452451
}
453452
}
454453

454+
void TextFieldTTF::setTextColorInternally(const Color4B& color)
455+
{
456+
if (_currentLabelType == LabelType::BMFONT) {
457+
Label::setColor(Color3B(color));
458+
return;
459+
}
460+
461+
Label::setTextColor(color);
462+
}
463+
455464
void TextFieldTTF::setTextColor(const Color4B &color)
456465
{
457466
_colorText = color;
458-
if (!_inputText.empty())
467+
if (!_inputText.empty())
459468
{
460-
Label::setTextColor(_colorText);
469+
setTextColorInternally(color);
461470
}
462471
}
463472

@@ -484,6 +493,9 @@ void TextFieldTTF::update(float delta)
484493

485494
if (sprite)
486495
{
496+
if (_currentLabelType == LabelType::BMFONT) {
497+
sprite->setColor(getColor());
498+
}
487499
if (_cursorShowingTime >= 0.0f)
488500
{
489501
sprite->setOpacity(255);
@@ -504,22 +516,15 @@ const Color4B& TextFieldTTF::getColorSpaceHolder()
504516

505517
void TextFieldTTF::setColorSpaceHolder(const Color3B& color)
506518
{
507-
_colorSpaceHolder.r = color.r;
508-
_colorSpaceHolder.g = color.g;
509-
_colorSpaceHolder.b = color.b;
510-
_colorSpaceHolder.a = 255;
511-
if (_inputText.empty())
512-
{
513-
Label::setTextColor(_colorSpaceHolder);
514-
}
519+
setColorSpaceHolder(Color4B(color));
515520
}
516521

517522
void TextFieldTTF::setColorSpaceHolder(const Color4B& color)
518523
{
519524
_colorSpaceHolder = color;
520525
if (_inputText.empty())
521526
{
522-
Label::setTextColor(_colorSpaceHolder);
527+
setTextColorInternally(_colorSpaceHolder);
523528
}
524529
}
525530

@@ -569,14 +574,13 @@ void TextFieldTTF::setString(const std::string &text)
569574
// if there is no input text, display placeholder instead
570575
if (_inputText.empty() && (!_cursorEnabled || !_isAttachWithIME))
571576
{
572-
Label::setTextColor(_colorSpaceHolder);
577+
setTextColorInternally(_colorSpaceHolder);
573578
Label::setString(_placeHolder);
574579
}
575580
else
576581
{
577582
makeStringSupportCursor(displayText);
578-
579-
Label::setTextColor(_colorText);
583+
setTextColorInternally(_colorText);
580584
Label::setString(displayText);
581585
}
582586
_charCount = charCount;
@@ -596,7 +600,7 @@ void TextFieldTTF::makeStringSupportCursor(std::string& displayText)
596600
if (displayText.empty())
597601
{
598602
// \b - Next char not change x position
599-
if (_currentLabelType == LabelType::TTF)
603+
if (_currentLabelType == LabelType::TTF || _currentLabelType == LabelType::BMFONT)
600604
displayText.push_back((char) TextFormatter::NextCharNoChangeX);
601605
displayText.push_back(_cursorChar);
602606
}
@@ -612,7 +616,7 @@ void TextFieldTTF::makeStringSupportCursor(std::string& displayText)
612616
}
613617
std::string cursorChar;
614618
// \b - Next char not change x position
615-
if (_currentLabelType == LabelType::TTF)
619+
if (_currentLabelType == LabelType::TTF || _currentLabelType == LabelType::BMFONT)
616620
cursorChar.push_back((char)TextFormatter::NextCharNoChangeX);
617621
cursorChar.push_back(_cursorChar);
618622
stringUTF8.insert(_cursorPosition, cursorChar);
@@ -699,7 +703,7 @@ void TextFieldTTF::setPlaceHolder(const std::string& text)
699703
_placeHolder = text;
700704
if (_inputText.empty() && !_isAttachWithIME)
701705
{
702-
Label::setTextColor(_colorSpaceHolder);
706+
setTextColorInternally(_colorSpaceHolder);
703707
Label::setString(_placeHolder);
704708
}
705709
}
@@ -711,21 +715,24 @@ const std::string& TextFieldTTF::getPlaceHolder() const
711715

712716
void TextFieldTTF::setCursorEnabled(bool enabled)
713717
{
714-
if (_cursorEnabled != enabled)
718+
if (_cursorEnabled == enabled)
715719
{
716-
_cursorEnabled = enabled;
717-
if (_cursorEnabled)
718-
{
719-
_cursorPosition = _charCount;
720-
if (_currentLabelType == LabelType::TTF)
721-
scheduleUpdate();
722-
}
723-
else
724-
{
725-
_cursorPosition = 0;
726-
if (_currentLabelType == LabelType::TTF)
727-
unscheduleUpdate();
720+
return;
721+
}
722+
723+
_cursorEnabled = enabled;
724+
if (_cursorEnabled)
725+
{
726+
_cursorPosition = _charCount;
727+
if (_currentLabelType == LabelType::TTF || _currentLabelType == LabelType::BMFONT) {
728+
scheduleUpdate();
728729
}
730+
return;
731+
}
732+
733+
_cursorPosition = 0;
734+
if (_currentLabelType == LabelType::TTF || _currentLabelType == LabelType::BMFONT) {
735+
unscheduleUpdate();
729736
}
730737
}
731738

@@ -763,3 +770,4 @@ bool TextFieldTTF::isSecureTextEntry() const
763770
}
764771

765772
NS_CC_END
773+

cocos/2d/CCTextFieldTTF.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,7 @@ class CC_DLL TextFieldTTF : public Label, public IMEDelegate
279279
void makeStringSupportCursor(std::string& displayText);
280280
void updateCursorDisplayText();
281281
void setAttachWithIME(bool isAttachWithIME);
282+
void setTextColorInternally(const Color4B& color);
282283

283284
private:
284285
class LengthStack;

cocos/platform/android/libcocos2dx-with-controller/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.cocos2dx.lib">
22

3+
<uses-permission android:name="android.permission.VIBRATE" />
4+
35
<application android:allowBackup="true">
46

57
</application>

cocos/platform/android/libcocos2dx/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.cocos2dx.lib">
22

3+
<uses-permission android:name="android.permission.VIBRATE" />
4+
35
<application android:allowBackup="true">
46

57
</application>

cocos/ui/UITextField.cpp

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,9 @@ void TextField::setFontSize(int size)
446446
{
447447
_textFieldRenderer->setSystemFontSize(size);
448448
}
449+
else if (_fontType == FontType::BMFONT) {
450+
_textFieldRenderer->setBMFontSize(size);
451+
}
449452
else
450453
{
451454
TTFConfig config = _textFieldRenderer->getTTFConfig();
@@ -466,11 +469,19 @@ void TextField::setFontName(const std::string& name)
466469
{
467470
if(FileUtils::getInstance()->isFileExist(name))
468471
{
469-
TTFConfig config = _textFieldRenderer->getTTFConfig();
470-
config.fontFilePath = name;
471-
config.fontSize = _fontSize;
472-
_textFieldRenderer->setTTFConfig(config);
473-
_fontType = FontType::TTF;
472+
std::string lcName = name;
473+
std::transform(lcName.begin(), lcName.end(), lcName.begin(), ::tolower);
474+
if(lcName.substr(lcName.length() - 4) == ".fnt") {
475+
_textFieldRenderer->setBMFontFilePath(name);
476+
_fontType = FontType::BMFONT;
477+
}
478+
else {
479+
TTFConfig config = _textFieldRenderer->getTTFConfig();
480+
config.fontFilePath = name;
481+
config.fontSize = _fontSize;
482+
_textFieldRenderer->setTTFConfig(config);
483+
_fontType = FontType::TTF;
484+
}
474485
}
475486
else
476487
{

cocos/ui/UITextField.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,8 @@ class CC_GUI_DLL TextField : public Widget
694694
enum class FontType
695695
{
696696
SYSTEM,
697-
TTF
697+
TTF,
698+
BMFONT
698699
};
699700

700701
std::string _fontName;

templates/cpp-template-default/proj.android/app/AndroidManifest.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
package="org.cocos2dx.hellocpp"
44
android:installLocation="auto">
55

6+
<uses-permission android:name="android.permission.INTERNET"/>
7+
68
<uses-feature android:glEsVersion="0x00020000" />
79

810
<application
@@ -28,6 +30,4 @@
2830
</activity>
2931
</application>
3032

31-
<uses-permission android:name="android.permission.INTERNET"/>
32-
3333
</manifest>

templates/cpp-template-default/proj.android/app/proguard-rules.pro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
-dontwarn org.cocos2dx.**
2222
-keep public class com.chukong.** { *; }
2323
-dontwarn com.chukong.**
24-
-keep public com.huawei.android.** { *; }
24+
-keep public class com.huawei.android.** { *; }
2525
-dontwarn com.huawei.android.**
2626

2727
# Proguard Apache HTTP for release

0 commit comments

Comments
 (0)