Skip to content

Commit

Permalink
Rename/organize
Browse files Browse the repository at this point in the history
  • Loading branch information
kphoenix137 committed Sep 20, 2024
1 parent 71a6eaa commit 4d9dd9f
Show file tree
Hide file tree
Showing 2 changed files with 97 additions and 105 deletions.
120 changes: 60 additions & 60 deletions Source/stores.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ void StoreSession::DrawGossip()
SetLineAsOptionsBackButton();
}

void StoreSession::SetHeader(const std::string &header)
void StoreSession::SetMainMenuHeader(const std::string &header)
{
// Check if the header contains "\n\n", which indicates a two-line header
std::string::size_type pos = header.find("\n\n");
Expand Down Expand Up @@ -490,7 +490,7 @@ void StoreSession::SetupTownerMainMenu()

const TownerLine &lines = TownerLines[towner];

SetHeader(lines.menuHeader);
SetMainMenuHeader(lines.menuHeader);

SetLineAsDivider(MainMenuDividerLine);

Expand Down Expand Up @@ -587,7 +587,7 @@ void StoreSession::DrawItemListForTowner(TalkID talkId, int idx, bool selling /*
}
}

void StoreSession::SetBuyMenuText()
void StoreSession::SetBuyMenuHeader()
{
const UiFlags flags = UiFlags::ColorWhitegold;

Expand All @@ -597,7 +597,7 @@ void StoreSession::SetBuyMenuText()
SetLineText(20, 1, _("I have this item for sale:"), flags, false);
}

void StoreSession::SetWitchBookMinMag(Item &bookItem)
void StoreSession::UpdateBookMinMagic(Item &bookItem)
{
if (bookItem._iMiscId != IMISC_BOOK)
return;
Expand Down Expand Up @@ -637,7 +637,7 @@ void StoreSession::UpdateItemStatFlags(TalkID talkId)
case TalkID::WitchBuy:
for (Item &item : witchItem) {
if (!item.isEmpty()) {
SetWitchBookMinMag(item);
UpdateBookMinMagic(item);
item._iStatFlag = MyPlayer->CanUseItem(item);
playerItemIdx++;
}
Expand All @@ -662,7 +662,7 @@ void StoreSession::UpdateItemStatFlags(TalkID talkId)
}
}

void StoreSession::DrawTownerBuy(TalkID talkId)
void StoreSession::SetupTownerBuyMenu(TalkID talkId)
{
isTextFullSize = true;
currentScrollPos = 0;
Expand All @@ -677,11 +677,43 @@ void StoreSession::DrawTownerBuy(TalkID talkId)
UpdateItemStatFlags(talkId);
hasScrollbar = playerItemIdx > BuyLineSpace ? true : false;
numTextLines = std::max(playerItemIdx - BuyLineSpace, 0);
SetBuyMenuText();
SetBuyMenuHeader();
AddItemListBackButton(talkId, true);
}

void StoreSession::DrawTownerSell(TalkID talkId)
bool StoreSession::CanSellToTowner(TalkID talkId, int i)
{
Item *pI = (i >= 0) ? &MyPlayer->InvList[i] : &MyPlayer->SpdList[-(i + 1)];

if (pI->isEmpty())
return false;

if (pI->_itype == ItemType::Gold || pI->_iClass == ICLASS_QUEST || pI->IDidx == IDI_LAZSTAFF)
return false;

switch (talkId) {
case TalkID::SmithSell:
if (pI->_iMiscId > IMISC_OILFIRST && pI->_iMiscId < IMISC_OILLAST)
return true;
if (pI->_itype == ItemType::Misc)
return false;
if (pI->_itype == ItemType::Staff && (!gbIsHellfire || IsValidSpell(pI->_iSpell)))
return false;
return true;

case TalkID::WitchSell:
if (pI->_itype == ItemType::Misc && (pI->_iMiscId <= 29 || pI->_iMiscId >= 41))
return false;
if (pI->_itype == ItemType::Staff && (!gbIsHellfire || IsValidSpell(pI->_iSpell)))
return true;
return pI->_itype == ItemType::Misc;

default:
return false;
}
}

void StoreSession::SetupTownerSellMenu(TalkID talkId)
{
isTextFullSize = true;
bool sellOk = false;
Expand Down Expand Up @@ -746,39 +778,7 @@ void StoreSession::DrawTownerSell(TalkID talkId)
AddItemListBackButton(talkId);
}

bool StoreSession::CanSellToTowner(TalkID talkId, int i)
{
Item *pI = (i >= 0) ? &MyPlayer->InvList[i] : &MyPlayer->SpdList[-(i + 1)];

if (pI->isEmpty())
return false;

if (pI->_itype == ItemType::Gold || pI->_iClass == ICLASS_QUEST || pI->IDidx == IDI_LAZSTAFF)
return false;

switch (talkId) {
case TalkID::SmithSell:
if (pI->_iMiscId > IMISC_OILFIRST && pI->_iMiscId < IMISC_OILLAST)
return true;
if (pI->_itype == ItemType::Misc)
return false;
if (pI->_itype == ItemType::Staff && (!gbIsHellfire || IsValidSpell(pI->_iSpell)))
return false;
return true;

case TalkID::WitchSell:
if (pI->_itype == ItemType::Misc && (pI->_iMiscId <= 29 || pI->_iMiscId >= 41))
return false;
if (pI->_itype == ItemType::Staff && (!gbIsHellfire || IsValidSpell(pI->_iSpell)))
return true;
return pI->_itype == ItemType::Misc;

default:
return false;
}
}

bool StoreSession::CanSmithRepair(int i) const
bool StoreSession::CanTownerRepair(int i) const
{
const Item &item = MyPlayer->InvList[i];

Expand Down Expand Up @@ -851,7 +851,7 @@ void StoreSession::DrawSmithRepair()
for (int i = 0; i < MyPlayer->_pNumInv; i++) {
if (playerItemIdx >= 48)
break;
if (CanSmithRepair(i)) {
if (CanTownerRepair(i)) {
AddPlayerItemToRepairList(&MyPlayer->InvList[i], i);
}
}
Expand Down Expand Up @@ -891,7 +891,7 @@ void StoreSession::RestoreMana()
RedrawComponent(PanelDrawComponent::Mana);
}

bool StoreSession::CanWitchRecharge(int i)
bool StoreSession::CanTownerRecharge(int i)
{
const auto &item = MyPlayer->InvList[i];

Expand Down Expand Up @@ -936,7 +936,7 @@ void StoreSession::DrawWitchRecharge()
for (int i = 0; i < MyPlayer->_pNumInv; i++) {
if (playerItemIdx >= 48)
break;
if (CanWitchRecharge(i)) {
if (CanTownerRecharge(i)) {
rechargeok = true;
AddPlayerItemToRechargeList(MyPlayer->InvList[i], i);
}
Expand Down Expand Up @@ -974,7 +974,7 @@ void StoreSession::RestoreLife()
RedrawComponent(PanelDrawComponent::Health);
}

bool StoreSession::CanStorytellerIdentify(Item *i)
bool StoreSession::CanTownerIdentify(Item *i)
{
if (i->isEmpty()) {
return false;
Expand Down Expand Up @@ -1005,43 +1005,43 @@ void StoreSession::DrawStorytellerIdentify()
}

auto &helmet = MyPlayer->InvBody[INVLOC_HEAD];
if (CanStorytellerIdentify(&helmet)) {
if (CanTownerIdentify(&helmet)) {
idok = true;
AddPlayerItemToIdentifyList(helmet, -1);
}

auto &armor = MyPlayer->InvBody[INVLOC_CHEST];
if (CanStorytellerIdentify(&armor)) {
if (CanTownerIdentify(&armor)) {
idok = true;
AddPlayerItemToIdentifyList(armor, -2);
}

auto &leftHand = MyPlayer->InvBody[INVLOC_HAND_LEFT];
if (CanStorytellerIdentify(&leftHand)) {
if (CanTownerIdentify(&leftHand)) {
idok = true;
AddPlayerItemToIdentifyList(leftHand, -3);
}

auto &rightHand = MyPlayer->InvBody[INVLOC_HAND_RIGHT];
if (CanStorytellerIdentify(&rightHand)) {
if (CanTownerIdentify(&rightHand)) {
idok = true;
AddPlayerItemToIdentifyList(rightHand, -4);
}

auto &leftRing = MyPlayer->InvBody[INVLOC_RING_LEFT];
if (CanStorytellerIdentify(&leftRing)) {
if (CanTownerIdentify(&leftRing)) {
idok = true;
AddPlayerItemToIdentifyList(leftRing, -5);
}

auto &rightRing = MyPlayer->InvBody[INVLOC_RING_RIGHT];
if (CanStorytellerIdentify(&rightRing)) {
if (CanTownerIdentify(&rightRing)) {
idok = true;
AddPlayerItemToIdentifyList(rightRing, -6);
}

auto &amulet = MyPlayer->InvBody[INVLOC_AMULET];
if (CanStorytellerIdentify(&amulet)) {
if (CanTownerIdentify(&amulet)) {
idok = true;
AddPlayerItemToIdentifyList(amulet, -7);
}
Expand All @@ -1050,7 +1050,7 @@ void StoreSession::DrawStorytellerIdentify()
if (playerItemIdx >= 48)
break;
auto &item = MyPlayer->InvList[i];
if (CanStorytellerIdentify(&item)) {
if (CanTownerIdentify(&item)) {
idok = true;
AddPlayerItemToIdentifyList(item, i);
}
Expand Down Expand Up @@ -2045,7 +2045,7 @@ void StoreSession::StartStore(TalkID s)
break;
}
if (hasAnyItems)
DrawTownerBuy(s);
SetupTownerBuyMenu(s);
else {
activeStore = TalkID::SmithBuy;
oldTextLine = 12;
Expand All @@ -2055,7 +2055,7 @@ void StoreSession::StartStore(TalkID s)
break;
}
case TalkID::SmithSell:
DrawTownerSell(s);
SetupTownerSellMenu(s);
break;
case TalkID::SmithRepair:
DrawSmithRepair();
Expand All @@ -2066,10 +2066,10 @@ void StoreSession::StartStore(TalkID s)
break;
case TalkID::WitchBuy:
if (playerItemIdx > 0)
DrawTownerBuy(s);
SetupTownerBuyMenu(s);
break;
case TalkID::WitchSell:
DrawTownerSell(s);
SetupTownerSellMenu(s);
break;
case TalkID::WitchRecharge:
DrawWitchRecharge();
Expand All @@ -2088,7 +2088,7 @@ void StoreSession::StartStore(TalkID s)
SetupTownerMainMenu();
break;
case TalkID::BoyBuy:
DrawTownerBuy(s);
SetupTownerBuyMenu(s);
break;
case TalkID::Healer:
towner = TOWN_HEALER;
Expand All @@ -2100,13 +2100,13 @@ void StoreSession::StartStore(TalkID s)
break;
case TalkID::HealerBuy:
if (playerItemIdx > 0)
DrawTownerBuy(s);
SetupTownerBuyMenu(s);
break;
case TalkID::StorytellerIdentify:
DrawStorytellerIdentify();
break;
case TalkID::SmithPremiumBuy:
DrawTownerBuy(s);
SetupTownerBuyMenu(s);
break;
case TalkID::Gossip:
DrawGossip();
Expand Down
Loading

0 comments on commit 4d9dd9f

Please sign in to comment.