Commit 85b9ba78 authored by feihuaduo's avatar feihuaduo
parents 02637e1a 5ac6b6ce
......@@ -288,8 +288,8 @@ bool ClientCard::deck_sort_def(code_pointer p1, code_pointer p2) {
return p1->first < p2->first;
}
bool ClientCard::deck_sort_name(code_pointer p1, code_pointer p2) {
const wchar_t* name1 = dataManager.GetName(p1->first);
const wchar_t* name2 = dataManager.GetName(p2->first);
const wchar_t* name1 = mainGame->dataManager->GetName(p1->first);
const wchar_t* name2 = mainGame->dataManager->GetName(p2->first);
int res = wcscmp(name1, name2);
if(res != 0)
return res < 0;
......
......@@ -447,7 +447,7 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) {
else if(conti_selecting)
mainGame->imageLoading.insert(std::make_pair(mainGame->btnCardSelect[i], selectable_cards[i]->chain_code));
else
mainGame->btnCardSelect[i]->setImage(imageManager.tCover[selectable_cards[i]->controler]);
mainGame->btnCardSelect[i]->setImage(mainGame->imageManager->tCover[selectable_cards[i]->controler]);
mainGame->btnCardSelect[i]->setRelativePosition(rect<s32>((startpos + i * 125) * mainGame->xScale, 65 * mainGame->yScale, (startpos + 120 + i * 125) * mainGame->xScale, 235 * mainGame->yScale));
mainGame->btnCardSelect[i]->setPressed(false);
mainGame->btnCardSelect[i]->setVisible(true);
......@@ -457,13 +457,13 @@ void ClientField::ShowSelectCard(bool buttonok, bool chain) {
if(conti_selecting)
myswprintf(formatBuffer, L"%ls", DataManager::unknown_string);
else if(cant_check_grave && selectable_cards[i]->location == LOCATION_GRAVE)
myswprintf(formatBuffer, L"%ls", dataManager.FormatLocation(selectable_cards[i]->location, 0));
myswprintf(formatBuffer, L"%ls", mainGame->dataManager->FormatLocation(selectable_cards[i]->location, 0));
else if(selectable_cards[i]->location == LOCATION_OVERLAY)
myswprintf(formatBuffer, L"%ls[%d](%d)",
dataManager.FormatLocation(selectable_cards[i]->overlayTarget->location, selectable_cards[i]->overlayTarget->sequence),
mainGame->dataManager->FormatLocation(selectable_cards[i]->overlayTarget->location, selectable_cards[i]->overlayTarget->sequence),
selectable_cards[i]->overlayTarget->sequence + 1, selectable_cards[i]->sequence + 1);
else
myswprintf(formatBuffer, L"%ls[%d]", dataManager.FormatLocation(selectable_cards[i]->location, selectable_cards[i]->sequence),
myswprintf(formatBuffer, L"%ls[%d]", mainGame->dataManager->FormatLocation(selectable_cards[i]->location, selectable_cards[i]->sequence),
selectable_cards[i]->sequence + 1);
mainGame->stCardPos[i]->setText(formatBuffer);
// color
......@@ -535,12 +535,12 @@ void ClientField::ShowChainCard() {
if(selectable_cards[i]->code)
mainGame->imageLoading.insert(std::make_pair(mainGame->btnCardSelect[i], selectable_cards[i]->code));
else
mainGame->btnCardSelect[i]->setImage(imageManager.tCover[selectable_cards[i]->controler]);
mainGame->btnCardSelect[i]->setImage(mainGame->imageManager->tCover[selectable_cards[i]->controler]);
mainGame->btnCardSelect[i]->setRelativePosition(rect<s32>((startpos + i * 125) * mainGame->xScale, 65 * mainGame->yScale, (startpos + 120 + i * 125) * mainGame->xScale, 235 * mainGame->yScale));
mainGame->btnCardSelect[i]->setPressed(false);
mainGame->btnCardSelect[i]->setVisible(true);
wchar_t formatBuffer[2048];
myswprintf(formatBuffer, L"%ls[%d]", dataManager.FormatLocation(selectable_cards[i]->location, selectable_cards[i]->sequence),
myswprintf(formatBuffer, L"%ls[%d]", mainGame->dataManager->FormatLocation(selectable_cards[i]->location, selectable_cards[i]->sequence),
selectable_cards[i]->sequence + 1);
mainGame->stCardPos[i]->setText(formatBuffer);
if(selectable_cards[i]->location == LOCATION_OVERLAY) {
......@@ -592,17 +592,17 @@ void ClientField::ShowLocationCard() {
if(display_cards[i]->code)
mainGame->imageLoading.insert(std::make_pair(mainGame->btnCardDisplay[i], display_cards[i]->code));
else
mainGame->btnCardDisplay[i]->setImage(imageManager.tCover[display_cards[i]->controler]);
mainGame->btnCardDisplay[i]->setImage(mainGame->imageManager->tCover[display_cards[i]->controler]);
mainGame->btnCardDisplay[i]->setRelativePosition(rect<s32>((startpos + i * 125) * mainGame->xScale, 65 * mainGame->yScale, (startpos + 120 + i * 125) * mainGame->xScale, 235 * mainGame->yScale));
mainGame->btnCardDisplay[i]->setPressed(false);
mainGame->btnCardDisplay[i]->setVisible(true);
wchar_t formatBuffer[2048];
if(display_cards[i]->location == LOCATION_OVERLAY)
myswprintf(formatBuffer, L"%ls[%d](%d)",
dataManager.FormatLocation(display_cards[i]->overlayTarget->location, display_cards[i]->overlayTarget->sequence),
mainGame->dataManager->FormatLocation(display_cards[i]->overlayTarget->location, display_cards[i]->overlayTarget->sequence),
display_cards[i]->overlayTarget->sequence + 1, display_cards[i]->sequence + 1);
else
myswprintf(formatBuffer, L"%ls[%d]", dataManager.FormatLocation(display_cards[i]->location, display_cards[i]->sequence),
myswprintf(formatBuffer, L"%ls[%d]", mainGame->dataManager->FormatLocation(display_cards[i]->location, display_cards[i]->sequence),
display_cards[i]->sequence + 1);
mainGame->stDisplayPos[i]->setText(formatBuffer);
if(display_cards[i]->location == LOCATION_OVERLAY) {
......@@ -651,13 +651,13 @@ void ClientField::ShowSelectOption(int select_hint) {
bool quickmode = true;
mainGame->gMutex.lock();
for(auto option : select_options) {
if(mainGame->guiFont->getDimension(dataManager.GetDesc(option)).Width > 370 * mainGame->xScale) {
if(mainGame->guiFont->getDimension(mainGame->dataManager->GetDesc(option)).Width > 370 * mainGame->xScale) {
quickmode = false;
break;
}
}
for(int i = 0; (i < count) && (i < 5) && quickmode; i++) {
const wchar_t* option = dataManager.GetDesc(select_options[i]);
const wchar_t* option = mainGame->dataManager->GetDesc(select_options[i]);
mainGame->btnOption[i]->setText(option);
}
if(quickmode) {
......@@ -681,7 +681,7 @@ void ClientField::ShowSelectOption(int select_hint) {
mainGame->bgOptions->setRelativePosition(rect<s32>(0, 0, (scrollbar ? 405 : 390) * mainGame->xScale, pos.LowerRightCorner.Y - pos.UpperLeftCorner.Y));
} else {
mainGame->SetStaticText(mainGame->stOptions, 350 * mainGame->xScale, mainGame->guiFont,
(wchar_t*)dataManager.GetDesc(select_options[0]));
(wchar_t*)mainGame->dataManager->GetDesc(select_options[0]));
mainGame->stOptions->setVisible(true);
mainGame->btnOptionp->setVisible(false);
mainGame->btnOptionn->setVisible(count > 1);
......@@ -693,9 +693,9 @@ void ClientField::ShowSelectOption(int select_hint) {
mainGame->wOptions->setRelativePosition(pos);
}
if(select_hint)
myswprintf(textBuffer, L"%ls", dataManager.GetDesc(select_hint));
myswprintf(textBuffer, L"%ls", mainGame->dataManager->GetDesc(select_hint));
else
myswprintf(textBuffer, dataManager.GetSysString(555));
myswprintf(textBuffer, mainGame->dataManager->GetSysString(555));
mainGame->stOptions->setText(textBuffer);
mainGame->PopupElement(mainGame->wOptions);
mainGame->gMutex.unlock();
......@@ -1139,9 +1139,9 @@ bool ClientField::ShowSelectSum(bool panelmode) {
select_ready = true;
mainGame->wCardSelect->setVisible(false);
wchar_t wbuf[256], *pwbuf = wbuf;
BufferIO::CopyWStrRef(dataManager.GetSysString(209), pwbuf, 256);
BufferIO::CopyWStrRef(mainGame->dataManager->GetSysString(209), pwbuf, 256);
*pwbuf++ = L'\n';
BufferIO::CopyWStrRef(dataManager.GetSysString(210), pwbuf, 256);
BufferIO::CopyWStrRef(mainGame->dataManager->GetSysString(210), pwbuf, 256);
mainGame->stQMessage->setText(wbuf);
mainGame->PopupElement(mainGame->wQuery);
}
......@@ -1160,9 +1160,9 @@ bool ClientField::ShowSelectSum(bool panelmode) {
} else {
select_ready = true;
wchar_t wbuf[256], *pwbuf = wbuf;
BufferIO::CopyWStrRef(dataManager.GetSysString(209), pwbuf, 256);
BufferIO::CopyWStrRef(mainGame->dataManager->GetSysString(209), pwbuf, 256);
*pwbuf++ = L'\n';
BufferIO::CopyWStrRef(dataManager.GetSysString(210), pwbuf, 256);
BufferIO::CopyWStrRef(mainGame->dataManager->GetSysString(210), pwbuf, 256);
mainGame->stQMessage->setText(wbuf);
mainGame->PopupElement(mainGame->wQuery);
}
......@@ -1539,7 +1539,7 @@ void ClientField::UpdateDeclarableList() {
int trycode = BufferIO::GetVal(pname);
CardString cstr;
CardData cd;
if(dataManager.GetString(trycode, &cstr) && dataManager.GetData(trycode, &cd) && is_declarable(cd, declare_opcodes)) {
if(mainGame->dataManager->GetString(trycode, &cstr) && mainGame->dataManager->GetData(trycode, &cd) && is_declarable(cd, declare_opcodes)) {
mainGame->lstANCard->clear();
ancard.clear();
mainGame->lstANCard->addItem(cstr.name.c_str());
......@@ -1553,7 +1553,7 @@ void ClientField::UpdateDeclarableList() {
int selcode = (sel == -1) ? 0 : cache[sel];
mainGame->lstANCard->clear();
for(const auto& trycode : cache) {
if(dataManager.GetString(trycode, &cstr) && dataManager.GetData(trycode, &cd) && is_declarable(cd, declare_opcodes)) {
if(mainGame->dataManager->GetString(trycode, &cstr) && mainGame->dataManager->GetData(trycode, &cd) && is_declarable(cd, declare_opcodes)) {
ancard.push_back(trycode);
mainGame->lstANCard->addItem(cstr.name.c_str());
if(trycode == selcode)
......@@ -1565,9 +1565,9 @@ void ClientField::UpdateDeclarableList() {
}
mainGame->lstANCard->clear();
ancard.clear();
for(auto cit = dataManager._strings.begin(); cit != dataManager._strings.end(); ++cit) {
for(auto cit = mainGame->dataManager->_strings.begin(); cit != mainGame->dataManager->_strings.end(); ++cit) {
if(cit->second.name.find(pname) != std::wstring::npos) {
auto cp = dataManager.GetCodePointer(cit->first); //verified by _strings
auto cp = mainGame->dataManager->GetCodePointer(cit->first); //verified by _strings
//datas.alias can be double card names or alias
if(is_declarable(cp->second, declare_opcodes)) {
if(pname == cit->second.name) { //exact match
......
......@@ -7,7 +7,6 @@ namespace ygo {
const wchar_t* DataManager::unknown_string = L"???";
byte DataManager::scriptBuffer[0x20000];
IFileSystem* DataManager::FileSystem;
DataManager dataManager;
bool DataManager::LoadDB(const wchar_t* wfile) {
char file[256];
......@@ -153,7 +152,6 @@ bool DataManager::Error(spmemvfs_db_t* pDB, sqlite3_stmt* pStmt, int errNo) {
BufferIO::DecodeUTF8(msg, strBuffer);
if(pStmt)
sqlite3_finalize(pStmt);
int len = strlen(msg);
ALOGE("cdb Error code=%d,msg=%s", errNo, msg);
spmemvfs_close_db(pDB);
spmemvfs_env_fini();
......@@ -359,7 +357,7 @@ const wchar_t* DataManager::FormatLinkMarker(int link_marker) {
return lmBuffer;
}
int DataManager::CardReader(int code, void* pData) {
if(!dataManager.GetData(code, (CardData*)pData))
if(!mainGame->dataManager->GetData(code, (CardData*)pData))
memset(pData, 0, sizeof(CardData));
return 0;
}
......
......@@ -64,8 +64,6 @@ public:
static IFileSystem* FileSystem;
};
extern DataManager dataManager;
}
#endif // DATAMANAGER_H
This diff is collapsed.
......@@ -6,8 +6,6 @@
namespace ygo {
DeckManager deckManager;
void DeckManager::LoadLFListSingle(const char* path) {
LFList* cur = nullptr;
FILE* fp = fopen(path, "r");
......@@ -63,7 +61,7 @@ const wchar_t* DeckManager::GetLFListName(int lfhash) {
});
if(lit != _lfList.end())
return lit->listName.c_str();
return dataManager.unknown_string;
return mainGame->dataManager->unknown_string;
}
std::unordered_map<int, int>* DeckManager::GetLFListContent(int lfhash) {
auto lit = std::find_if(_lfList.begin(), _lfList.end(), [lfhash](const ygo::LFList& list) {
......@@ -149,7 +147,7 @@ int DeckManager::LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec) {
CardData cd;
for(int i = 0; i < mainc; ++i) {
code = dbuf[i];
if(!dataManager.GetData(code, &cd)) {
if(!mainGame->dataManager->GetData(code, &cd)) {
errorcode = code;
continue;
}
......@@ -158,21 +156,21 @@ int DeckManager::LoadDeck(Deck& deck, int* dbuf, int mainc, int sidec) {
else if(cd.type & (TYPE_FUSION | TYPE_SYNCHRO | TYPE_XYZ | TYPE_LINK)) {
if(deck.extra.size() >= 15)
continue;
deck.extra.push_back(dataManager.GetCodePointer(code)); //verified by GetData()
deck.extra.push_back(mainGame->dataManager->GetCodePointer(code)); //verified by GetData()
} else if(deck.main.size() < 60) {
deck.main.push_back(dataManager.GetCodePointer(code));
deck.main.push_back(mainGame->dataManager->GetCodePointer(code));
}
}
for(int i = 0; i < sidec; ++i) {
code = dbuf[mainc + i];
if(!dataManager.GetData(code, &cd)) {
if(!mainGame->dataManager->GetData(code, &cd)) {
errorcode = code;
continue;
}
if(cd.type & TYPE_TOKEN)
continue;
if(deck.side.size() < 15)
deck.side.push_back(dataManager.GetCodePointer(code)); //verified by GetData()
deck.side.push_back(mainGame->dataManager->GetCodePointer(code)); //verified by GetData()
}
return errorcode;
}
......
......@@ -54,9 +54,6 @@ public:
bool DeleteCategory(const wchar_t* name);
int TypeCount(std::vector<code_pointer> list, unsigned int ctype);
};
extern DeckManager deckManager;
}
#endif //DECKMANAGER_H
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -6,6 +6,8 @@
#include "deck_con.h"
#include "menu_handler.h"
#include "sound_manager.h"
#include "deck_manager.h"
#include "image_manager.h"
#include <unordered_map>
#include <vector>
#include <list>
......@@ -127,7 +129,7 @@ struct FadingUnit {
irr::core::vector2di fadingDiff;
};
class Game :IProcessEventReceiver{
class Game{
public:
#ifdef _IRR_ANDROID_PLATFORM_
......@@ -152,7 +154,7 @@ public:
void DrawBackGround();
void DrawSelField(int player, int loc, size_t seq, irr::video::ITexture* texture, bool reverse = false, bool spin = false);
void DrawLinkedZones(ClientCard* pcard, ClientCard* fcard = 0);
void CheckMutual(ClientCard* pcard, int mark);
void CheckMutual(ClientCard* pcard, int mark){}
void DrawCards();
void DrawCard(ClientCard* pcard);
void DrawShadowText(irr::gui::CGUITTFont* font, const core::stringw& text, const core::rect<s32>& position, const core::rect<s32>& padding, video::SColor color = 0xffffffff, video::SColor shadowcolor = 0xff000000, bool hcenter = false, bool vcenter = false, const core::rect<s32>* clip = 0);
......@@ -206,6 +208,9 @@ public:
// don't merge
std::unique_ptr<SoundManager> soundManager;
std::unique_ptr<DeckManager> deckManager;
std::unique_ptr<ImageManager> imageManager;
std::unique_ptr<DataManager> dataManager;
std::mutex gMutex;
Signal frameSignal;
Signal actionSignal;
......@@ -657,27 +662,6 @@ public:
Signal externalSignal;
static void onHandleAndroidCommand(ANDROID_APP app, int32_t cmd);
#endif
void setPositionFix(core::position2di fix){
InputFix = fix;
}
float optX(float x) {
float x2 = x - InputFix.X;
if (x2 < 0) {
return 0;
}
return x2;
}
float optY(float y) {
float y2 = y - InputFix.Y;
if (y2 < 0) {
return 0;
}
return y2;
}
void process(irr::SEvent &event);
private:
core::position2di InputFix;
};
extern Game *mainGame;
......
......@@ -40,17 +40,18 @@ int GetListBoxIndex(IGUIListBox* listbox, const wchar_t * target){
return -1;
}
void android_main(ANDROID_APP app) {
app->inputPollSource.process = android::process_input;
app_dummy();
#else
int main(int argc, char* argv[]) {
#endif
evthread_use_pthreads();
ygo::Game _game;
ygo::mainGame = &_game;
auto game = new ygo::Game;
if(ygo::mainGame != nullptr){
delete ygo::mainGame;
}
ygo::mainGame = game;
#ifdef _IRR_ANDROID_PLATFORM_
android::InitOptions *options = android::getInitOptions(app);
if(!ygo::mainGame->Initialize(app, options)){
if(!game->Initialize(app, options)){
delete options;
return;
}
......@@ -78,29 +79,29 @@ int main(int argc, char* argv[]) {
wchar_t fname[1024];
char* tmp = sub_string(arg, 2);
BufferIO::DecodeUTF8(tmp, fname);
ygo::dataManager.LoadDB(fname);
game->dataManager->LoadDB(fname);
delete tmp;
} else if(!strcmp(arg, "-k")) { // Keep on return
exit_on_return = false;
keep_on_return = true;
} else if(!strcmp(arg, "-c")) { // Create host
exit_on_return = !keep_on_return;
ygo::mainGame->HideElement(ygo::mainGame->wMainMenu);
ClickButton(ygo::mainGame->btnJoinHost);
game->HideElement(game->wMainMenu);
ClickButton(game->btnJoinHost);
break;
} else if(!strcmp(arg, "-j")) { // Join host
exit_on_return = !keep_on_return;
ygo::mainGame->HideElement(ygo::mainGame->wMainMenu);
ClickButton(ygo::mainGame->btnJoinHost);
game->HideElement(game->wMainMenu);
ClickButton(game->btnJoinHost);
break;
} else if(!strcmp(arg, "-r")) { // Replay
exit_on_return = !keep_on_return;
//显示录像窗口
ygo::mainGame->HideElement(ygo::mainGame->wMainMenu);
ygo::mainGame->ShowElement(ygo::mainGame->wReplay);
ygo::mainGame->ebRepStartTurn->setText(L"1");
ygo::mainGame->stReplayInfo->setText(L"");
ygo::mainGame->RefreshReplay();
game->HideElement(game->wMainMenu);
game->ShowElement(game->wReplay);
game->ebRepStartTurn->setText(L"1");
game->stReplayInfo->setText(L"");
game->RefreshReplay();
int index = -1;
if((i+1) < argc){//下一个参数是录像名
#ifdef _IRR_ANDROID_PLATFORM_
......@@ -111,24 +112,24 @@ int main(int argc, char* argv[]) {
wchar_t fname[1024];
BufferIO::DecodeUTF8(name, fname);
index = GetListBoxIndex(ygo::mainGame->lstReplayList, fname);
index = GetListBoxIndex(game->lstReplayList, fname);
ALOGD("open replay file:index=%d, name=%s", index, name);
}
ygo::mainGame->HideElement(ygo::mainGame->wMainMenu);
ClickButton(ygo::mainGame->btnReplayMode);
game->HideElement(game->wMainMenu);
ClickButton(game->btnReplayMode);
if (index >= 0) {
ygo::mainGame->lstReplayList->setSelected(index);
ClickButton(ygo::mainGame->btnLoadReplay);
game->lstReplayList->setSelected(index);
ClickButton(game->btnLoadReplay);
}
break;//只播放一个
} else if(!strcmp(arg, "-s")) { // Single
exit_on_return = !keep_on_return;
//显示残局窗口
ygo::mainGame->HideElement(ygo::mainGame->wMainMenu);
ygo::mainGame->ShowElement(ygo::mainGame->wSinglePlay);
ygo::mainGame->RefreshSingleplay();
ygo::mainGame->RefreshBot();
game->HideElement(game->wMainMenu);
game->ShowElement(game->wSinglePlay);
game->RefreshSingleplay();
game->RefreshBot();
int index = -1;
if((i+1) < argc){//下一个参数是文件名
#ifdef _IRR_ANDROID_PLATFORM_
......@@ -138,12 +139,12 @@ int main(int argc, char* argv[]) {
#endif
wchar_t fname[1024];
BufferIO::DecodeUTF8(name, fname);
index = GetListBoxIndex(ygo::mainGame->lstSinglePlayList, fname);
index = GetListBoxIndex(game->lstSinglePlayList, fname);
ALOGD("open single file:index=%d, name=%s", index, name);
}
if(index >= 0){
ygo::mainGame->lstSinglePlayList->setSelected(index);
ClickButton(ygo::mainGame->btnLoadSinglePlay);
game->lstSinglePlayList->setSelected(index);
ClickButton(game->btnLoadSinglePlay);
}
break;
}
......@@ -151,8 +152,8 @@ int main(int argc, char* argv[]) {
#ifdef _IRR_ANDROID_PLATFORM_
delete options;
#endif
ygo::mainGame->externalSignal.Set();
ygo::mainGame->externalSignal.SetNoWait(true);
ygo::mainGame->MainLoop();
game->externalSignal.Set();
game->externalSignal.SetNoWait(true);
game->MainLoop();
return;
}
......@@ -3,8 +3,6 @@
namespace ygo {
ImageManager imageManager;
bool ImageManager::Initial(const path dir) {
tCover[0] = driver->getTexture((dir + path("/textures/cover.jpg")).c_str());
tCover[1] = driver->getTexture((dir + path("/textures/cover2.jpg")).c_str());
......
......@@ -80,8 +80,6 @@ public:
std::list<std::string> support_types;
};
extern ImageManager imageManager;
}
#endif // IMAGEMANAGER_H
......@@ -23,14 +23,14 @@ void UpdateDeck() {
char deckbuf[1024];
char* pdeck = deckbuf;
BufferIO::WriteInt32(pdeck, deckManager.current_deck.main.size() + deckManager.current_deck.extra.size());
BufferIO::WriteInt32(pdeck, deckManager.current_deck.side.size());
for(size_t i = 0; i < deckManager.current_deck.main.size(); ++i)
BufferIO::WriteInt32(pdeck, deckManager.current_deck.main[i]->first);
for(size_t i = 0; i < deckManager.current_deck.extra.size(); ++i)
BufferIO::WriteInt32(pdeck, deckManager.current_deck.extra[i]->first);
for(size_t i = 0; i < deckManager.current_deck.side.size(); ++i)
BufferIO::WriteInt32(pdeck, deckManager.current_deck.side[i]->first);
BufferIO::WriteInt32(pdeck, mainGame->deckManager->current_deck.main.size() + mainGame->deckManager->current_deck.extra.size());
BufferIO::WriteInt32(pdeck, mainGame->deckManager->current_deck.side.size());
for(size_t i = 0; i < mainGame->deckManager->current_deck.main.size(); ++i)
BufferIO::WriteInt32(pdeck, mainGame->deckManager->current_deck.main[i]->first);
for(size_t i = 0; i < mainGame->deckManager->current_deck.extra.size(); ++i)
BufferIO::WriteInt32(pdeck, mainGame->deckManager->current_deck.extra[i]->first);
for(size_t i = 0; i < mainGame->deckManager->current_deck.side.size(); ++i)
BufferIO::WriteInt32(pdeck, mainGame->deckManager->current_deck.side[i]->first);
DuelClient::SendBufferToServer(CTOS_UPDATE_DECK, deckbuf, pdeck - deckbuf);
}
bool MenuHandler::OnEvent(const irr::SEvent& event) {
......@@ -99,7 +99,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
if(status != 0) {
mainGame->gMutex.lock();
mainGame->soundManager->PlaySoundEffect(SoundManager::SFX::INFO);
mainGame->addMessageBox(L"", dataManager.GetSysString(1412));
mainGame->addMessageBox(L"", mainGame->dataManager->GetSysString(1412));
mainGame->gMutex.unlock();
break;
} else {
......@@ -181,7 +181,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
}
case BUTTON_HP_READY: {
if(mainGame->cbCategorySelect->getSelected() == -1 || mainGame->cbDeckSelect->getSelected() == -1 ||
!deckManager.LoadDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect)) {
!mainGame->deckManager->LoadDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect)) {
break;
}
UpdateDeck();
......@@ -266,7 +266,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
break;
mainGame->gMutex.lock();
wchar_t textBuffer[256];
myswprintf(textBuffer, L"%ls\n%ls", mainGame->lstReplayList->getListItem(sel), dataManager.GetSysString(1363));
myswprintf(textBuffer, L"%ls\n%ls", mainGame->lstReplayList->getListItem(sel), mainGame->dataManager->GetSysString(1363));
mainGame->SetStaticText(mainGame->stQMessage, 370 * mainGame->xScale, mainGame->textFont, textBuffer);
mainGame->PopupElement(mainGame->wQuery);
mainGame->gMutex.unlock();
......@@ -296,7 +296,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
if(sel == -1)
break;
mainGame->gMutex.lock();
mainGame->wReplaySave->setText(dataManager.GetSysString(1364));
mainGame->wReplaySave->setText(mainGame->dataManager->GetSysString(1364));
mainGame->ebRSName->setText(mainGame->lstReplayList->getListItem(sel));
mainGame->PopupElement(mainGame->wReplaySave);
mainGame->gMutex.unlock();
......@@ -334,15 +334,15 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
int main = replay.ReadInt32();
Deck tmp_deck;
for(int j = 0; j < main; ++j)
tmp_deck.main.push_back(dataManager.GetCodePointer(replay.ReadInt32()));
tmp_deck.main.push_back(mainGame->dataManager->GetCodePointer(replay.ReadInt32()));
int extra = replay.ReadInt32();
for(int j = 0; j < extra; ++j)
tmp_deck.extra.push_back(dataManager.GetCodePointer(replay.ReadInt32()));
tmp_deck.extra.push_back(mainGame->dataManager->GetCodePointer(replay.ReadInt32()));
FileSystem::SafeFileName(namebuf[i]);
myswprintf(filename, L"deck/%ls-%d %ls.ydk", ex_filename, i + 1, namebuf[i]);
deckManager.SaveDeck(tmp_deck, filename);
mainGame->deckManager->SaveDeck(tmp_deck, filename);
}
mainGame->stACMessage->setText(dataManager.GetSysString(1335));
mainGame->stACMessage->setText(mainGame->dataManager->GetSysString(1335));
mainGame->PopupElement(mainGame->wACMessage, 20);
break;
}
......@@ -367,7 +367,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
wchar_t arg1[512];
if(mainGame->botInfo[sel].select_deckfile) {
wchar_t botdeck[256];
deckManager.GetDeckFile(botdeck, mainGame->cbBotDeckCategory, mainGame->cbBotDeck);
mainGame->deckManager->GetDeckFile(botdeck, mainGame->cbBotDeckCategory, mainGame->cbBotDeck);
myswprintf(arg1, L"%ls DeckFile='%ls'", mainGame->botInfo[sel].command, botdeck);
}
else
......@@ -385,7 +385,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
wchar_t warg1[512];
if(mainGame->botInfo[sel].select_deckfile) {
wchar_t botdeck[256];
deckManager.GetDeckFile(botdeck, mainGame->cbBotDeckCategory, mainGame->cbBotDeck);
mainGame->deckManager->GetDeckFile(botdeck, mainGame->cbBotDeckCategory, mainGame->cbBotDeck);
myswprintf(warg1, L"%ls DeckFile='%ls'", mainGame->botInfo[sel].command, botdeck);
}
else
......@@ -412,7 +412,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
wchar_t warg1[512];
if(mainGame->botInfo[sel].select_deckfile) {
wchar_t botdeck[256];
deckManager.GetDeckFile(botdeck, mainGame->cbBotDeckCategory, mainGame->cbBotDeck);
mainGame->deckManager->GetDeckFile(botdeck, mainGame->cbBotDeckCategory, mainGame->cbBotDeck);
myswprintf(warg1, L"%ls DeckFile='%ls'", mainGame->botInfo[sel].command, botdeck);
}
else
......@@ -456,7 +456,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
case BUTTON_DECK_EDIT: {
mainGame->RefreshCategoryDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
if(mainGame->cbDBCategory->getSelected() != -1 && mainGame->cbDBDecks->getSelected() != -1) {
deckManager.LoadDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
mainGame->deckManager->LoadDeck(mainGame->cbDBCategory, mainGame->cbDBDecks);
mainGame->ebDeckname->setText(L"");
}
mainGame->HideElement(mainGame->wMainMenu);
......@@ -492,7 +492,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
if(Replay::RenameReplay(mainGame->lstReplayList->getListItem(prev_sel), newname)) {
mainGame->lstReplayList->setItem(prev_sel, newname, -1);
} else {
mainGame->addMessageBox(L"", dataManager.GetSysString(1365));
mainGame->addMessageBox(L"", mainGame->dataManager->GetSysString(1365));
}
}
prev_operation = 0;
......@@ -635,7 +635,7 @@ bool MenuHandler::OnEvent(const irr::SEvent& event) {
mainGame->env->setFocus(mainGame->wHostPrepare);
if(static_cast<irr::gui::IGUICheckBox*>(caller)->isChecked()) {
if(mainGame->cbCategorySelect->getSelected() == -1 || mainGame->cbDeckSelect->getSelected() == -1 ||
!deckManager.LoadDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect)) {
!mainGame->deckManager->LoadDeck(mainGame->cbCategorySelect, mainGame->cbDeckSelect)) {
static_cast<irr::gui::IGUICheckBox*>(caller)->setChecked(false);
break;
}
......
#include "netserver.h"
#include "single_duel.h"
#include "tag_duel.h"
#include "game.h"
namespace ygo {
std::unordered_map<bufferevent*, DuelPlayer> NetServer::users;
......@@ -238,14 +239,14 @@ void NetServer::HandleCTOSPacket(DuelPlayer* dp, char* data, unsigned int len) {
if(pkt->info.mode > 2)
pkt->info.mode = 0;
unsigned int hash = 1;
for(auto lfit = deckManager._lfList.begin(); lfit != deckManager._lfList.end(); ++lfit) {
for(auto lfit = mainGame->deckManager->_lfList.begin(); lfit != mainGame->deckManager->_lfList.end(); ++lfit) {
if(pkt->info.lflist == lfit->hash) {
hash = pkt->info.lflist;
break;
}
}
if(hash == 1)
pkt->info.lflist = deckManager._lfList[0].hash;
pkt->info.lflist = mainGame->deckManager->_lfList[0].hash;
#ifdef _IRR_ANDROID_PLATFORM_
HostInfo tmp;
memcpy(&tmp, &pkt->info, sizeof(struct HostInfo));
......
......@@ -244,7 +244,7 @@ void ReplayMode::EndDuel() {
if(!is_closing) {
mainGame->actionSignal.Reset();
mainGame->gMutex.lock();
mainGame->stMessage->setText(dataManager.GetSysString(1501));
mainGame->stMessage->setText(mainGame->dataManager->GetSysString(1501));
mainGame->HideElement(mainGame->wCardSelect);
mainGame->PopupElement(mainGame->wMessage);
mainGame->gMutex.unlock();
......
......@@ -251,7 +251,7 @@ void SingleDuel::PlayerReady(DuelPlayer* dp, bool is_ready) {
if(deck_error[dp->type]) {
deckerror = (DECKERROR_UNKNOWNCARD << 28) + deck_error[dp->type];
} else {
deckerror = deckManager.CheckDeck(pdeck[dp->type], host_info.lflist, host_info.rule);
deckerror = mainGame->deckManager->CheckDeck(pdeck[dp->type], host_info.lflist, host_info.rule);
}
}
if(deckerror) {
......@@ -295,9 +295,9 @@ void SingleDuel::UpdateDeck(DuelPlayer* dp, void* pdata, unsigned int len) {
return;
}
if(duel_count == 0) {
deck_error[dp->type] = deckManager.LoadDeck(pdeck[dp->type], (int*)deckbuf, mainc, sidec);
deck_error[dp->type] = mainGame->deckManager->LoadDeck(pdeck[dp->type], (int*)deckbuf, mainc, sidec);
} else {
if(deckManager.LoadSide(pdeck[dp->type], (int*)deckbuf, mainc, sidec)) {
if(mainGame->deckManager->LoadSide(pdeck[dp->type], (int*)deckbuf, mainc, sidec)) {
ready[dp->type] = true;
NetServer::SendPacketToPlayer(dp, STOC_DUEL_START);
if(ready[0] && ready[1]) {
......
......@@ -75,7 +75,7 @@ int SingleMode::SinglePlayThread() {
mainGame->wInfos->setVisible(true);
mainGame->wPallet->setVisible(true);
mainGame->btnLeaveGame->setVisible(true);
mainGame->btnLeaveGame->setText(dataManager.GetSysString(1210));
mainGame->btnLeaveGame->setText(mainGame->dataManager->GetSysString(1210));
mainGame->wPhase->setVisible(true);
mainGame->dField.Clear();
mainGame->dInfo.isFirst = true;
......@@ -122,7 +122,7 @@ int SingleMode::SinglePlayThread() {
wcsftime(timetext, 40, L"%Y-%m-%d %H-%M-%S", localedtime);
mainGame->ebRSName->setText(timetext);
if(!mainGame->chkAutoSaveReplay->isChecked()) {
mainGame->wReplaySave->setText(dataManager.GetSysString(1340));
mainGame->wReplaySave->setText(mainGame->dataManager->GetSysString(1340));
mainGame->PopupElement(mainGame->wReplaySave);
mainGame->gMutex.unlock();
mainGame->replaySignal.Reset();
......@@ -130,7 +130,7 @@ int SingleMode::SinglePlayThread() {
} else {
mainGame->actionParam = 1;
wchar_t msgbuf[256];
myswprintf(msgbuf, dataManager.GetSysString(1367), timetext);
myswprintf(msgbuf, mainGame->dataManager->GetSysString(1367), timetext);
mainGame->SetStaticText(mainGame->stACMessage, 310, mainGame->guiFont, msgbuf);
mainGame->PopupElement(mainGame->wACMessage, 20);
mainGame->gMutex.unlock();
......
......@@ -151,7 +151,7 @@ void SoundManager::StopBGM() {
}
bool SoundManager::PlayChant(unsigned int code) {
CardData cd;
if(dataManager.GetData(code, &cd) && (cd.alias != 0))
if(mainGame->dataManager->GetData(code, &cd) && (cd.alias != 0))
code = cd.alias;
if(ChantsList.count(code) && bgm_PlayingName != ChantsList[code]) {
......
......@@ -226,7 +226,7 @@ void TagDuel::PlayerReady(DuelPlayer* dp, bool is_ready) {
if(deck_error[dp->type]) {
deckerror = (DECKERROR_UNKNOWNCARD << 28) + deck_error[dp->type];
} else {
deckerror = deckManager.CheckDeck(pdeck[dp->type], host_info.lflist, host_info.rule);
deckerror = mainGame->deckManager->CheckDeck(pdeck[dp->type], host_info.lflist, host_info.rule);
}
}
if(deckerror) {
......@@ -269,7 +269,7 @@ void TagDuel::UpdateDeck(DuelPlayer* dp, void* pdata, unsigned int len) {
NetServer::SendPacketToPlayer(dp, STOC_ERROR_MSG, scem);
return;
}
deck_error[dp->type] = deckManager.LoadDeck(pdeck[dp->type], (int*)deckbuf, mainc, sidec);
deck_error[dp->type] = mainGame->deckManager->LoadDeck(pdeck[dp->type], (int*)deckbuf, mainc, sidec);
}
void TagDuel::StartDuel(DuelPlayer* dp) {
if(dp != host_player)
......
......@@ -121,8 +121,8 @@ namespace ygo {
}
}
void Utils::changeCursor(irr::gui::ECURSOR_ICON icon) {
irr::gui::ICursorControl* cursor = mainGame->device->getCursorControl();
void Utils::changeCursor(irr::IrrlichtDevice* device, irr::gui::ECURSOR_ICON icon) {
irr::gui::ICursorControl* cursor = device->getCursorControl();
if (cursor->getActiveIcon() != icon) {
cursor->setActiveIcon(icon);
}
......@@ -205,8 +205,8 @@ namespace ygo {
return res;
}
irr::io::IReadFile* Utils::FindandOpenFileFromArchives(const path_string & path, const path_string & name) {
for(auto& archive : mainGame->archives) {
irr::io::IReadFile* Utils::FindandOpenFileFromArchives(std::vector<Utils::IrrArchiveHelper> archives, const path_string & path, const path_string & name) {
for(auto& archive : archives) {
int res = -1;
Utils::FindfolderFiles(archive, path, [match = &name, &res](int index, path_string name, bool isdir, void* payload)->bool {
if(isdir)
......
......@@ -35,13 +35,12 @@ namespace ygo {
static bool Deletedirectory(const path_string& source);
static void CreateResourceFolders();
static void takeScreenshot(irr::IrrlichtDevice* device);
static void ToggleFullscreen();
static void changeCursor(irr::gui::ECURSOR_ICON icon);
static void changeCursor(irr::IrrlichtDevice* device, irr::gui::ECURSOR_ICON icon);
static void FindfolderFiles(const path_string& path, const std::function<void(path_string, bool, void*)>& cb, void* payload = nullptr);
static std::vector<path_string> FindfolderFiles(const path_string& path, std::vector<path_string> extensions, int subdirectorylayers = 0);
static void FindfolderFiles(IrrArchiveHelper& archive, const path_string& path, const std::function<bool(int, path_string, bool, void*)>& cb, void* payload = nullptr);
static std::vector<int> FindfolderFiles(IrrArchiveHelper& archive, const path_string& path, std::vector<path_string> extensions, int subdirectorylayers = 0);
static irr::io::IReadFile* FindandOpenFileFromArchives(const path_string& path, const path_string& name);
static irr::io::IReadFile* FindandOpenFileFromArchives(std::vector<Utils::IrrArchiveHelper> archives, const path_string& path, const path_string& name);
static std::wstring NormalizePath(std::wstring path, bool trailing_slash = true);
static std::wstring GetFileExtension(std::wstring file);
static std::wstring GetFilePath(std::wstring file);
......
......@@ -2,12 +2,15 @@
buildscript {
repositories {
maven { url 'https://maven.aliyun.com/repository/public'}
maven { url 'https://maven.aliyun.com/repository/google'}
jcenter()
maven { url "https://jitpack.io" }
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.1'
classpath 'com.android.tools.build:gradle-experimental:0.11.1'
//classpath 'me.tatarka:gradle-retrolambda:3.2.5'
}
}
......@@ -20,6 +23,8 @@ ext {
allprojects {
repositories {
maven { url 'https://maven.aliyun.com/repository/public'}
maven { url 'https://maven.aliyun.com/repository/google'}
jcenter()
google()
maven { url "https://jitpack.io" }
......
......@@ -11,7 +11,8 @@
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
#Mon Aug 31 19:03:54 CST 2020
org.gradle.jvmargs=-Xmx4096M -Dkotlin.daemon.jvm.options="-Xmx4096M"
org.gradle.parallel=true
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx2048M -Dkotlin.daemon.jvm.options\="-Xmx2048M"
android.injected.testOnly=false
\ No newline at end of file
......@@ -749,9 +749,9 @@ void toggleGlobalIME(ANDROID_APP app, bool pShow) {
app->activity->vm->DetachCurrentThread();
}
core::position2di initJavaBridge(ANDROID_APP app, void* handle) {
void initJavaBridge(ANDROID_APP app, void* handle) {
if (!app || !app->activity || !app->activity->vm)
return core::position2di(0, 0);
return;
JNIEnv* jni = nullptr;
app->activity->vm->AttachCurrentThread(&jni, NULL);
jobject lNativeActivity = app->activity->clazz;
......@@ -760,18 +760,9 @@ core::position2di initJavaBridge(ANDROID_APP app, void* handle) {
"setNativeHandle", "(J)V");
jlong code = (jlong) handle;
jni->CallVoidMethod(lNativeActivity, MethodSetHandle, code);
jmethodID methodX = jni->GetMethodID(ClassNativeActivity,
"getPositionX", "()I");
jint posX = jni->CallIntMethod(lNativeActivity, methodX);
jmethodID methodY = jni->GetMethodID(ClassNativeActivity,
"getPositionY", "()I");
jint posY = jni->CallIntMethod(lNativeActivity, methodY);
jni->DeleteLocalRef(ClassNativeActivity);
app->activity->vm->DetachCurrentThread();
__android_log_print(ANDROID_LOG_INFO, "ygo", "Android command initJavaBridge posX=%d, posY=%d", posX, posY);
return core::position2di((int)posX, (int)posY);
__android_log_print(ANDROID_LOG_INFO, "ygo", "Android command initJavaBridge");
}
InitOptions* getInitOptions(ANDROID_APP app) {
......@@ -807,7 +798,7 @@ int getLocalAddr(ANDROID_APP app) {
return addr;
}
void OnShareFile(ANDROID_APP app, const char* title, const char* ext){
void OnShareFile(ANDROID_APP app, const char* _type, const char* name){
if (!app || !app->activity || !app->activity->vm)
return;
JNIEnv* jni = nullptr;
......@@ -817,8 +808,8 @@ void OnShareFile(ANDROID_APP app, const char* title, const char* ext){
jobject lNativeActivity = app->activity->clazz;
jclass ClassNativeActivity = jni->GetObjectClass(lNativeActivity);
jmethodID methodId = jni->GetMethodID(ClassNativeActivity, "shareFile", "(Ljava/lang/String;Ljava/lang/String;)V");
jstring s_title = jni->NewStringUTF(title);
jstring s_ext = jni->NewStringUTF(ext);
jstring s_title = jni->NewStringUTF(_type);
jstring s_ext = jni->NewStringUTF(name);
jni->CallVoidMethod(lNativeActivity, methodId, s_title, s_ext);
if (s_title) {
//不需要用ReleaseStringUTFChars,因为是c变量,函数外面自己释放
......@@ -869,30 +860,6 @@ void toggleOverlayView(ANDROID_APP app, bool pShow) {
app->activity->vm->DetachCurrentThread();
}
void process_input(ANDROID_APP app,
struct android_poll_source* source) {
AInputEvent* event = NULL;
if (AInputQueue_getEvent(app->inputQueue, &event) >= 0) {
int type = AInputEvent_getType(event);
bool skip_predispatch = AInputEvent_getType(event)
== AINPUT_EVENT_TYPE_KEY
&& AKeyEvent_getKeyCode(event) == AKEYCODE_BACK;
// skip predispatch (all it does is send to the IME)
if (!skip_predispatch
&& AInputQueue_preDispatchEvent(app->inputQueue, event)) {
return;
}
int32_t handled = 0;
if (app->onInputEvent != NULL)
handled = app->onInputEvent(app, event);
AInputQueue_finishEvent(app->inputQueue, event, handled);
} else {
// LOGE("Failure reading next input event: %s\n", strerror(errno));
}
}
void onGameExit(ANDROID_APP app){
if (!app || !app->activity || !app->activity->vm)
return;
......
......@@ -99,7 +99,7 @@ extern float getScreenWidth(ANDROID_APP app);
extern float getScreenHeight(ANDROID_APP app);
extern void OnShareFile(ANDROID_APP app, const char* title, const char* ext);
extern void OnShareFile(ANDROID_APP app, const char* _type, const char* name);
// Get SDCard path.
extern irr::io::path getExternalStorageDir(ANDROID_APP app);
......@@ -126,7 +126,7 @@ extern void toggleGlobalIME(ANDROID_APP app, bool pShow);
extern void toggleIME(ANDROID_APP app, bool pShow, const char* hint);
//Init Java Irrlicht world.
extern core::position2di initJavaBridge(ANDROID_APP app, void* handle);
extern void initJavaBridge(ANDROID_APP app, void* handle);
//Cause a haptic feedback.
extern void perfromHapticFeedback(ANDROID_APP app);
......@@ -186,10 +186,6 @@ extern bool getFontAntiAlias(ANDROID_APP app);
extern void showAndroidComboBoxCompat(ANDROID_APP app, bool pShow,
char** pContents, int count, int mode = 0);
/* android event handlers*/
extern void process_input(ANDROID_APP app,
struct android_poll_source* source);
extern s32 handleInput(ANDROID_APP app, AInputEvent* androidEvent);
extern bool android_deck_delete(const char* deck_name);
......
APP_ABI := arm64-v8a armeabi-v7a x86
APP_ABI := arm64-v8a #armeabi-v7a x86
APP_PLATFORM := android-21
#APP_MODULES := YGOMobile
#NDK_TOOLCHAIN_VERSION=4.8
......
......@@ -294,14 +294,6 @@ static void* join_game_thread(void* param) {
}
}
JNIEXPORT void JNICALL Java_cn_garymb_ygomobile_core_IrrlichtBridge_nativeSetInputFix(
JNIEnv* env, jclass clazz, jlong handle, jint x, jint y) {
if(ygo::mainGame) {
ALOGD("setInputFix posX=%d, posY=%d", x, y);
ygo::mainGame->setPositionFix(core::position2di(x, y));
}
}
static void* cancel_chain_thread(void* param) {
IrrlichtDevice* device = (IrrlichtDevice*) param;
irr::os::Printer::log("before send cancel chain");
......
package cn.garymb.ygomobile.controller;
import android.os.Looper;
import android.util.Log;
import android.view.InputEvent;
import android.view.InputQueue;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
import cn.garymb.ygomobile.utils.AndroidHideApi;
/**
* 仅测试安卓7-11
*/
public class InputQueueCompat implements InvocationHandler {
private static final String TAG = "kk-java";
private static Constructor<InputQueue> InputQueue_ctr;
private static Method getNativePtr_method;
private static Class<?> FinishedInputEventCallback_class;
//sendInputEvent(InputEvent e, Object token, boolean predispatch,
// FinishedInputEventCallback callback)
private static Method sendInputEvent_method;
private FinishedInputEventCallbackCompat finishedInputEventCallbackCompat;
static {
AndroidHideApi.enableHideApi();
try {
Looper.getMainLooper();
InputQueue_ctr = InputQueue.class.getDeclaredConstructor();
// InputQueue_ctr.setAccessible(true);
getNativePtr_method = InputQueue.class.getMethod("getNativePtr");
// getNativePtr_method.setAccessible(true);
FinishedInputEventCallback_class = Class.forName(InputQueue.class.getName() + "$FinishedInputEventCallback");
sendInputEvent_method = InputQueue.class.getMethod("sendInputEvent", InputEvent.class, Object.class, boolean.class,
FinishedInputEventCallback_class);
} catch (Throwable e) {
Log.e(TAG, "InputQueueCompat init", e);
}
}
private final InputQueue inputQueue;
private final Object callback;
public InputQueueCompat(InputQueue inputQueue) {
this.inputQueue = inputQueue;
if(inputQueue != null) {
callback = Proxy.newProxyInstance(InputQueue.class.getClassLoader(), new Class[]{FinishedInputEventCallback_class},
this);
} else {
callback = null;
}
}
@Override
public Object invoke(Object proxy, Method method, Object[] args) {
//void onFinishedInputEvent(Object token, boolean handled);
if ("onFinishedInputEvent".equals(method.getName())) {
Object token = args[0];
boolean handled = (boolean) args[1];
onFinishedInputEvent(token, handled);
return 0;
}
return 0;
}
public InputQueueCompat() {
this(create());
}
public void setFinishedInputEventCallback(FinishedInputEventCallbackCompat finishedInputEventCallbackCompat) {
this.finishedInputEventCallbackCompat = finishedInputEventCallbackCompat;
}
public boolean isValid() {
return inputQueue != null && sendInputEvent_method != null && getNativePtr_method != null;
}
private static InputQueue create() {
try {
return InputQueue_ctr.newInstance();
} catch (Throwable e) {
Log.w(TAG, "InputQueue<init>", e);
return null;
}
}
public long getNativePtr() {
if (getNativePtr_method == null || inputQueue == null) {
return 0;
}
try {
Long ret = (Long) getNativePtr_method.invoke(inputQueue);
if (ret == null) {
return 0;
}
return ret;
} catch (Throwable e) {
Log.w(TAG, "getNativePtr", e);
return 0;
}
}
public InputQueue getInputQueue() {
return inputQueue;
}
public void sendInputEvent(InputEvent e, Object token, boolean predispatch) {
if (sendInputEvent_method == null) {
return;
}
try {
Log.d(TAG, "inputQueue:sendInputEvent:" + e);
sendInputEvent_method.invoke(inputQueue, e, token, predispatch, callback);
} catch (Throwable ex) {
Log.w(TAG, "inputQueue:sendInputEvent", ex);
}
}
public void onFinishedInputEvent(Object token, boolean handled) {
//TODO
Log.d(TAG, "onFinishedInputEvent:" + token + ", handled=" + handled);
if(this.finishedInputEventCallbackCompat != null){
finishedInputEventCallbackCompat.onFinishedInputEvent(token, handled);
}
}
public interface FinishedInputEventCallbackCompat{
void onFinishedInputEvent(Object token, boolean handled);
}
}
package cn.garymb.ygomobile.core;
import android.annotation.SuppressLint;
import android.app.NativeActivity;
import android.os.Bundle;
import android.util.Log;
import android.util.Size;
import android.view.Gravity;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.widget.FrameLayout;
import cn.garymb.ygomobile.controller.InputQueueCompat;
public abstract class GameActivity extends NativeActivity {
protected FrameLayout mLayout;
protected SurfaceView mSurfaceView;
private boolean replaced = false;
//自定义surface,方便控制窗口大小
private static final boolean USE_SURFACE = true;
//精准触摸事件
private static final boolean USE_MY_INPUT = true;
protected InputQueueCompat inputQueueCompat;
@Override
protected final void onCreate(Bundle savedInstanceState) {
if (USE_SURFACE) {
mSurfaceView = new SurfaceView(this);
}
if (USE_MY_INPUT) {
inputQueueCompat = new InputQueueCompat();
if (!inputQueueCompat.isValid()) {
inputQueueCompat = null;
}
}
initBeforeOnCreate();
super.onCreate(savedInstanceState);
initAfterOnCreate();
}
@Override
public void onWindowFocusChanged(boolean hasFocus) {
if (hasFocus) {
if (inputQueueCompat != null) {
super.onInputQueueCreated(inputQueueCompat.getInputQueue());
}
} else {
if (inputQueueCompat != null) {
super.onInputQueueDestroyed(inputQueueCompat.getInputQueue());
}
}
super.onWindowFocusChanged(hasFocus);
}
@SuppressLint("ClickableViewAccessibility")
@Override
public void setContentView(View view) {
Size size = getGameWindowSize();
mLayout = new FrameLayout(this);
FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(size.getWidth(), size.getHeight());
// mLayout.setBackgroundColor(Color.BLACK);
lp.gravity = Gravity.CENTER;
if (USE_SURFACE) {
mLayout.addView(mSurfaceView, lp);
mLayout.addView(view, lp);
super.setContentView(mLayout);
// app().attachGame(this);
// changeGameSize();
getWindow().takeSurface(null);
if (USE_MY_INPUT && inputQueueCompat != null) {
getWindow().takeInputQueue(null);
}
replaced = true;
mSurfaceView.getHolder().addCallback(this);
mSurfaceView.requestFocus();
getWindow().setGravity(Gravity.CENTER);
if (USE_MY_INPUT && inputQueueCompat != null) {
Log.d(IrrlichtBridge.TAG, "use java input queue:" + inputQueueCompat.getNativePtr());
mSurfaceView.setOnTouchListener((v, event) -> {
onSurfaceTouch(v, event);
return true;
});
}
} else {
mLayout.addView(view, lp);
getWindow().setGravity(Gravity.CENTER);
super.setContentView(mLayout);
}
}
protected void onSurfaceTouch(View v, MotionEvent event){
if (inputQueueCompat != null) {
inputQueueCompat.sendInputEvent(event, v, true);
}
}
@Override
public void surfaceCreated(SurfaceHolder holder) {
if (USE_SURFACE) {
if (!replaced) {
return;
}
}
super.surfaceCreated(holder);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
if (USE_SURFACE) {
if (!replaced) {
return;
}
}
super.surfaceChanged(holder, format, width, height);
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
if (USE_SURFACE) {
if (!replaced) {
return;
}
}
super.surfaceDestroyed(holder);
}
@Override
public void surfaceRedrawNeeded(SurfaceHolder holder) {
if (USE_SURFACE) {
if (!replaced) {
return;
}
}
super.surfaceRedrawNeeded(holder);
}
//
// @Override
// public boolean onKeyDown(int keyCode, KeyEvent event) {
// if(inputQueueCompat != null) {
// if (keyCode == KeyEvent.KEYCODE_BACK) {
// inputQueueCompat.sendInputEvent(event, this, true);
// return true;
// }
// }
// return super.onKeyDown(keyCode, event);
// }
//
// @Override
// public boolean onKeyUp(int keyCode, KeyEvent event) {
// if(inputQueueCompat != null) {
// if (keyCode == KeyEvent.KEYCODE_BACK) {
// inputQueueCompat.sendInputEvent(event, this, true);
// return true;
// }
// }
// return super.onKeyUp(keyCode, event);
// }
protected abstract Size getGameWindowSize();
protected abstract void initBeforeOnCreate();
protected abstract void initAfterOnCreate();
}
......@@ -82,8 +82,6 @@ public final class IrrlichtBridge {
private static native void nativeJoinGame(long handle, ByteBuffer buffer, int length);
private static native void nativeSetInputFix(long handle, int x, int y);
private static final boolean DEBUG = false;
public static void setArgs(Intent intent, String[] args) {
......@@ -155,10 +153,6 @@ public final class IrrlichtBridge {
}
}
public static void setInputFix(int x, int y) {
nativeSetInputFix(sNativeHandle, x, y);
}
public static void cancelChain() {
nativeCancelChain(sNativeHandle);
}
......@@ -231,7 +225,7 @@ public final class IrrlichtBridge {
void showComboBoxCompat(String[] items, boolean isShow, int mode);
void shareFile(String title, String ext);
void shareFile(String type, String name);
void performHapticFeedback();
......@@ -244,10 +238,6 @@ public final class IrrlichtBridge {
void setNativeHandle(long nativeHandle);
int getPositionX();
int getPositionY();
void onGameExit();
}
}
package cn.garymb.ygomobile.utils;
import android.os.Build;
import java.lang.reflect.Method;
public class AndroidHideApi {
private static boolean sBypassedP = false;
public static void enableHideApi() {
if (sBypassedP) {
return;
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
try {
Method forNameMethod = Class.class.getDeclaredMethod("forName", String.class);
Class<?> clazz = (Class<?>) forNameMethod.invoke(null, "dalvik.system.VMRuntime");
Method getMethodMethod = Class.class.getDeclaredMethod("getDeclaredMethod", String.class, Class[].class);
Method getRuntime = (Method) getMethodMethod.invoke(clazz, "getRuntime", new Class[0]);
Method setHiddenApiExemptions = (Method) getMethodMethod.invoke(clazz, "setHiddenApiExemptions", new Class[]{String[].class});
Object runtime = getRuntime.invoke(null);
setHiddenApiExemptions.invoke(runtime, new Object[]{
new String[]{
"Landroid/",
"Lcom/android/",
"Ljava/lang/",
"Ldalvik/system/",
"Llibcore/io/",
"Lhuawei/"
}
});
} catch (Throwable e) {
e.printStackTrace();
}
}
sBypassedP = true;
}
}
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="combobox_choose_item">请选择其中一个</string>
<string name="ignore_chain">忽略时点</string>
<string name="react_chain">显示时点</string>
<string name="refresh_textures">刷新界面</string>
<string name="combobox_choose_item">하나를 선택하십시오 </string>
<string name="ignore_chain">시점 무시 </string>
<string name="react_chain">표시 시간 </string>
<string name="refresh_textures">인터페이스 새로 고침 </string>
<string name="tip_exit_game">게임을 종료하려면 뒤로 버튼을 다시 클릭하십시오. </string>
</resources>
\ No newline at end of file
......@@ -4,4 +4,5 @@
<string name="ignore_chain">忽略时点</string>
<string name="react_chain">显示时点</string>
<string name="refresh_textures">刷新界面</string>
<string name="tip_exit_game">再次点击返回键退出游戏</string>
</resources>
\ No newline at end of file
......@@ -5,4 +5,5 @@
<string name="ignore_chain">Ignore All Timing</string>
<string name="react_chain">Show All Timing</string>
<string name="refresh_textures">Refresh Textures</string>
<string name="tip_exit_game">Click the BACK key again to exit the game </string>
</resources>
\ No newline at end of file
......@@ -64,6 +64,16 @@ public class App extends GameApplication {
public float getYScale() {
return AppsSettings.get().getYScale(getGameWidth(), getGameHeight());
}
//
// @Override
// public int getGameHeight() {
// return 720;
// }
//
// @Override
// public int getGameWidth() {
// return 1280;
// }
@Override
public String getCardImagePath() {
......
......@@ -3,6 +3,7 @@ package cn.garymb.ygomobile;
import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Point;
import android.os.ParcelFileDescriptor;
import android.text.TextUtils;
import android.util.Log;
import android.view.WindowManager;
......@@ -18,9 +19,11 @@ import java.util.Arrays;
import java.util.List;
import java.util.Locale;
import cn.garymb.ygomobile.core.IrrlichtBridge;
import cn.garymb.ygomobile.lite.R;
import cn.garymb.ygomobile.ui.preference.PreferenceFragmentPlus;
import cn.garymb.ygomobile.utils.DeckUtil;
import cn.garymb.ygomobile.utils.DensityUtils;
import cn.garymb.ygomobile.utils.IOUtils;
import static cn.garymb.ygomobile.Constants.CORE_DECK_PATH;
......@@ -33,6 +36,7 @@ import static cn.garymb.ygomobile.Constants.DEF_PREF_KEEP_SCALE;
import static cn.garymb.ygomobile.Constants.DEF_PREF_NOTCH_HEIGHT;
import static cn.garymb.ygomobile.Constants.DEF_PREF_ONLY_GAME;
import static cn.garymb.ygomobile.Constants.DEF_PREF_READ_EX;
import static cn.garymb.ygomobile.Constants.DEF_PREF_WINDOW_TOP_BOTTOM;
import static cn.garymb.ygomobile.Constants.PREF_DEF_IMMERSIVE_MODE;
import static cn.garymb.ygomobile.Constants.PREF_DEF_SENSOR_REFRESH;
import static cn.garymb.ygomobile.Constants.PREF_FONT_SIZE;
......@@ -43,6 +47,7 @@ import static cn.garymb.ygomobile.Constants.PREF_NOTCH_HEIGHT;
import static cn.garymb.ygomobile.Constants.PREF_ONLY_GAME;
import static cn.garymb.ygomobile.Constants.PREF_READ_EX;
import static cn.garymb.ygomobile.Constants.PREF_SENSOR_REFRESH;
import static cn.garymb.ygomobile.Constants.PREF_WINDOW_TOP_BOTTOM;
import static cn.garymb.ygomobile.Constants.WINDBOT_DECK_PATH;
import static cn.garymb.ygomobile.Constants.WINDBOT_PATH;
import static cn.garymb.ygomobile.Constants.YDK_FILE_EX;
......@@ -53,8 +58,8 @@ public class AppsSettings {
private static AppsSettings sAppsSettings;
private final Point mScreenSize = new Point();
private final Point mRealScreenSize = new Point();
private Context context;
private PreferenceFragmentPlus.SharedPreferencesPlus mSharedPreferences;
private final Context context;
private final PreferenceFragmentPlus.SharedPreferencesPlus mSharedPreferences;
private float mDensity;
private AppsSettings(Context context) {
......@@ -134,6 +139,7 @@ public class AppsSettings {
}
public float getXScale(int w, int h) {
//曲面屏
if (isKeepScale()) {
float sx = getScreenHeight() / w;
float sy = getScreenWidth() / h;
......@@ -156,6 +162,15 @@ public class AppsSettings {
return mSharedPreferences.getBoolean(PREF_KEEP_SCALE, DEF_PREF_KEEP_SCALE);
}
public int getScreenPadding() {
//ListPreference都是string
String str = mSharedPreferences.getString(PREF_WINDOW_TOP_BOTTOM, null);
if (!TextUtils.isEmpty(str) && TextUtils.isDigitsOnly(str)) {
return Integer.parseInt(str);
}
return 0;
}
public float getScreenWidth() {
int w, h;
if (isImmerSiveMode()) {
......@@ -165,7 +180,11 @@ public class AppsSettings {
w = mScreenSize.x;
h = mScreenSize.y;
}
return Math.min(w, h);
int ret = Math.min(w, h);
//测试代码,曲面屏左右2变需要留空白,但是游戏画面比例不对,需要修改c那边代码
int fix_h = DensityUtils.dp2px(context, getScreenPadding());
Log.d(IrrlichtBridge.TAG, "screen padding=" + fix_h);
return ret - fix_h * 2;
}
public float getScreenHeight() {
......@@ -518,7 +537,8 @@ public class AppsSettings {
}
//获得最后卡组绝对路径
public @Nullable String getLastDeckPath() {
public @Nullable
String getLastDeckPath() {
String path;
if (TextUtils.equals(context.getString(R.string.category_pack), getLastCategory())) {
path = getResourcePath() + "/" + CORE_PACK_PATH + "/" + getLastDeckName() + YDK_FILE_EX;
......@@ -680,6 +700,6 @@ public class AppsSettings {
@Deprecated
//获取收藏文件
public File getFavoriteFile() {
return new File(getResourcePath(), CORE_SYSTEM_PATH);
return new File(getResourcePath(), "/favorite.txt");
}
}
......@@ -117,6 +117,10 @@ public interface Constants {
String PREF_KEEP_SCALE = "pref_settings_keep_scale";
boolean DEF_PREF_KEEP_SCALE = false;
//dp单位,游戏高度减少,留空白
String PREF_WINDOW_TOP_BOTTOM = "pref_settings_window_top_bottom";
int DEF_PREF_WINDOW_TOP_BOTTOM = 0;
int REQUEST_CUT_IMG = 0x1000 + 0x10;
int REQUEST_CHOOSE_FILE = 0x1000 + 0x20;
int REQUEST_CHOOSE_IMG = 0x1000 + 0x21;
......
......@@ -114,9 +114,7 @@ public class GameUriManager {
}
return new File(dir, "tmp_" + System.currentTimeMillis() + ".ydk");
} else {
if (!dir.exists()) {
dir.mkdirs();
}
IOUtils.createFolder(dir);
}
return file;
}
......@@ -180,10 +178,7 @@ public class GameUriManager {
ParcelFileDescriptor pfd = null;
FileInputStream input = null;
try {
File dir = local.getParentFile();
if (!dir.exists()) {
dir.mkdirs();
}
IOUtils.createFolder(local.getParentFile());
if (remoteFile != null) {
FileUtils.copyFile(remoteFile, local);
} else {
......
package cn.garymb.ygomobile.loader;
import android.text.TextUtils;
import android.util.Log;
import java.util.ArrayList;
import java.util.List;
import cn.garymb.ygomobile.core.IrrlichtBridge;
import ocgcore.DataManager;
import ocgcore.data.Card;
public class CardKeyWord {
private final String word;
private final List<ICardFilter> filterList = new ArrayList<>();
private final boolean empty;
public CardKeyWord(String word) {
this.word = word;
if (!TextUtils.isEmpty(word)) {
if (TextUtils.isDigitsOnly(word)) {
//搜索卡密
filterList.add(new CodeFilter(Long.parseLong(word)));
} else {
String[] ws = word.split(" ");
for (String w : ws) {
if (TextUtils.isEmpty(w)) {
continue;
}
boolean exclude = false;
if (w.startsWith("-")) {
exclude = true;
w = w.substring(1);
}
boolean onlyText = false;
if (w.startsWith("\"") || w.startsWith("“") || w.startsWith("”")) {
//只搜索文字
onlyText = true;
if (w.endsWith("\"") || w.endsWith("“") || w.endsWith("”")) {
w = w.substring(1, w.length() - 1);
} else {
w = w.substring(1);
}
}
if (!onlyText) {
long setcode = DataManager.get().getStringManager().getSetCode(w);
if (setcode != 0) {
//如果是系列名
filterList.add(new SetcodeFilter(setcode, exclude));
}
}
// Log.d(IrrlichtBridge.TAG, "filter:word=" + w + ", exclude=" + exclude + ", onlyText=" + onlyText);
filterList.add(new NameFilter(w, exclude));
}
}
}
empty = filterList.size() == 0;
}
public String getValue() {
return word;
}
public boolean isValid(Card card) {
if (empty) {
return true;
}
for (ICardFilter filter : filterList) {
if (!filter.isValid(card)) {
return false;
}
}
return true;
}
private static class NameFilter implements ICardFilter {
private final boolean exclude;
private final String word;
public NameFilter(String word, boolean exclude) {
this.exclude = exclude;
this.word = word;
}
@Override
public boolean isValid(Card card) {
if (exclude) {
return !card.Name.contains(word);
} else {
return card.Name.contains(word);
}
}
}
private static class SetcodeFilter implements ICardFilter {
private final boolean exclude;
private final long setcode;
public SetcodeFilter(long setcode, boolean exclude) {
this.exclude = exclude;
this.setcode = setcode;
}
@Override
public boolean isValid(Card card) {
if (exclude) {
return !card.isSetCode(setcode);
} else {
return card.isSetCode(setcode);
}
}
}
private static class CodeFilter implements ICardFilter {
private final long code;
public CodeFilter(long code) {
this.code = code;
}
@Override
public boolean isValid(Card card) {
return card.Code == code || card.Alias == code;
}
}
}
......@@ -91,7 +91,7 @@ public class CardLoader implements ICardSearcher {
}
public void loadData() {
loadData(null);
loadData(null, null);
}
@Override
......@@ -114,7 +114,7 @@ public class CardLoader implements ICardSearcher {
}
}
private void loadData(CardSearchInfo searchInfo) {
private void loadData(CardSearchInfo searchInfo, List<Integer> inCards) {
if (!isOpen()) {
return;
}
......@@ -129,7 +129,11 @@ public class CardLoader implements ICardSearcher {
List<Card> list = new ArrayList<>();
for (int i = 0; i < cards.size(); i++) {
Card card = cards.valueAt(i);
if (searchInfo == null || searchInfo.check(card)) {
//ָΧ
if (inCards != null && (!inCards.contains(card.Code) && !inCards.contains(card.Alias))) {
continue;
}
if (searchInfo == null || searchInfo.isValid(card)) {
list.add(card);
}
}
......@@ -178,38 +182,16 @@ public class CardLoader implements ICardSearcher {
}
@Override
public void search(String prefixWord, String suffixWord,
long attribute, long level, long race,
String limitName, long limit,
String atk, String def, long pscale,
long setcode, long category, long ot, int linkKey, long... types) {
CardSearchInfo searchInfo = new CardSearchInfo();
if (!TextUtils.isEmpty(prefixWord)) {
searchInfo.keyWord1 = prefixWord;
searchInfo.keyWordSetcode1 = mStringManager.getSetCode(prefixWord);
}
if (!TextUtils.isEmpty(suffixWord)) {
searchInfo.keyWord2 = suffixWord;
searchInfo.keyWordSetcode2 = mStringManager.getSetCode(suffixWord);
}
searchInfo.attribute = (int) attribute;
searchInfo.level = (int) level;
searchInfo.atk = atk;
searchInfo.def = def;
searchInfo.ot = (int) ot;
searchInfo.linkKey = linkKey;
searchInfo.types = types;
searchInfo.category = category;
searchInfo.race = race;
searchInfo.pscale = (int) pscale;
searchInfo.setcode = setcode;
public void search(CardSearchInfo searchInfo) {
String limitName = searchInfo.getLimitName();
int limit = searchInfo.getLimitType();
LimitList limitList = null;
List<Integer> inCards = null;
if (!TextUtils.isEmpty(limitName)) {
limitList = mLimitManager.getLimit(limitName);
setLimitList(limitList);
LimitType cardLimitType = LimitType.valueOf(limit);
if (limitList != null) {
LimitType cardLimitType = LimitType.valueOf(limit);
List<Integer> ids;
if (cardLimitType == LimitType.Forbidden) {
ids = limitList.forbidden;
......@@ -222,13 +204,11 @@ public class CardLoader implements ICardSearcher {
} else {
ids = null;
}
if (ids != null) {
searchInfo.inCards = ids;
}
inCards = ids;
}
} else {
setLimitList(null);
}
loadData(searchInfo);
loadData(searchInfo, inCards);
}
}
......@@ -8,19 +8,158 @@ import ocgcore.data.Card;
import ocgcore.enums.CardOt;
import ocgcore.enums.CardType;
class CardSearchInfo {
public class CardSearchInfo implements ICardFilter{
//名字或者描述
String keyWord1, keyWord2;
int attribute;
int level, ot, pscale = -1;
long race, category;
String atk, def;
int linkKey;
List<Integer> inCards;
long[] types;
long setcode, keyWordSetcode1, keyWordSetcode2;
private CardKeyWord keyWord;
private int attribute;
private int level;
private int ot;
private int pscale = -1;
private long race;
private long category;
private String atk;
private String def;
private int linkKey;
private long[] types;
private long setcode;
private int limitType;
private String limitName;
CardSearchInfo() {
private CardSearchInfo() {
}
public int getLimitType() {
return limitType;
}
public String getLimitName() {
return limitName;
}
public CardKeyWord getKeyWord() {
return keyWord;
}
public int getAttribute() {
return attribute;
}
public int getLevel() {
return level;
}
public int getOt() {
return ot;
}
public int getPscale() {
return pscale;
}
public long getRace() {
return race;
}
public long getCategory() {
return category;
}
public String getAtk() {
return atk;
}
public String getDef() {
return def;
}
public int getLinkKey() {
return linkKey;
}
public long[] getTypes() {
return types;
}
public long getSetcode() {
return setcode;
}
public static class Builder {
private final CardSearchInfo searchInfo = new CardSearchInfo();
public CardSearchInfo build() {
return searchInfo;
}
public Builder limitType(int limit){
searchInfo.limitType = limit;
return this;
}
public Builder limitName(String val) {
searchInfo.limitName = val;
return this;
}
public Builder keyword(String val) {
searchInfo.keyWord = new CardKeyWord(val);
return this;
}
public Builder attribute(int val) {
searchInfo.attribute = val;
return this;
}
public Builder level(int val) {
searchInfo.level = val;
return this;
}
public Builder ot(int val) {
searchInfo.ot = val;
return this;
}
public Builder pscale(int val) {
searchInfo.pscale = val;
return this;
}
public Builder race(long val) {
searchInfo.race = val;
return this;
}
public Builder category(long val) {
searchInfo.category = val;
return this;
}
public Builder atk(String val) {
searchInfo.atk = val;
return this;
}
public Builder def(String val) {
searchInfo.def = val;
return this;
}
public Builder linkKey(int linkKey) {
searchInfo.linkKey = linkKey;
return this;
}
public Builder types(long[] types) {
searchInfo.types = types;
return this;
}
public Builder setcode(long setcode) {
searchInfo.setcode = setcode;
return this;
}
}
public static boolean containsIgnoreCase(String src, String what) {
......@@ -45,32 +184,11 @@ class CardSearchInfo {
return false;
}
List<Integer> getInCards() {
return inCards;
}
public boolean check(Card card) {
if (inCards != null && !inCards.contains(Integer.valueOf(card.Code))) {
return false;
}
if (!TextUtils.isEmpty(keyWord1)) {
if (TextUtils.isDigitsOnly(keyWord1) && keyWord1.length() >= 5) {
//code
long code = Long.parseLong(keyWord1);
return card.Code == code || card.Alias == code;
} else if (!((card.Name != null && containsIgnoreCase(card.Name, keyWord1))
|| (card.Desc != null && containsIgnoreCase(card.Desc, keyWord1))
|| (keyWordSetcode1 > 0 && card.isSetCode(keyWordSetcode1)))) {
@Override
public boolean isValid(Card card) {
if(keyWord != null && !keyWord.isValid(card)){
return false;
}
}
if (!TextUtils.isEmpty(keyWord2)) {
if (!((card.Name != null && containsIgnoreCase(card.Name, keyWord2))
|| (card.Desc != null && containsIgnoreCase(card.Desc, keyWord2))
|| (keyWordSetcode2 > 0 && card.isSetCode(keyWordSetcode2)))) {
return false;
}
}
if (attribute != 0) {
if (card.Attribute != attribute) {
return false;
......@@ -113,7 +231,7 @@ class CardSearchInfo {
}
}
if (ot > CardOt.ALL.getId()) {
if(ot == CardOt.NO_EXCLUSIVE.getId()){
if (ot == CardOt.NO_EXCLUSIVE.getId()) {
if (card.Ot == CardOt.OCG.getId() || card.Ot == CardOt.TCG.getId()) {
return false;
}
......
package cn.garymb.ygomobile.loader;
import ocgcore.data.Card;
public interface ICardFilter {
boolean isValid(Card card);
}
......@@ -3,10 +3,7 @@ package cn.garymb.ygomobile.loader;
import ocgcore.data.LimitList;
public interface ICardSearcher extends ICardLoader{
void search(String prefixWord, String suffixWord,
long attribute, long level, long race,String limitName,long limit,
String atk, String def,long pscale,
long setcode, long category, long ot,int link, long... types);
void search(CardSearchInfo searchInfo);
void onReset();
void setLimitList(LimitList limit);
LimitList getLimitList();
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment