示例#1
0
void EC_VideoSource::UpdateSignals()
{
    if (!GetParentEntity())
    {
        LogError("Couldn't update singals cause component dont have parent entity set.");
        return;
    }
    Scene::SceneManager *scene = GetParentEntity()->GetScene();
    if(!scene)
    {
        LogError("Fail to update signals cause parent entity's scene is null.");
        return;
    }

    // hack hack: seems phonon is more unstable to if we login to a world and instantiate many
    // players ~at the same time, so here we do a random timer to instantiate the objects so the QThreads are not
    // started ~at the same time and we minimize risk or crashing. Yes i know its stupid, blame phonon!
    int rand_time = qrand();
    while(rand_time > 3000)
        rand_time /= 2;
        if (rand_time < 500)
            rand_time = 500;
 
    // The magic number of instances before certain unstability is two, 
    // lets not let instantiate more phonon players than that for now
    Scene::EntityList list = GetFramework()->Scene()->GetDefaultScene()->GetEntitiesWithComponent(TypeNameStatic());
    if (list.size() < 2)
    {
        LogDebug(QString("Launching video ec in %1 ms").arg(rand_time).toStdString());
        QTimer::singleShot(rand_time, this, SLOT(InitializePhonon()));
    }
    else
    {
        LogDebug("Will not instantiate Phonon objects, world already has 2 EC_VideoSources. Limit hit.");
        canvas_ = Get3DCanvas();
        if (!canvas_)
        {
            LogError("Could not get 3D Canvas component");
            return;
        }

        // Tell in the 3D scene that the video cannot be displayed as two videos are already instantiated
        error_label_ = new QLabel("Maximum of inworld videos already in use");
        error_label_->setFont(QFont("Arial", 14));
        error_label_->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
        error_label_->setAlignment(Qt::AlignCenter);
        QSize size = error_label_->size();
        size.setHeight(size.height()+10);
        size.setWidth(size.width()+10);
        error_label_->resize(size);
  
        canvas_->SetWidget(error_label_);
        canvas_->SetRefreshRate(0);
        canvas_->SetSubmesh(0);
        QTimer::singleShot(100, canvas_, SLOT(Update()));
    }

    RegisterActions();
}
示例#2
0
EC_Touchable::EC_Touchable(IModule *module) :
    IComponent(module->GetFramework()),
    entityClone_(0),
    sceneNode_(0),
    materialName(this, "material name", "Touchable"),
    highlightOnHover(this, "highligh on hover", true),
    hoverCursor(this, "hover cursor", Qt::ArrowCursor)
{
    static AttributeMetadata metadata;
    static bool metadataInitialized = false;
    if(!metadataInitialized)
    {
        metadata.enums[Qt::ArrowCursor] = "ArrowCursor";
        metadata.enums[Qt::UpArrow] = "UpArrowCursor";
        metadata.enums[Qt::CrossCursor] = "CrossCursor";
        metadata.enums[Qt::WaitCursor] = "WaitCursor";
        metadata.enums[Qt::IBeamCursor] = "IBeamCursor";
        metadata.enums[Qt::SizeVerCursor] = "SizeVerCursor";
        metadata.enums[Qt::SizeHorCursor] = "SizeHorCursor";
        metadata.enums[Qt::SizeBDiagCursor] = "SizeBDiagCursor";
        metadata.enums[Qt::SizeFDiagCursor] = "SizeFDiagCursor";
        metadata.enums[Qt::SizeAllCursor] = "SizeAllCursor";
        metadata.enums[Qt::BlankCursor] = "BlankCursor";
        metadata.enums[Qt::SplitVCursor] = "SplitVCursor";
        metadata.enums[Qt::SplitHCursor] = "SplitHCursor";
        metadata.enums[Qt::PointingHandCursor] = "PointingHandCursor";
        metadata.enums[Qt::ForbiddenCursor] = "ForbiddenCursor";
        metadata.enums[Qt::WhatsThisCursor] = "WhatsThisCursor";
        metadata.enums[Qt::BusyCursor] = "BusyCursor";
        metadata.enums[Qt::OpenHandCursor] = "OpenHandCursor";
        metadata.enums[Qt::ClosedHandCursor] = "ClosedHandCursor";
        metadataInitialized = true;
    }

    hoverCursor.SetMetadata(&metadata);

    renderer_ = module->GetFramework()->GetServiceManager()->GetService<OgreRenderer::Renderer>(Service::ST_Renderer);
    connect(this, SIGNAL(AttributeChanged(IAttribute*, AttributeChange::Type)), SLOT(UpdateMaterial()));
    connect(this, SIGNAL(ParentEntitySet()), SLOT(RegisterActions()));
//    connect(this, SIGNAL(ParentEntitySet()), SLOT(Create()));
}
CNoWeapon::CNoWeapon()
: CWeapon()
{
	RegisterActions();
}
示例#4
0
bool GuiPage::Load(
	const std::string & path,
	const std::string & texpath,
	const float hwratio,
	const GuiLanguage & lang,
	const Font & font,
	const StrSignalMap & vsignalmap,
	const StrVecSlotMap & vnactionmap,
	const StrSlotMap & vactionmap,
	IntSlotMap nactionmap,
	SlotMap actionmap,
	ContentManager & content,
	std::ostream & error_output)
{
	Clear();

	Config pagefile;
	if (!pagefile.load(path))
	{
		error_output << "Couldn't find GUI page file: " << path << std::endl;
		return false;
	}

	if (!pagefile.get("", "name", name, error_output))
		return false;

	//error_output << "Loading " << path << std::endl;

	// load widgets and controls
	active_control = 0;
	std::map<std::string, GuiWidget*> widgetmap;			// labels, images, sliders
	std::map<std::string, GuiWidgetList*> widgetlistmap;	// labels, images lists
	std::vector<Config::const_iterator> controlit;			// control iterator cache
	std::vector<Config::const_iterator> controlnit;			// control list iterator cache
	std::vector<GuiControlList*> controllists;				// control list cache
	for (Config::const_iterator section = pagefile.begin(); section != pagefile.end(); ++section)
	{
		if (section->first.empty()) continue;

		Rect r = LoadRect(pagefile, section, hwratio);
		float x0 = r.x - r.w * 0.5;
		float y0 = r.y - r.h * 0.5;
		float x1 = r.x + r.w * 0.5;
		float y1 = r.y + r.h * 0.5;

		GuiWidget * widget = 0;

		// load widget(list)
		std::string value;
		if (pagefile.get(section, "text", value))
		{
			std::string alignstr;
			float fontsize = 0.03;
			pagefile.get(section, "fontsize", fontsize);
			pagefile.get(section, "align", alignstr);

			int align = 0;
			if (alignstr == "right") align = 1;
			else if (alignstr == "left") align = -1;

			float scaley = fontsize;
			float scalex = fontsize * hwratio;

			GuiLabelList * widget_list = 0;
			if (LoadList(pagefile, section, x0, y0, x1, y1, hwratio, widget_list))
			{
				// connect with the value list
				StrVecSlotMap::const_iterator vni = vnactionmap.find(value);
				if (vni != vnactionmap.end())
				{
					StrSignalMap::const_iterator vsi = vsignalmap.find(value + ".update");
					if (vsi != vsignalmap.end())
					{
						widget_list->update_list.connect(*vsi->second);
						vni->second->connect(widget_list->get_values);
					}
				}

				// init drawable
				widget_list->SetupDrawable(node, font, align, scalex, scaley, r.z);

				widgetlistmap[section->first] = widget_list;
				widget = widget_list;
			}
			else
			{
				// none is reserved for empty text string
				if (value == "none")
					value.clear();
				else
					value = lang(value);

				GuiLabel * new_widget = new GuiLabel();
				new_widget->SetupDrawable(
					node, font, align, scalex, scaley,
					r.x, r.y, r.w, r.h, r.z);

				ConnectAction(value, vsignalmap, new_widget->set_value);

				std::string name;
				if (pagefile.get(section, "name", name))
					labels[name] = new_widget;

				widgetmap[section->first] = new_widget;
				widget = new_widget;
			}
		}
		else if (pagefile.get(section, "image", value))
		{
			std::string slider, ext, path = texpath;
			pagefile.get(section, "path", path);
			pagefile.get(section, "ext", ext);

			GuiImageList * widget_list = 0;
			if (LoadList(pagefile, section, x0, y0, x1, y1, hwratio, widget_list))
			{
				// init drawable
				widget_list->SetupDrawable(node, content, path, ext, r.z);

				// connect with the value list
				StrVecSlotMap::const_iterator vni = vnactionmap.find(value);
				if (vni != vnactionmap.end())
				{
					StrSignalMap::const_iterator vsi = vsignalmap.find(value + ".update");
					if (vsi != vsignalmap.end())
					{
						widget_list->update_list.connect(*vsi->second);
						vni->second->connect(widget_list->get_values);
					}
				}
				else
				{
					// special case of list containing the same image?
					widget_list->SetImage(value);
				}

				widgetlistmap[section->first] = widget_list;
				widget = widget_list;
			}
			else if (pagefile.get(section, "slider", slider))
			{
				bool fill = false;
				pagefile.get(section, "fill", fill);

				TextureInfo texinfo;
				texinfo.mipmap = false;
				texinfo.repeatu = false;
				texinfo.repeatv = false;
				std::tr1::shared_ptr<Texture> tex;
				content.load(tex, texpath, value, texinfo);

				float radius = 0.0;
				if (pagefile.get(section, "radius", radius))
				{
					float start_angle(0), end_angle(2 * M_PI);
					pagefile.get(section, "start-angle", start_angle);
					pagefile.get(section, "end-angle", end_angle);

					GuiRadialSlider * new_widget = new GuiRadialSlider();
					new_widget->SetupDrawable(
						node, tex,
						r.x, r.y, r.w, r.h, r.z,
						start_angle, end_angle, radius,
						hwratio, fill, error_output);

					ConnectAction(slider, vsignalmap, new_widget->set_value);
					widget = new_widget;
				}
				else
				{
					GuiSlider * new_widget = new GuiSlider();
					new_widget->SetupDrawable(
						node, tex,
						r.x, r.y, r.w, r.h, r.z,
						fill, error_output);

					ConnectAction(slider, vsignalmap, new_widget->set_value);
					widget = new_widget;
				}

				widgetmap[section->first] = widget;
			}
			else
			{
				GuiImage * new_widget = new GuiImage();
				new_widget->SetupDrawable(
					node, content, path, ext,
					r.x, r.y, r.w, r.h, r.z);

				ConnectAction(value, vsignalmap, new_widget->set_image);

				widgetmap[section->first] = new_widget;
				widget = new_widget;
			}
		}

		// set widget properties (connect property slots)
		if (widget)
		{
			std::string val;
			if (pagefile.get(section, "visible", val))
				ConnectAction(val, vsignalmap, widget->set_visible);
			if (pagefile.get(section, "opacity", val))
				ConnectAction(val, vsignalmap, widget->set_opacity);
			if (pagefile.get(section, "color", val))
				ConnectAction(val, vsignalmap, widget->set_color);
			if (pagefile.get(section, "hue", val))
				ConnectAction(val, vsignalmap, widget->set_hue);
			if (pagefile.get(section, "sat", val))
				ConnectAction(val, vsignalmap, widget->set_sat);
			if (pagefile.get(section, "val", val))
				ConnectAction(val, vsignalmap, widget->set_val);

			widgets.push_back(widget);
		}

		// load controls
		bool focus;
		if (pagefile.get(section, "focus", focus))
		{
			GuiControl * control = 0;
			GuiControlList * control_list = 0;
			if (LoadList(pagefile, section, x0, y0, x1, y1, hwratio, control_list))
			{
				// register control list scroll actions
				actionmap[section->first + ".scrollf"] = &control_list->scroll_fwd;
				actionmap[section->first + ".scrollr"] = &control_list->scroll_rev;

				// connect with item list
				if (pagefile.get(section, "list", value))
				{
					StrSignalMap::const_iterator vsu = vsignalmap.find(value + ".update");
					StrSignalMap::const_iterator vsn = vsignalmap.find(value + ".nth");
					if (vsu != vsignalmap.end() && vsn != vsignalmap.end())
					{
						control_list->update_list.connect(*vsu->second);
						control_list->set_nth.connect(*vsn->second);
					}
					else
					{
						error_output << value << " is not a list." << std::endl;
					}
				}

				control = control_list;
				controlnit.push_back(section);
				controllists.push_back(control_list);
			}
			else
			{
				control = new GuiControl();
				controlit.push_back(section);
				controls.push_back(control);
			}
			control->SetRect(x0, y0, x1, y1);

			if (focus)
				active_control = control;
		}
	}

	// load control actions (connect control signals)

	// parse control event actions with values(arguments)
	typedef std::pair<std::string, Slot2<int, const std::string &>*> ActionValn;
	typedef std::pair<std::string, Slot1<const std::string &>*> ActionVal;
	std::set<ActionValn> action_valn_set;
	std::set<ActionVal> action_val_set;
	std::string actionstr;
	for (size_t i = 0; i < controlit.size(); ++i)
	{
		for (size_t j = 0; j < GuiControl::signal_names.size(); ++j)
		{
			if (pagefile.get(controlit[i], GuiControl::signal_names[j], actionstr))
				ParseActions(actionstr, vactionmap, widgetmap, widgetlistmap,
					action_val_set, action_valn_set);
		}
	}
	for (size_t i = 0; i < controlnit.size(); ++i)
	{
		for (size_t j = 0; j < GuiControl::signal_names.size(); ++j)
		{
			if (pagefile.get(controlnit[i], GuiControl::signal_names[j], actionstr))
				ParseActions(actionstr, vactionmap, widgetmap, widgetlistmap,
					action_val_set, action_valn_set);
		}
	}

	// parse page event actions with values
	if (pagefile.get("", "onfocus", actionstr))
		ParseActions(actionstr, vactionmap, widgetmap, widgetlistmap,
			action_val_set, action_valn_set);

	if (pagefile.get("", "oncancel", actionstr))
		ParseActions(actionstr, vactionmap, widgetmap, widgetlistmap,
			action_val_set, action_valn_set);

	// register controls, so that they can be activated by control events
	control_set.reserve(controlit.size() + controlnit.size());
	RegisterControls(controlit, controls, this, control_set, actionmap);
	RegisterControls(controlnit, controllists, this, control_set, actionmap);

	// register action calls with a parameter, so that they can be signaled by controls
	RegisterActions(lang, action_val_set, action_set, actionmap);
	RegisterActions(lang, action_valn_set, action_setn, nactionmap);

	// connect control signals with their actions
	for (size_t i = 0; i < controlit.size(); ++i)
	{
		for (size_t j = 0; j < GuiControl::EVENTNUM; ++j)
		{
			if (pagefile.get(controlit[i], GuiControl::signal_names[j], actionstr))
				ConnectActions(actionstr, actionmap, controls[i]->m_signal[j]);
		}
		for (size_t j = 0; j < GuiControl::EVENTVNUM; ++j)
		{
			if (pagefile.get(controlit[i], GuiControl::signal_names[GuiControl::EVENTNUM + j], actionstr))
				ConnectActions(actionstr, vactionmap, controls[i]->m_signalv[j]);
		}
	}
	for (size_t i = 0; i < controlnit.size(); ++i)
	{
		for (size_t j = 0; j < GuiControl::EVENTNUM; ++j)
		{
			if (pagefile.get(controlnit[i], GuiControl::signal_names[j], actionstr))
			{
				ConnectActions(actionstr, actionmap, controllists[i]->m_signal[j]);
				ConnectActions(actionstr, nactionmap, controllists[i]->m_signaln[j]);
			}
		}
	}

	// connect page event signals with their actions
	if (pagefile.get("", "onfocus", actionstr))
		ConnectActions(actionstr, actionmap, onfocus);

	if (pagefile.get("", "oncancel", actionstr))
		ConnectActions(actionstr, actionmap, oncancel);

	controls.insert(controls.end(), controllists.begin(), controllists.end());

	// set active control
	if (!active_control && !controls.empty())
		active_control = controls[0];

	// enable active control
	if (active_control)
		active_control->Signal(GuiControl::FOCUS);

	// set default control
	default_control = active_control;

	return true;
}