diff options
author | Björn Steinbrink <B.Steinbrink@gmx.de> | 2006-02-01 10:32:43 +0000 |
---|---|---|
committer | Björn Steinbrink <B.Steinbrink@gmx.de> | 2006-02-01 10:32:43 +0000 |
commit | 6bff53b318937999a70d775bb6ecea2b18576e0f (patch) | |
tree | 66092571b605344a34c7360bccda50e86bc90b30 /src/gui/buysell.cpp | |
parent | 0e6385c12f325fa77ad57eba9b578de10d505ff7 (diff) | |
download | mana-6bff53b318937999a70d775bb6ecea2b18576e0f.tar.gz mana-6bff53b318937999a70d775bb6ecea2b18576e0f.tar.bz2 mana-6bff53b318937999a70d775bb6ecea2b18576e0f.tar.xz mana-6bff53b318937999a70d775bb6ecea2b18576e0f.zip |
Simplified button creation code in some windows. Fixed a bug where the game crashes if there's a message dialog from a npc that no longer exists. Reverted properties to private.
Diffstat (limited to 'src/gui/buysell.cpp')
-rw-r--r-- | src/gui/buysell.cpp | 47 |
1 files changed, 20 insertions, 27 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); |