From 35c5ee97ef76064b3139e9a5d574654f08b15111 Mon Sep 17 00:00:00 2001 From: Martin Haye Date: Thu, 23 Mar 2017 07:07:36 -0700 Subject: [PATCH] More progress on store buying. --- Platform/Apple/virtual/src/plasma/gamelib.plh | 3 +- .../Apple/virtual/src/plasma/gameloop.pla | 12 +- Platform/Apple/virtual/src/plasma/store.pla | 107 +++++++++++------- 3 files changed, 81 insertions(+), 41 deletions(-) diff --git a/Platform/Apple/virtual/src/plasma/gamelib.plh b/Platform/Apple/virtual/src/plasma/gamelib.plh index 2f75dfe2..a3dede42 100644 --- a/Platform/Apple/virtual/src/plasma/gamelib.plh +++ b/Platform/Apple/virtual/src/plasma/gamelib.plh @@ -30,7 +30,8 @@ import gamelib predef addPlayerToParty, removePlayerFromParty, partyHasPlayer, loadFrameImg, loadMainFrameImg predef scriptSwapTile, setIntimateMode, fontCmd, setIntimateMode predef callGlobalFunc, getCharResponse, memcpy, checkEncounter, finalWin, addUnique - predef benchPlayer, unbenchPlayer, buyFromStore, sellToStore, setOversizeWindow, convertDec + predef benchPlayer, unbenchPlayer, buyFromStore, sellToStore, setOversizeWindow + predef rawDisplayf1, rawDisplayf2, rawDisplayf3 // This pointer is the root of all heap-tracked (and garbage collected) objects. // See playtype.plh for definitions of all the datastructures and how they interconnect. diff --git a/Platform/Apple/virtual/src/plasma/gameloop.pla b/Platform/Apple/virtual/src/plasma/gameloop.pla index 0b466a9a..a7e3f90f 100644 --- a/Platform/Apple/virtual/src/plasma/gameloop.pla +++ b/Platform/Apple/virtual/src/plasma/gameloop.pla @@ -1010,7 +1010,7 @@ end /////////////////////////////////////////////////////////////////////////////////////////////////// // Convert signed decimal to string in decimalBuf (@decimalBuf returned) -export def convertDec(n) +def convertDec(n) word n0 word p p = @decimalBuf + 1 @@ -1071,6 +1071,16 @@ end export def displayf1(str, arg1); displayf3(str, arg1, 0, 0); end export def displayf2(str, arg1, arg2); displayf3(str, arg1, arg2, 0); end +// Like printf, but displays text using font engine +export def rawDisplayf3(str, arg1, arg2, arg3) + buildString(@addToString) + printf3(str, arg1, arg2, arg3) + rawDisplayStr(finishString(isPlural)) +end + +export def rawDisplayf1(str, arg1); rawDisplayf3(str, arg1, 0, 0); end +export def rawDisplayf2(str, arg1, arg2); rawDisplayf3(str, arg1, arg2, 0); end + /////////////////////////////////////////////////////////////////////////////////////////////////// def parseDec(str) word n diff --git a/Platform/Apple/virtual/src/plasma/store.pla b/Platform/Apple/virtual/src/plasma/store.pla index 6f4002c4..534eeb97 100644 --- a/Platform/Apple/virtual/src/plasma/store.pla +++ b/Platform/Apple/virtual/src/plasma/store.pla @@ -14,7 +14,7 @@ include "globalDefs.plh" include "gen_modules.plh" include "gen_items.plh" -const PAGE_SIZE = 19 +const PAGE_SIZE = 13 // Exported functions go here. First a predef for each one, then a table with function pointers // in the same order as the constants are defined in the header. @@ -26,8 +26,6 @@ const MAX_PAGE_ITEMS = 20 // should be plenty word pageItems[MAX_PAGE_ITEMS] word pagePrices[MAX_PAGE_ITEMS] -byte selStrBuf[2] - /////////////////////////////////////////////////////////////////////////////////////////////////// // Definitions used by assembly code asm _defs @@ -113,63 +111,94 @@ def unloadItems() end /////////////////////////////////////////////////////////////////////////////////////////////////// -def displayBuyTitle() - rawDisplayStr("^T108Buying\n\n") - rawDisplayStr("^LSel^T025Price^T060Item^L") +def displayBuyTitle(pageNum, nPages) + clearWindow() + // Can't use centering mode on oversize window - font engine can't handle width > 255 + if (nPages > 0) + rawDisplayf2("^T073Buying (page %d of %d)", pageNum+1, nPages) + else + rawDisplayStr("^T108Buying") + fin + rawDisplayStr("\n\n^LSel^T025Price^T060Item^L") end /////////////////////////////////////////////////////////////////////////////////////////////////// -def displayBuyLine(num, name, price) - word buf - rawDisplayStr("\n") - ^(@buf) = 1 - ^(@buf + 1) = num + 'A' - rawDisplayStr(@buf) - rawDisplayStr(".^T025") - rawDisplayStr(convertDec(price)) - rawDisplayStr("^T060") - rawDisplayStr(name) +def displayBuyLine(num, price, name) + rawDisplayf3("\n%c.^T025%d^T060%s", num + 'A', price, name) end /////////////////////////////////////////////////////////////////////////////////////////////////// -def displayBuyPage(pItemFunc, markupRatio) +def displayBuyPage(pItemTbl, markupRatio, pageNum, nPages) byte itemNum - itemNum = 0 - displayBuyTitle() + word pFunc, pItem + + displayBuyTitle(pageNum, nPages) mmgr(HEAP_COLLECT, 0) - while itemNum < PAGE_SIZE-5 - pageItems[itemNum] = (*pItemFunc)() - pagePrices[itemNum] = max(1, pageItems[itemNum]=>w_price + calcMarkup(pageItems[itemNum]=>w_price, markupRatio)) - if pageItems[itemNum]->t_type == TYPE_STUFF // show plural for countable stuff like ammo, pelts - setPlural(TRUE) - else - setPlural(FALSE) - fin - displayBuyLine(itemNum, pageItems[itemNum]=>s_name, pagePrices[itemNum]) - itemNum++ - pItemFunc = pItemFunc + 2 - if !*pItemFunc; break; fin - loop + + pFunc = pItemTbl + ((pageNum*PAGE_SIZE) << 1) + for itemNum = 0 to PAGE_SIZE-1 + if !(*pFunc); break; fin + pItem = (*pFunc)() + pageItems[itemNum] = pItem + pagePrices[itemNum] = max(1, pItem=>w_price + calcMarkup(pItem=>w_price, markupRatio)) + setPlural(FALSE) + if pItem->t_type == TYPE_STUFF; setPlural(TRUE); fin + displayBuyLine(itemNum, pagePrices[itemNum], pItem=>s_name) + pFunc = pFunc + 2 + next + + rawDisplayf1("\n\nBrowse item [A-%c], ", itemNum-1+'A') + if nPages > 0 + rawDisplayf1("page [1-%d], ", nPages) + fin + rawDisplayStr("or [Esc].") return itemNum end +/////////////////////////////////////////////////////////////////////////////////////////////////// +def countArray(arr) + byte count + for count = 0 to 127 + if !*arr; return count; fin + arr = arr + 2 + next +end + /////////////////////////////////////////////////////////////////////////////////////////////////// def _buyFromStore(storeCode, markupRatio) - word pItemTbl, topItem, choice + word pItemTbl, choice + byte nItemsOnPage, pageNum, nPages, redisplay setOversizeWindow() - clearWindow() loadItems() pItemTbl = pItemsModule()=>items_forStoreCode(storeCode) - topItem = pItemTbl + nPages = (countArray(pItemTbl) + PAGE_SIZE) / PAGE_SIZE + pageNum = 0 + + redisplay = TRUE while TRUE - displayBuyPage(topItem, markupRatio) - rawDisplayStr("\n\nSelect item, Return for next pg, Esc to leave") - choice = readStr() - break + if redisplay + nItemsOnPage = displayBuyPage(pItemTbl + ((pageNum*PAGE_SIZE)<<1), markupRatio, pageNum, nPages) + fin + choice = getUpperKey() + redisplay = TRUE + if choice >= '1' and (choice-'1') < nPages + pageNum = choice - '1' + elsif choice >= 'A' and (choice-'A' < nItemsOnPage) + rawDisplayf1("\nTODO: browse it, maybe buy\n") + getUpperKey() + elsif choice == $1B // Esc + break + else + beep() + redisplay = FALSE + fin loop + + unloadItems() + mmgr(HEAP_COLLECT, 0) end ///////////////////////////////////////////////////////////////////////////////////////////////////