diff --git a/JGE/include/JResourceManager.h b/JGE/include/JResourceManager.h index eb86ab469..d3a787762 100644 --- a/JGE/include/JResourceManager.h +++ b/JGE/include/JResourceManager.h @@ -42,6 +42,7 @@ public: bool LoadResource(const string& resourceName); virtual void RemoveAll(); + virtual void RemoveJLBFonts(); virtual int CreateTexture(const string &textureName); virtual JTexture* GetTexture(const string &textureName); @@ -51,36 +52,19 @@ public: virtual JQuad* GetQuad(const string &quadName); virtual JQuad* GetQuad(int id); - virtual int LoadJLBFont(const string &fontName, int height); + virtual JLBFont * LoadJLBFont(const string &fontName, int height); virtual JLBFont* GetJLBFont(const string &fontName); virtual JLBFont* GetJLBFont(int id); -// int RegisterParticleEffect(const string &effectName); -// JParticleEffect* GetParticleEffect(const string &effectName); -// JParticleEffect* GetParticleEffect(int id); -// -// int RegisterMotionEmitter(const string &emitterName); -// JMotionEmitter* GetMotionEmitter(const string &emitterName); -// JMotionEmitter* GetMotionEmitter(int id); protected: - //JRenderer *mRenderer; - - //string mResourceRoot; - vector mTextureList; map mTextureMap; vector mQuadList; map mQuadMap; -// vector mParticleEffectList; -// map mParticleEffectMap; -// -// vector mMotionEmitterList; -// map mMotionEmitterMap; - vector mFontList; map mFontMap; }; diff --git a/JGE/lib/psp/libfreetype.a b/JGE/lib/psp/libfreetype.a index d245e3efd..32dac4a49 100644 Binary files a/JGE/lib/psp/libfreetype.a and b/JGE/lib/psp/libfreetype.a differ diff --git a/JGE/lib/psp/libjpeg.a b/JGE/lib/psp/libjpeg.a index f3e390e5b..8999fdc92 100644 Binary files a/JGE/lib/psp/libjpeg.a and b/JGE/lib/psp/libjpeg.a differ diff --git a/JGE/lib/psp/libmikmod.a b/JGE/lib/psp/libmikmod.a index dd54ec66e..5ee1bc09e 100644 Binary files a/JGE/lib/psp/libmikmod.a and b/JGE/lib/psp/libmikmod.a differ diff --git a/JGE/lib/psp/libpng.a b/JGE/lib/psp/libpng.a index 5f9fe008e..4c2556293 100644 Binary files a/JGE/lib/psp/libpng.a and b/JGE/lib/psp/libpng.a differ diff --git a/JGE/lib/psp/libz.a b/JGE/lib/psp/libz.a index 40023a916..d6e66e392 100644 Binary files a/JGE/lib/psp/libz.a and b/JGE/lib/psp/libz.a differ diff --git a/JGE/lib/win/jge.lib b/JGE/lib/win/jge.lib index 7034b5682..4f101ef23 100644 Binary files a/JGE/lib/win/jge.lib and b/JGE/lib/win/jge.lib differ diff --git a/JGE/src/JResourceManager.cpp b/JGE/src/JResourceManager.cpp index 6a956ad2d..bb6ab9dd1 100644 --- a/JGE/src/JResourceManager.cpp +++ b/JGE/src/JResourceManager.cpp @@ -55,6 +55,13 @@ JResourceManager::~JResourceManager() RemoveAll(); } +void JResourceManager::RemoveJLBFonts(){ + for (vector::iterator font = mFontList.begin(); font != mFontList.end(); ++font) + delete *font; + + mFontList.clear(); + mFontMap.clear(); +} void JResourceManager::RemoveAll() { @@ -70,11 +77,7 @@ void JResourceManager::RemoveAll() mQuadList.clear(); mQuadMap.clear(); - for (vector::iterator font = mFontList.begin(); font != mFontList.end(); ++font) - delete *font; - - mFontList.clear(); - mFontMap.clear(); + RemoveJLBFonts(); } @@ -82,10 +85,6 @@ bool JResourceManager::LoadResource(const string& resourceName) { string path = /*mResourceRoot + */resourceName; -// TiXmlDocument doc(path.c_str()); -// -// if (!doc.LoadFile()) return false; - JGE *engine = JGE::GetInstance(); if (engine == NULL) return false; @@ -164,11 +163,6 @@ bool JResourceManager::LoadResource(const string& resourceName) else hotspotY = height/2; -// if (element->QueryFloatAttribute("regx", &value) == TIXML_SUCCESS) -// hotspotX = width/2; -// -// if (element->QueryFloatAttribute("regy", &value) == TIXML_SUCCESS) -// hotspotY = height/2; int id = CreateQuad(quadName, textureName, x, y, width, height); if (id != INVALID_ID) @@ -179,14 +173,7 @@ bool JResourceManager::LoadResource(const string& resourceName) else if (strcmp(element->Value(), "font")==0) { } -// else if (strcmp(element->Value(), "effect")==0) -// { -// RegisterParticleEffect(element->Attribute("name")); -// } -// else if (strcmp(element->Value(), "motion_emitter")==0) -// { -// RegisterMotionEmitter(element->Attribute("name")); -// } + } } @@ -297,26 +284,22 @@ JQuad *JResourceManager::GetQuad(int id) } -int JResourceManager::LoadJLBFont(const string &fontName, int height) +JLBFont * JResourceManager::LoadJLBFont(const string &fontName, int height) { map::iterator itr = mFontMap.find(fontName); - if (itr == mFontMap.end()) - { - string path = /*mResourceRoot + */fontName; + if (itr != mFontMap.end()) return mFontList[itr->second]; - printf("creating font:%s\n", path.c_str()); + string path = fontName; - int id = mFontList.size(); - /////////////////////////////////////// - mFontList.push_back(NEW JLBFont(path.c_str(), height, true)); + int id = mFontList.size(); - mFontMap[fontName] = id; + mFontList.push_back(NEW JLBFont(path.c_str(), height, true)); + + mFontMap[fontName] = id; + + return mFontList[id]; - return id; - } - else - return itr->second; } diff --git a/JGE/src/win/JRenderer_Win.cpp b/JGE/src/win/JRenderer_Win.cpp index 425c10c77..41786ba87 100644 --- a/JGE/src/win/JRenderer_Win.cpp +++ b/JGE/src/win/JRenderer_Win.cpp @@ -76,22 +76,12 @@ void JQuad::GetTextureRect(float *x, float *y, float *w, float *h) *x=mX; *y=mY; *w=mWidth; *h=mHeight; } - -// void JQuad::SetColor(JColor color) -// { -// for (int i=0;i<4;i++) -// mColor[i].color = color.color; -// } -// - void JQuad::SetColor(PIXEL_TYPE color) { for (int i=0;i<4;i++) mColor[i].color = color; } - - void JQuad::SetHotSpot(float x, float y) { mHotSpotX = x; diff --git a/projects/mtg/include/GameStateDeckViewer.h b/projects/mtg/include/GameStateDeckViewer.h index 645e84acf..24e969dae 100644 --- a/projects/mtg/include/GameStateDeckViewer.h +++ b/projects/mtg/include/GameStateDeckViewer.h @@ -104,9 +104,7 @@ private: JMusic * bgMusic; JQuad * backQuad; SimpleMenu * welcome_menu; - JLBFont * mFont; bool showing_user_deck; - JLBFont * menuFont; SimpleMenu * menu; SimpleMenu * sellMenu; PriceList* pricelist; diff --git a/projects/mtg/include/GameStateDuel.h b/projects/mtg/include/GameStateDuel.h index 89ab8a9e9..f12d4711a 100644 --- a/projects/mtg/include/GameStateDuel.h +++ b/projects/mtg/include/GameStateDuel.h @@ -31,7 +31,6 @@ class GameStateDuel: public GameState, public JGuiListener SimpleMenu * opponentMenu; SimpleMenu * menu; bool premadeDeck; - JLBFont* mFont, *opponentMenuFont; void loadPlayer(int playerId, int decknb = 0, int isAI = 0); void loadPlayerMomir(int playerId, int isAI); diff --git a/projects/mtg/include/GameStateShop.h b/projects/mtg/include/GameStateShop.h index bcacafd87..6222e1a55 100644 --- a/projects/mtg/include/GameStateShop.h +++ b/projects/mtg/include/GameStateShop.h @@ -19,8 +19,6 @@ class GameStateShop: public GameState, public JGuiListener private: ShopItems * shop; - JLBFont * menuFont; - JLBFont * itemFont; JTexture * altThumb[8]; JQuad * mBack; JQuad * mBg; diff --git a/projects/mtg/include/SimpleMenu.h b/projects/mtg/include/SimpleMenu.h index 41691520f..73a7f96dd 100644 --- a/projects/mtg/include/SimpleMenu.h +++ b/projects/mtg/include/SimpleMenu.h @@ -19,7 +19,7 @@ class SimpleMenu:public JGuiController{ private: int mHeight, mWidth, mX, mY; - JLBFont* mFont; + int fontId; std::string title; int displaytitle; int maxItems,startId; @@ -40,7 +40,7 @@ class SimpleMenu:public JGuiController{ public: bool autoTranslate; - SimpleMenu(int id, JGuiListener* listener, JLBFont* font, int x, int y, const char * _title = "", int _maxItems = 7); + SimpleMenu(int id, JGuiListener* listener, int fontId, int x, int y, const char * _title = "", int _maxItems = 7); void Render(); void Update(float dt); void Add(int id, const char * Text,string desc = "", bool forceFocus = false); diff --git a/projects/mtg/include/SimpleMenuItem.h b/projects/mtg/include/SimpleMenuItem.h index c997a97e9..f25d2ff10 100644 --- a/projects/mtg/include/SimpleMenuItem.h +++ b/projects/mtg/include/SimpleMenuItem.h @@ -18,14 +18,14 @@ class SimpleMenuItem: public JGuiObject private: bool mHasFocus; SimpleMenu* parent; - JLBFont *mFont; + int fontId; string mText; float mScale; float mTargetScale; public: string desc; - SimpleMenuItem(SimpleMenu* _parent, int id, JLBFont *font, string text, int x, int y, bool hasFocus = false, bool autoTranslate = false); + SimpleMenuItem(SimpleMenu* _parent, int id, int fontId, string text, int x, int y, bool hasFocus = false, bool autoTranslate = false); int mX; int mY; diff --git a/projects/mtg/include/TextScroller.h b/projects/mtg/include/TextScroller.h index 293fdfdb6..2dc706868 100644 --- a/projects/mtg/include/TextScroller.h +++ b/projects/mtg/include/TextScroller.h @@ -11,7 +11,7 @@ class TextScroller: public JGuiObject{ protected: string mText; string tempText; - JLBFont * mFont; + int fontId; float mWidth; float mSpeed; float mX; @@ -25,7 +25,7 @@ public: void Add(string text); void Reset(); void setRandom(int mode = 1); - TextScroller(JLBFont * font, float x, float y, float width, float speed = 30); + TextScroller(int fontId, float x, float y, float width, float speed = 30); void Render(); void Update(float dt); virtual ostream& toString(ostream& out) const; diff --git a/projects/mtg/include/WResourceManager.h b/projects/mtg/include/WResourceManager.h index 31b79f15d..5bca99684 100644 --- a/projects/mtg/include/WResourceManager.h +++ b/projects/mtg/include/WResourceManager.h @@ -175,8 +175,9 @@ public: JTexture* GetTexture(const string &textureName); JTexture* GetTexture(int id); + int reloadJLBFonts(); //Wrapped from JResourceManger. TODO: Privatize - int LoadJLBFont(const string &fontName, int height); + JLBFont * LoadJLBFont(const string &fontName, int height); //Wrapped from JSoundSystem. TODO: Privatize. JMusic * ssLoadMusic(const char *fileName); diff --git a/projects/mtg/src/ActionLayer.cpp b/projects/mtg/src/ActionLayer.cpp index ed3fef4d2..d0e79bf71 100644 --- a/projects/mtg/src/ActionLayer.cpp +++ b/projects/mtg/src/ActionLayer.cpp @@ -219,8 +219,7 @@ void ActionLayer::setMenuObject(Targetable * object){ SAFE_DELETE(abilitiesMenu); - JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT); - abilitiesMenu = NEW SimpleMenu(10, this, mFont, 100, 100); + abilitiesMenu = NEW SimpleMenu(10, this, Constants::MAIN_FONT, 100, 100); for (int i=0;iSetTracking(-1); resources.LoadJLBFont("f3",16); resources.LoadJLBFont("magic",16); + resources.LoadJLBFont("smallface", 7); resources.RetrieveTexture("phasebar.png",RETRIEVE_MANAGE); @@ -277,6 +278,7 @@ void GameApp::Update() void GameApp::Render() { + JRenderer::GetInstance()->FillRect(0,0,10,10,ARGB(255,255,255,255)); //This is an attempt at getting rif of the purple screen bug. If you ever get a purple screen while this line is here, just delete it. if (systemError.size()){ fprintf(stderr, systemError.c_str()); JLBFont * mFont= resources.GetJLBFont("simon"); diff --git a/projects/mtg/src/GameStateDeckViewer.cpp b/projects/mtg/src/GameStateDeckViewer.cpp index d45a76f5e..256e7fad1 100644 --- a/projects/mtg/src/GameStateDeckViewer.cpp +++ b/projects/mtg/src/GameStateDeckViewer.cpp @@ -85,7 +85,7 @@ void GameStateDeckViewer::switchDisplay(){ void GameStateDeckViewer::updateDecks(){ SAFE_DELETE(welcome_menu); - welcome_menu = NEW SimpleMenu(10,this,menuFont,20,20); + welcome_menu = NEW SimpleMenu(10,this,Constants::MENU_FONT,20,20); nbDecks = fillDeckMenu(welcome_menu,options.profileFile()); deckNum = 0; newDeckname = ""; @@ -106,10 +106,8 @@ void GameStateDeckViewer::Start() myCollection = NEW DeckDataWrapper(NEW MTGDeck(options.profileFile(PLAYER_COLLECTION).c_str(), mParent->collection)); displayed_deck = myCollection; myDeck = NULL; - menuFont = resources.GetJLBFont(Constants::MENU_FONT); - mFont = resources.GetJLBFont(Constants::MAIN_FONT); - menu = NEW SimpleMenu(11,this,menuFont,SCREEN_WIDTH/2-150,20); + menu = NEW SimpleMenu(11,this,Constants::MENU_FONT,SCREEN_WIDTH/2-150,20); menu->Add(0,"Save"); menu->Add(1,"Save & Rename"); menu->Add(2,"Switch decks without saving"); @@ -143,8 +141,7 @@ void GameStateDeckViewer::Start() backQuad = resources.GetQuad("back"); - menuFont = resources.GetJLBFont("f3"); - welcome_menu = NEW SimpleMenu(10,this,menuFont,20,20); + welcome_menu = NEW SimpleMenu(10,this,Constants::MENU_FONT,20,20); nbDecks = fillDeckMenu(welcome_menu,options.profileFile()); deckNum = 0; welcome_menu->Add(nbDecks+1, "--NEW--"); @@ -293,7 +290,7 @@ void GameStateDeckViewer::Update(float dt) price = pricelist->getPrice(card->getMTGId()) / 2; price = price - price * (rnd -10)/100; sprintf(buffer,"%s : %i %s",_(card->getName()).c_str(),price,_("credits").c_str()); - sellMenu = NEW SimpleMenu(2,this,mFont,SCREEN_WIDTH-300,SCREEN_HEIGHT/2,buffer); + sellMenu = NEW SimpleMenu(2,this,Constants::MAIN_FONT,SCREEN_WIDTH-300,SCREEN_HEIGHT/2,buffer); sellMenu->Add(20,"Yes"); sellMenu->Add(21,"No","",true); } @@ -401,6 +398,7 @@ void GameStateDeckViewer::Update(float dt) void GameStateDeckViewer::renderOnScreenBasicInfo(){ + JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT); char buffer[30], buffer2[30]; float y = 0; @@ -418,6 +416,8 @@ void GameStateDeckViewer::renderOnScreenBasicInfo(){ void GameStateDeckViewer::renderSlideBar(){ + JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT); + int total = displayed_deck->getCount(colorFilter); float filler = 15; float y = SCREEN_HEIGHT_F-25; @@ -627,36 +627,36 @@ void GameStateDeckViewer::renderOnScreenMenu(){ r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255)); - mFont->DrawString(_("Lands"), 20 + leftTransition, posY); + font->DrawString(_("Lands"), 20 + leftTransition, posY); sprintf(buffer, _("%i").c_str(), stw.countLands); - mFont->DrawString(buffer, posX + leftTransition, posY); + font->DrawString(buffer, posX + leftTransition, posY); posY += 14; r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255)); - mFont->DrawString( _("Creatures"), 20 + leftTransition, posY); + font->DrawString( _("Creatures"), 20 + leftTransition, posY); sprintf(buffer, _("%i").c_str(), stw.countCreatures); - mFont->DrawString(buffer, posX + leftTransition, posY); + font->DrawString(buffer, posX + leftTransition, posY); posY += 14; r->DrawLine(20 + leftTransition, posY - 1, posX + 40 + leftTransition, posY - 1, ARGB(128, 255, 255, 255)); - mFont->DrawString(_("Spells"), 20 + leftTransition, posY); + font->DrawString(_("Spells"), 20 + leftTransition, posY); sprintf(buffer, _("%i").c_str(), stw.countSpells); - mFont->DrawString(buffer, posX + leftTransition, posY); + font->DrawString(buffer, posX + leftTransition, posY); posY += 10; - mFont->DrawString(_("Instants"), 30 + leftTransition, posY); + font->DrawString(_("Instants"), 30 + leftTransition, posY); sprintf(buffer, _("%i").c_str(), stw.countInstants); - mFont->DrawString(buffer, posX + leftTransition, posY); + font->DrawString(buffer, posX + leftTransition, posY); posY += 10; - mFont->DrawString(_("Enchantments"), 30 + leftTransition, posY); + font->DrawString(_("Enchantments"), 30 + leftTransition, posY); sprintf(buffer, _("%i").c_str(), stw.countEnchantments); - mFont->DrawString(buffer, posX + leftTransition, posY); + font->DrawString(buffer, posX + leftTransition, posY); posY += 10; - mFont->DrawString(_("Sorceries"), 30 + leftTransition, posY); + font->DrawString(_("Sorceries"), 30 + leftTransition, posY); sprintf(buffer, _("%i").c_str(), stw.countSorceries); - mFont->DrawString(buffer, posX + leftTransition, posY); + font->DrawString(buffer, posX + leftTransition, posY); //sprintf(buffer, "Artifacts: %i", stw.countArtifacts); //mFont->DrawString(buffer, 20, 123); @@ -1176,9 +1176,9 @@ int GameStateDeckViewer::countCardsByType(const char * _type) { } void GameStateDeckViewer::renderCard(int id, float rotation){ + JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT); MTGCard * card = cardIndex[id]; - float max_scale = 0.96f; float x_center_0 = 180; float right_border = SCREEN_WIDTH - 20 ; @@ -1256,9 +1256,10 @@ void GameStateDeckViewer::renderCard (int id){ renderCard(id, 0); } -void GameStateDeckViewer::Render() -{ - // void RenderQuad(JQuad* quad, float xo, float yo, float angle=0.0f, float xScale=1.0f, float yScale=1.0f); +void GameStateDeckViewer::Render() { + + JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT); + JRenderer * r = JRenderer::GetInstance(); r->ClearScreen(ARGB(0,0,0,0)); diff --git a/projects/mtg/src/GameStateDuel.cpp b/projects/mtg/src/GameStateDuel.cpp index 6258646df..fc430404f 100644 --- a/projects/mtg/src/GameStateDuel.cpp +++ b/projects/mtg/src/GameStateDuel.cpp @@ -51,7 +51,6 @@ GameStateDuel::GameStateDuel(GameApp* parent): GameState(parent) { game = NULL; deckmenu = NULL; opponentMenu = NULL; - opponentMenuFont = NULL; menu = NULL; #ifdef TESTSUITE testSuite = NULL; @@ -77,11 +76,8 @@ void GameStateDuel::Start() mGamePhase = DUEL_STATE_CHOOSE_DECK1; credits = NEW Credits(); - mFont = resources.GetJLBFont(Constants::MENU_FONT); - mFont->SetBase(0); - opponentMenuFont = mFont; - menu = NEW SimpleMenu(DUEL_MENU_GAME_MENU, this, mFont, SCREEN_WIDTH/2-100, 25); + menu = NEW SimpleMenu(DUEL_MENU_GAME_MENU, this, Constants::MENU_FONT, SCREEN_WIDTH/2-100, 25); menu->Add(12,"Back to main menu"); menu->Add(13, "Cancel"); @@ -91,7 +87,7 @@ void GameStateDuel::Start() for (int i = 0; i<2; i ++){ if (mParent->players[i] == PLAYER_TYPE_HUMAN){ decksneeded = 1; - deckmenu = NEW SimpleMenu(DUEL_MENU_CHOOSE_DECK, this, mFont, 35, 25, "Choose a Deck"); + deckmenu = NEW SimpleMenu(DUEL_MENU_CHOOSE_DECK, this, Constants::MENU_FONT, 35, 25, "Choose a Deck"); int nbDecks = fillDeckMenu(deckmenu,options.profileFile()); if (nbDecks) decksneeded = 0; break; @@ -306,7 +302,7 @@ void GameStateDuel::Update(float dt) else{ if (mParent->players[0] == PLAYER_TYPE_HUMAN){ if (!opponentMenu){ - opponentMenu = NEW SimpleMenu(DUEL_MENU_CHOOSE_OPPONENT, this, opponentMenuFont, 35, 25, "Choose Opponent"); + opponentMenu = NEW SimpleMenu(DUEL_MENU_CHOOSE_OPPONENT, this, Constants::MENU_FONT, 35, 25, "Choose Opponent"); opponentMenu->Add(0,"Random"); if (options[Options::EVILTWIN_MODE_UNLOCKED].number) opponentMenu->Add(-1,"Evil Twin", "Can you play against yourself?"); @@ -367,7 +363,6 @@ void GameStateDuel::Update(float dt) End(); Start(); } - mFont->SetColor(ARGB(255,255,255,255)); } if (mEngine->GetButtonClick(PSP_CTRL_START)){ mGamePhase = DUEL_STATE_MENU; @@ -399,6 +394,7 @@ void GameStateDuel::Update(float dt) void GameStateDuel::Render() { + JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT); //Erase LOG("Start Render\n"); JRenderer::GetInstance()->ClearScreen(ARGB(0,0,0,0)); diff --git a/projects/mtg/src/GameStateMenu.cpp b/projects/mtg/src/GameStateMenu.cpp index 89e4af27e..1547e5221 100644 --- a/projects/mtg/src/GameStateMenu.cpp +++ b/projects/mtg/src/GameStateMenu.cpp @@ -109,8 +109,9 @@ void GameStateMenu::Create() if (!langChosen){ currentState = MENU_STATE_MAJOR_LANG | MENU_STATE_MINOR_NONE; } - scroller = NEW TextScroller(resources.GetJLBFont(Constants::MAIN_FONT), SCREEN_WIDTH/2 - 90 , SCREEN_HEIGHT-17,180); + scroller = NEW TextScroller(Constants::MAIN_FONT, SCREEN_WIDTH/2 - 90 , SCREEN_HEIGHT-17,180); scrollerSet = 0; + } @@ -283,8 +284,7 @@ void GameStateMenu::setLang(int id){ } void GameStateMenu::loadLangMenu(){ - JLBFont * mFont = resources.GetJLBFont(Constants::MENU_FONT); - subMenuController = NEW SimpleMenu(103, this, mFont, 150,60); + subMenuController = NEW SimpleMenu(103, this, Constants::MENU_FONT, 150,60); if (!subMenuController) return; resetDirectory(); if (!mDip){ @@ -401,8 +401,7 @@ void GameStateMenu::Update(float dt) if (MENU_STATE_MINOR_NONE == (currentState & MENU_STATE_MINOR)) { if (!hasChosenGameType){ currentState = MENU_STATE_MAJOR_SUBMENU; - JLBFont * mFont = resources.GetJLBFont(Constants::MENU_FONT); - subMenuController = NEW SimpleMenu(102, this, mFont, 150,60); + subMenuController = NEW SimpleMenu(102, this, Constants::MENU_FONT, 150,60); if (subMenuController){ subMenuController->Add(SUBMENUITEM_CLASSIC,"Classic"); if (options[Options::MOMIR_MODE_UNLOCKED].number) @@ -546,7 +545,7 @@ JLBFont * mFont = resources.GetJLBFont(Constants::MENU_FONT); switch (controlId) { case MENUITEM_PLAY: - subMenuController = NEW SimpleMenu(102, this, mFont, 150,60); + subMenuController = NEW SimpleMenu(102, this, Constants::MENU_FONT, 150,60); if (subMenuController){ subMenuController->Add(SUBMENUITEM_1PLAYER,"1 Player"); // TODO Put 2 players mode back diff --git a/projects/mtg/src/GameStateOptions.cpp b/projects/mtg/src/GameStateOptions.cpp index dfce76345..79122034b 100644 --- a/projects/mtg/src/GameStateOptions.cpp +++ b/projects/mtg/src/GameStateOptions.cpp @@ -73,8 +73,7 @@ void GameStateOptions::Start() optionsList->failMsg = ""; optionsTabs->Add(optionsList); - JLBFont * mFont = resources.GetJLBFont("f3"); - optionsMenu = NEW SimpleMenu(-102, this,mFont, 50,170); + optionsMenu = NEW SimpleMenu(-102, this,Constants::MENU_FONT, 50,170); optionsMenu->Add(1, "Save & Back to Main Menu"); optionsMenu->Add(2, "Back to Main Menu"); optionsMenu->Add(3, "Cancel"); diff --git a/projects/mtg/src/GameStateShop.cpp b/projects/mtg/src/GameStateShop.cpp index a6fad5ca6..169fc65b6 100644 --- a/projects/mtg/src/GameStateShop.cpp +++ b/projects/mtg/src/GameStateShop.cpp @@ -48,9 +48,6 @@ void GameStateShop::Start() else mBg = NULL; - menuFont = resources.GetJLBFont(Constants::MENU_FONT); - itemFont = resources.GetJLBFont(Constants::MAIN_FONT); - JRenderer::GetInstance()->EnableVSync(true); shop = NULL; @@ -109,7 +106,7 @@ void GameStateShop::load(){ - shop = NEW ShopItems(10, this, itemFont, 10, 0, mParent->collection, setIds); + shop = NEW ShopItems(10, this, resources.GetJLBFont(Constants::MAIN_FONT), 10, 0, mParent->collection, setIds); MTGSetInfo * si = NULL; for (int i = 0; i < SHOP_BOOSTERS; i++){ si = setlist.getInfo(setIds[i]); @@ -157,7 +154,7 @@ void GameStateShop::Update(float dt) if (menu){ menu->Update(dt); }else{ - menu = NEW SimpleMenu(11,this,menuFont,SCREEN_WIDTH/2-100,20); + menu = NEW SimpleMenu(11,this,Constants::MENU_FONT,SCREEN_WIDTH/2-100,20); menu->Add(12,"Save & Back to Main Menu"); menu->Add(13, "Cancel"); } diff --git a/projects/mtg/src/OptionItem.cpp b/projects/mtg/src/OptionItem.cpp index a8aeed241..70ba1b7c2 100644 --- a/projects/mtg/src/OptionItem.cpp +++ b/projects/mtg/src/OptionItem.cpp @@ -867,8 +867,7 @@ void WDecoConfirm::Entering(u32 key){ SAFE_DELETE(confirmMenu); mState = OP_CONFIRMED; - JLBFont * mFont = resources.GetJLBFont("f3"); - confirmMenu = NEW SimpleMenu(444, listener,mFont, 50,170); + confirmMenu = NEW SimpleMenu(444, listener,Constants::MENU_FONT, 50,170); confirmMenu->Add(1,confirm.c_str()); confirmMenu->Add(2,cancel.c_str()); } diff --git a/projects/mtg/src/ShopItem.cpp b/projects/mtg/src/ShopItem.cpp index 511e203a6..a1c6ef434 100644 --- a/projects/mtg/src/ShopItem.cpp +++ b/projects/mtg/src/ShopItem.cpp @@ -257,7 +257,7 @@ void ShopItems::Update(float dt){ char buffer[4096]; sprintf(buffer,"%s : %i credits",item->getText(),price); if(!dialog){ - dialog = NEW SimpleMenu(1,this,resources.GetJLBFont(Constants::MENU_FONT),SCREEN_WIDTH-300,SCREEN_HEIGHT/2,buffer); + dialog = NEW SimpleMenu(1,this,Constants::MENU_FONT,SCREEN_WIDTH-300,SCREEN_HEIGHT/2,buffer); dialog->Add(1,"Yes"); dialog->Add(2,"No"); if(options[Options::CHEATMODE].number) { diff --git a/projects/mtg/src/SimpleMenu.cpp b/projects/mtg/src/SimpleMenu.cpp index ce72d6369..55f1007df 100644 --- a/projects/mtg/src/SimpleMenu.cpp +++ b/projects/mtg/src/SimpleMenu.cpp @@ -27,13 +27,12 @@ PIXEL_TYPE SimpleMenu::jewelGraphics[9] = {0x3FFFFFFF,0x63645AEA,0x610D0D98, 0x610D0D98,0xFF110F67,0xFD030330}; -SimpleMenu::SimpleMenu(int id, JGuiListener* listener, JLBFont* font, int x, int y, const char * _title, int _maxItems): JGuiController(id, listener){ +SimpleMenu::SimpleMenu(int id, JGuiListener* listener, int fontId, int x, int y, const char * _title, int _maxItems): JGuiController(id, listener), fontId(fontId){ autoTranslate = true; mHeight = 2 * VMARGIN; mWidth = 0; mX = x; mY = y; - mFont = font; title = _(_title); startId = 0; maxItems = _maxItems; @@ -52,11 +51,6 @@ SimpleMenu::SimpleMenu(int id, JGuiListener* listener, JLBFont* font, int x, int if (NULL == spadeR) spadeR = resources.RetrieveQuad("spade_ur.png", 2, 1, 16, 13, "spade_ur", RETRIEVE_MANAGE); if (NULL == jewel) jewel = NEW JQuad(jewelTex, 1, 1, 3, 3); if (NULL == side) side = resources.RetrieveQuad("menuside.png", 1, 1, 1, 7,"menuside", RETRIEVE_MANAGE); - - if (NULL == titleFont) { - resources.LoadJLBFont("smallface", 7); - titleFont = resources.GetJLBFont("smallface"); - } if (NULL == stars) { JQuad * starQuad = resources.GetQuad("stars"); @@ -94,6 +88,8 @@ void SimpleMenu::drawVertPole(int x, int y, int height) { } void SimpleMenu::Render() { + JLBFont * titleFont = resources.GetJLBFont("smallface"); + JLBFont * mFont = resources.GetJLBFont(fontId); if (0 == mWidth) { float sY = mY + VMARGIN; for (int i = startId; i < startId + mCount; ++i) { @@ -167,7 +163,7 @@ void SimpleMenu::Update(float dt){ } void SimpleMenu::Add(int id, const char * text,string desc, bool forceFocus){ - SimpleMenuItem * smi = NEW SimpleMenuItem(this, id, mFont, text, 0, mY + VMARGIN + mCount*LINE_HEIGHT, (mCount == 0),autoTranslate); + SimpleMenuItem * smi = NEW SimpleMenuItem(this, id, fontId, text, 0, mY + VMARGIN + mCount*LINE_HEIGHT, (mCount == 0),autoTranslate); smi->desc = desc; JGuiController::Add(smi); if (mCount <= maxItems) mHeight += LINE_HEIGHT; diff --git a/projects/mtg/src/SimpleMenuItem.cpp b/projects/mtg/src/SimpleMenuItem.cpp index 846f8142b..d903c82af 100644 --- a/projects/mtg/src/SimpleMenuItem.cpp +++ b/projects/mtg/src/SimpleMenuItem.cpp @@ -1,8 +1,9 @@ #include "../include/config.h" #include "../include/SimpleMenuItem.h" #include "../include/Translate.h" +#include "../include/WResourceManager.h" -SimpleMenuItem::SimpleMenuItem(SimpleMenu* _parent, int id, JLBFont *font, string text, int x, int y, bool hasFocus, bool autoTranslate): JGuiObject(id), parent(_parent), mFont(font), mX(x), mY(y) +SimpleMenuItem::SimpleMenuItem(SimpleMenu* _parent, int id, int fontId, string text, int x, int y, bool hasFocus, bool autoTranslate): JGuiObject(id), parent(_parent), fontId(fontId), mX(x), mY(y) { if (autoTranslate) mText = _(text); else mText = text; @@ -18,6 +19,7 @@ SimpleMenuItem::SimpleMenuItem(SimpleMenu* _parent, int id, JLBFont *font, strin void SimpleMenuItem::RenderWithOffset(float yOffset) { + JLBFont * mFont = resources.GetJLBFont(fontId); //mFont->SetColor(ARGB(255,255,255,255)); mFont->DrawString(mText.c_str(), mX, mY + yOffset, JGETEXT_CENTER); } @@ -71,6 +73,7 @@ void SimpleMenuItem::Relocate(int x, int y) int SimpleMenuItem::GetWidth() { + JLBFont * mFont = resources.GetJLBFont(fontId); mFont->SetScale(1.0); return mFont->GetStringWidth(mText.c_str()); } @@ -84,7 +87,6 @@ ostream& SimpleMenuItem::toString(ostream& out) const { return out << "SimpleMenuItem ::: mHasFocus : " << mHasFocus << " ; parent : " << parent - << " ; mFont : " << mFont << " ; mText : " << mText << " ; mScale : " << mScale << " ; mTargetScale : " << mTargetScale diff --git a/projects/mtg/src/TextScroller.cpp b/projects/mtg/src/TextScroller.cpp index 17e8f70e9..a8a9db9d5 100644 --- a/projects/mtg/src/TextScroller.cpp +++ b/projects/mtg/src/TextScroller.cpp @@ -1,9 +1,9 @@ #include "../include/TextScroller.h" +#include "../include/WResourceManager.h" #include "../include/utils.h" #include -TextScroller::TextScroller(JLBFont * font, float x, float y, float width, float speed):JGuiObject(0){ - mFont = font; +TextScroller::TextScroller(int fontId, float x, float y, float width, float speed):JGuiObject(0),fontId(fontId){ mWidth = width; mSpeed = speed; mX = x; @@ -35,6 +35,7 @@ void TextScroller::Update(float dt){ if(!strings.size()) return; start+=mSpeed*dt; + JLBFont * mFont = resources.GetJLBFont(fontId); if (start > mFont->GetStringWidth(mText.c_str())){ start = -mWidth; if (mRandom){ @@ -49,6 +50,7 @@ void TextScroller::Update(float dt){ } void TextScroller::Render(){ + JLBFont * mFont = resources.GetJLBFont(fontId); mFont->DrawString(mText.c_str(),mX,mY,JGETEXT_LEFT,start,mWidth); } @@ -56,7 +58,6 @@ ostream& TextScroller::toString(ostream& out) const { return out << "TextScroller ::: mText : " << mText << " ; tempText : " << tempText - << " ; mFont : " << mFont << " ; mWidth : " << mWidth << " ; mSpeed : " << mSpeed << " ; mX,mY : " << mX << "," << mY diff --git a/projects/mtg/src/WResourceManager.cpp b/projects/mtg/src/WResourceManager.cpp index 2f8e4056c..479403655 100644 --- a/projects/mtg/src/WResourceManager.cpp +++ b/projects/mtg/src/WResourceManager.cpp @@ -767,24 +767,38 @@ int WResourceManager::fileOK(string filename, bool relative){ return result; } -int WResourceManager::LoadJLBFont(const string &fontName, int height){ +int WResourceManager::reloadJLBFonts(){ + vector fontNames; + vector fontSizes; + fontNames.resize(mFontList.size()); + fontSizes.resize(mFontList.size()); + for ( map::iterator itr = mFontMap.begin(); itr != mFontMap.end(); ++itr){ + fontNames[itr->second] = itr->first; + fontSizes[itr->second] = mFontList[itr->second]->GetHeight(); + } + + RemoveJLBFonts(); + + for(size_t i = 0; i < fontNames.size(); ++i){ + LoadJLBFont(fontNames[i],fontSizes[i]); + } + return 1; +} + + +JLBFont * WResourceManager::LoadJLBFont(const string &fontName, int height){ map::iterator itr = mFontMap.find(fontName); - if (itr == mFontMap.end()) - { - string path = graphicsFile(fontName); + if (itr != mFontMap.end()) return mFontList[itr->second]; - printf("creating font:%s\n", path.c_str()); + string mFontName = fontName + ".png"; + string path = graphicsFile(mFontName); + if (path.size() > 4 ) path = path.substr(0, path.size() - 4); //some stupid manipulation because of the way JLBFont works in JGE + int id = mFontList.size(); + mFontList.push_back(NEW JLBFont(path.c_str(), height, true)); + mFontMap[fontName] = id; - int id = mFontList.size(); - mFontList.push_back(NEW JLBFont(path.c_str(), height, true)); - - mFontMap[fontName] = id; - - return id; - } - else - return itr->second; + return mFontList[id]; } @@ -809,6 +823,7 @@ JMusic * WResourceManager::ssLoadMusic(const char *fileName){ void WResourceManager::Refresh(){ //Really easy cache relinking. + reloadJLBFonts(); sampleWCache.Refresh(); textureWCache.Refresh(); psiWCache.Refresh();