Avoid more conflicts. We could now do unit builds...

and make the linker put every data element and function into its own section.
On linktime, we can output every discarded section and get a list of dead
code (for that build).
This commit is contained in:
Tobias Loose
2013-11-23 17:04:24 +01:00
parent 3e94de985f
commit e0428ac7b0
6 changed files with 81 additions and 81 deletions

View File

@@ -7,42 +7,42 @@
#include "Closest.cpp" #include "Closest.cpp"
#include "GameObserver.h" #include "GameObserver.h"
struct Left: public Exp struct CardSelectorLeft: public Exp
{ {
static inline bool test(CardSelector::Target* ref, CardSelector::Target* test) static inline bool test(CardSelector::Target* ref, CardSelector::Target* test)
{ {
return ref->x - test->x > fabs(ref->y - test->y); return ref->x - test->x > fabs(ref->y - test->y);
} }
}; };
struct Right: public Exp struct CardSelectorRight: public Exp
{ {
static inline bool test(CardSelector::Target* ref, CardSelector::Target* test) static inline bool test(CardSelector::Target* ref, CardSelector::Target* test)
{ {
return test->x - ref->x > fabs(ref->y - test->y); return test->x - ref->x > fabs(ref->y - test->y);
} }
}; };
struct Up: public Exp struct CardSelectorUp: public Exp
{ {
static inline bool test(CardSelector::Target* ref, CardSelector::Target* test) static inline bool test(CardSelector::Target* ref, CardSelector::Target* test)
{ {
return ref->y - test->y > fabs(ref->x - test->x); return ref->y - test->y > fabs(ref->x - test->x);
} }
}; };
struct Down: public Exp struct CardSelectorDown: public Exp
{ {
static inline bool test(CardSelector::Target* ref, CardSelector::Target* test) static inline bool test(CardSelector::Target* ref, CardSelector::Target* test)
{ {
return test->y - ref->y > fabs(ref->x - test->x); return test->y - ref->y > fabs(ref->x - test->x);
} }
}; };
struct Diff: public Exp struct CardSelectorDiff: public Exp
{ {
static inline bool test(CardSelector::Target* ref, CardSelector::Target* test) static inline bool test(CardSelector::Target* ref, CardSelector::Target* test)
{ {
return ref != test; return ref != test;
} }
}; };
struct True: public Exp struct CardSelectorTrue: public Exp
{ {
static inline bool test(CardSelector::Target*, CardSelector::Target*) static inline bool test(CardSelector::Target*, CardSelector::Target*)
{ {
@@ -94,7 +94,7 @@ void CardSelector::Remove(CardSelector::Target* card)
CardView* c = dynamic_cast<CardView*> (active); CardView* c = dynamic_cast<CardView*> (active);
if (c) if (c)
c->zoom = 1.0f; c->zoom = 1.0f;
active = closest<Diff> (cards, limitor, active); active = closest<CardSelectorDiff> (cards, limitor, active);
c = dynamic_cast<CardView*> (active); c = dynamic_cast<CardView*> (active);
if (c) if (c)
c->zoom = 1.4f; c->zoom = 1.4f;
@@ -120,7 +120,7 @@ CardSelector::Target* CardSelector::fetchMemory(SelectorMemory& memory)
} }
// We come here if the card is not in the selector any more, or if // We come here if the card is not in the selector any more, or if
// it is there but it is now refused by the limitor. // it is there but it is now refused by the limitor.
return closest<True> (cards, limitor, memory.x, memory.y); return closest<CardSelectorTrue> (cards, limitor, memory.x, memory.y);
} }
void CardSelector::Push() void CardSelector::Push()
@@ -182,7 +182,7 @@ bool CardSelector::CheckUserInput(JButton key)
if(!jge) return false; if(!jge) return false;
if(jge->GetLeftClickCoordinates(x, y)) if(jge->GetLeftClickCoordinates(x, y))
{ {
active = closest<True> (cards, limitor, static_cast<float> (x), static_cast<float> (y)); active = closest<CardSelectorTrue> (cards, limitor, static_cast<float> (x), static_cast<float> (y));
} }
switch (key) switch (key)
@@ -196,16 +196,16 @@ bool CardSelector::CheckUserInput(JButton key)
goto switch_active; goto switch_active;
break; break;
case JGE_BTN_LEFT: case JGE_BTN_LEFT:
active = closest<Left> (cards, limitor, active); active = closest<CardSelectorLeft> (cards, limitor, active);
break; break;
case JGE_BTN_RIGHT: case JGE_BTN_RIGHT:
active = closest<Right> (cards, limitor, active); active = closest<CardSelectorRight> (cards, limitor, active);
break; break;
case JGE_BTN_UP: case JGE_BTN_UP:
active = closest<Up> (cards, limitor, active); active = closest<CardSelectorUp> (cards, limitor, active);
break; break;
case JGE_BTN_DOWN: case JGE_BTN_DOWN:
active = closest<Down> (cards, limitor, active); active = closest<CardSelectorDown> (cards, limitor, active);
break; break;
case JGE_BTN_CANCEL: case JGE_BTN_CANCEL:
mDrawMode = (mDrawMode + 1) % DrawMode::kNumDrawModes; mDrawMode = (mDrawMode + 1) % DrawMode::kNumDrawModes;

View File

@@ -13,16 +13,16 @@
#include <iomanip> #include <iomanip>
namespace namespace DeckMenuConst
{ {
const float kVerticalMargin = 16; const float kVerticalMargin = 16;
const float kHorizontalMargin = 20; const float kHorizontalMargin = 20;
const float kLineHeight = 25; const float kLineHeight = 25;
const float kDescriptionVerticalBoxPadding = -5; const float kDescriptionVerticalBoxPadding = -5;
const float kDescriptionHorizontalBoxPadding = 5; const float kDescriptionHorizontalBoxPadding = 5;
const float kDefaultFontScale = 1.0f; const float kDefaultFontScale = 1.0f;
const float kVerticalScrollSpeed = 7.0f; const float kVerticalScrollSpeed = 7.0f;
const int DETAILED_INFO_THRESHOLD = 20; const int DETAILED_INFO_THRESHOLD = 20;
const int kDetailedInfoButtonId = 10000; const int kDetailedInfoButtonId = 10000;
@@ -52,8 +52,8 @@ JGuiController(JGE::GetInstance(), id, listener), fontId(fontId), mShowDetailsSc
titleY = 15; titleY = 15;
titleWidth = 180; // width of inner box of title titleWidth = 180; // width of inner box of title
descX = 260 + kDescriptionHorizontalBoxPadding; descX = 260 + DeckMenuConst::kDescriptionHorizontalBoxPadding;
descY = 100 + kDescriptionVerticalBoxPadding; descY = 100 + DeckMenuConst::kDescriptionVerticalBoxPadding;
descHeight = 145; descHeight = 145;
descWidth = 195; descWidth = 195;
@@ -73,11 +73,11 @@ JGuiController(JGE::GetInstance(), id, listener), fontId(fontId), mShowDetailsSc
float scrollerWidth = 200.0f; float scrollerWidth = 200.0f;
float scrollerHeight = 28.0f; float scrollerHeight = 28.0f;
mScroller = NEW VerticalTextScroller(Fonts::MAIN_FONT, 14, 235, scrollerWidth, scrollerHeight, kVerticalScrollSpeed); mScroller = NEW VerticalTextScroller(Fonts::MAIN_FONT, 14, 235, scrollerWidth, scrollerHeight, DeckMenuConst::kVerticalScrollSpeed);
mAutoTranslate = true; mAutoTranslate = true;
maxItems = 6; maxItems = 6;
mHeight = 2 * kVerticalMargin + (maxItems * kLineHeight); mHeight = 2 * DeckMenuConst::kVerticalMargin + (maxItems * DeckMenuConst::kLineHeight);
// we want to cap the deck titles to 15 characters to avoid overflowing deck names // we want to cap the deck titles to 15 characters to avoid overflowing deck names
title = _(_title); title = _(_title);
@@ -94,7 +94,7 @@ JGuiController(JGE::GetInstance(), id, listener), fontId(fontId), mShowDetailsSc
else else
titleFontScale = SCALE_NORMAL; titleFontScale = SCALE_NORMAL;
mSelectionTargetY = selectionY = kVerticalMargin; mSelectionTargetY = selectionY = DeckMenuConst::kVerticalMargin;
if (NULL == stars) if (NULL == stars)
stars = NEW hgeParticleSystem(WResourceManager::Instance()->RetrievePSI("stars.psi", WResourceManager::Instance()->GetQuad("stars").get())); stars = NEW hgeParticleSystem(WResourceManager::Instance()->RetrievePSI("stars.psi", WResourceManager::Instance()->GetQuad("stars").get()));
@@ -106,7 +106,7 @@ JGuiController(JGE::GetInstance(), id, listener), fontId(fontId), mShowDetailsSc
float stringWidth = descriptionFont->GetStringWidth(detailedInfoString.c_str()); float stringWidth = descriptionFont->GetStringWidth(detailedInfoString.c_str());
float boxStartX = detailedInfoBoxX - stringWidth / 2 + 20; float boxStartX = detailedInfoBoxX - stringWidth / 2 + 20;
dismissButton = NEW InteractiveButton( this, kDetailedInfoButtonId, Fonts::MAIN_FONT, detailedInfoString, boxStartX, detailedInfoBoxY, JGE_BTN_CANCEL); dismissButton = NEW InteractiveButton( this, DeckMenuConst::kDetailedInfoButtonId, Fonts::MAIN_FONT, detailedInfoString, boxStartX, detailedInfoBoxY, JGE_BTN_CANCEL);
JGuiController::Add(dismissButton, true); JGuiController::Add(dismissButton, true);
updateScroller(); updateScroller();
@@ -181,7 +181,7 @@ bool DeckMenu::showDetailsScreen()
if (currentMenuItem) if (currentMenuItem)
{ {
if (mAlwaysShowDetailsButton) return true; if (mAlwaysShowDetailsButton) return true;
if (mShowDetailsScreen && currentMenuItem->getVictories() > DETAILED_INFO_THRESHOLD) return true; if (mShowDetailsScreen && currentMenuItem->getVictories() > DeckMenuConst::DETAILED_INFO_THRESHOLD) return true;
} }
return false; return false;
@@ -189,10 +189,10 @@ bool DeckMenu::showDetailsScreen()
void DeckMenu::initMenuItems() void DeckMenu::initMenuItems()
{ {
float sY = mY + kVerticalMargin; float sY = mY + DeckMenuConst::kVerticalMargin;
for (int i = startId; i < mCount; ++i) for (int i = startId; i < mCount; ++i)
{ {
float y = mY + kVerticalMargin + i * kLineHeight; float y = mY + DeckMenuConst::kVerticalMargin + i * DeckMenuConst::kLineHeight;
DeckMenuItem * currentMenuItem = static_cast<DeckMenuItem*> (mObjects[i]); DeckMenuItem * currentMenuItem = static_cast<DeckMenuItem*> (mObjects[i]);
currentMenuItem->Relocate(mX, y); currentMenuItem->Relocate(mX, y);
if (currentMenuItem->hasFocus()) sY = y; if (currentMenuItem->hasFocus()) sY = y;
@@ -248,7 +248,7 @@ void DeckMenu::Render()
{ {
if (i > mCount - 1) break; if (i > mCount - 1) break;
DeckMenuItem *currentMenuItem = static_cast<DeckMenuItem*> (mObjects[i]); DeckMenuItem *currentMenuItem = static_cast<DeckMenuItem*> (mObjects[i]);
if (currentMenuItem->getY() - kLineHeight * startId < mY + height - kLineHeight + 7) if (currentMenuItem->getY() - DeckMenuConst::kLineHeight * startId < mY + height - DeckMenuConst::kLineHeight + 7)
{ {
// only load stats for visible items in the list // only load stats for visible items in the list
DeckMetaData* metaData = currentMenuItem->getMetaData(); DeckMetaData* metaData = currentMenuItem->getMetaData();
@@ -309,7 +309,7 @@ void DeckMenu::Render()
} }
else // reset the font color to be slightly muted else // reset the font color to be slightly muted
mFont->SetColor(ARGB(150,255,255,255)); mFont->SetColor(ARGB(150,255,255,255));
currentMenuItem->RenderWithOffset(-kLineHeight * startId); currentMenuItem->RenderWithOffset(-DeckMenuConst::kLineHeight * startId);
} }
} }
@@ -342,8 +342,8 @@ void DeckMenu::Update(float dt)
selectionT += 3 * dt; selectionT += 3 * dt;
selectionY += (mSelectionTargetY - selectionY) * 8 * dt; selectionY += (mSelectionTargetY - selectionY) * 8 * dt;
float starsX = starsOffsetX + ((mWidth - 2 * kHorizontalMargin) * (1 + cos(selectionT)) / 2); float starsX = starsOffsetX + ((mWidth - 2 * DeckMenuConst::kHorizontalMargin) * (1 + cos(selectionT)) / 2);
float starsY = selectionY + 5 * cos(selectionT * 2.35f) + kLineHeight / 2 - kLineHeight * startId; float starsY = selectionY + 5 * cos(selectionT * 2.35f) + DeckMenuConst::kLineHeight / 2 - DeckMenuConst::kLineHeight * startId;
stars->MoveTo(starsX, starsY); stars->MoveTo(starsX, starsY);
// //
@@ -371,7 +371,7 @@ void DeckMenu::Update(float dt)
void DeckMenu::Add(int id, const char * text, string desc, bool forceFocus, DeckMetaData * deckMetaData) void DeckMenu::Add(int id, const char * text, string desc, bool forceFocus, DeckMetaData * deckMetaData)
{ {
DeckMenuItem * menuItem = NEW DeckMenuItem(this, id, fontId, text, 0, DeckMenuItem * menuItem = NEW DeckMenuItem(this, id, fontId, text, 0,
mY + kVerticalMargin + mCount * kLineHeight, (mCount == 0), mAutoTranslate, deckMetaData); mY + DeckMenuConst::kVerticalMargin + mCount * DeckMenuConst::kLineHeight, (mCount == 0), mAutoTranslate, deckMetaData);
Translator * t = Translator::GetInstance(); Translator * t = Translator::GetInstance();
map<string, string>::iterator it = t->deckValues.find(text); map<string, string>::iterator it = t->deckValues.find(text);
string deckDescription = ""; string deckDescription = "";
@@ -384,7 +384,7 @@ void DeckMenu::Add(int id, const char * text, string desc, bool forceFocus, Deck
menuItem->setDescription(deckDescription); menuItem->setDescription(deckDescription);
JGuiController::Add(menuItem); JGuiController::Add(menuItem);
if (mCount <= maxItems) mHeight += kLineHeight; if (mCount <= maxItems) mHeight += DeckMenuConst::kLineHeight;
if (forceFocus) if (forceFocus)
{ {

View File

@@ -21,7 +21,7 @@ enum ENUM_AWARDS_STATE
}; };
namespace GameStateAwardsConstants namespace GameStateAwardsConst
{ {
const int kBackToTrophiesID = 2; const int kBackToTrophiesID = 2;
const int kBackToMainMenuID = 1; const int kBackToMainMenuID = 1;
@@ -186,8 +186,8 @@ void GameStateAwards::Update(float dt)
SAFE_DELETE(menu); SAFE_DELETE(menu);
menu = NEW SimpleMenu(JGE::GetInstance(), WResourceManager::Instance(), EXIT_AWARDS_MENU, this, Fonts::MENU_FONT, 50, 170); menu = NEW SimpleMenu(JGE::GetInstance(), WResourceManager::Instance(), EXIT_AWARDS_MENU, this, Fonts::MENU_FONT, 50, 170);
if (mState == STATE_DETAILS) if (mState == STATE_DETAILS)
menu->Add(GameStateAwardsConstants::kBackToTrophiesID, "Back to Trophies"); menu->Add(GameStateAwardsConst::kBackToTrophiesID, "Back to Trophies");
menu->Add(GameStateAwardsConstants::kBackToMainMenuID, "Back to Main Menu"); menu->Add(GameStateAwardsConst::kBackToMainMenuID, "Back to Main Menu");
menu->Add(kCancelMenuID, "Cancel"); menu->Add(kCancelMenuID, "Cancel");
break; break;
case JGE_BTN_PREV: case JGE_BTN_PREV:
@@ -359,11 +359,11 @@ void GameStateAwards::ButtonPressed(int controllerId, int controlId)
if (controllerId == EXIT_AWARDS_MENU) if (controllerId == EXIT_AWARDS_MENU)
switch (controlId) switch (controlId)
{ {
case GameStateAwardsConstants::kBackToMainMenuID: case GameStateAwardsConst::kBackToMainMenuID:
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_MENU); mParent->DoTransition(TRANSITION_FADE, GAME_STATE_MENU);
showMenu = false; showMenu = false;
break; break;
case GameStateAwardsConstants::kBackToTrophiesID: case GameStateAwardsConst::kBackToTrophiesID:
mState = STATE_LISTVIEW; mState = STATE_LISTVIEW;
SAFE_DELETE(detailview); SAFE_DELETE(detailview);
showMenu = false; showMenu = false;

View File

@@ -7,7 +7,7 @@
#include "SimplePad.h" #include "SimplePad.h"
#include "Translate.h" #include "Translate.h"
namespace GameStateOptionsConstants namespace GameStateOptionsConst
{ {
const int kSaveAndBackToMainMenuID = 1; const int kSaveAndBackToMainMenuID = 1;
const int kBackToMainMenuID = 2; const int kBackToMainMenuID = 2;
@@ -77,7 +77,7 @@ void GameStateOptions::Start()
optionsList->Add(NEW WGuiSplit(cPrf, cThm)); optionsList->Add(NEW WGuiSplit(cPrf, cThm));
optionsList->Add(cStyle); optionsList->Add(cStyle);
optionsList->Add(NEW WGuiButton(NEW WGuiHeader("New Profile"), -102, GameStateOptionsConstants::kNewProfileID, this)); optionsList->Add(NEW WGuiButton(NEW WGuiHeader("New Profile"), -102, GameStateOptionsConst::kNewProfileID, this));
optionsList->Add(NEW WDecoCheat(NEW OptionInteger(Options::CHEATMODE, "Enable Cheat Mode"))); optionsList->Add(NEW WDecoCheat(NEW OptionInteger(Options::CHEATMODE, "Enable Cheat Mode")));
optionsList->Add(NEW WDecoCheat(NEW OptionInteger(Options::OPTIMIZE_HAND, "Optimize Starting Hand"))); optionsList->Add(NEW WDecoCheat(NEW OptionInteger(Options::OPTIMIZE_HAND, "Optimize Starting Hand")));
@@ -117,8 +117,8 @@ void GameStateOptions::Start()
optionsTabs->Add(optionsList); optionsTabs->Add(optionsList);
optionsMenu = NEW SimpleMenu(JGE::GetInstance(), WResourceManager::Instance(), -102, this, Fonts::MAIN_FONT, 50, 170); optionsMenu = NEW SimpleMenu(JGE::GetInstance(), WResourceManager::Instance(), -102, this, Fonts::MAIN_FONT, 50, 170);
optionsMenu->Add(GameStateOptionsConstants::kBackToMainMenuID, "Back to Main Menu"); optionsMenu->Add(GameStateOptionsConst::kBackToMainMenuID, "Back to Main Menu");
optionsMenu->Add(GameStateOptionsConstants::kSaveAndBackToMainMenuID, "Save And Exit"); optionsMenu->Add(GameStateOptionsConst::kSaveAndBackToMainMenuID, "Save And Exit");
optionsMenu->Add(kCancelMenuID, "Cancel"); optionsMenu->Add(kCancelMenuID, "Cancel");
optionsTabs->Entering(JGE_BTN_NONE); optionsTabs->Entering(JGE_BTN_NONE);
@@ -284,21 +284,21 @@ void GameStateOptions::ButtonPressed(int controllerId, int controlId)
if (controllerId == -102) if (controllerId == -102)
switch (controlId) switch (controlId)
{ {
case GameStateOptionsConstants::kSaveAndBackToMainMenuID: case GameStateOptionsConst::kSaveAndBackToMainMenuID:
mState = SAVE; mState = SAVE;
break; break;
//Set Audio volume //Set Audio volume
case GameStateOptionsConstants::kBackToMainMenuID: case GameStateOptionsConst::kBackToMainMenuID:
mParent->DoTransition(TRANSITION_FADE, GAME_STATE_MENU); mParent->DoTransition(TRANSITION_FADE, GAME_STATE_MENU);
break; break;
case kCancelMenuID: case kCancelMenuID:
mState = SHOW_OPTIONS; mState = SHOW_OPTIONS;
break; break;
case GameStateOptionsConstants::kNewProfileID: case GameStateOptionsConst::kNewProfileID:
options.keypadStart("", &newProfile); options.keypadStart("", &newProfile);
options.keypadTitle("New Profile"); options.keypadTitle("New Profile");
break; break;
case GameStateOptionsConstants::kReloadID: case GameStateOptionsConst::kReloadID:
mReload = true; mReload = true;
break; break;
} }

View File

@@ -16,21 +16,21 @@ const float kZoom_level1 = 1.4f;
const float kZoom_level2 = 2.2f; const float kZoom_level2 = 2.2f;
const float kZoom_level3 = 2.7f; const float kZoom_level3 = 2.7f;
struct True: public Exp struct GuiCombatTrue: public Exp
{ {
static inline bool test(DamagerDamaged*, DamagerDamaged*) static inline bool test(DamagerDamaged*, DamagerDamaged*)
{ {
return true; return true;
} }
}; };
struct Left: public Exp struct GuiCombatLeft: public Exp
{ {
static inline bool test(DamagerDamaged* ref, DamagerDamaged* test) static inline bool test(DamagerDamaged* ref, DamagerDamaged* test)
{ {
return ref->y == test->y && ref->x > test->x && test->show; return ref->y == test->y && ref->x > test->x && test->show;
} }
}; };
struct Right: public Exp struct GuiCombatRight: public Exp
{ {
static inline bool test(DamagerDamaged* ref, DamagerDamaged* test) static inline bool test(DamagerDamaged* ref, DamagerDamaged* test)
{ {
@@ -217,7 +217,7 @@ void GuiCombat::shiftLeft()
case ATK: case ATK:
{ {
DamagerDamaged* old = active; DamagerDamaged* old = active;
active = closest<Left> (attackers, NULL, static_cast<AttackerDamaged*> (active)); active = closest<GuiCombatLeft> (attackers, NULL, static_cast<AttackerDamaged*> (active));
activeAtk = static_cast<AttackerDamaged*> (active); activeAtk = static_cast<AttackerDamaged*> (active);
if (old != active) if (old != active)
{ {
@@ -231,7 +231,7 @@ void GuiCombat::shiftLeft()
case BLK: case BLK:
{ {
DamagerDamaged* old = active; DamagerDamaged* old = active;
active = closest<Left> (activeAtk->blockers, NULL, static_cast<DefenserDamaged*> (active)); active = closest<GuiCombatLeft> (activeAtk->blockers, NULL, static_cast<DefenserDamaged*> (active));
if (old != active) if (old != active)
{ {
if (old) if (old)
@@ -255,7 +255,7 @@ void GuiCombat::shiftRight( DamagerDamaged* oldActive )
case BLK: case BLK:
{ {
DamagerDamaged* old = active; DamagerDamaged* old = active;
active = closest<Right> (activeAtk->blockers, NULL, static_cast<DefenserDamaged*> (active)); active = closest<GuiCombatRight> (activeAtk->blockers, NULL, static_cast<DefenserDamaged*> (active));
if (old != active) if (old != active)
{ {
if (old) if (old)
@@ -268,7 +268,7 @@ void GuiCombat::shiftRight( DamagerDamaged* oldActive )
case ATK: case ATK:
{ {
DamagerDamaged* old = active; DamagerDamaged* old = active;
active = closest<Right> (attackers, NULL, static_cast<AttackerDamaged*> (active)); active = closest<GuiCombatRight> (attackers, NULL, static_cast<AttackerDamaged*> (active));
if (active == oldActive) if (active == oldActive)
{ {
active = activeAtk = NULL; active = activeAtk = NULL;
@@ -321,7 +321,7 @@ bool GuiCombat::CheckUserInput(JButton key)
// position selected card // position selected card
if (BLK == cursor_pos) if (BLK == cursor_pos)
{ {
DamagerDamaged* selectedCard = closest<True> (activeAtk->blockers, NULL, static_cast<float> (x), static_cast<float> (y)); DamagerDamaged* selectedCard = closest<GuiCombatTrue> (activeAtk->blockers, NULL, static_cast<float> (x), static_cast<float> (y));
// find the index into the vector where the current selected card is. // find the index into the vector where the current selected card is.
int c1 = 0, c2 = 0; int c1 = 0, c2 = 0;
int i = 0; int i = 0;

View File

@@ -6,7 +6,7 @@
#include "GameApp.h" #include "GameApp.h"
#include "Translate.h" #include "Translate.h"
namespace namespace SimpleMenuConst
{ {
const float kPoleWidth = 7; const float kPoleWidth = 7;
const float kVerticalMargin = 20; const float kVerticalMargin = 20;
@@ -38,7 +38,7 @@ SimpleMenu::SimpleMenu(JGE* jge, WResourceManager* resourceManager, int id, JGui
{ {
autoTranslate = true; autoTranslate = true;
isMultipleChoice = false; isMultipleChoice = false;
mHeight = 2 * kVerticalMargin; mHeight = 2 * SimpleMenuConst::kVerticalMargin;
mWidth = 0; mWidth = 0;
mX = x; mX = x;
mY = y; mY = y;
@@ -48,7 +48,7 @@ SimpleMenu::SimpleMenu(JGE* jge, WResourceManager* resourceManager, int id, JGui
selectionT = 0; selectionT = 0;
timeOpen = 0; timeOpen = 0;
mClosed = false; mClosed = false;
selectionTargetY = selectionY = y + kVerticalMargin; selectionTargetY = selectionY = y + SimpleMenuConst::kVerticalMargin;
if(resourceManager) if(resourceManager)
{ {
@@ -61,7 +61,7 @@ SimpleMenu::SimpleMenu(JGE* jge, WResourceManager* resourceManager, int id, JGui
spadeL = resourceManager->RetrieveQuad("spade_ul.png", 0, 0, 0, 0, "spade_ul", RETRIEVE_MANAGE); spadeL = resourceManager->RetrieveQuad("spade_ul.png", 0, 0, 0, 0, "spade_ul", RETRIEVE_MANAGE);
spadeR = resourceManager->RetrieveQuad("spade_ur.png", 0, 0, 0, 0, "spade_ur", RETRIEVE_MANAGE); spadeR = resourceManager->RetrieveQuad("spade_ur.png", 0, 0, 0, 0, "spade_ur", RETRIEVE_MANAGE);
jewel.reset(NEW JQuad(jewelTex, 1, 1, 3, 3)); jewel.reset(NEW JQuad(jewelTex, 1, 1, 3, 3));
side = resourceManager->RetrieveQuad("menuside.png", 1, 1, 1, kPoleWidth, "menuside", RETRIEVE_MANAGE); side = resourceManager->RetrieveQuad("menuside.png", 1, 1, 1, SimpleMenuConst::kPoleWidth, "menuside", RETRIEVE_MANAGE);
stars = NEW hgeParticleSystem(resourceManager->RetrievePSI("stars.psi", resourceManager->GetQuad("stars").get())); stars = NEW hgeParticleSystem(resourceManager->RetrievePSI("stars.psi", resourceManager->GetQuad("stars").get()));
@@ -78,16 +78,16 @@ void SimpleMenu::drawHorzPole(float x, float y, float width)
{ {
JRenderer* renderer = JRenderer::GetInstance(); JRenderer* renderer = JRenderer::GetInstance();
float leftXOffset = (spadeR->mWidth - kPoleWidth) / 2; float leftXOffset = (spadeR->mWidth - SimpleMenuConst::kPoleWidth) / 2;
float rightXOffset = leftXOffset; float rightXOffset = leftXOffset;
float yOffset = leftXOffset; float yOffset = leftXOffset;
if (spadeR->mWidth != spadeR->mHeight) if (spadeR->mWidth != spadeR->mHeight)
{ {
//We have a weird case to deal with in the "Classic" theme, the spades graphics need to be aligned specifically, //We have a weird case to deal with in the "Classic" theme, the spades graphics need to be aligned specifically,
// While the ones in the "Final Saga" theme need to be centered // While the ones in the "Final Saga" theme need to be centered
leftXOffset = kSpadeWidthOffset; leftXOffset = SimpleMenuConst::kSpadeWidthOffset;
yOffset = kSpadeHeightOffset; yOffset = SimpleMenuConst::kSpadeHeightOffset;
rightXOffset = kSpadeRightBottomOffset; rightXOffset = SimpleMenuConst::kSpadeRightBottomOffset;
} }
renderer->RenderQuad(side.get(), x, y, 0, width); renderer->RenderQuad(side.get(), x, y, 0, width);
@@ -104,23 +104,23 @@ void SimpleMenu::drawVertPole(float x, float y, float height)
{ {
JRenderer* renderer = JRenderer::GetInstance(); JRenderer* renderer = JRenderer::GetInstance();
float xOffset = (spadeR->mWidth - kPoleWidth) / 2; float xOffset = (spadeR->mWidth - SimpleMenuConst::kPoleWidth) / 2;
float topYOffset = xOffset; float topYOffset = xOffset;
float bottomYOffset = xOffset; float bottomYOffset = xOffset;
if (spadeR->mWidth != spadeR->mHeight) if (spadeR->mWidth != spadeR->mHeight)
{ {
//We have a weird case to deal with in the "Classic" theme, the spades graphics need to be aligned specifically, //We have a weird case to deal with in the "Classic" theme, the spades graphics need to be aligned specifically,
// While the ones in the "Final Saga" theme need to be centered // While the ones in the "Final Saga" theme need to be centered
xOffset = kSpadeHeightOffset; xOffset = SimpleMenuConst::kSpadeHeightOffset;
topYOffset = kSpadeWidthOffset; topYOffset = SimpleMenuConst::kSpadeWidthOffset;
bottomYOffset = kSpadeRightBottomOffset; bottomYOffset = SimpleMenuConst::kSpadeRightBottomOffset;
} }
renderer->RenderQuad(side.get(), x + kPoleWidth, y, M_PI / 2, height); renderer->RenderQuad(side.get(), x + SimpleMenuConst::kPoleWidth, y, M_PI / 2, height);
spadeR->SetHFlip(true); spadeR->SetHFlip(true);
spadeL->SetHFlip(false); spadeL->SetHFlip(false);
renderer->RenderQuad(spadeR.get(), x + kPoleWidth + xOffset, y - topYOffset, M_PI / 2); renderer->RenderQuad(spadeR.get(), x + SimpleMenuConst::kPoleWidth + xOffset, y - topYOffset, M_PI / 2);
renderer->RenderQuad(spadeL.get(), x + kPoleWidth + xOffset, y + height - bottomYOffset, M_PI / 2); renderer->RenderQuad(spadeL.get(), x + SimpleMenuConst::kPoleWidth + xOffset, y + height - bottomYOffset, M_PI / 2);
renderer->RenderQuad(jewel.get(), x - 1, y - 1); renderer->RenderQuad(jewel.get(), x - 1, y - 1);
renderer->RenderQuad(jewel.get(), x - 1, y + height - 1); renderer->RenderQuad(jewel.get(), x - 1, y + height - 1);
@@ -133,7 +133,7 @@ void SimpleMenu::Render()
WFont * mFont = WResourceManager::Instance()->GetWFont(fontId); WFont * mFont = WResourceManager::Instance()->GetWFont(fontId);
if (0 == mWidth) if (0 == mWidth)
{ {
float sY = mY + kVerticalMargin; float sY = mY + SimpleMenuConst::kVerticalMargin;
for (int i = 0; i < mCount; ++i) for (int i = 0; i < mCount; ++i)
{ {
@@ -146,7 +146,7 @@ void SimpleMenu::Render()
if ((!title.empty()) && (mWidth < titleFont->GetStringWidth(title.c_str()))) if ((!title.empty()) && (mWidth < titleFont->GetStringWidth(title.c_str())))
mWidth = titleFont->GetStringWidth(title.c_str()); mWidth = titleFont->GetStringWidth(title.c_str());
titleFont->SetScale(scaleFactor); titleFont->SetScale(scaleFactor);
mWidth += 2 * kHorizontalMargin; mWidth += 2 * SimpleMenuConst::kHorizontalMargin;
if (mCenterHorizontal) if (mCenterHorizontal)
mX = (SCREEN_WIDTH_F - mWidth) / 2; mX = (SCREEN_WIDTH_F - mWidth) / 2;
@@ -156,7 +156,7 @@ void SimpleMenu::Render()
for (int i = 0; i < mCount; ++i) for (int i = 0; i < mCount; ++i)
{ {
float y = mY + kVerticalMargin + i * kLineHeight; float y = mY + SimpleMenuConst::kVerticalMargin + i * SimpleMenuConst::kLineHeight;
SimpleMenuItem * smi = static_cast<SimpleMenuItem*> (mObjects[i]); SimpleMenuItem * smi = static_cast<SimpleMenuItem*> (mObjects[i]);
smi->Relocate(mX + mWidth / 2, y); smi->Relocate(mX + mWidth / 2, y);
if (smi->hasFocus()) sY = y; if (smi->hasFocus()) sY = y;
@@ -171,7 +171,7 @@ void SimpleMenu::Render()
float height = mHeight; float height = mHeight;
if (timeOpen < 1) height *= timeOpen > 0 ? timeOpen : -timeOpen; if (timeOpen < 1) height *= timeOpen > 0 ? timeOpen : -timeOpen;
float heightPadding = kLineHeight/2; // this to reduce the bottom padding of the menu float heightPadding = SimpleMenuConst::kLineHeight/2; // this to reduce the bottom padding of the menu
renderer->FillRect(mX, mY, mWidth, height - heightPadding, ARGB(180,0,0,0)); renderer->FillRect(mX, mY, mWidth, height - heightPadding, ARGB(180,0,0,0));
renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA); renderer->SetTexBlend(BLEND_SRC_ALPHA, BLEND_ONE_MINUS_SRC_ALPHA);
@@ -200,8 +200,8 @@ void SimpleMenu::Render()
{ {
if (i > mCount - 1) break; if (i > mCount - 1) break;
SimpleMenuItem *currentMenuItem = static_cast<SimpleMenuItem*>(mObjects[i]); SimpleMenuItem *currentMenuItem = static_cast<SimpleMenuItem*>(mObjects[i]);
float currentY = currentMenuItem->getY() - kLineHeight * startId; float currentY = currentMenuItem->getY() - SimpleMenuConst::kLineHeight * startId;
float menuBottomEdge = mY + height - kLineHeight + 7; float menuBottomEdge = mY + height - SimpleMenuConst::kLineHeight + 7;
if (currentY < menuBottomEdge) if (currentY < menuBottomEdge)
{ {
if (currentMenuItem->hasFocus()) if (currentMenuItem->hasFocus())
@@ -214,7 +214,7 @@ void SimpleMenu::Render()
{ {
mFont->SetColor(ARGB(150,255,255,255)); mFont->SetColor(ARGB(150,255,255,255));
} }
(static_cast<SimpleMenuItem*> (mObjects[i]))->RenderWithOffset(-kLineHeight * startId); (static_cast<SimpleMenuItem*> (mObjects[i]))->RenderWithOffset(-SimpleMenuConst::kLineHeight * startId);
} }
mFont->SetScale(SCALE_NORMAL); mFont->SetScale(SCALE_NORMAL);
} }
@@ -244,8 +244,8 @@ bool SimpleMenu::CheckUserInput(JButton key)
if (mObjects.size()) if (mObjects.size())
{ {
float top, left; float top, left;
float menuTopEdge = mY + kLineHeight; float menuTopEdge = mY + SimpleMenuConst::kLineHeight;
float menuBottomEdge = mY + mHeight - (kLineHeight/2); float menuBottomEdge = mY + mHeight - (SimpleMenuConst::kLineHeight/2);
if (y < menuTopEdge) if (y < menuTopEdge)
n = (mCurr - 1) > 0 ? mCurr -1 : 0; n = (mCurr - 1) > 0 ? mCurr -1 : 0;
@@ -257,7 +257,7 @@ bool SimpleMenu::CheckUserInput(JButton key)
{ {
if (mObjects[i]->getTopLeft(top, left)) if (mObjects[i]->getTopLeft(top, left))
{ {
if ( (y > top) && (y <= (top + kLineHeight)) ) if ( (y > top) && (y <= (top + SimpleMenuConst::kLineHeight)) )
n = i; n = i;
} }
} }
@@ -308,8 +308,8 @@ void SimpleMenu::Update(float dt)
selectionT += 3 * dt; selectionT += 3 * dt;
selectionY += (selectionTargetY - selectionY) * 8 * dt; selectionY += (selectionTargetY - selectionY) * 8 * dt;
if(stars) if(stars)
stars->MoveTo(mX + kHorizontalMargin + ((mWidth - 2 * kHorizontalMargin) * (1 + cos(selectionT)) / 2), selectionY + 5 * cos( stars->MoveTo(mX + SimpleMenuConst::kHorizontalMargin + ((mWidth - 2 * SimpleMenuConst::kHorizontalMargin) * (1 + cos(selectionT)) / 2), selectionY + 5 * cos(
selectionT * 2.35f) + kLineHeight / 2 - kLineHeight * startId); selectionT * 2.35f) + SimpleMenuConst::kLineHeight / 2 - SimpleMenuConst::kLineHeight * startId);
if (timeOpen < 0) if (timeOpen < 0)
{ {
timeOpen += dt * 10; timeOpen += dt * 10;
@@ -330,12 +330,12 @@ void SimpleMenu::Update(float dt)
void SimpleMenu::Add(int id, const char * text, string desc, bool forceFocus) void SimpleMenu::Add(int id, const char * text, string desc, bool forceFocus)
{ {
SimpleMenuItem * smi = NEW SimpleMenuItem(this, id, fontId, text, 0, mY + kVerticalMargin + mCount * kLineHeight, SimpleMenuItem * smi = NEW SimpleMenuItem(this, id, fontId, text, 0, mY + SimpleMenuConst::kVerticalMargin + mCount * SimpleMenuConst::kLineHeight,
(mCount == 0), autoTranslate); (mCount == 0), autoTranslate);
smi->setDescription(desc); smi->setDescription(desc);
JGuiController::Add(smi); JGuiController::Add(smi);
if (mCount <= maxItems) mHeight += kLineHeight; if (mCount <= maxItems) mHeight += SimpleMenuConst::kLineHeight;
if (forceFocus) if (forceFocus)
{ {
mObjects[mCurr]->Leaving(JGE_BTN_DOWN); mObjects[mCurr]->Leaving(JGE_BTN_DOWN);