diff --git a/projects/mtg/include/GameOptions.h b/projects/mtg/include/GameOptions.h index 9511747a8..c2f984369 100644 --- a/projects/mtg/include/GameOptions.h +++ b/projects/mtg/include/GameOptions.h @@ -32,6 +32,7 @@ public: OSD, CLOSEDHAND, HANDDIRECTION, + MANADISPLAY, REVERSETRIGGERS, DISABLECARDS, INTERRUPT_SECONDS, diff --git a/projects/mtg/include/GuiMana.h b/projects/mtg/include/GuiMana.h index 81b54f49d..f28f20842 100644 --- a/projects/mtg/include/GuiMana.h +++ b/projects/mtg/include/GuiMana.h @@ -9,9 +9,6 @@ class ManaIcon : public Pos { - static const float DESTX; - static const float DESTY; - hgeParticleSystem* particleSys; JQuad* icon; @@ -20,6 +17,7 @@ class ManaIcon : public Pos float yP1, yP2, yP3; float tP1; float f; + float destx,desty; public: enum { ALIVE, WITHERING, DROPPING, DEAD } mode; int color; @@ -27,7 +25,7 @@ class ManaIcon : public Pos void Update(float dt, float shift); void Wither(); void Drop(); - ManaIcon(int color, float x, float y); + ManaIcon(int color, float x, float y,float destx, float desty); ~ManaIcon(); }; @@ -35,8 +33,11 @@ class GuiMana : public GuiLayer { protected: vector manas; + float x, y; + Player * owner; + void RenderStatic(); public: - GuiMana(); + GuiMana(float x, float y, Player *p); ~GuiMana(); virtual void Render(); virtual void Update(float dt); diff --git a/projects/mtg/include/OptionItem.h b/projects/mtg/include/OptionItem.h index bf6c85a8d..e8c244302 100644 --- a/projects/mtg/include/OptionItem.h +++ b/projects/mtg/include/OptionItem.h @@ -249,4 +249,17 @@ private: static EnumDefinition * definition; }; +class OptionManaDisplay : public OptionEnum { + public: + friend class GameSettings; + enum { DYNAMIC = 0, STATIC = 1, BOTH = 2}; + OptionManaDisplay(int id, string displayValue); + + static EnumDefinition * getDefinition(); + EnumDefinition * ourDefined() const { return getDefinition();}; + +private: + static EnumDefinition * definition; +}; + #endif diff --git a/projects/mtg/src/DuelLayers.cpp b/projects/mtg/src/DuelLayers.cpp index 641a24df8..bff9f01c8 100644 --- a/projects/mtg/src/DuelLayers.cpp +++ b/projects/mtg/src/DuelLayers.cpp @@ -30,7 +30,8 @@ void DuelLayers::init(){ //Other display elements action->Add(NEW HUDDisplay(-1)); - Add(NEW GuiMana()); + Add(NEW GuiMana(20,20,go->players[1])); + Add(NEW GuiMana(440,20,go->players[0])); Add(stack = NEW ActionStack(go)); Add(combat = NEW GuiCombat(go)); Add(action); diff --git a/projects/mtg/src/GameOptions.cpp b/projects/mtg/src/GameOptions.cpp index 2a22be12e..03b08f428 100644 --- a/projects/mtg/src/GameOptions.cpp +++ b/projects/mtg/src/GameOptions.cpp @@ -19,6 +19,7 @@ const char * Options::optionNames[] = { "displayOSD", "closed_hand", "hand_direction", + "mana_display", "reverse_triggers", "disable_cards", "interruptSeconds", @@ -317,6 +318,8 @@ bool GameOptions::load_option(int id, string input){ return read_enum(id, input, OptionHandDirection::getDefinition()); case Options::CLOSEDHAND: return read_enum(id, input, OptionClosedHand::getDefinition()); + case Options::MANADISPLAY: + return read_enum(id, input, OptionManaDisplay::getDefinition()); default: return read_default(id, input); } @@ -353,6 +356,8 @@ bool GameOptions::save_option(std::ofstream * file, int id, string name, GameOpt return write_enum(file, name, opt, OptionHandDirection::getDefinition()); case Options::CLOSEDHAND: return write_enum(file, name, opt, OptionClosedHand::getDefinition()); + case Options::MANADISPLAY: + return write_enum(file, name, opt, OptionManaDisplay::getDefinition()); default: return write_default(file, name, opt); } @@ -442,6 +447,7 @@ GameSettings::~GameSettings(){ SAFE_DELETE(keypad); SAFE_DELETE(OptionHandDirection::definition); SAFE_DELETE(OptionClosedHand::definition); + SAFE_DELETE(OptionManaDisplay::definition); } GameOption GameSettings::invalid_option = GameOption(0); diff --git a/projects/mtg/src/GameStateOptions.cpp b/projects/mtg/src/GameStateOptions.cpp index 2856c3a46..c3c686461 100644 --- a/projects/mtg/src/GameStateOptions.cpp +++ b/projects/mtg/src/GameStateOptions.cpp @@ -44,6 +44,7 @@ void GameStateOptions::Start() optionsList = NEW OptionsList("Game"); optionsList->Add(NEW OptionClosedHand(Options::CLOSEDHAND, "Closed hand")); optionsList->Add(NEW OptionHandDirection(Options::HANDDIRECTION, "Hand direction")); + optionsList->Add(NEW OptionManaDisplay(Options::MANADISPLAY, "Mana display")); optionsList->Add(NEW OptionInteger(Options::REVERSETRIGGERS, "Reverse left and right triggers")); optionsList->Add(NEW OptionInteger(Options::DISABLECARDS,"Disable card image loading")); optionsTabs->Add(optionsList); diff --git a/projects/mtg/src/GuiHand.cpp b/projects/mtg/src/GuiHand.cpp index a96d40877..f984b9e89 100644 --- a/projects/mtg/src/GuiHand.cpp +++ b/projects/mtg/src/GuiHand.cpp @@ -164,6 +164,7 @@ bool GuiHandSelf::CheckUserInput(u32 key) return false; } + void GuiHandSelf::Update(float dt) { backpos.Update(dt); diff --git a/projects/mtg/src/GuiMana.cpp b/projects/mtg/src/GuiMana.cpp index 85c7b1d18..a475d1803 100644 --- a/projects/mtg/src/GuiMana.cpp +++ b/projects/mtg/src/GuiMana.cpp @@ -1,14 +1,13 @@ #include #include "../include/GuiMana.h" +#include "../include/OptionItem.h" + using std::cout; using std::endl; -const float ManaIcon::DESTX = 440; -const float ManaIcon::DESTY = 20; - -ManaIcon::ManaIcon(int color, float x, float y) : Pos(x, y, 0.5, 0.0, 255), f(-1), mode(ALIVE), color(color) +ManaIcon::ManaIcon(int color, float x, float y, float destx, float desty) : Pos(x, y, 0.5, 0.0, 255), f(-1), destx(destx), desty(desty), mode(ALIVE), color(color) { hgeParticleSystemInfo * psi = NULL; JQuad * mq = resources.GetQuad("stars"); @@ -145,6 +144,9 @@ void ManaIcon::Update(float dt, float shift) zoomP3 += zoomP5 * dt; zoomP4 += zoomP6 * dt; + if (OptionManaDisplay::STATIC == options[Options::MANADISPLAY].number) + shift = 0; + switch (mode) { case DROPPING : @@ -162,33 +164,41 @@ void ManaIcon::Update(float dt, float shift) if (f < 0) mode = DEAD; break; case ALIVE : - x += 10 * dt * (DESTX - x); - y += 10 * dt * (DESTY + shift - y); + x += 10 * dt * (destx - x); + y += 10 * dt * (desty + shift - y); yP1 += yP3 * dt; actY = y + yP2 * sinf(M_PI * yP1); + + if (particleSys && (fabs(destx - x) < 5) && (fabs(desty + shift - y) < 5)){ + if (OptionManaDisplay::STATIC == options[Options::MANADISPLAY].number){ + SAFE_DELETE(particleSys); //Static Mana Only: avoid expensive particle processing + } + } break; case DEAD : break; } - particleSys->MoveTo(actX, actY); - particleSys->Update(dt); + if (particleSys){ + particleSys->MoveTo(actX, actY); + particleSys->Update(dt); + } } void ManaIcon::Wither() { mode = WITHERING; f = 1.0; - particleSys->Stop(); + if (particleSys) particleSys->Stop(); } void ManaIcon::Drop() { mode = DROPPING; if (f < 0) f = 0; - particleSys->Stop(); + if (particleSys) particleSys->Stop(); } -GuiMana::GuiMana() +GuiMana::GuiMana(float x, float y, Player *p):x(x),y(y),owner(p) { } @@ -198,11 +208,56 @@ GuiMana::~GuiMana(){ } } + +void GuiMana::RenderStatic(){ + int values[Constants::MTG_NB_COLORS]; + int totalColors = 0; + JLBFont * mFont = resources.GetJLBFont(Constants::MAIN_FONT); + JRenderer * r = JRenderer::GetInstance(); + for (int i = 0; i < Constants::MTG_NB_COLORS; ++i) + values[i] = 0; + for (vector::iterator it = manas.begin(); it != manas.end(); ++it) + if (ManaIcon::ALIVE == (*it)->mode) { + values[(*it)->color]++; + if (values[(*it)->color] == 1) totalColors++; + } + + if (!totalColors) return; + + float x0 = x - 20*totalColors; + if (x0 < 10) x0 = 10; + float xEnd = x0 + 20*totalColors; + r->FillRoundRect(x0,y - 5 ,20*totalColors + 5,20,2,ARGB(128,0,0,0)); + + int offset = 0; + for (int i = 0; i < Constants::MTG_NB_COLORS; ++i){ + if (values[i]){ + offset-=20; + r->RenderQuad(manaIcons[i],xEnd + 15 + offset, y + 5,0,0.7,0.7); + } + } + r->FillRoundRect(x0,y ,20*totalColors + 5,8,2,ARGB(100,0,0,0)); + offset = 0; + for (int i = 0; i < Constants::MTG_NB_COLORS; ++i){ + if (values[i]){ + offset-=20; + char buf[4]; + sprintf(buf,"%i",values[i]); + mFont->SetColor(ARGB(255,255,255,255)); + mFont->DrawString(buf,xEnd+offset + 9, y); + } + } +} + void GuiMana::Render() { - + for (vector::iterator it = manas.begin(); it != manas.end(); ++it) (*it)->Render(); + + if (OptionManaDisplay::DYNAMIC != options[Options::MANADISPLAY].number) + RenderStatic(); + } bool remove_dead(ManaIcon* m) { return ManaIcon::DEAD != m->mode; } void GuiMana::Update(float dt) @@ -225,10 +280,11 @@ int GuiMana::receiveEventPlus(WEvent* e) { if (WEventEngageMana *event = dynamic_cast(e)) { + if (event->destination != owner->getManaPool()) return 0; if (event->card && event->card->view) - manas.push_back(NEW ManaIcon(event->color, event->card->view->actX, event->card->view->actY)); + manas.push_back(NEW ManaIcon(event->color, event->card->view->actX, event->card->view->actY, x, y)); else - manas.push_back(NEW ManaIcon(event->color, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2)); + manas.push_back(NEW ManaIcon(event->color, SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, x, y)); return 1; } else return 0; @@ -238,14 +294,19 @@ int GuiMana::receiveEventMinus(WEvent* e) { if (WEventConsumeMana *event = dynamic_cast(e)) { + if (event->source != owner->getManaPool()) return 0; for (vector::iterator it = manas.begin(); it != manas.end(); ++it) - if ((event->color == (*it)->color) && (ManaIcon::ALIVE == (*it)->mode)) { (*it)->Wither(); return 1; } + if ((event->color == (*it)->color) && (ManaIcon::ALIVE == (*it)->mode)) { + (*it)->Wither(); + return 1; + } return 1; } - else if (dynamic_cast(e)) + else if (WEventEmptyManaPool *event2 = dynamic_cast(e)) { + if (event2->source != owner->getManaPool()) return 0; for (vector::iterator it = manas.begin(); it != manas.end(); ++it) - (*it)->Drop(); //TODO: split according to which manapool was emptied... + (*it)->Drop(); return 1; } return 0; diff --git a/projects/mtg/src/OptionItem.cpp b/projects/mtg/src/OptionItem.cpp index fa3b9178a..fd916f6bc 100644 --- a/projects/mtg/src/OptionItem.cpp +++ b/projects/mtg/src/OptionItem.cpp @@ -903,3 +903,22 @@ OptionHandDirection::OptionHandDirection(int id, string displayName) : OptionEnu getDefinition(); Reload(); }; + +EnumDefinition * OptionManaDisplay::definition = NULL; + +EnumDefinition * OptionManaDisplay::getDefinition(){ + if(!definition){ + definition = NEW EnumDefinition(); + definition->values.push_back(EnumDefinition::assoc(STATIC, "simple")); + definition->values.push_back(EnumDefinition::assoc(DYNAMIC, "Eye candy")); + definition->values.push_back(EnumDefinition::assoc(BOTH, "Both")); + } + return definition; +} + +OptionManaDisplay::OptionManaDisplay(int id, string displayName) : OptionEnum(id, displayName) +{ + getDefinition(); + Reload(); +}; + diff --git a/projects/mtg/src/WResourceManager.cpp b/projects/mtg/src/WResourceManager.cpp index 3cc1d4fd1..d98094d88 100644 --- a/projects/mtg/src/WResourceManager.cpp +++ b/projects/mtg/src/WResourceManager.cpp @@ -304,10 +304,8 @@ JQuad * WResourceManager::RetrieveQuad(string filename, float offX, float offY, //No quad, but we have a managed texture for this! WCachedTexture * jtex = NULL; - if(style == RETRIEVE_MANAGE) - jtex = textureWCache.Retrieve(filename,RETRIEVE_MANAGE,submode); - else if(style == RETRIEVE_EXISTING) - jtex = textureWCache.Retrieve(filename,RETRIEVE_EXISTING,submode); + if(style == RETRIEVE_MANAGE || style == RETRIEVE_EXISTING) + jtex = textureWCache.Retrieve(filename,style,submode); else jtex = textureWCache.Retrieve(filename,RETRIEVE_NORMAL,submode); @@ -1194,11 +1192,8 @@ cacheItem * WCache::Get(string id, int style, int submod string lookup = makeID(id,submode); //Check for managed resources first. Always - it = managed.end(); - for(it = managed.begin();it!=managed.end();it++){ - if(it->first == lookup) - break; - } + it = managed.find(lookup); + //Something is managed. if(it != managed.end()) { if(!it->second && style == RETRIEVE_RESOURCE) @@ -1214,11 +1209,7 @@ cacheItem * WCache::Get(string id, int style, int submod //Not managed, so look in cache. if(it == managed.end() && style != RETRIEVE_MANAGE && style != RETRIEVE_RESOURCE ){ - it = cache.end(); - for(it = cache.begin();it!=cache.end();it++){ - if(it->first == lookup) - break; - } + it = cache.find(lookup); //Well, we've found something... if(it != cache.end()) { if(!it->second && (submode & CACHE_EXISTING)){