Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

MenuOptions.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2004 Ivo Danihelka (ivo@danihelka.net)
00003  *
00004  * This program is free software; you can redistribute it and/or modify
00005  * it under the terms of the GNU General Public License as published by
00006  * the Free Software Foundation; either version 2 of the License, or
00007  * (at your option) any later version.
00008  */
00009 #include "MenuOptions.h"
00010 
00011 #include "Path.h"
00012 #include "HBox.h"
00013 #include "VBox.h"
00014 #include "WiPicture.h"
00015 #include "WiSpace.h"
00016 #include "WiButton.h"
00017 #include "WiStatusBar.h"
00018 #include "Slider.h"
00019 #include "SelectLang.h"
00020 #include "RadioBox.h"
00021 
00022 #include "Font.h"
00023 #include "Labels.h"
00024 #include "SimpleMsg.h"
00025 #include "OptionsInput.h"
00026 #include "OptionAgent.h"
00027 #include "SurfaceTool.h"
00028 #include "StringMsg.h"
00029 #include "UnknownMsgException.h"
00030 
00031 //-----------------------------------------------------------------
00032 MenuOptions::MenuOptions()
00033 {
00034     m_container = NULL;
00035     m_statusBar = NULL;
00036     m_needRefresh = false;
00037     registerDrawable(this);
00038     prepareMenu();
00039 
00040     takeHandler(new OptionsInput(this));
00041 }
00042 //-----------------------------------------------------------------
00043 MenuOptions::~MenuOptions()
00044 {
00045     delete m_container;
00046 }
00047 //-----------------------------------------------------------------
00048 /**
00049  * Display menu.
00050  */
00051     void
00052 MenuOptions::own_initState()
00053 {
00054     registerWatcher("lang");
00055     own_resumeState();
00056 }
00057 //-----------------------------------------------------------------
00058 /**
00059  * Display options menu.
00060  * Menu will be centred on screen.
00061  */
00062     void
00063 MenuOptions::own_resumeState()
00064 {
00065     int contentW = m_container->getW();
00066     int contentH = m_container->getH();
00067     OptionAgent *options = OptionAgent::agent();
00068     int screenW = options->getAsInt("screen_width");
00069     int screenH = options->getAsInt("screen_height");
00070 
00071     m_container->setShift(
00072             V2((screenW - contentW) / 2, (screenH - contentH) / 2));
00073 }
00074 //-----------------------------------------------------------------
00075 /**
00076  * Update statusbar.
00077  */
00078     void
00079 MenuOptions::own_updateState()
00080 {
00081     if (m_needRefresh) {
00082         m_needRefresh = false;
00083         prepareMenu();
00084         own_resumeState();
00085     }
00086     std::string tooltip = m_container->getTip(getInput()->getMouseLoc());
00087     m_statusBar->setLabel(tooltip);
00088 }
00089 //-----------------------------------------------------------------
00090 void
00091 MenuOptions::prepareMenu()
00092 {
00093     if (m_container) {
00094         deregisterDrawable(m_container);
00095         delete m_container;
00096         m_container = NULL;
00097     }
00098 
00099     Labels labels(Path::dataReadPath("script/labels.lua"));
00100     IWidget *soundBox = createSoundPanel(labels);
00101     IWidget *musicBox = createMusicPanel(labels);
00102 
00103     VBox *vbox = new VBox();
00104     vbox->addWidget(soundBox);
00105     vbox->addWidget(new WiSpace(0, 10));
00106     vbox->addWidget(musicBox);
00107     vbox->addWidget(new WiSpace(0, 10));
00108     vbox->addWidget(createLangPanel(labels));
00109     vbox->addWidget(new WiSpace(0, 5));
00110     vbox->addWidget(createSpeechPanel(labels));
00111     vbox->addWidget(new WiSpace(0, 5));
00112     vbox->addWidget(createSubtitlesPanel(labels));
00113 
00114     IWidget *backButton = createBackButton(labels);
00115     m_statusBar = createStatusBar(musicBox->getW() - backButton->getW());
00116     HBox *backBox = new HBox();
00117     backBox->addWidget(m_statusBar);
00118     backBox->addWidget(backButton);
00119 
00120     vbox->addWidget(backBox);
00121     m_container = vbox;
00122     registerDrawable(m_container);
00123 }
00124 //-----------------------------------------------------------------
00125 IWidget *
00126 MenuOptions::createSoundPanel(const Labels &labels)
00127 {
00128     HBox *soundBox = new HBox();
00129     soundBox->addWidget(new WiPicture(
00130                 Path::dataReadPath("images/menu/volume_sound.png")));
00131     soundBox->addWidget(new WiSpace(10, 0));
00132     soundBox->addWidget(new Slider("volume_sound", 0, 100));
00133     soundBox->setTip(labels.getLabel("menu_sound"));
00134     return soundBox;
00135 }
00136 //-----------------------------------------------------------------
00137 IWidget *
00138 MenuOptions::createMusicPanel(const Labels &labels)
00139 {
00140     HBox *musicBox = new HBox();
00141     musicBox->addWidget(new WiPicture(
00142                 Path::dataReadPath("images/menu/volume_music.png")));
00143     musicBox->addWidget(new WiSpace(10, 0));
00144     musicBox->addWidget(new Slider("volume_music", 0, 100));
00145     musicBox->setTip(labels.getLabel("menu_music"));
00146     return musicBox;
00147 }
00148 //-----------------------------------------------------------------
00149 IWidget *
00150 MenuOptions::createLangPanel(const Labels &labels)
00151 {
00152     HBox *langBox = new HBox();
00153     langBox->addWidget(new WiPicture(
00154                 Path::dataReadPath("images/menu/lang.png")));
00155     langBox->addWidget(new WiSpace(10, 0));
00156     langBox->addWidget(new SelectLang("lang",
00157                 Path::dataReadPath("script/select_lang.lua")));
00158     langBox->setTip(labels.getLabel("menu_lang"));
00159     return langBox;
00160 }
00161 //-----------------------------------------------------------------
00162 /**
00163  * Creates menu to select 'speech'.
00164  * NOTE: default speech is "cs".
00165  */
00166 IWidget *
00167 MenuOptions::createSpeechPanel(const Labels &labels)
00168 {
00169     OptionAgent::agent()->setDefault("speech", "cs");
00170     HBox *speechBox = new HBox();
00171     speechBox->addWidget(new WiPicture(
00172                 Path::dataReadPath("images/menu/speech.png")));
00173     speechBox->addWidget(new WiSpace(10, 0));
00174     speechBox->addWidget(new SelectLang("speech",
00175             Path::dataReadPath("script/select_speech.lua")));
00176     speechBox->setTip(labels.getLabel("menu_speech"));
00177     return speechBox;
00178 }
00179 //-----------------------------------------------------------------
00180 IWidget *
00181 MenuOptions::createSubtitlesPanel(const Labels &labels)
00182 {
00183     HBox *chooseBox = new HBox();
00184     chooseBox->addWidget(new WiPicture(
00185                 Path::dataReadPath("images/menu/subtitle.png")));
00186     chooseBox->addWidget(new WiSpace(10, 0));
00187     chooseBox->addWidget(new RadioBox("subtitles", "1",
00188                 Path::dataReadPath("images/menu/subtitles/yes.png")));
00189     chooseBox->addWidget(new RadioBox("subtitles", "0",
00190                 Path::dataReadPath("images/menu/subtitles/no.png")));
00191     chooseBox->setTip(labels.getLabel("menu_subtitles"));
00192     return chooseBox;
00193 }
00194 //-----------------------------------------------------------------
00195 IWidget *
00196 MenuOptions::createBackButton(const Labels &labels)
00197 {
00198     IWidget *button = new WiButton(
00199             new WiPicture(Path::dataReadPath("images/menu/back.png")),
00200             new SimpleMsg(this, "quit"));
00201     button->setTip(labels.getLabel("menu_back"));
00202     return button;
00203 }
00204 //-----------------------------------------------------------------
00205 WiStatusBar *
00206 MenuOptions::createStatusBar(int width)
00207 {
00208     SDL_Color color = {0, 255, 0, 255};
00209     Font *new_font = new Font(Path::dataReadPath("font/font_menu.ttf"), 16);
00210     return new WiStatusBar(new_font, color, width);
00211 }
00212 //-----------------------------------------------------------------
00213 /**
00214  * Start level under pressed button.
00215  * Start pedometer when level is solved already.
00216  */
00217     void
00218 MenuOptions::mouseButton(const MouseStroke &stroke)
00219 {
00220     m_container->mouseButton(stroke);
00221 }
00222 //-----------------------------------------------------------------
00223 void
00224 MenuOptions::drawOn(SDL_Surface *screen)
00225 {
00226     SDL_Color gray = {0xf0, 0xf0, 0xf0, 128};
00227     SurfaceTool::alphaFill(screen, NULL, gray);
00228 }
00229 //-----------------------------------------------------------------
00230 /**
00231  * Handle incoming message.
00232  * Messages:
00233  * - param_changed(lang) ... refresh menu
00234  *
00235  * @throws UnknownMsgException
00236  */
00237     void
00238 MenuOptions::receiveString(const StringMsg *msg)
00239 {
00240     if (msg->equalsName("param_changed")) {
00241         std::string param = msg->getValue();
00242         if ("lang" == param) {
00243             m_needRefresh = true;
00244         }
00245         else {
00246             throw UnknownMsgException(msg);
00247         }
00248     }
00249     else {
00250         throw UnknownMsgException(msg);
00251     }
00252 }
00253 

Generated on Wed Jun 1 09:54:31 2005 for Fish Fillets - Next Generation by  doxygen 1.4.2