summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2004-12-28 17:28:21 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2004-12-28 17:28:21 +0000
commitff63c0e4a73f56558de77f255765e68b662008f6 (patch)
tree348aed36d6824fd60bf5e9fd8c6f0a0c7730b28f /src
parentc962acb281f41830a52df7c1888f92658aaf2700 (diff)
downloadmana-ff63c0e4a73f56558de77f255765e68b662008f6.tar.gz
mana-ff63c0e4a73f56558de77f255765e68b662008f6.tar.bz2
mana-ff63c0e4a73f56558de77f255765e68b662008f6.tar.xz
mana-ff63c0e4a73f56558de77f255765e68b662008f6.zip
Make stats window display numbers instead of characters.
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp123
-rw-r--r--src/graphic/graphic.cpp3
-rw-r--r--src/gui/stats.cpp68
-rw-r--r--src/gui/stats.h18
-rw-r--r--src/main.cpp10
5 files changed, 97 insertions, 125 deletions
diff --git a/src/game.cpp b/src/game.cpp
index aff40d47..1ca1b35f 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -53,7 +53,6 @@ extern unsigned char screen_mode;
Setup *setup = NULL;
StatsWindow *stats = NULL;
-bool show_stats;
#define MAX_TIME 10000
@@ -99,10 +98,9 @@ short get_elapsed_time(short start_time) {
void game() {
status("INIT");
do_init();
- //init_graphic();
GraphicEngine *graphicEngine = new GraphicEngine();
- while(state!=EXIT) {
+ while (state != EXIT) {
status("INPUT");
do_input();
status("GRAPHIC");
@@ -113,13 +111,13 @@ void game() {
flush();
}
+ delete graphicEngine;
close_session();
}
/** Initialize game engine */
void do_init() {
-
- if(!load_map(map_path)) {
+ if (!load_map(map_path)) {
error("Could not find map file");
}
@@ -150,7 +148,7 @@ void do_init() {
player_node->speed = 150;
player_node->hair_color = char_info->hair_color;
player_node->hair_style = char_info->hair_style;
- if(char_info->weapon==11) {
+ if (char_info->weapon == 11) {
char_info->weapon = 1;
}
player_node->weapon = char_info->weapon;
@@ -243,68 +241,59 @@ void do_input() {
//alert("","","","","",0,0);
}
- if(key[KEY_F10] && action_time==true) {
- //was 3 goes to 0
- //was 0 goes to 3
-
- screen_mode = 1-(screen_mode-1)+1;//Bug is here
- if( 0 != set_gfx_mode(screen_mode, 800, 600, 0, 0))//less than: to add support for other hardware platforms
- error(allegro_error);
- }
-
- if(key[KEY_F9] && action_time==true) {
- setup = Setup::create_setup();
- }
-
- // Emotions, Skill dialog
- if(key_shifts & KB_ALT_FLAG && action_time == true) {
- if(player_node->emotion==0) {
- unsigned char emotion = 0;
- if(key[KEY_1])
- emotion = 1;
- else if(key[KEY_2])
- emotion = 2;
- else if(key[KEY_3])
- emotion = 3;
- else if(key[KEY_4])
- emotion = 4;
- else if(key[KEY_5])
- emotion = 5;
- else if(key[KEY_6])
- emotion = 6;
- else if(key[KEY_7])
- emotion = 7;
- else if(key[KEY_8])
- emotion = 8;
- else if(key[KEY_9])
- emotion = 9;
- else if(key[KEY_0])
- emotion = 10;
- if(emotion!=0) {
- WFIFOW(0) = net_w_value(0x00bf);
- WFIFOB(2) = emotion;
- WFIFOSET(3);
- action_time = false;
- }
- }
+ if (key[KEY_F10] && action_time == true) {
+ // was 3 goes to 0
+ // was 0 goes to 3
+ screen_mode = 3 - screen_mode;
+ if (set_gfx_mode(screen_mode, 800, 600, 0, 0) != 0) {
+ // less than: to add support for other hardware platforms
+ error(allegro_error);
+ }
+ }
+
+ if (key[KEY_F9] && action_time == true) {
+ setup = Setup::create_setup();
+ }
+
+ // Emotions, Skill dialog
+ if (key_shifts & KB_ALT_FLAG && action_time == true) {
+ if (player_node->emotion == 0) {
+ unsigned char emotion = 0;
+ if (key[KEY_1]) emotion = 1;
+ else if (key[KEY_2]) emotion = 2;
+ else if (key[KEY_3]) emotion = 3;
+ else if (key[KEY_4]) emotion = 4;
+ else if (key[KEY_5]) emotion = 5;
+ else if (key[KEY_6]) emotion = 6;
+ else if (key[KEY_7]) emotion = 7;
+ else if (key[KEY_8]) emotion = 8;
+ else if (key[KEY_9]) emotion = 9;
+ else if (key[KEY_0]) emotion = 10;
+ if (emotion != 0) {
+ WFIFOW(0) = net_w_value(0x00bf);
+ WFIFOB(2) = emotion;
+ WFIFOSET(3);
+ action_time = false;
+ }
+ }
- if(key[KEY_S]) {
- show_stats = !show_stats;
- if(stats == NULL)
- stats = StatsWindow::create_statswindow();
- else if(show_stats) stats->setVisible(true);
- else if(!show_stats) stats->setVisible(false);
- action_time = false;
- } else if(key[KEY_I]) {
- inventoryWindow->setVisible(!inventoryWindow->isVisible());
- action_time = false;
- } else if(key[KEY_K]) {
- show_skill_list_dialog = !show_skill_dialog;
- action_time = false;
- }
- }
+ if (key[KEY_S]) {
+ if (stats == NULL)
+ stats = StatsWindow::create_statswindow();
+ else {
+ stats->setVisible(!stats->isVisible());
+ }
+ action_time = false;
+ } else if (key[KEY_I]) {
+ inventoryWindow->setVisible(!inventoryWindow->isVisible());
+ action_time = false;
+ } else if (key[KEY_K]) {
+ show_skill_list_dialog = !show_skill_dialog;
+ action_time = false;
+ }
+ }
- if(mouse_b&2) {
+ if (mouse_b & 2) {
//if(show_npc_dialog==0) {
int npc_x = mouse_x/32+camera_x;
int npc_y = mouse_y/32+camera_y;
@@ -318,7 +307,7 @@ void do_input() {
//}
}
- if(key[KEY_ESC]) {
+ if (key[KEY_ESC]) {
state = EXIT;
}
}
diff --git a/src/graphic/graphic.cpp b/src/graphic/graphic.cpp
index 6a870d2e..2635a194 100644
--- a/src/graphic/graphic.cpp
+++ b/src/graphic/graphic.cpp
@@ -554,5 +554,4 @@ void GraphicEngine::refresh() {
"[%i fps] %i,%i", fps, mouse_x/32+camera_x, mouse_y/32+camera_y);
blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
-
-} \ No newline at end of file
+}
diff --git a/src/gui/stats.cpp b/src/gui/stats.cpp
index 5b933339..54fbfaff 100644
--- a/src/gui/stats.cpp
+++ b/src/gui/stats.cpp
@@ -25,30 +25,21 @@
extern PLAYER_INFO *char_info;
-/**
- * Constructor
- */
StatsWindow::StatsWindow(gcn::Container *parent)
: Window(parent, "Stats")
{
- std::stringstream statsStr[6];
-
- statsStr[0] << "Strenght: " << char_info->STR;
- statsStr[1] << "Agility: " << char_info->AGI;
- statsStr[2] << "Vitality: " << char_info->VIT;
- statsStr[3] << "Inteligence: " << char_info->INT;
- statsStr[4] << "Dexternity: " << char_info->DEX;
- statsStr[5] << "Luck: " << char_info->LUK;
-
- /* New labels */
- for (i = 0; i < 6; i++)
- statsLabel[i] = new gcn::Label(statsStr[i].str());
+ // New labels
+ for (i = 0; i < 6; i++) {
+ statsLabel[i] = new gcn::Label();
+ }
+ update();
- /* New buttons */
- for (i = 0; i < 6; i++)
+ // New buttons
+ for (i = 0; i < 6; i++) {
statsButton[i] = new Button("+");
+ }
- /* Set button events Id */
+ // Set button events Id
statsButton[0]->setEventId("STR");
statsButton[1]->setEventId("AGI");
statsButton[2]->setEventId("VIT");
@@ -56,13 +47,13 @@ StatsWindow::StatsWindow(gcn::Container *parent)
statsButton[4]->setEventId("DEX");
statsButton[5]->setEventId("LUK");
- /* Set position */
+ // Set position
for (i = 0; i < 6; i++) {
statsLabel[i]->setPosition(10,(i*22)+10);
statsButton[i]->setPosition(170,(i*22)+10);
}
- /* Assemble */
+ // Assemble
for(i = 0; i < 6; i++) {
add(statsLabel[i]);
add(statsButton[i]);
@@ -72,27 +63,24 @@ StatsWindow::StatsWindow(gcn::Container *parent)
setSize(200, 150);
setLocationRelativeTo(getParent());
}
-/**
- * Method updates stats in window
- */
+
void StatsWindow::update(){
std::stringstream statsStr[6];
- statsStr[0] << "Strenght: " << char_info->STR;
- statsStr[1] << "Agility: " << char_info->AGI;
- statsStr[2] << "Vitality: " << char_info->VIT;
- statsStr[3] << "Inteligence: " << char_info->INT;
- statsStr[4] << "Dexternity: " << char_info->DEX;
- statsStr[5] << "Luck: " << char_info->LUK;
+ statsStr[0] << "Strenght: " << (int)char_info->STR;
+ statsStr[1] << "Agility: " << (int)char_info->AGI;
+ statsStr[2] << "Vitality: " << (int)char_info->VIT;
+ statsStr[3] << "Inteligence: " << (int)char_info->INT;
+ statsStr[4] << "Dexternity: " << (int)char_info->DEX;
+ statsStr[5] << "Luck: " << (int)char_info->LUK;
- /* Update labels */
- for (i = 0; i < 6; i++)
+ // Update labels
+ for (i = 0; i < 6; i++) {
statsLabel[i]->setCaption(statsStr[i].str());
+ statsLabel[i]->adjustSize();
+ }
}
-/**
- * Destructor
- */
StatsWindow::~StatsWindow() {
for(int i = 0; i < 6; i++) {
delete statsLabel[i];
@@ -100,21 +88,17 @@ StatsWindow::~StatsWindow() {
}
}
-/**
- * Static method for creating singleton objects
- */
StatsWindow * StatsWindow::ptr = NULL;
StatsWindow * StatsWindow::create_statswindow() {
- if (ptr == NULL)
+ if (ptr == NULL) {
ptr = new StatsWindow(guiTop);
- else
+ }
+ else {
ptr->setVisible(true);
+ }
return ptr;
}
-/**
- * Event handling method
- */
void StatsWindow::action(const std::string& eventId) {
//TODO: update char_info
if (eventId == "STR") {
diff --git a/src/gui/stats.h b/src/gui/stats.h
index c58c837f..deccba28 100644
--- a/src/gui/stats.h
+++ b/src/gui/stats.h
@@ -21,8 +21,8 @@
* $Id$
*/
-#ifndef _STATS_WINDOW_H
-#define _STATS_WINDOW_H
+#ifndef _TMW_STATS_WINDOW_H
+#define _TMW_STATS_WINDOW_H
#include "button.h"
#include "window.h"
@@ -33,17 +33,17 @@
class StatsWindow : public Window, public gcn::ActionListener {
public:
/**
- * Create the Stats window
+ * Creates the Stats window.
*/
static StatsWindow *create_statswindow();
/**
- * Metod called when receiving actions from widget.
+ * Called when receiving actions from widget.
*/
void action(const std::string& eventId);
/**
- * Metod updates stats in window.
+ * Updates stats in window.
*/
void update();
@@ -51,17 +51,17 @@ class StatsWindow : public Window, public gcn::ActionListener {
int i;
/**
- * Stats captions
+ * Stats captions.
*/
gcn::Label *statsLabel[6];
/**
- * Stats buttons
+ * Stats buttons.
*/
Button *statsButton[6];
/**
- * Stats window ptr
+ * Stats window ptr.
*/
static StatsWindow *ptr;
@@ -76,4 +76,4 @@ class StatsWindow : public Window, public gcn::ActionListener {
virtual ~StatsWindow();
};
-#endif /* _STATS_Window_H */
+#endif /* _TMW_STATS_WINDOW_H */
diff --git a/src/main.cpp b/src/main.cpp
index 20206e6b..07eafbf0 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -276,15 +276,15 @@ int main() {
init_engine();
// initialize sound-engine and start playing intro-theme /-kth5
try {
- if(config.getValue("sound", 0)==1)
- sound.Init(32,20);
- sound.SetVol(128,128,128);
- } catch(const char * err) {
+ if (config.getValue("sound", 0) == 1)
+ sound.Init(32, 20);
+ sound.SetVol(128, 128, 128);
+ } catch (const char *err) {
ok("Sound Engine", err);
warning(err);
}
- while(state!=EXIT) {
+ while (state != EXIT) {
switch(state) {
case LOGIN:
status("LOGIN");