Files
wagic/projects/mtg/src/ActionLayer.cpp
wagic.the.homebrew 6d1d5d751a Erwan
- new Ability : ALifeGiver (bottle gnomes)
- Added a few cards from Tempest
- Hybrid mana fix for hybrid mana involving uncolored mana costs (see tests/generic/hybridmana2.txt - spectral possession)
- Fixed bugs with targetting for TargetAbilities
- Fixed multiple sacrifice abilities cost (Siege gang commander, see tests)
- Fixed a small font issue
2009-02-11 09:38:20 +00:00

201 lines
4.8 KiB
C++

#include "../include/config.h"
#include "../include/ActionLayer.h"
#include "../include/GameObserver.h"
#include "../include/Targetable.h"
int ActionLayer::unstopableRenderInProgress(){
for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if (currentAction->getActivity() > 0){
return 1;
}
}
}
return 0;
}
bool ActionLayer::CheckUserInput(u32 key){
if (menuObject){
return false;
}
for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if (currentAction->CheckUserInput(key)) return true;
}
}
return false;
}
void ActionLayer::Update(float dt){
if (menuObject){
abilitiesMenu->Update(dt);
return;
}
modal = 0;
for (int i=mCount -1 ;i>=0;i--){
if (mObjects[i]!= NULL){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if (currentAction->testDestroy()){
currentAction->destroy();
Remove(currentAction);
}
}
}
int newPhase = GameObserver::GetInstance()->getCurrentGamePhase();
for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL){
ActionElement * currentAction = (ActionElement *)mObjects[i];
currentAction->newPhase = newPhase;
currentAction->Update(dt);
currentAction->currentPhase = newPhase;
}
}
}
void ActionLayer::Render (){
if (menuObject){
abilitiesMenu->Render();
return;
}
for (int i=0;i<mCount;i++){
if (mObjects[i]!=NULL){
ActionElement * currentAction = (ActionElement *)mObjects[i];
//if (currentAction->getActivity() > 0){
currentAction->Render();
//return;
//}
}
}
}
TargetChooser * ActionLayer::getCurrentTargetChooser(){
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer) return currentAction->tc;
}
return NULL;
}
int ActionLayer::isWaitingForAnswer(){
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer) return 1;
}
return 0;
}
int ActionLayer::isReactingToTargetClick(Targetable * card){
int result = 0;
if (isWaitingForAnswer()) return -1;
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
result += currentAction->isReactingToTargetClick(card);
}
return result;
}
int ActionLayer::reactToTargetClick(Targetable * card){
int result = 0;
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer){
return currentAction->reactToTargetClick(card);
}
}
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
result += currentAction->reactToTargetClick(card);
}
return result;
}
//TODO Simplify with only object !!!
int ActionLayer::isReactingToClick(MTGCardInstance * card){
int result = 0;
if (isWaitingForAnswer()) return -1;
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
result += currentAction->isReactingToClick(card);
}
return result;
}
int ActionLayer::reactToClick(MTGCardInstance * card){
int result = 0;
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if(currentAction->waitingForAnswer){
return currentAction->reactToClick(card);
}
}
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
OutputDebugString(currentAction->getMenuText());
result += currentAction->reactToClick(card);
if (result) return result;
}
return result;
}
void ActionLayer::setMenuObject(Targetable * object){
menuObject = object;
SAFE_DELETE(abilitiesMenu);
JLBFont * mFont = GameApp::CommonRes->GetJLBFont(Constants::MAIN_FONT);
abilitiesMenu = NEW SimpleMenu(10, this, mFont, 100, 100);
for (int i=0;i<mCount;i++){
ActionElement * currentAction = (ActionElement *)mObjects[i];
if (currentAction->isReactingToTargetClick(object)){
abilitiesMenu->Add(i,currentAction->getMenuText());
}
}
abilitiesMenu->Add(-1, "Cancel");
modal = 1;
}
void ActionLayer::doReactTo(int menuIndex){
if (menuObject){
int controlid = abilitiesMenu->mObjects[menuIndex]->GetId();
char buf[4096];
sprintf(buf, "doReact To %i\n",controlid);
OutputDebugString(buf);
ActionElement * currentAction = (ActionElement *)mObjects[controlid];
currentAction->reactToTargetClick(menuObject);
menuObject = 0;
}
}
void ActionLayer::ButtonPressed(int controllerid, int controlid){
if (controlid == -1){
}else{
ActionElement * currentAction = (ActionElement *)mObjects[controlid];
currentAction->reactToTargetClick(menuObject);
}
menuObject = 0;
}