Skip to content

Commit

Permalink
Add option to force using default font
Browse files Browse the repository at this point in the history
fix some bugs:
- crash by fetching space character bitmap
- etcpak edge error
- gsotSimple may cause something wrong in trans effect

some ui improving for skin support
  • Loading branch information
ZeaS committed Apr 5, 2017
1 parent 2081dc0 commit 6152dbf
Show file tree
Hide file tree
Showing 14 changed files with 96 additions and 73 deletions.
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ Video playback module modified from [kodi](https://github.com/xbmc/xbmc)
Some string code from [glibc](https://www.gnu.org/s/libc) and [Apple Libc](https://opensource.apple.com/source/Libc).

Real-time texture codec modified from [etcpak](https://bitbucket.org/wolfpld/etcpak.git), [pvrtccompressor](https://bitbucket.org/jthlim/pvrtccompressor), [astcrt](https://github.com/daoo/astcrt)

Android storage accessing code from [AmazeFileManager](https://github.com/arpitkh96/AmazeFileManager)
12 changes: 8 additions & 4 deletions src/core/environ/ui/FileSelectorForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ void TVPBaseFileSelectorForm::onCellLongPress(int idx)
LocaleConfigManager::GetInstance()->initText(reader.findController<Text>("titleCopy"));
LocaleConfigManager::GetInstance()->initText(reader.findController<Text>("titleCut"));
LocaleConfigManager::GetInstance()->initText(reader.findController<Text>("titlePaste"));
LocaleConfigManager::GetInstance()->initText(reader.findController<Text>("titleUnpack", false));
LocaleConfigManager::GetInstance()->initText(reader.findController<Text>("titleUnpack"));
LocaleConfigManager::GetInstance()->initText(reader.findController<Text>("titleRepack", false));
LocaleConfigManager::GetInstance()->initText(reader.findController<Text>("titleDelete"));
LocaleConfigManager::GetInstance()->initText(reader.findController<Text>("titleSendTo"));
Expand Down Expand Up @@ -385,7 +385,7 @@ TVPBaseFileSelectorForm::FileItemCellImpl* TVPBaseFileSelectorForm::FetchCell(Fi
CellModel->retain();
}
bool selected = _selectedFileIndex.find(idx) != _selectedFileIndex.end();
CellModel->setInfo(CurrentDirList[idx], selected, !_selectedFileIndex.empty());
CellModel->setInfo(idx, CurrentDirList[idx], selected, !_selectedFileIndex.empty());
return CellModel;
}

Expand Down Expand Up @@ -420,7 +420,7 @@ Size TVPBaseFileSelectorForm::tableCellSizeForIndex(TableView *table, ssize_t id
if (!CellTemplateForSize) {
CellTemplateForSize = FetchCell(nullptr, table, idx);
} else {
CellTemplateForSize->setInfo(CurrentDirList[idx], false, false);
CellTemplateForSize->setInfo(idx, CurrentDirList[idx], false, false);
}
info.CellSize = CellTemplateForSize->getContentSize();
}
Expand Down Expand Up @@ -783,9 +783,11 @@ void TVPBaseFileSelectorForm::FileItemCellImpl::initFromFile(const char * filena
}
});
}
BgOdd = reader.findController("bg_odd", false);
BgEven = reader.findController("bg_even", false);
}

void TVPBaseFileSelectorForm::FileItemCellImpl::setInfo(const FileInfo &info, bool selected, bool showSelect) {
void TVPBaseFileSelectorForm::FileItemCellImpl::setInfo(int idx, const FileInfo &info, bool selected, bool showSelect) {
if (FileNameNode) {
FileNameNode->ignoreContentAdaptWithSize(true);
FileNameNode->setTextAreaSize(CellTextAreaSize);
Expand All @@ -801,6 +803,8 @@ void TVPBaseFileSelectorForm::FileItemCellImpl::setInfo(const FileInfo &info, bo
if (showSelect) SelectBox->setSelected(selected);
ui::Helper::doLayout(_root);
_set = true;
if (BgOdd) BgOdd->setVisible((idx + 1) & 1);
if (BgEven) BgEven->setVisible(idx & 1);
}

void TVPBaseFileSelectorForm::FileItemCellImpl::onClicked(cocos2d::Ref* p) {
Expand Down
4 changes: 2 additions & 2 deletions src/core/environ/ui/FileSelectorForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class TVPBaseFileSelectorForm : public iTVPBaseForm, public cocos2d::extension::

void initFromFile(const char * filename, float width);

void setInfo(const FileInfo &info, bool selected, bool showSelect);
void setInfo(int idx, const FileInfo &info, bool selected, bool showSelect);

void reset() {
_set = false;
Expand All @@ -127,7 +127,7 @@ class TVPBaseFileSelectorForm : public iTVPBaseForm, public cocos2d::extension::
bool _set;
cocos2d::Size OrigCellModelSize, CellTextAreaSize, OrigCellTextSize;
cocos2d::ui::Text *FileNameNode;
cocos2d::Node *DirIcon, *_root;
cocos2d::Node *DirIcon, *_root, *BgOdd, *BgEven;
cocos2d::ui::CheckBox *SelectBox;
FileItemCell *_owner;
};
Expand Down
17 changes: 11 additions & 6 deletions src/core/environ/ui/InGameMenuForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ui/UIText.h"
#include "MenuItemImpl.h"
#include "ui/UIHelper.h"
#include "tjsGlobalStringMap.h"

using namespace cocos2d;
using namespace cocos2d::ui;
Expand Down Expand Up @@ -47,19 +48,23 @@ void TVPInGameMenuForm::initMenu(const std::string& title, tTJSNI_MenuItem *item
}

int count = item->GetChildren().size();
int idx = 0;
ttstr seperator = TJS::TJSMapGlobalStringMap(TJS_W("-"));
for (int i = 0; i < count; ++i) {
tTJSNI_MenuItem *subitem = static_cast<tTJSNI_MenuItem*>(item->GetChildren().at(i));
ttstr caption; subitem->GetCaption(caption);
if (caption.IsEmpty() || caption == TJS_W("+")) continue;
_list->pushBackCustomItem(createMenuItem(subitem, caption.AsStdString()));
_list->pushBackCustomItem(createMenuItem(idx, subitem, caption.AsStdString()));
if(caption != seperator)
++idx;
}
}

cocos2d::ui::Widget * TVPInGameMenuForm::createMenuItem(tTJSNI_MenuItem *item, const std::string &caption) {
cocos2d::ui::Widget * TVPInGameMenuForm::createMenuItem(int idx, tTJSNI_MenuItem *item, const std::string &caption) {
iPreferenceItem *ret = nullptr;
const Size &size = _list->getContentSize();
if (!item->GetChildren().empty()) {
ret = CreatePreferenceItem<tPreferenceItemSubDir>(size, caption);
ret = CreatePreferenceItem<tPreferenceItemSubDir>(idx, size, caption);
ret->addClickEventListener([=](Ref*){
TVPMainScene::GetInstance()->pushUIForm(create(caption, item));
});
Expand All @@ -69,15 +74,15 @@ cocos2d::ui::Widget * TVPInGameMenuForm::createMenuItem(tTJSNI_MenuItem *item, c
item->OnClick();
TVPMainScene::GetInstance()->popAllUIForm();
};
ret = CreatePreferenceItem<tPreferenceItemCheckBox>(size, caption,
ret = CreatePreferenceItem<tPreferenceItemCheckBox>(idx, size, caption,
[=](tPreferenceItemCheckBox* item) {
item->_getter = getter;
item->_setter = setter;
});
} else if (item->GetChecked()) {
auto getter = [=]()->bool{ return item->GetChecked(); };
auto setter = [=](bool b){ item->OnClick(); };
ret = CreatePreferenceItem<tPreferenceItemCheckBox>(size, caption,
ret = CreatePreferenceItem<tPreferenceItemCheckBox>(idx, size, caption,
[=](tPreferenceItemCheckBox* item) {
item->_getter = getter;
item->_setter = setter;
Expand All @@ -91,7 +96,7 @@ cocos2d::ui::Widget * TVPInGameMenuForm::createMenuItem(tTJSNI_MenuItem *item, c
ui::Helper::doLayout(root);
return root;
} else {
ret = CreatePreferenceItem<tPreferenceItemConstant>(size, caption);
ret = CreatePreferenceItem<tPreferenceItemConstant>(idx, size, caption);
ret->addClickEventListener([=](Ref*){
TVPMainScene::GetInstance()->scheduleOnce(
std::bind(&TVPMainScene::popAllUIForm, TVPMainScene::GetInstance()), 0, "close_menu");
Expand Down
2 changes: 1 addition & 1 deletion src/core/environ/ui/InGameMenuForm.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class TVPInGameMenuForm : public iTVPBaseForm {
void initMenu(const std::string& title, tTJSNI_MenuItem *item);

private:
cocos2d::ui::Widget *createMenuItem(tTJSNI_MenuItem *item, const std::string &caption);
cocos2d::ui::Widget *createMenuItem(int idx, tTJSNI_MenuItem *item, const std::string &caption);

cocos2d::ui::ListView *_list;
cocos2d::ui::Button *_title;
Expand Down
69 changes: 31 additions & 38 deletions src/core/environ/ui/PreferenceConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,22 @@ static Size PrefListSize;
class tTVPPreferenceInfoConstant : public iTVPPreferenceInfo {
public:
tTVPPreferenceInfoConstant(const std::string &cap) : iTVPPreferenceInfo(cap, "") {}
virtual iPreferenceItem *createItem() override {
virtual iPreferenceItem *createItem(int idx) override {
LocaleConfigManager *locmgr = LocaleConfigManager::GetInstance();
return CreatePreferenceItem<tPreferenceItemConstant>(PrefListSize, locmgr->GetText(Caption));
return CreatePreferenceItem<tPreferenceItemConstant>(idx, PrefListSize, locmgr->GetText(Caption));
}
};

class tTVPPreferenceInfoCheckBox : public tTVPPreferenceInfo<bool> {
public:
tTVPPreferenceInfoCheckBox(const std::string &cap, const std::string &key, bool defval)
: tTVPPreferenceInfo<bool>(cap, key, defval) {}
virtual iPreferenceItem *createItem() override {
GlobalConfigManager *mgr = GlobalConfigManager::GetInstance();
virtual iPreferenceItem *createItem(int idx) override {
LocaleConfigManager *locmgr = LocaleConfigManager::GetInstance();
return CreatePreferenceItem<tPreferenceItemCheckBox>(PrefListSize, locmgr->GetText(Caption),
[mgr, this](tPreferenceItemCheckBox* item) {
item->_getter = std::bind(&GlobalConfigManager::GetValue<bool>, mgr, Key, DefaultValue);
item->_setter = [this](bool v){
GlobalConfigManager::GetInstance()->SetValueInt(Key, v);
};
return CreatePreferenceItem<tPreferenceItemCheckBox>(idx, PrefListSize, locmgr->GetText(Caption),
[this](tPreferenceItemCheckBox* item) {
item->_getter = std::bind(&PreferenceGetValueBool, Key, DefaultValue);
item->_setter = std::bind(&PreferenceSetValueBool, Key, std::placeholders::_1);
});
}
};
Expand All @@ -37,20 +34,20 @@ class tTVPPreferenceInfoSelectList : public tTVPPreferenceInfo<std::string>, tPr
tTVPPreferenceInfoSelectList(const std::string &cap, const std::string &key, const std::string &defval,
const std::initializer_list<std::pair<std::string, std::string> > &listinfo)
: tTVPPreferenceInfo<std::string>(cap, key, defval), ListInfo(listinfo){}
virtual iPreferenceItem *createItem() override {
virtual iPreferenceItem *createItem(int idx) override {
LocaleConfigManager *locmgr = LocaleConfigManager::GetInstance();
return CreatePreferenceItem<tPreferenceItemSelectList>(PrefListSize, locmgr->GetText(Caption),
return CreatePreferenceItem<tPreferenceItemSelectList>(idx, PrefListSize, locmgr->GetText(Caption),
[this](tPreferenceItemSelectList* item) {
item->initInfo(this);
item->_getter = std::bind(&GlobalConfigManager::GetValue<std::string>, GlobalConfigManager::GetInstance(), Key, DefaultValue);
item->_getter = std::bind(&PreferenceGetValueString, Key, DefaultValue);
item->_setter = [this](std::string v){ onSetValue(v); };
});
}
virtual const std::vector<std::pair<std::string, std::string> >& getListInfo() override {
return ListInfo;
}
virtual void onSetValue(const std::string &v) {
GlobalConfigManager::GetInstance()->SetValue(Key, v);
PreferenceSetValueString(Key, v);
}
std::vector<std::pair<std::string, std::string> > ListInfo;
};
Expand Down Expand Up @@ -99,14 +96,12 @@ class tTVPPreferenceInfoSelectFile : public tTVPPreferenceInfo<std::string> {
tTVPPreferenceInfoSelectFile(const std::string &cap, const std::string &key, const std::string &defval)
: tTVPPreferenceInfo<std::string>(cap, key, defval) {}

virtual iPreferenceItem *createItem() override {
virtual iPreferenceItem *createItem(int idx) override {
LocaleConfigManager *locmgr = LocaleConfigManager::GetInstance();
return CreatePreferenceItem<tPreferenceItemFileSelect>(PrefListSize, locmgr->GetText(Caption),
return CreatePreferenceItem<tPreferenceItemFileSelect>(idx, PrefListSize, locmgr->GetText(Caption),
[this](tPreferenceItemFileSelect* item) {
item->_getter = std::bind(&GlobalConfigManager::GetValue<std::string>, GlobalConfigManager::GetInstance(), Key, DefaultValue);
item->_setter = [this](std::string v) {
GlobalConfigManager::GetInstance()->SetValue(Key, v);
};
item->_getter = std::bind(&PreferenceGetValueString, Key, DefaultValue);
item->_setter = std::bind(&PreferenceSetValueString, Key, std::placeholders::_1);
});
}
};
Expand All @@ -115,16 +110,16 @@ class tTVPPreferenceInfoRendererSubPref : public iTVPPreferenceInfo {
public:
tTVPPreferenceInfoRendererSubPref(const std::string &cap) { Caption = cap; } // Key is useless
static tPreferenceScreen* GetSubPreferenceInfo() {
std::string renderer = GlobalConfigManager::GetInstance()->GetValue<std::string>("renderer", "software");
std::string renderer = PreferenceGetValueString("renderer", "software");
if (renderer == "opengl")
return &OpenglOptPreference;
else if (renderer == "software")
return &SoftRendererOptPreference;
return nullptr;
}
virtual iPreferenceItem *createItem() override {
virtual iPreferenceItem *createItem(int idx) override {
LocaleConfigManager *locmgr = LocaleConfigManager::GetInstance();
iPreferenceItem *ret = CreatePreferenceItem<tPreferenceItemSubDir>(PrefListSize, locmgr->GetText(Caption));
iPreferenceItem *ret = CreatePreferenceItem<tPreferenceItemSubDir>(idx, PrefListSize, locmgr->GetText(Caption));
ret->addClickEventListener([](Ref*) {
TVPMainScene::GetInstance()->pushUIForm(TVPGlobalPreferenceForm::create(GetSubPreferenceInfo()));
});
Expand All @@ -141,9 +136,9 @@ class tTVPPreferenceInfoSubPref : public iTVPPreferenceInfo {
{
Caption = title;
}
virtual iPreferenceItem *createItem() override {
virtual iPreferenceItem *createItem(int idx) override {
LocaleConfigManager *locmgr = LocaleConfigManager::GetInstance();
iPreferenceItem *ret = CreatePreferenceItem<tPreferenceItemSubDir>(PrefListSize, locmgr->GetText(Caption));
iPreferenceItem *ret = CreatePreferenceItem<tPreferenceItemSubDir>(idx, PrefListSize, locmgr->GetText(Caption));
ret->addClickEventListener([this](Ref*){
TVPMainScene::GetInstance()->pushUIForm(TVPGlobalPreferenceForm::create(&Preference));
});
Expand All @@ -156,15 +151,14 @@ class tTVPPreferenceInfoSliderIcon : public tTVPPreferenceInfo<float> {
public:
tTVPPreferenceInfoSliderIcon(const std::string &cap, const std::string &key, float defval)
: tTVPPreferenceInfo<float>(cap, key, defval) {}
virtual iPreferenceItem *createItem() override {
virtual iPreferenceItem *createItem(int idx) override {
LocaleConfigManager *locmgr = LocaleConfigManager::GetInstance();
GlobalConfigManager *mgr = GlobalConfigManager::GetInstance();

tPreferenceItemCursorSlider * ret = new tPreferenceItemCursorSlider(DefaultValue, TVPMainScene::convertCursorScale);
ret->autorelease();
ret->_getter = std::bind(&GlobalConfigManager::GetValue<float>, mgr, Key, DefaultValue);
ret->_setter = std::bind(&GlobalConfigManager::SetValueFloat, mgr, Key, std::placeholders::_1);
ret->initFromInfo(PrefListSize, locmgr->GetText(Caption));
ret->_getter = std::bind(&PreferenceGetValueFloat, Key, DefaultValue);
ret->_setter = std::bind(&PreferenceSetValueFloat, Key, std::placeholders::_1);
ret->initFromInfo(idx, PrefListSize, locmgr->GetText(Caption));
return ret;
}
};
Expand All @@ -180,25 +174,23 @@ class tTVPPreferenceInfoSliderText : public tTVPPreferenceInfo<float> {
return buf;
}

virtual iPreferenceItem *createItem() override {
virtual iPreferenceItem *createItem(int idx) override {
LocaleConfigManager *locmgr = LocaleConfigManager::GetInstance();
GlobalConfigManager *mgr = GlobalConfigManager::GetInstance();

tPreferenceItemTextSlider * ret = new tPreferenceItemTextSlider(DefaultValue, convertPercentScale);
ret->autorelease();
ret->_getter = std::bind(&GlobalConfigManager::GetValue<float>, mgr, Key, DefaultValue);
ret->_setter = std::bind(&GlobalConfigManager::SetValueFloat, mgr, Key, std::placeholders::_1);
ret->initFromInfo(PrefListSize, locmgr->GetText(Caption));
ret->_getter = std::bind(&PreferenceGetValueFloat, Key, DefaultValue);
ret->_setter = std::bind(&PreferenceSetValueFloat, Key, std::placeholders::_1);
ret->initFromInfo(idx, PrefListSize, locmgr->GetText(Caption));
return ret;
}
};

class tTVPPreferenceInfoFetchSDCardPermission : public iTVPPreferenceInfo {
public:
tTVPPreferenceInfoFetchSDCardPermission(const std::string &cap) : iTVPPreferenceInfo(cap, "") {}
virtual iPreferenceItem *createItem() override {
virtual iPreferenceItem *createItem(int idx) override {
LocaleConfigManager *locmgr = LocaleConfigManager::GetInstance();
tPreferenceItemConstant* ret = CreatePreferenceItem<tPreferenceItemConstant>(PrefListSize, locmgr->GetText(Caption));
tPreferenceItemConstant* ret = CreatePreferenceItem<tPreferenceItemConstant>(idx, PrefListSize, locmgr->GetText(Caption));
ret->setTouchEnabled(true);
ret->addClickEventListener([](Ref*) {
TVPFetchSDCardPermission();
Expand All @@ -219,6 +211,7 @@ static void initAllConfig() {
}),
new tTVPPreferenceInfoRendererSubPref("preference_renderer_opt"),
new tTVPPreferenceInfoSelectFile("preference_default_font", "default_font", ""),
new tTVPPreferenceInfoCheckBox("preference_force_def_font", "force_default_font", false),
#ifdef CC_TARGET_OS_IPHONE
new tTVPPreferenceInfoSelectList("preference_mem_limit", "memusage", "high", {
#else
Expand Down
15 changes: 10 additions & 5 deletions src/core/environ/ui/PreferenceForm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ void TVPPreferenceForm::initPref(const tPreferenceScreen *config) {
Config = config;
PrefList->removeAllItems();
LocaleConfigManager::GetInstance()->initText(_title, config->Title);
for (auto info : config->Preferences) {
for (int idx = 0; idx < config->Preferences.size(); ++idx) {
auto info = config->Preferences[idx];
if (info) {
PrefList->pushBackCustomItem(info->createItem());
PrefList->pushBackCustomItem(info->createItem(idx));
}
}
Widget *nullcell = new Widget();
Expand Down Expand Up @@ -51,7 +52,7 @@ void tPreferenceScreen::clear() {
Preferences.clear();
}

void iPreferenceItem::initFromInfo(Size size, const std::string& title) {
void iPreferenceItem::initFromInfo(int idx, Size size, const std::string& title) {
init();
CSBReader reader;
Node * root = reader.Load(getUIFileName());
Expand All @@ -62,6 +63,10 @@ void iPreferenceItem::initFromInfo(Size size, const std::string& title) {
addChild(root);
_title = static_cast<Text*>(reader.findController("title"));
if (!title.empty()) _title->setString(title);
BgOdd = reader.findController("bg_odd", false);
BgEven = reader.findController("bg_even", false);
if (BgOdd) BgOdd->setVisible((idx + 1) & 1);
if (BgEven) BgEven->setVisible(idx & 1);
initController(reader);
}

Expand Down Expand Up @@ -257,7 +262,7 @@ TVPCustomPreferenceForm * TVPCustomPreferenceForm::create(const std::string &tid
const std::function<std::pair<std::string, std::string>(int)> &getter,
const std::function<void(int, const std::pair<std::string, std::string>&)> &setter) {
TVPCustomPreferenceForm *ret = new TVPCustomPreferenceForm;
ret->initFromFile("ui/NaviBar.csb", "ui/ListView.csb", "ui/BottomBar.csb");
ret->initFromFile("ui/NaviBar.csb", "ui/ListView.csb", nullptr);
ret->initFromInfo(tid_title, count, getter, setter);
ret->autorelease();
return ret;
Expand Down Expand Up @@ -296,7 +301,7 @@ void TVPCustomPreferenceForm::initFromInfo(const std::string &tid_title, int cou
_setter(i, val);
};
item->autorelease();
item->initFromInfo(size, nullptr);
item->initFromInfo(i, size, nullptr);
_listview->pushBackCustomItem(item);
}
Widget *nullcell = new Widget();
Expand Down
Loading

0 comments on commit 6152dbf

Please sign in to comment.