00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #include "gui/menuwindow.h"
00023
00024 #include "gui/widgets/button.h"
00025 #include "gui/widgets/window.h"
00026
00027 #include "graphics.h"
00028
00029 #include "utils/gettext.h"
00030
00031 #include <guichan/actionlistener.hpp>
00032
00033 #include <string>
00034
00035 extern Window *chatWindow;
00036 extern Window *equipmentWindow;
00037 extern Window *inventoryWindow;
00038 extern Window *itemShortcutWindow;
00039 extern Window *emoteWindow;
00040 extern Window *setupWindow;
00041 extern Window *skillDialog;
00042 extern Window *statusWindow;
00043 #ifdef TMWSERV_SUPPORT
00044 extern Window *buddyWindow;
00045 extern Window *guildWindow;
00046 extern Window *magicDialog;
00047 #endif
00048
00049 namespace {
00050 struct MenuWindowListener : public gcn::ActionListener
00051 {
00055 void action(const gcn::ActionEvent &event);
00056 } listener;
00057 }
00058
00059 MenuWindow::MenuWindow():
00060 Popup("Menu")
00061 {
00062
00063 static const char *buttonNames[] =
00064 {
00065 N_("Chat"),
00066 N_("Status"),
00067 N_("Equipment"),
00068 N_("Inventory"),
00069 N_("Skills"),
00070 #ifdef TMWSERV_SUPPORT
00071 N_("Magic"),
00072 N_("Guilds"),
00073 N_("Buddys"),
00074 #endif
00075 N_("Shortcut"),
00076 N_("Emote"),
00077 N_("Setup"),
00078 0
00079 };
00080 int x = 0, h = 0;
00081
00082 for (const char **curBtn = buttonNames; *curBtn; curBtn++)
00083 {
00084 gcn::Button *btn = new Button(gettext(*curBtn), *curBtn, &listener);
00085 btn->setPosition(x, 0);
00086 add(btn);
00087 x += btn->getWidth() + 3;
00088 h = btn->getHeight();
00089 }
00090
00091 setPosition(graphics->getWidth() - x - 3, 3);
00092 setContentSize(x - 3, h);
00093
00094 setVisible((bool) config.getValue(getPopupName() + "Visible", true));
00095 }
00096
00097 void MenuWindow::draw(gcn::Graphics *graphics)
00098 {
00099 drawChildren(graphics);
00100 }
00101
00102 void MenuWindowListener::action(const gcn::ActionEvent &event)
00103 {
00104 Window *window = NULL;
00105
00106 if (event.getId() == "Chat")
00107 {
00108 window = chatWindow;
00109 }
00110 else if (event.getId() == "Status")
00111 {
00112 window = statusWindow;
00113 }
00114 else if (event.getId() == "Equipment")
00115 {
00116 window = equipmentWindow;
00117 }
00118 else if (event.getId() == "Inventory")
00119 {
00120 window = inventoryWindow;
00121 }
00122 else if (event.getId() == "Skills")
00123 {
00124 window = skillDialog;
00125 }
00126 #ifdef TMWSERV_SUPPORT
00127 else if (event.getId() == "Magic")
00128 {
00129 window = magicDialog;
00130 }
00131 else if (event.getId() == "Guilds")
00132 {
00133 window = guildWindow;
00134 }
00135 else if (event.getId() == "Buddys")
00136 {
00137 window = buddyWindow;
00138 }
00139 #endif
00140 else if (event.getId() == "Shortcut")
00141 {
00142 window = itemShortcutWindow;
00143 }
00144 else if (event.getId() == "Emote")
00145 {
00146 window = emoteWindow;
00147 }
00148 else if (event.getId() == "Setup")
00149 {
00150 window = setupWindow;
00151 }
00152
00153 if (window)
00154 {
00155 window->setVisible(!window->isVisible());
00156 if (window->isVisible())
00157 {
00158 window->requestMoveToTop();
00159 }
00160 }
00161 }