summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/gui/buysell.cpp47
-rw-r--r--src/gui/menuwindow.cpp51
-rw-r--r--src/gui/npc_text.cpp3
-rw-r--r--src/properties.h2
4 files changed, 38 insertions, 65 deletions
diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp
index 6547a849..f443e237 100644
--- a/src/gui/buysell.cpp
+++ b/src/gui/buysell.cpp
@@ -30,42 +30,35 @@
BuySellDialog::BuySellDialog():
Window("Shop")
{
- gcn::Button *buyButton = new Button("Buy");
- gcn::Button *sellButton = new Button("Sell");
- gcn::Button *cancelButton = new Button("Cancel");
+ Button *buyButton = 0;
+ char *buttonNames[] = {
+ "Buy", "Sell", "Cancel", 0
+ };
+ int x = 10, y = 10, h;
- buyButton->setPosition(10, 10);
- sellButton->setPosition(
- buyButton->getX() + buyButton->getWidth() + 10, 10);
- cancelButton->setPosition(
- sellButton->getX() + sellButton->getWidth() + 10, 10);
- setContentSize(cancelButton->getX() + cancelButton->getWidth() + 10,
- cancelButton->getY() + cancelButton->getHeight() + 10);
-
- buyButton->setEventId("buy");
- sellButton->setEventId("sell");
- cancelButton->setEventId("cancel");
-
- buyButton->addActionListener(this);
- sellButton->addActionListener(this);
- cancelButton->addActionListener(this);
-
- add(buyButton);
- add(sellButton);
- add(cancelButton);
+ for (char **curBtn = buttonNames; *curBtn; curBtn++)
+ {
+ Button *btn = new Button(*curBtn);
+ if (!buyButton) buyButton = btn; // For focus request
+ btn->setEventId(*curBtn);
+ btn->addActionListener(this);
+ btn->setPosition(x, y);
+ add(btn);
+ x += btn->getWidth() + 10;
+ }
+ buyButton->requestFocus();
+ setContentSize(x, 2 * y + buyButton->getHeight());
setLocationRelativeTo(getParent());
- buyButton->requestFocus();
}
void BuySellDialog::action(const std::string& eventId)
{
- if (eventId == "buy") {
+ if (eventId == "Buy") {
current_npc->buy();
- }
- else if (eventId == "sell") {
+ } else if (eventId == "Sell") {
current_npc->sell();
- } else if (eventId == "cancel") {
+ } else if (eventId == "Cancel") {
current_npc = 0;
}
setVisible(false);
diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp
index ed32f61d..b243cd57 100644
--- a/src/gui/menuwindow.cpp
+++ b/src/gui/menuwindow.cpp
@@ -53,43 +53,22 @@ MenuWindow::MenuWindow():
// Buttons
// ------------
- gcn::Button *statusButton, *equipmentButton, *skillsButton,
- *inventoryButton, *setupButton;
-
- statusButton = new Button("Status");
- statusButton->setEventId("Status");
- statusButton->addActionListener(&menuWindowListener);
- statusButton->setPosition(0, 3);
- add(statusButton);
-
- equipmentButton = new Button("Equipment");
- equipmentButton->setEventId("Equipment");
- equipmentButton->addActionListener(&menuWindowListener);
- equipmentButton->setPosition(statusButton->getX() + statusButton->getWidth() + 3, statusButton->getY());
- add(equipmentButton);
-
- inventoryButton = new Button("Inventory");
- inventoryButton->setEventId("Inventory");
- inventoryButton->addActionListener(&menuWindowListener);
- inventoryButton->setPosition(equipmentButton->getX() + equipmentButton->getWidth() + 3, statusButton->getY());
- add(inventoryButton);
-
- skillsButton = new Button("Skills");
- skillsButton->setEventId("Skills");
- skillsButton->addActionListener(&menuWindowListener);
- skillsButton->setPosition(inventoryButton->getX() + inventoryButton->getWidth() + 3, statusButton->getY());
- add(skillsButton);
-
- setupButton = new Button("Setup");
- setupButton->setEventId("Setup");
- setupButton->addActionListener(&menuWindowListener);
- setupButton->setPosition(skillsButton->getX() + skillsButton->getWidth() + 3, statusButton->getY());
- add(setupButton);
+ char *buttonNames[] = {
+ "Status", "Equipment", "Inventory", "Skills", "Setup", 0
+ };
+ int x = 0, y = 3, h = 0;
+
+ for (char **curBtn = buttonNames; *curBtn; curBtn++) {
+ gcn::Button *btn = new Button(*curBtn);
+ btn->setEventId(*curBtn);
+ btn->addActionListener(&menuWindowListener);
+ btn->setPosition(x, y);
+ add(btn);
+ x += btn->getWidth() + 3;
+ h = btn->getHeight();
+ }
- int menuWidth = setupButton->getX() + setupButton->getWidth();
- setDefaultSize((graphics->getWidth() - menuWidth - 5), 0,
- menuWidth,
- (setupButton->getY() + setupButton->getHeight()));
+ setDefaultSize((graphics->getWidth() - x - 2), 0, x, (y + h));
}
void MenuWindow::draw(gcn::Graphics *g)
diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp
index 0769021e..27232f3b 100644
--- a/src/gui/npc_text.cpp
+++ b/src/gui/npc_text.cpp
@@ -76,7 +76,8 @@ NpcTextDialog::action(const std::string& eventId)
{
setText("");
setVisible(false);
- current_npc->nextDialog();
+ if (current_npc)
+ current_npc->nextDialog();
current_npc = 0;
}
}
diff --git a/src/properties.h b/src/properties.h
index 18caa6e1..ccf8cd00 100644
--- a/src/properties.h
+++ b/src/properties.h
@@ -77,7 +77,7 @@ class Properties
properties[name] = value;
}
- protected:
+ private:
std::map<std::string, std::string> properties;
};