📄 inventory.cpp
字号:
/*************************************************************************** inventory.cpp - description ------------------- begin : Sat May 3 2003 copyright : (C) 2003 by Gabor Torok email : cctorok@yahoo.com ***************************************************************************//*************************************************************************** * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * * ***************************************************************************/#include "inventory.h"/** *@author Gabor Torok */Inventory::Inventory(Scourge *scourge) { this->scourge = scourge; // allocate strings for list this->pcInvText = (char**)malloc(MAX_INVENTORY_SIZE * sizeof(char*)); for(int i = 0; i < MAX_INVENTORY_SIZE; i++) { this->pcInvText[i] = (char*)malloc(120 * sizeof(char)); } this->skillLine = (char**)malloc(Constants::SKILL_COUNT * sizeof(char*)); for(int i = 0; i < Constants::SKILL_COUNT; i++) { this->skillLine[i] = (char*)malloc(120 * sizeof(char)); } this->stateLine = (char**)malloc(Constants::STATE_MOD_COUNT * sizeof(char*)); this->icons = (GLuint*)malloc(Constants::STATE_MOD_COUNT * sizeof(GLuint)); for(int i = 0; i < Constants::STATE_MOD_COUNT; i++) { this->stateLine[i] = (char*)malloc(120 * sizeof(char)); } this->objectiveText = (char**)malloc(MAX_INVENTORY_SIZE * sizeof(char*)); this->missionColor = (Color*)malloc(MAX_INVENTORY_SIZE * sizeof(Color)); for(int i = 0; i < MAX_INVENTORY_SIZE; i++) { this->objectiveText[i] = (char*)malloc(120 * sizeof(char)); } this->schoolText = (char**)malloc(MAX_INVENTORY_SIZE * sizeof(char*)); for(int i = 0; i < MAX_INVENTORY_SIZE; i++) { this->schoolText[i] = (char*)malloc(120 * sizeof(char)); } this->spellText = (char**)malloc(MAX_INVENTORY_SIZE * sizeof(char*)); for(int i = 0; i < MAX_INVENTORY_SIZE; i++) { this->spellText[i] = (char*)malloc(120 * sizeof(char)); } selected = selectedMode = 0; // construct UI mainWin = new Window( scourge->getSDLHandler(), 100, 50, 525, 505, strdup("Party Information"), scourge->getShapePalette()->getGuiTexture() ); char buttonText[80]; sprintf(buttonText, "%s (%s)", scourge->getParty()->getParty(0)->getName(), scourge->getParty()->getParty(0)->getCharacter()->getShortName()); player1Button = mainWin->createButton( 0, 0, 105, 30, strdup(buttonText), true); //player1Button->createLabel( 0, 42, scourge->getParty()->getParty(0)->getCharacter()->getName()); sprintf(buttonText, "%s (%s)", scourge->getParty()->getParty(1)->getName(), scourge->getParty()->getParty(1)->getCharacter()->getShortName()); player2Button = mainWin->createButton( 0, 30, 105, 60, strdup(buttonText), true); //mainWin->createLabel( 0, 74, scourge->getParty()->getParty(1)->getCharacter()->getName()); sprintf(buttonText, "%s (%s)", scourge->getParty()->getParty(2)->getName(), scourge->getParty()->getParty(2)->getCharacter()->getShortName()); player3Button = mainWin->createButton( 0, 60, 105, 90, strdup(buttonText), true ); //mainWin->createLabel( 0, 106, scourge->getParty()->getParty(2)->getCharacter()->getName()); sprintf(buttonText, "%s (%s)", scourge->getParty()->getParty(3)->getName(), scourge->getParty()->getParty(3)->getCharacter()->getShortName()); player4Button = mainWin->createButton( 0, 90, 105, 120, strdup(buttonText), true ); //mainWin->createLabel( 0, 138, scourge->getParty()->getParty(3)->getCharacter()->getName()); inventoryButton = mainWin->createButton( 420,0, 525, 30, strdup("Inventory"), true); skillsButton = mainWin->createButton( 420,30, 525, 60, strdup("Skills"), true); spellsButton = mainWin->createButton( 420,60, 525, 90, strdup("Spells"), true); missionButton = mainWin->createButton( 420, 90, 525, 120, strdup("Mission"), true); cards = new CardContainer(mainWin); // inventory page cards->createLabel(115, 15, strdup("Inventory:"), INVENTORY, Constants::RED_COLOR); inventoryWeightLabel = cards->createLabel(190, 15, NULL, INVENTORY); coinsLabel = cards->createLabel(300, 212, NULL, INVENTORY); cards->createLabel(115, 212, strdup("Equipped Items:"), INVENTORY, Constants::RED_COLOR); paperDoll = new Canvas(115, 220, 411, 251 + (Character::INVENTORY_COUNT * 15), this, this); cards->addWidget(paperDoll, INVENTORY); invList = new ScrollingList(115, 20, 295, 175, this); cards->addWidget(invList, INVENTORY); cards->createLabel(115, 475, Constants::getMessage(Constants::EXPLAIN_DRAG_AND_DROP), INVENTORY); int yy = 160; equipButton = cards->createButton( 0, yy, 105, yy + 30, strdup("Don/Doff"), INVENTORY); yy+=30; fixButton = cards->createButton( 0, yy, 105, yy + 30, strdup("Fix Item"), INVENTORY); yy+=30; removeCurseButton = cards->createButton( 0, yy, 105, yy + 30, strdup("Remove Curse"), INVENTORY ); yy+=30; combineButton = cards->createButton( 0, yy, 105, yy + 30, strdup("Combine Item"), INVENTORY ); yy+=30; enchantButton = cards->createButton( 0, yy, 105, yy + 30, strdup("Enchant Item"), INVENTORY ); yy+=30; identifyButton = cards->createButton( 0, yy, 105, yy + 30, strdup("Identify Item"), INVENTORY ); yy+=30; openButton = cards->createButton( 0, yy, 105, yy + 30, Constants::getMessage(Constants::OPEN_CONTAINER_LABEL), INVENTORY ); yy+=30; eatDrinkButton = cards->createButton( 0, yy, 105, yy + 30, strdup("Eat/Drink"), INVENTORY ); yy+=30; castScrollButton = cards->createButton( 0, yy, 105, yy + 30, strdup("Cast Scroll"), INVENTORY ); yy+=30; transcribeButton = cards->createButton( 0, yy, 105, yy + 30, strdup("Transcribe"), INVENTORY ); // character info nameAndClassLabel = cards->createLabel(115, 45, NULL, CHARACTER, Constants::RED_COLOR); attrCanvas = new Canvas( 115, 50, 405, 150, this ); cards->addWidget( attrCanvas, CHARACTER ); cards->createLabel(115, 165, strdup("Current State:"), CHARACTER, Constants::RED_COLOR); stateList = new ScrollingList(115, 170, 290, 70); cards->addWidget(stateList, CHARACTER); strcpy(skillsStr, "Skills:"); cards->createLabel(115, 255, skillsStr, CHARACTER, Constants::RED_COLOR); skillModLabel = cards->createLabel(220, 255, NULL, CHARACTER); skillList = new ScrollingList(115, 260, 290, 180); cards->addWidget(skillList, CHARACTER); skillAddButton = cards->createButton( 115, 445, 200, 475, strdup(" + "), CHARACTER); skillSubButton = cards->createButton( 320, 445, 405, 475, strdup(" - "), CHARACTER); levelUpButton = cards->createButton( 205, 445, 315, 475, strdup("Level Up"), CHARACTER); // spellbook cards->createLabel(115, 45, strdup("School of magic: (with provider deity)"), SPELL, Constants::RED_COLOR); schoolList = new ScrollingList(115, 50, 290, 100); cards->addWidget(schoolList, SPELL); cards->createLabel(115, 170, strdup("Spells memorized:"), SPELL, Constants::RED_COLOR); spellList = new ScrollingList(115, 175, 290, 150); cards->addWidget(spellList, SPELL); cards->createLabel(115, 345, strdup("Spell notes:"), SPELL, Constants::RED_COLOR); spellDescriptionLabel = new Label(115, 360, strdup(""), 58); cards->addWidget(spellDescriptionLabel, SPELL); castButton = cards->createButton( 0, 160, 105, 190, strdup("Cast"), SPELL); // mission cards->createLabel(115, 45, strdup("Current Mission"), MISSION, Constants::RED_COLOR); missionDescriptionLabel = new Label(115, 60, strdup(""), 50); cards->addWidget(missionDescriptionLabel, MISSION); cards->createLabel(115, 280, strdup("Mission Objectives"), MISSION, Constants::RED_COLOR); objectiveList = new ScrollingList(115, 285, 295, 175); cards->addWidget(objectiveList, MISSION); setSelectedPlayerAndMode(0, INVENTORY);}Inventory::~Inventory() {}void Inventory::drawWidget(Widget *w) { Creature *p = scourge->getParty()->getParty(selected); if(w == paperDoll) { float x = 125; for(int i = 0; i < Character::INVENTORY_COUNT; i++) { Item *item = scourge->getParty()->getParty(selected)->getEquippedInventory(i); if(item) { w->applySelectionColor(); glBegin( GL_QUADS ); glVertex2f( x, i * 16 ); glVertex2f( x, (i + 1) * 16 ); glVertex2f( w->getWidth(), (i + 1) * 16 ); glVertex2f( w->getWidth(), i * 16 ); glEnd(); } } ShapePalette *shapePal = scourge->getShapePalette();// glEnable(GL_ALPHA_TEST); //glAlphaFunc(GL_NOTEQUAL, 0); glPixelZoom( 1.0, -1.0 ); glRasterPos2f( 1, 1 ); glDrawPixels(shapePal->paperDoll->w, shapePal->paperDoll->h, GL_BGRA, GL_UNSIGNED_BYTE, shapePal->paperDollImage); //glDisable(GL_ALPHA_TEST); w->applyBorderColor(); glBegin( GL_LINES ); glVertex2f( x, 0 ); glVertex2f( x, w->getHeight() ); glEnd(); for(int i = 0; i < Character::INVENTORY_COUNT; i++) { Item *item = scourge->getParty()->getParty(selected)->getEquippedInventory(i); w->applyBorderColor(); glBegin( GL_LINES ); glVertex2f( x, (i + 1) * 16 ); glVertex2f( w->getWidth(), (i + 1) * 16 ); glEnd(); glColor3f( 0, 0, 0 ); if(!item) continue; scourge->getSDLHandler()->texPrint( x + 5, (i + 1) * 16 - 4, item->getItemName()); } } else { int y = 15; char s[80]; sprintf(s, "Exp: %u(%u)", p->getExp(), p->getExpOfNextLevel()); if(p->getStateMod(Constants::leveled)) { glColor4f( 1.0f, 0.2f, 0.0f, 1.0f ); } else { w->applyColor(); } scourge->getSDLHandler()->texPrint(5, y, s); w->applyColor(); sprintf(s, "HP: %d (%d)", p->getHp(), p->getMaxHp()); scourge->getSDLHandler()->texPrint(5, y + 15, s); sprintf(s, "MP: %d (%d)", p->getMp(), p->getMaxMp()); scourge->getSDLHandler()->texPrint(5, y + 30, s); sprintf(s, "AC: %d (%d)", p->getSkillModifiedArmor(), p->getArmor()); scourge->getSDLHandler()->texPrint(5, y + 45, s); sprintf(s, "Thirst: %d (10)", p->getThirst()); scourge->getSDLHandler()->texPrint(5, y + 60, s); sprintf(s, "Hunger: %d (10)", p->getHunger()); scourge->getSDLHandler()->texPrint(5, y + 75, s); Util::drawBar( 160, y - 3, 120, (float)p->getExp(), (float)p->getExpOfNextLevel(), 1.0f, 0.65f, 1.0f, false ); Util::drawBar( 160, y + 12, 120, (float)p->getHp(), (float)p->getMaxHp() ); Util::drawBar( 160, y + 27, 120, (float)p->getMp(), (float)p->getMaxMp(), 0.45f, 0.65f, 1.0f, false ); Util::drawBar( 160, y + 42, 120, (float)p->getSkillModifiedArmor(), (float)p->getArmor(), 0.45f, 0.65f, 1.0f, false ); Util::drawBar( 160, y + 57, 120, (float)p->getThirst(), 10.0f, 0.45f, 0.65f, 1.0f, false ); Util::drawBar( 160, y + 72, 120, (float)p->getHunger(), 10.0f, 0.45f, 0.65f, 1.0f, false ); }}bool Inventory::handleEvent(Widget *widget, SDL_Event *event) { Creature *creature = scourge->getParty()->getParty(selected); char *error = NULL; if(widget == mainWin->closeButton) mainWin->setVisible(false);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -