diff options
-rw-r--r-- | include/entities.h | 24 | ||||
-rw-r--r-- | include/inventory.h | 1 | ||||
-rw-r--r-- | src/entities.cpp | 6 | ||||
-rw-r--r-- | src/inventory.cpp | 8 | ||||
-rw-r--r-- | src/ui.cpp | 30 | ||||
-rw-r--r-- | src/world.cpp | 16 | ||||
-rw-r--r-- | xml/playerSpawnHill1.xml | 2 |
7 files changed, 63 insertions, 24 deletions
diff --git a/include/entities.h b/include/entities.h index 334bfeb..0714650 100644 --- a/include/entities.h +++ b/include/entities.h @@ -55,19 +55,35 @@ enum BUILD_SUB{ class BuySell{ public: int member; + // 0 = Buy/Sell + // 1 = Trade union{ struct{ - std::string item1; - std::string item2; + std::string item; + std::string itemt; }trade; struct{ - enum type{BUY,SELL}; + int type; + // 0 = buy + // 1 = sell std::string item; int price; }cost; }; - BuySell(){} + BuySell(int typ, std::string itm, int prc){ + this->cost.type = typ; + this->cost.item = itm; + this->cost.price = prc; + this->member = 0; + } + BuySell(std::string itm, std::string itmt){ + this->trade.item = itm; + this->trade.itemt = itmt; + this->member = 1; + } ~BuySell(){} + BuySell(const BuySell&){} + BuySell(){} }; class World; diff --git a/include/inventory.h b/include/inventory.h index 8225ab2..cf6e480 100644 --- a/include/inventory.h +++ b/include/inventory.h @@ -62,6 +62,7 @@ void initInventorySprites(void); void destroyInventory(void); const char *getItemTexturePath(std::string name); +Texturec *getItemTexture(std::string name); float getItemWidth(std::string name); float getItemHeight(std::string name); diff --git a/src/entities.cpp b/src/entities.cpp index 5c60386..8abc727 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -450,8 +450,12 @@ void NPC::interact(){ //have the npc's interact back to the player void Merchant::interact(){ ui::merchantBox(name, &bsinv, ":Accept:Good-Bye", false, "Welcome to Smithy\'s. Buy your sausages here you freaking meme lording screw-face"); - //ui::merchantBox(); ui::waitForDialog(); + if(ui::dialogOptChosen == 1){ + std::cout << "Gimme ye' munny" << std::endl; + }else{ + std::cout << "See ye!" << std::endl; + } } void Object::interact(void){ diff --git a/src/inventory.cpp b/src/inventory.cpp index 203e707..cd8bb71 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -142,6 +142,14 @@ const char *getItemTexturePath(std::string name){ return NULL; } +Texturec *getItemTexture(std::string name){ + for(auto &i : itemMap){ + if(i->name == name) + return i->tex; + } + return NULL; +} + float getItemWidth(std::string name){ for(auto &i : itemMap){ if(i->name == name) @@ -665,6 +665,8 @@ namespace ui { setFontSize(16); } }else if(dialogMerchant){ + static int dispItem; + x=offset.x-SCREEN_WIDTH/6; y=(offset.y+SCREEN_HEIGHT/2)-HLINE*8; @@ -684,30 +686,32 @@ namespace ui { // draw typeOut'd text putString(x + HLINE, y - fontSize - HLINE, (rtext = typeOut(dialogBoxText))); merchAOptLoc[0][0] = offset.x - (SCREEN_WIDTH / 6.5) - 16; - merchAOptLoc[0][1] = offset.x + (SCREEN_WIDTH / 6.5); - merchAOptLoc[1][0] = offset.y + (SCREEN_HEIGHT *.25); + merchAOptLoc[1][0] = offset.x + (SCREEN_WIDTH / 6.5); + merchAOptLoc[0][1] = offset.y + (SCREEN_HEIGHT *.25); merchAOptLoc[1][1] = offset.y + (SCREEN_HEIGHT *.25); - merchAOptLoc[2][0] = offset.x - (SCREEN_WIDTH / 6.5); - merchAOptLoc[2][1] = offset.x + (SCREEN_WIDTH / 6.5) + 16; + merchAOptLoc[0][2] = offset.x - (SCREEN_WIDTH / 6.5); + merchAOptLoc[1][2] = offset.x + (SCREEN_WIDTH / 6.5) + 16; for(i = 0; i < 2; i++){ - if(mouse.x > merchAOptLoc[0][i] && mouse.x < merchAOptLoc[2][i] && - mouse.y > merchAOptLoc[1][i] - 8 && mouse.y < merchAOptLoc[1][i] + 8){ - glColor3ub(255, 255, 0); + if(mouse.x > merchAOptLoc[i][0] && mouse.x < merchAOptLoc[i][2] && + mouse.y > merchAOptLoc[i][1] - 8 && mouse.y < merchAOptLoc[i][1] + 8){ + dispItem++; + glColor3ub(255,255, 0); }else{ glColor3ub(255,255,255); } } glBegin(GL_TRIANGLES); - glVertex2f(merchAOptLoc[0][0],merchAOptLoc[1][0]); - glVertex2f(merchAOptLoc[2][0],merchAOptLoc[1][0]-8); - glVertex2f(merchAOptLoc[2][0],merchAOptLoc[1][0]+8); + glVertex2f(merchAOptLoc[0][0],merchAOptLoc[0][1]); + glVertex2f(merchAOptLoc[0][2],merchAOptLoc[0][1]-8); + glVertex2f(merchAOptLoc[0][2],merchAOptLoc[0][1]+8); - glVertex2f(merchAOptLoc[2][1],merchAOptLoc[1][1]); - glVertex2f(merchAOptLoc[0][1],merchAOptLoc[1][1]-8); - glVertex2f(merchAOptLoc[0][1],merchAOptLoc[1][1]+8); + glVertex2f(merchAOptLoc[1][2],merchAOptLoc[1][1]); + glVertex2f(merchAOptLoc[1][0],merchAOptLoc[1][1]-8); + glVertex2f(merchAOptLoc[1][0],merchAOptLoc[1][1]+8); glEnd(); + // draw / handle dialog options if they exist for(i = 0; i < dialogOptCount; i++){ diff --git a/src/world.cpp b/src/world.cpp index bef6fc0..e4ce1fd 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -1416,6 +1416,7 @@ loadWorldFromXMLNoSave( std::string path ) { while(vil){ name = vil->Name(); randx = 0; + //static BuySell bs; /** * READS DATA ABOUT STRUCTURE CONTAINED IN VILLAGE @@ -1437,10 +1438,17 @@ loadWorldFromXMLNoSave( std::string path ) { vil->StrAttribute("texture"), vil->StrAttribute("inside")); tmp->addMerchant(0,100); - if(!strcmp(name,"buy")){ - std::cout << "Buying"; - }else if(!strcmp(name,"sell")){ - std::cout << "Selling"; + if(vil->FirstChildElement("buy")){ + std::cout << "Buy" << std::endl; + /*bs.member = 0; + bs.cost.type = 0; + bs.cost.item = vil->FirstChildElement("buy")->Attribute("item"); + bs.cost.price =vil->FirstChildElement("buy")->IntAttribute("cost");*/ + tmp->merchant.back()->bsinv.push_back({0,"Dank MayMay",420}); + }if(vil->FirstChildElement("sell")){ + std::cout << "Sell" << std::endl; + }if(vil->FirstChildElement("trade")){ + std::cout << "Trade" << std::endl; } strcpy(tmp->merchant.back()->name,"meme"); diff --git a/xml/playerSpawnHill1.xml b/xml/playerSpawnHill1.xml index 2cac743..370cc03 100644 --- a/xml/playerSpawnHill1.xml +++ b/xml/playerSpawnHill1.xml @@ -17,8 +17,6 @@ <stall type="market" texture="assets/style/classic/stall.png"> <buy item="Dank MayMay" cost="420"/> <sell item="Dank MayMay" cost="666"/> - </stall> - <stall type="trader" texture="assets/style/classic/stall.png"> <trade item="Dank MayMay" item1="Sword"/> </stall> </village> |