00001 /* 00002 * The Mana World 00003 * Copyright (C) 2004 The Mana World Development Team 00004 * 00005 * This file is part of The Mana World. 00006 * 00007 * This program is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 2 of the License, or 00010 * any later version. 00011 * 00012 * This program is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with this program; if not, write to the Free Software 00019 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 */ 00021 00022 #include "buysell.h" 00023 00024 #include "npc.h" 00025 00026 #include "gui/widgets/button.h" 00027 00028 #include "net/net.h" 00029 #include "net/npchandler.h" 00030 00031 #include "utils/gettext.h" 00032 00033 BuySellDialog::BuySellDialog(): 00034 Window(_("Shop")) 00035 { 00036 setWindowName("BuySell"); 00037 Button *buyButton = 0; 00038 static const char *buttonNames[] = { 00039 N_("Buy"), N_("Sell"), N_("Cancel"), 0 00040 }; 00041 int x = 10, y = 10; 00042 00043 for (const char **curBtn = buttonNames; *curBtn; curBtn++) 00044 { 00045 Button *btn = new Button(gettext(*curBtn), *curBtn, this); 00046 if (!buyButton) 00047 buyButton = btn; // For focus request 00048 btn->setPosition(x, y); 00049 add(btn); 00050 x += btn->getWidth() + 10; 00051 } 00052 buyButton->requestFocus(); 00053 00054 setContentSize(x, 2 * y + buyButton->getHeight()); 00055 00056 center(); 00057 setDefaultSize(); 00058 loadWindowState(); 00059 } 00060 00061 void BuySellDialog::logic() 00062 { 00063 Window::logic(); 00064 00065 if (isVisible() && !current_npc) 00066 setVisible(false); 00067 } 00068 00069 void BuySellDialog::setVisible(bool visible) 00070 { 00071 Window::setVisible(visible); 00072 00073 if (visible) 00074 requestFocus(); 00075 } 00076 00077 void BuySellDialog::action(const gcn::ActionEvent &event) 00078 { 00079 setVisible(false); 00080 00081 NPC::isTalking = false; 00082 00083 if (event.getId() == "Buy") 00084 { 00085 Net::getNpcHandler()->buy(current_npc); 00086 } 00087 else if (event.getId() == "Sell") 00088 { 00089 Net::getNpcHandler()->sell(current_npc); 00090 } 00091 else if (event.getId() == "Cancel") 00092 { 00093 current_npc = 0; 00094 return; 00095 } 00096 }