Esempio n. 1
0
void Client::initEventHandlers(MyGUI::Widget* pRootWidget)
{
	MyGUI::EnumeratorWidgetPtr enumerator = pRootWidget->getEnumerator();

	while (enumerator.next())
	{
		// buttons
		MyGUI::Widget* pCurrentElement = enumerator.current();
		const std::string widgetName = enumerator.current()->getName();

		if (widgetName.find("Button") != std::string::npos)
		{
			pCurrentElement->eventMouseButtonClick += MyGUI::newDelegate(this, &Client::button_handler);
		}

		// editboxes
		else if (widgetName.find("EditBox") != std::string::npos)
		{
			pCurrentElement->castType<MyGUI::EditBox>()->eventKeyButtonPressed += MyGUI::newDelegate(this, &Client::editBox_handler);
		}

		// sliders
		else if (widgetName.find("Slider") != std::string::npos)
		{
			pCurrentElement->castType<MyGUI::ScrollBar>()->eventScrollChangePosition += MyGUI::newDelegate(this, &Client::scrollChangePosition_handler);
		}

		// comboboxes
		else if (widgetName.find("ComboBox") != std::string::npos)
		{
			pCurrentElement->castType<MyGUI::ComboBox>()->eventComboChangePosition += MyGUI::newDelegate(this, &Client::comboBox_handler);
		}

		// checkboxes
		else if (widgetName.find("CheckBox") != std::string::npos)
		{
			pCurrentElement->eventMouseButtonClick += MyGUI::newDelegate(this, &Client::button_handler);
		}

		else if (pCurrentElement->getChildCount() > 0)
		{
			initEventHandlers(pCurrentElement);
		}
	}
}
Esempio n. 2
0
//-------------------------------------------------------------------------------
void MaterialViewer::onClickApply(MyGUI::WidgetPtr)
{
    //Update properties.
    MyGUI::EnumeratorWidgetPtr iter = mWindow->getEnumerator();
    while (iter.next())
    {
        MyGUI::Widget *widget = iter.current();
        if (widget->getUserString("type") == "MaterialProperty") 
            mMaterialSettings[widget->getUserString("property")] = dynamic_cast<MyGUI::Edit*>(widget)->getOnlyText();
    }
    MyGUI::ComboBoxPtr list = GlbVar.gui->findWidget<MyGUI::ComboBox>("cmb_materialType");
    mMaterialType = list->getItemNameAt(list->getIndexSelected());
    
    //Compile.
    compileMaterial();
}
Esempio n. 3
0
    void SettingsWindow::configureWidgets(MyGUI::Widget* widget)
    {
        MyGUI::EnumeratorWidgetPtr widgets = widget->getEnumerator();
        while (widgets.next())
        {
            MyGUI::Widget* current = widgets.current();

            std::string type = getSettingType(current);
            if (type == checkButtonType)
            {
                std::string initialValue = Settings::Manager::getBool(getSettingName(current),
                                                                      getSettingCategory(current))
                        ? "#{sOn}" : "#{sOff}";
                current->castType<MyGUI::Button>()->setCaptionWithReplacing(initialValue);
                current->eventMouseButtonClick += MyGUI::newDelegate(this, &SettingsWindow::onButtonToggled);
            }
            if (type == sliderType)
            {
                MyGUI::ScrollBar* scroll = current->castType<MyGUI::ScrollBar>();
                std::string valueStr;
                if (getSettingValueType(current) == "Float")
                {
                    // TODO: ScrollBar isn't meant for this. should probably use a dedicated FloatSlider widget
                    float min,max;
                    getSettingMinMax(scroll, min, max);
                    float value = Settings::Manager::getFloat(getSettingName(current), getSettingCategory(current));
                    valueStr = MyGUI::utility::toString((int)value);
                    value = std::max(min, std::min(value, max));
                    value = (value-min)/(max-min);

                    scroll->setScrollPosition(static_cast<size_t>(value * (scroll->getScrollRange() - 1)));
                }
                else
                {
                    int value = Settings::Manager::getInt(getSettingName(current), getSettingCategory(current));
                    valueStr = MyGUI::utility::toString(value);
                    scroll->setScrollPosition(value);
                }
                scroll->eventScrollChangePosition += MyGUI::newDelegate(this, &SettingsWindow::onSliderChangePosition);
                updateSliderLabel(scroll, valueStr);
            }

            configureWidgets(current);
        }
    }
void DashBoard::loadLayoutRecursive(MyGUI::WidgetPtr w)
{
    std::string name     = w->getName();
    std::string anim     = w->getUserString("anim");
    std::string debug    = w->getUserString("debug");
    std::string linkArgs = w->getUserString("link");

    // make it unclickable
    w->setUserString("interactive", "0");

    if (!debug.empty())
    {
        w->setVisible(false);
        return;
    }

    // find the root widget and ignore debug widgets
    if (name.size() > prefix.size())
    {
        std::string prefixLessName = name.substr(prefix.size());
        if (prefixLessName == "_Main")
        {
            mainWidget = (MyGUI::WindowPtr)w;
            // resize it
            windowResized();
        }

        // ignore debug widgets
        if (prefixLessName == "DEBUG")
        {
            w->setVisible(false);
            return;
        }
    }


    // animations for this control?
    if (!linkArgs.empty())
    {

        layoutLink_t ctrl;
        memset(&ctrl, 0, sizeof(ctrl));

        if (!name.empty()) strncpy(ctrl.name, name.c_str(), 255);
        ctrl.widget          = w;
        ctrl.initialSize     = w->getSize();
        ctrl.initialPosition = w->getPosition();
        ctrl.last            = 1337.1337f; // force update
        ctrl.lastState       = true;

        // establish the link
        {

            replaceString(linkArgs, "&gt;", ">");
            replaceString(linkArgs, "&lt;", "<");
            String linkName = "";
            if (linkArgs.empty())
            {
                LOG("Dashboard ("+filename+"/"+name+"): empty Link");
                return;
            }
            // conditional checks
            // TODO: improve the logic, this is crap ...
            if (linkArgs.find(">") != linkArgs.npos)
            {
                Ogre::StringVector args = Ogre::StringUtil::split(linkArgs, ">");
                if (args.size() == 2)
                {
                    linkName = args[0];
                    ctrl.conditionArgument = StringConverter::parseReal(args[1]);
                    ctrl.condition = CONDITION_GREATER;
                } else
                {
                    LOG("Dashboard ("+filename+"/"+name+"): error in conditional Link: " + linkArgs);
                    return;
                }
            } else if (linkArgs.find("<") != linkArgs.npos )
            {
                Ogre::StringVector args = Ogre::StringUtil::split(linkArgs, "<");
                if (args.size() == 2)
                {
                    linkName = args[0];
                    ctrl.conditionArgument = StringConverter::parseReal(args[1]);
                    ctrl.condition = CONDITION_LESSER;
                } else
                {
                    LOG("Dashboard ("+filename+"/"+name+"): error in conditional Link: " + linkArgs);
                    return;
                }
            } else
            {
                ctrl.condition         = CONDITION_NONE;
                ctrl.conditionArgument = 0;
                linkName               = linkArgs;
            }

            // now try to get the enum id for it
            int linkID = manager->getLinkIDForName(linkName);
            if (linkID < 0)
            {
                LOG("Dashboard ("+filename+"/"+name+"): unknown Link: " + linkName);
                return;
            }
            ctrl.linkID = linkID;
        }

        // parse more attributes
        ctrl.wmin = StringConverter::parseReal(w->getUserString("min"));
        ctrl.wmax = StringConverter::parseReal(w->getUserString("max"));
        ctrl.vmin = StringConverter::parseReal(w->getUserString("vmin"));
        ctrl.vmax = StringConverter::parseReal(w->getUserString("vmax"));

        String texture = w->getUserString("texture");
        if (!texture.empty()) strncpy(ctrl.texture, texture.c_str(), 255);

        String format = w->getUserString("format");
        if (!format.empty()) strncpy(ctrl.format, format.c_str(), 255);

        String direction = w->getUserString("direction");
        if (direction == "right")     ctrl.direction = DIRECTION_RIGHT;
        else if (direction == "left") ctrl.direction = DIRECTION_LEFT;
        else if (direction == "down") ctrl.direction = DIRECTION_DOWN;
        else if (direction == "up")   ctrl.direction = DIRECTION_UP;
        else if (!direction.empty())
        {
            LOG("Dashboard ("+filename+"/"+name+"): unknown direction: " + direction);
            return;

        }
        // then specializations
        if (anim == "rotate")
        {
            ctrl.animationType = ANIM_ROTATE;
            // check if its the correct control
            // try to cast, will throw
            // and if the link is a float
            /*
            if (manager->getDataType(ctrl.linkID) != DC_FLOAT)
            {
            	LOG("Dashboard ("+filename+"/"+name+"): Rotating controls can only link to floats");
            	continue;
            }
            */

            try
            {
                ctrl.rotImg = w->getSubWidgetMain()->castType<MyGUI::RotatingSkin>();
            }
            catch (...)
            {
                LOG("Dashboard ("+filename+"/"+name+"): Rotating controls must use the RotatingSkin");
                return;
            }
            if (!ctrl.rotImg)
            {
                LOG("Dashboard ("+filename+"/"+name+"): error loading rotation control");
                return;
            }

            // special: set rotation center now into the middle
            ctrl.rotImg->setCenter(MyGUI::IntPoint(w->getHeight() * 0.5f, w->getWidth() * 0.5f));

        }
        else if (anim == "scale")
        {
            ctrl.animationType = ANIM_SCALE;
            if (ctrl.direction == DIRECTION_NONE)
            {
                LOG("Dashboard ("+filename+"/"+name+"): direction empty: scale needs a direction");
                return;
            }
        }
        else if (anim == "translate")
        {
            ctrl.animationType = ANIM_TRANSLATE;
            if (ctrl.direction == DIRECTION_NONE)
            {
                LOG("Dashboard ("+filename+"/"+name+"): direction empty: translate needs a direction");
                return;
            }
        }
        else if (anim == "series")
        {
            ctrl.animationType = ANIM_SERIES;
            ctrl.img = (MyGUI::ImageBox *)w; //w->getSubWidgetMain()->castType<MyGUI::ImageBox>();
            if (!ctrl.img)
            {
                LOG("Dashboard ("+filename+"/"+name+"): error loading series control");
                return;
            }
        }
        else if (anim == "textcolor" || anim == "textcolour")
        {
            ctrl.animationType = ANIM_TEXTCOLOR;

            // try to cast, will throw
            try
            {
                ctrl.txt = (MyGUI::TextBox *)w;
            }
            catch (...)
            {
                LOG("Dashboard ("+filename+"/"+name+"): textcolor controls must use the TextBox Control");
                return;
            }
        }
        else if (anim == "textformat")
        {
            // try to cast, will throw
            try
            {
                ctrl.txt = (MyGUI::TextBox *)w; // w->getSubWidgetMain()->castType<MyGUI::TextBox>();
            }
            catch (...)
            {
                LOG("Dashboard ("+filename+"/"+name+"): Lamp controls must use the ImageBox Control");
                return;
            }
            ctrl.animationType = ANIM_TEXTFORMAT;
        }
        else if (anim == "textstring")
        {
            // try to cast, will throw
            try
            {
                ctrl.txt = (MyGUI::TextBox *)w; // w->getSubWidgetMain()->castType<MyGUI::TextBox>();
            }
            catch (...)
            {
                LOG("Dashboard ("+filename+"/"+name+"): Lamp controls must use the ImageBox Control");
                return;
            }
            ctrl.animationType = ANIM_TEXTSTRING;
        }
        else if (anim == "lamp")
        {
            // try to cast, will throw
            /*
            {
            	try
            	{
            		w->getSubWidgetMain()->castType<MyGUI::ImageBox>();
            	}
            	catch (...)
            	{
            		LOG("Dashboard ("+filename+"/"+name+"): Lamp controls must use the ImageBox Control");
            		continue;
            	}
            }
            */
            ctrl.animationType = ANIM_LAMP;
            ctrl.img = (MyGUI::ImageBox *)w; //w->getSubWidgetMain()->castType<MyGUI::ImageBox>();
            if (!ctrl.img)
            {
                LOG("Dashboard ("+filename+"/"+name+"): error loading Lamp control");
                return;
            }
        }


        controls[free_controls] = ctrl;
        free_controls++;
        if (free_controls >= MAX_CONTROLS)
        {
            LOG("maximum amount of controls reached, discarding the rest: " + TOSTRING(MAX_CONTROLS));
            return;
        }
    }

    // walk the children now
    MyGUI::EnumeratorWidgetPtr e = w->getEnumerator();
    while (e.next())
    {
        loadLayoutRecursive(e.current());
    }
}
Esempio n. 5
0
//-------------------------------------------------------------------------------
void MainMenu::init()
{
    int winHeight = GlbVar.ogreWindow->getHeight();
    int winWidth = GlbVar.ogreWindow->getWidth();
    GlbVar.fader->abortFade(0);

    //Gotta see where we click. :-)
    GlbVar.gui->setVisiblePointer(true);

    //Background, logo.
    mBackground = GlbVar.gui->createWidget<MyGUI::StaticImage>("StaticImage", MyGUI::IntCoord(0,0,winWidth,winHeight), MyGUI::Align::Default, "Back");
    mBackground->setImageTexture("MainMenuBgr.png");

    int logoX = winWidth - (LOGO_WIDTH + 5);
    int logoY = winHeight - (LOGO_HEIGHT + 5);
    mLogo = GlbVar.gui->createWidget<MyGUI::StaticImage>("StaticImage", MyGUI::IntCoord(logoX, logoY, LOGO_WIDTH, LOGO_HEIGHT), MyGUI::Align::Default, "Back");
    mLogo->setImageTexture("MainMenuLogo.png");

    //Get the Window.
    MyGUI::LayoutManager::getInstance().load("MainMenu.layout");
    mWindow = GlbVar.gui->findWidget<MyGUI::Window>("win_mainMenu");

    //Buttons, events.
    MyGUI::ButtonPtr button;
    button = GlbVar.gui->findWidget<MyGUI::Button>("but_newGame");
    button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickNewGame);

    button = GlbVar.gui->findWidget<MyGUI::Button>("but_continueGame");
    button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickContinueGame);
    if (GlbVar.records.firstTime)
        button->setEnabled(false);

    button = GlbVar.gui->findWidget<MyGUI::Button>("but_levelSelect");
    button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickLevelSelect);
    if (GlbVar.records.firstTime)
        button->setEnabled(false);

    button = GlbVar.gui->findWidget<MyGUI::Button>("but_userLevel");
    button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickUserLevel);
    if (GlbVar.userNgfNames.empty())
        button->setEnabled(false);

    button = GlbVar.gui->findWidget<MyGUI::Button>("but_options");
    button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickOptions);

    button = GlbVar.gui->findWidget<MyGUI::Button>("but_credits");
    button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickCredits);

    button = GlbVar.gui->findWidget<MyGUI::Button>("but_quit");
    button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickQuit);

    //Window properties.
    //Children don't inherit alpha.
    MyGUI::EnumeratorWidgetPtr iter = mWindow->getEnumerator();
    while (iter.next())
    {
        iter.current()->setInheritsAlpha(false);
    }

    mWindow->setAlpha(0);
    mWindow->setPosition(30,5);

    //Create child interfaces.

    //Level select.
    mLevelSelect = new LevelSelect();

    //Credits.
    MyGUI::LayoutManager::getInstance().load("Credits.layout");
    mCreditsWindow = GlbVar.gui->findWidget<MyGUI::Window>("win_credits");
    mCreditsWindow->setVisible(false);

    int height = mCreditsWindow->getHeight();
    int width = mCreditsWindow->getWidth();
    mCreditsWindow->setCoord(MyGUI::IntCoord((winWidth - width)*0.5, (winHeight - height)*0.5, width, height));

    button = GlbVar.gui->findWidget<MyGUI::Button>("but_cr_ok");
    button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickCloseCredits);

    MyGUI::EditPtr credits = GlbVar.gui->findWidget<MyGUI::Edit>("edt_cr_credits");
    credits->setOnlyText(creditsStr);
    credits->setTextAlign(MyGUI::Align::Left | MyGUI::Align::Top);

    //User level.
    MyGUI::LayoutManager::getInstance().load("LoadUserLevel.layout");
    mUserLevelWindow = GlbVar.gui->findWidget<MyGUI::Window>("win_userLevel");
    height = mUserLevelWindow->getHeight();
    width = mUserLevelWindow->getWidth();
    mUserLevelWindow->setCoord(MyGUI::IntCoord((winWidth - width)*0.5, (winHeight - height)*0.5, width, height));
    mUserLevelWindow->setVisible(false);

    //Tell the buttons to tell us.
    button = GlbVar.gui->findWidget<MyGUI::Button>("but_loadUserLevel");
    button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickLoadUserLevel);

    button = GlbVar.gui->findWidget<MyGUI::Button>("but_cancelUserLevel");
    button->eventMouseButtonClick = MyGUI::newDelegate(this, &MainMenu::onClickCancelUserLevel);

    //Populate the user level list.
    MyGUI::ComboBox *list = GlbVar.gui->findWidget<MyGUI::ComboBox>("cmb_userLevel");

    for (std::vector<Ogre::String>::iterator iter = GlbVar.userNgfNames.begin(); iter != GlbVar.userNgfNames.end(); ++iter)
        list->addItem(*iter);

    if (!(GlbVar.userNgfNames.empty()))
        list->setIndexSelected(0);
}
Esempio n. 6
0
//-------------------------------------------------------------------------------
void MaterialViewer::init()
{
    //Create the mesh.
    mNode = GlbVar.ogreSmgr->getRootSceneNode()->createChildSceneNode("materialcube-node");
    mEntity = GlbVar.ogreSmgr->createEntity("materialcube-entity", "Mesh_Cube.mesh");
    mNode->attachObject(mEntity);

    //Camera.
    mCameraYawNode = GlbVar.ogreSmgr->getRootSceneNode()->createChildSceneNode("materialviewercamera-yawnode");
    mCameraPitchNode = mCameraYawNode->createChildSceneNode("materialviewercamera-pitchnode");
    mCameraDist = 3;

    //Some test settings.
    mMaterialType = "BaseNormalMapParallax";
    mMaterialSettings["diffuse_tex"] = "WhiteTile1.png";
    mMaterialSettings["normal_tex"] = "WhiteTile_NM.png";
    mMaterialSettings["glow_tex"] = "WhiteLight_GW.png";

    mMaterialSettings["ambient"] = "0.7 0.7 0.7 1";
    mMaterialSettings["diffuse"] = "0.9 0.9 0.9 1";
    mMaterialSettings["specular"] = "0.8 0.8 0.8 1";
    mMaterialSettings["scaleBias"] = "0.04 0.02";
    mMaterialSettings["glow_amount"] = "0.5";

    //First compile.
    compileMaterial();

    //Load the layout.
    MyGUI::LayoutManager::getInstance().loadLayout("MaterialViewer.layout");
    mWindow = GlbVar.gui->findWidget<MyGUI::Window>("win_materialViewer");

    //Callbacks.
    MyGUI::ButtonPtr button = GlbVar.gui->findWidget<MyGUI::Button>("but_applyMaterial");
    button->eventMouseButtonClick += MyGUI::newDelegate(this, &MaterialViewer::onClickApply);

    button = GlbVar.gui->findWidget<MyGUI::Button>("but_saveMaterial");
    button->eventMouseButtonClick += MyGUI::newDelegate(this, &MaterialViewer::onClickSave);

    button = GlbVar.gui->findWidget<MyGUI::Button>("but_createLight");
    button->eventMouseButtonClick += MyGUI::newDelegate(this, &MaterialViewer::onClickCreateLight);

    //Update the editboxes.
    MyGUI::EnumeratorWidgetPtr iter = mWindow->getEnumerator();
    while (iter.next())
    {
        MyGUI::Widget *widget = iter.current();
        if (widget->getUserString("type") == "MaterialProperty") 
            dynamic_cast<MyGUI::Edit*>(widget)->setOnlyText(mMaterialSettings[widget->getUserString("property")]);
    }
    GlbVar.gui->findWidget<MyGUI::Edit>("edt_lightColour")->setOnlyText("0.7 0.7 0.7");

    //Populate the material type list.
    MyGUI::ComboBoxPtr list = GlbVar.gui->findWidget<MyGUI::ComboBox>("cmb_materialType");
    list->insertItemAt(0, "Base");
    list->insertItemAt(1, "BaseNormalMap");
    list->insertItemAt(2, "BaseNormalMapParallax");
    list->insertItemAt(3, "BaseGlow");
    list->insertItemAt(4, "BaseNormalMapGlow");
    list->insertItemAt(5, "BaseNormalMapParallaxGlow");
    list->insertItemAt(6, "BaseTransparent");
    list->setIndexSelected(2);
}