diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/game.cpp | 40 | ||||
-rw-r--r-- | src/graphic/graphic.cpp | 32 | ||||
-rw-r--r-- | src/graphic/graphic.h | 2 | ||||
-rw-r--r-- | src/gui/skill.cpp | 16 | ||||
-rw-r--r-- | src/gui/skill.h | 3 | ||||
-rw-r--r-- | src/gui/stats.cpp | 56 | ||||
-rw-r--r-- | src/gui/stats.h | 83 | ||||
-rw-r--r-- | src/resources/resourcemanager.cpp | 1 |
8 files changed, 111 insertions, 122 deletions
diff --git a/src/game.cpp b/src/game.cpp index 647da20f..eb94541a 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -53,7 +53,6 @@ extern unsigned char screen_mode; int fps = 0, frame = 0; Setup *setup = NULL; -StatsWindow *stats = NULL; #define MAX_TIME 10000 @@ -322,14 +321,9 @@ bool handle_key(int unicode, int scancode) inventoryWindow->setVisible(!inventoryWindow->isVisible()); return true; case KEY_S: - if (stats == NULL) - stats = StatsWindow::create_statswindow(); - else { - stats->setVisible(!stats->isVisible()); - } + statsWindow->setVisible(!statsWindow->isVisible()); return true; case KEY_K: - //show_skill_list_dialog = !show_skill_dialog; skillDialog->setVisible(!skillDialog->isVisible()); return true; } @@ -647,7 +641,7 @@ void do_parse() { //break; } statusWindow->update(); - if(char_info->hp==0) { + if (char_info->hp == 0) { //OkDialog *death = new OkDialog("Message", // "You're now dead, press ok to restart"); //alert("","","","","",0,0); @@ -845,21 +839,29 @@ void do_parse() { break; // ?? case 0x0119: - sprintf(pkt_nfo, "%i %i %i %i", RFIFOL(2), RFIFOW(6), RFIFOW(8), RFIFOW(10)); - //alert(pkt_nfo,"","","","",0,0); + sprintf(pkt_nfo, "%i %i %i %i", + RFIFOL(2), RFIFOW(6), RFIFOW(8), RFIFOW(10)); break; // Skill list TAG case 0x010f: { int n_skills = (len - 4) / 37; - //SKILL *temp_skill = NULL; - for(int k=0;k<(len-4)/37;k++) { - if(RFIFOW(4+k*37+6)!=0 || RFIFOB(4+k*37+36)!=0) { - int skillId = RFIFOW(4+k*37); - if(skillDialog->getModel()->hasSkill(skillId)) { - skillDialog->getModel()->setSkill(skillId, RFIFOW(4+k*37+6), RFIFOW(4+k*37+36)); - } else { - skillDialog->getModel()->addSkill(RFIFOW(4+k*37), RFIFOW(4+k*37+6), RFIFOW(4+k*37+8)); + for (int k = 0; k < n_skills; k++) + { + if (RFIFOW(4 + k * 37 + 6) != 0 || + RFIFOB(4 + k * 37 + 36)!=0) + { + int skillId = RFIFOW(4 + k * 37); + if (skillDialog->getModel()->hasSkill(skillId)) { + skillDialog->getModel()->setSkill(skillId, + RFIFOW(4 + k * 37 + 6), + RFIFOW(4 + k * 37 + 36)); + } + else { + skillDialog->getModel()->addSkill( + RFIFOW(4 + k * 37), + RFIFOW(4 + k * 37 + 6), + RFIFOW(4 + k * 37 + 8)); } } } @@ -894,7 +896,6 @@ void do_parse() { // instead make sure the string is \0 terminated. //parse_items(RFIFOP(8), RFIFOW(2)); npcListDialog->parseItems(RFIFOP(8)); - RFIFOW(2); npcListDialog->setVisible(true); break; // Look change @@ -922,7 +923,6 @@ void do_parse() { //alert(pkt_nfo,"","","","",0,0); break; } - //alert(pkt_nfo,"","","","",0,0); RFIFOSKIP(len); } diff --git a/src/graphic/graphic.cpp b/src/graphic/graphic.cpp index 7678506b..1759f72a 100644 --- a/src/graphic/graphic.cpp +++ b/src/graphic/graphic.cpp @@ -48,6 +48,7 @@ InventoryWindow *inventoryWindow; NpcListDialog *npcListDialog; NpcTextDialog *npcTextDialog; SkillDialog *skillDialog; +StatsWindow *statsWindow; void ChatListener::action(const std::string& eventId) { @@ -183,6 +184,10 @@ GraphicEngine::GraphicEngine() { skillDialog = new SkillDialog(); skillDialog->setVisible(false); + statsWindow = new StatsWindow(); + statsWindow->setVisible(false); + + // Give focus to the chat input chatInput->requestFocus(); @@ -221,6 +226,7 @@ GraphicEngine::~GraphicEngine() { delete npcListDialog; delete npcTextDialog; delete skillDialog; + delete statsWindow; delete tileset; delete monsterset; @@ -252,11 +258,11 @@ void GraphicEngine::refresh() { if (tile0 < 600) { tileset->spriteset[tile0]->draw(buffer, - i * 32 - offset_x, j * 32 - offset_y); + i * 32 - offset_x, j * 32 - offset_y); } if (tile1 > 0) { //&& tile1 < 600 tileset->spriteset[tile1]->draw(buffer, - i * 32 - offset_x, j * 32 - offset_y); + i * 32 - offset_x, j * 32 - offset_y); } } @@ -460,27 +466,9 @@ void GraphicEngine::refresh() { chatlog.chat_draw(buffer, 8, font); - /* - if (show_skill_dialog) { - update_skill_dialog(); - } - - if (show_skill_list_dialog) { - if (gui_update(skill_list_player) == 0) { - int ret = shutdown_dialog(skill_list_player); - if (ret == 1) { - if (char_info->skill_point > 0) { - WFIFOW(0) = net_w_value(0x0112); - WFIFOW(2) = net_w_value( - get_skill_id(skill_list_dialog[3].d1)); - WFIFOSET(4); - } - } else if(ret == 2) { - show_skill_list_dialog = false; - } - } + if (statsWindow->isVisible()) { + statsWindow->update(); } - */ // Update character status display statusWindow->update(); diff --git a/src/graphic/graphic.h b/src/graphic/graphic.h index f9a5b4e7..970b09c9 100644 --- a/src/graphic/graphic.h +++ b/src/graphic/graphic.h @@ -39,6 +39,7 @@ #include "../gui/inventory.h" #include "../gui/npc.h" #include "../gui/status.h" +#include "../gui/stats.h" #include "../resources/resourcemanager.h" #include "spriteset.h" #include <allegro.h> @@ -64,6 +65,7 @@ extern InventoryWindow *inventoryWindow; extern NpcListDialog *npcListDialog; extern NpcTextDialog *npcTextDialog; extern SkillDialog *skillDialog; +extern StatsWindow *statsWindow; char get_x_offset(char, char); char get_y_offset(char, char); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index f2bf610c..88e16047 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -77,7 +77,10 @@ std::string SkillListModel::getElementAt(int i) { //return skill_db[skillList[i]->id]; char tmp[128]; - sprintf(tmp, "%s Lv: %i Sp: %i", skill_db[skillList[i]->id], skillList[i]->lv, skillList[i]->sp); + sprintf(tmp, "%s Lv: %i Sp: %i", + skill_db[skillList[i]->id], + skillList[i]->lv, + skillList[i]->sp); return tmp; } return ""; @@ -158,6 +161,12 @@ void SkillDialog::action(const std::string& eventId) if (eventId == "inc") { //increment skill + //if (char_info->skill_point > 0) { + // WFIFOW(0) = net_w_value(0x0112); + // WFIFOW(2) = net_w_value( + // get_skill_id(skill_list_dialog[3].d1)); + // WFIFOSET(4); + //} } else if (eventId == "close") { @@ -165,6 +174,11 @@ void SkillDialog::action(const std::string& eventId) } } +SkillListModel* SkillDialog::getModel() +{ + return skills; +} + void SkillDialog::setPoints(int i) { char tmp[128]; diff --git a/src/gui/skill.h b/src/gui/skill.h index dd3772cc..1d68bffe 100644 --- a/src/gui/skill.h +++ b/src/gui/skill.h @@ -89,7 +89,8 @@ class SkillDialog : public Window, public gcn::ActionListener ~SkillDialog(); void action(const std::string&); - SkillListModel* getModel() { return skills; } + + SkillListModel* getModel(); void setPoints(int i); }; diff --git a/src/gui/stats.cpp b/src/gui/stats.cpp index c5a3ebbd..7e9f6924 100644 --- a/src/gui/stats.cpp +++ b/src/gui/stats.cpp @@ -26,22 +26,20 @@ extern PLAYER_INFO *char_info; StatsWindow::StatsWindow(): - Window("Stats") + Window("Stats") { // New labels for (i = 0; i < 6; i++) { statsLabel[i] = new gcn::Label(); - statsDisplayLabel[i] = new gcn::Label(); + statsDisplayLabel[i] = new gcn::Label(); } remainingStatsPointsLabel = new gcn::Label(); - - update(); - + // New buttons for (i = 0; i < 6; i++) { statsButton[i] = new Button("+"); } - + // Set button events Id statsButton[0]->setEventId("STR"); statsButton[1]->setEventId("AGI"); @@ -49,24 +47,26 @@ StatsWindow::StatsWindow(): statsButton[3]->setEventId("INT"); statsButton[4]->setEventId("DEX"); statsButton[5]->setEventId("LUK"); - + // Set position for (i = 0; i < 6; i++) { statsLabel[i]->setPosition(10,(i*23)+10); - statsDisplayLabel[i]->setPosition(120,(i*23)+10); + statsDisplayLabel[i]->setPosition(120,(i*23)+10); statsButton[i]->setPosition(170,(i*23)+10); } remainingStatsPointsLabel->setPosition(10, 156); - + // Assemble for(i = 0; i < 6; i++) { add(statsLabel[i]); - add(statsDisplayLabel[i]); + add(statsDisplayLabel[i]); add(statsButton[i]); statsButton[i]->addActionListener(this); } add(remainingStatsPointsLabel); - + + update(); + setSize(200, 180); setLocationRelativeTo(getParent()); } @@ -75,7 +75,7 @@ void StatsWindow::update(){ std::stringstream statsStr[6]; std::stringstream figureStr[6]; std::stringstream remainingStatsPointsStr; - + statsStr[0] << "Strength:"; figureStr[0] << (int)char_info->STR; statsStr[1] << "Agility:"; @@ -88,17 +88,17 @@ void StatsWindow::update(){ figureStr[4] << (int)char_info->DEX; statsStr[5] << "Luck:"; figureStr[5] << (int)char_info->LUK; - + // for testing only... - + //remainingStatsPointsStr << "Remaining Status Points : " << char_info->statsPointsToAttribute; - + // Update labels for (i = 0; i < 6; i++) { statsLabel[i]->setCaption(statsStr[i].str()); statsLabel[i]->adjustSize(); - statsDisplayLabel[i]->setCaption(figureStr[i].str()); - statsDisplayLabel[i]->adjustSize(); + statsDisplayLabel[i]->setCaption(figureStr[i].str()); + statsDisplayLabel[i]->adjustSize(); } remainingStatsPointsLabel->setCaption(remainingStatsPointsStr.str()); remainingStatsPointsLabel->adjustSize(); @@ -107,26 +107,15 @@ void StatsWindow::update(){ StatsWindow::~StatsWindow() { for (int i = 0; i < 6; i++) { delete statsLabel[i]; - delete statsDisplayLabel[i]; + delete statsDisplayLabel[i]; delete statsButton[i]; - delete remainingStatsPointsLabel; } -} - -StatsWindow *StatsWindow::ptr = NULL; -StatsWindow *StatsWindow::create_statswindow() { - if (ptr == NULL) { - ptr = new StatsWindow(); - } - else { - ptr->setVisible(true); - } - return ptr; + delete remainingStatsPointsLabel; } void StatsWindow::action(const std::string& eventId) { WFIFOW(0) = net_w_value(0x00bb); - + if (eventId == "STR") { WFIFOW(2) = net_w_value(0x000d); } @@ -145,7 +134,8 @@ void StatsWindow::action(const std::string& eventId) { if (eventId == "LUK") { WFIFOW(2) = net_w_value(0x0012); } - + flush(); - update(); + WFIFOW(4) = net_b_value(1); + WFIFOSET(5); } diff --git a/src/gui/stats.h b/src/gui/stats.h index b730aefb..a220f125 100644 --- a/src/gui/stats.h +++ b/src/gui/stats.h @@ -32,51 +32,46 @@ #include <sstream> class StatsWindow : public Window, public gcn::ActionListener { - public: - /** - * Creates the Stats window. - */ - static StatsWindow *create_statswindow(); - - /** - * Called when receiving actions from widget. - */ - void action(const std::string& eventId); - - /** - * Updates stats in window. - */ - void update(); - - private: - int i; + public: + /** + * Constructor. + */ + StatsWindow(); - /** - * Stats captions. - */ - gcn::Label *statsLabel[6]; - gcn::Label *statsDisplayLabel[6]; - gcn::Label *remainingStatsPointsLabel; - - /** - * Stats buttons. - */ - Button *statsButton[6]; - - /** - * Stats window ptr. - */ - static StatsWindow *ptr; - - /** - * Constructor. - */ - StatsWindow(); - - /** - * Destructor. - */ - virtual ~StatsWindow(); + /** + * Destructor. + */ + virtual ~StatsWindow(); + + /** + * Called when receiving actions from widget. + */ + void action(const std::string& eventId); + + /** + * Updates stats in window. + */ + void update(); + + private: + int i; + + /** + * Stats captions. + */ + gcn::Label *statsLabel[6]; + gcn::Label *statsDisplayLabel[6]; + gcn::Label *remainingStatsPointsLabel; + + /** + * Stats buttons. + */ + Button *statsButton[6]; + + /** + * Stats window ptr. + */ + static StatsWindow *ptr; }; #endif /* _TMW_STATS_WINDOW_H */ diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 94dc3e9d..0d936836 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -148,7 +148,6 @@ ResourceManager* ResourceManager::getInstance() { // Create a new instance if necessary. if (instance == NULL) instance = new ResourceManager(); - return instance; } |