Пример #1
0
void G_ExecuteCommand(char *action)
{
    alist_t	*al;
    
    al = ParseActions(action);
    al = DoRunActions(al, true);
    if(al)
    {
        AddActions(al);
        DerefActionList(al);
    }
}
Пример #2
0
static CMD(Alias)
{
    alist_t *al;
    
    if(!param[0])
    {
        I_Printf("Current Aliases:\n");
        G_ShowAliases(Actions);
        return;
    }
    al = ParseActions(param[1]);
    if(!al)
        G_UnregisterAction(param[0]);
    else
        G_AddCommand(param[0], G_RunAlias, (int64)al);
}
Пример #3
0
void G_BindAction(alist_t **plist, char *action)
{
    alist_t	*al;
    
    al = ParseActions(action);
    
    if(plist)
    {
        if(*plist)
            DerefActionList(*plist);
        *plist = al;
    }
    else
    {
        CON_Warnf("Unknown Key\n");
        DerefActionList(al);
    }
}
Пример #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;
}
bool CConfigParser::ParseConfig(string configFile, ADeviceListener& configClass)
{
	try
	{
		XMLPlatformUtils::Initialize();
	}
	catch(const XMLException& xmlEx)
	{	
		wstring message = L"Error initializing Xerces: ";
		message += xmlEx.getMessage();
		MessageBoxW(NULL, message.c_str(), L"Settings Error", MB_OK | MB_ICONERROR);
		return false;
	}

	XMLCh tempStr[100];
    XMLString::transcode("LS", tempStr, 99);
    DOMImplementation *impl = DOMImplementationRegistry::getDOMImplementation(tempStr);
    DOMBuilder* parser = ((DOMImplementationLS*)impl)->createDOMBuilder(DOMImplementationLS::MODE_SYNCHRONOUS, 0);

	if(parser->canSetFeature(XMLUni::fgDOMValidation, true))
        parser->setFeature(XMLUni::fgDOMValidation, true);
    if(parser->canSetFeature(XMLUni::fgDOMNamespaces, true))
        parser->setFeature(XMLUni::fgDOMNamespaces, true);
    if(parser->canSetFeature(XMLUni::fgDOMDatatypeNormalization, true))
        parser->setFeature(XMLUni::fgDOMDatatypeNormalization, true);

	char currentDir[MAX_PATH];
	::GetCurrentDirectory(MAX_PATH, (LPSTR)&currentDir);
	
	xercesc_2_7::DOMDocument* doc = NULL;

	// TODO: Should check to see if the file exists or not

	try
	{
		doc = parser->parseURI(configFile.c_str());
	}
	catch(const XMLException& xmlEx)
	{
		wstring message = L"Error parsing: ";
		message += xmlEx.getMessage();
		MessageBoxW(NULL, message.c_str(), L"Setting Parse Error", MB_OK | MB_ICONERROR);
		return false;
	}
	catch(const DOMException& domEx)
	{
		wstring message = L"Error parsing: ";
		message += domEx.getMessage();
		MessageBoxW(NULL, message.c_str(), L"Setting Parse Error", MB_OK | MB_ICONERROR);
		return false;
	}
	catch (...)
	{
		MessageBoxW(NULL, L"Unexpected error occured", L"Setting Parse Error", MB_OK | MB_ICONERROR);
		return false;
	}

	if(doc->getDocumentElement()->getAttributes()->getNamedItem(L"gestureTimeVariance"))
	{
		long variance = _wtoi(doc->getDocumentElement()->getAttributes()->getNamedItem(L"gestureTimeVariance")->getNodeValue());
		CTimeFrame::setVariance(variance);
	}

	if(!ParseDevices(doc->getElementsByTagName(L"devices"), configClass))
		return false;
	if(!ParseActions(doc->getElementsByTagName(L"actions"), configClass))
		return false;
	if(!ParseDeviceContexts(doc->getElementsByTagName(L"deviceContexts"), configClass))
		return false;
	if(!ParseContexts(doc->getElementsByTagName(L"contexts"), configClass))
		return false;

	// Set the current context to the first one in the list
	configClass.SetContext(configClass.GetContexts().begin()->first);

	parser->release();
	XMLPlatformUtils::Terminate();
	return true;
}
Пример #6
0
bool ParseReplay(const char *pszFilename, DWORD dwFlags)
{
  // Open replay file
  FileReader fr;
  if ( !fr.Open(pszFilename) )
    return false;

///////////////////// Header
  // Read replay resource identifier
  DWORD dwRepResourceID = 0;
  // Best guess: "reRS" is "replay RESOURCE"
  if ( !DecompressRead(&dwRepResourceID, sizeof(dwRepResourceID), fr) || dwRepResourceID != mmioFOURCC('r','e','R','S') )
    return errSimple("No Replay resource ID found.");

  // Read replay resource header
  if ( !DecompressRead(&replayHeader, sizeof(replayHeader), fr) )
    return errSimple("Unable to read replay header.");

////////////////// Actions
  // Read replay actions section size
  DWORD dwActionBufferSize = 0;
  if ( !DecompressRead(&dwActionBufferSize, 4, fr) )
    return errSimple("Unable to read actions size.");

  // Allocate and Read replay actions
  void *pActionBuffer = malloc(dwActionBufferSize);
  FileReader frActions(pActionBuffer, dwActionBufferSize);
  if ( dwActionBufferSize && !DecompressRead(pActionBuffer, dwActionBufferSize, fr) )
    return errSimple("Decompressing actions failed.");

/////////////////// Map Chk
  // get map chunk data size
  DWORD dwChkBufferSize = 0;
  if ( !DecompressRead(&dwChkBufferSize, 4, fr) )
    return errSimple("Unable to read chk size.");

  // Allocate and Read chk data
  void *pChkBuffer = malloc(dwChkBufferSize);
  //FileReader frChk(pChkBuffer, dwChkBufferSize);
  if ( dwChkBufferSize && !DecompressRead(pChkBuffer, dwChkBufferSize, fr) )
    return errSimple("Decompressing map failed.");

  // Write extracted replay data
  if ( dwFlags & RFLAG_EXTRACT )
  {
    WriteBuffer("%s.hdr", pszFilename, &replayHeader, sizeof(replayHeader));
    WriteBuffer("%s.act", pszFilename, pActionBuffer, dwActionBufferSize);
    WriteBuffer("%s.chk", pszFilename, pChkBuffer, dwChkBufferSize);
  }

  // parse data for repair
  if ( dwFlags & RFLAG_REPAIR )
  {
    // Parse replay actions
    ParseActions(frActions);

    if ( replayHeader.dwFrameCount < g_dwHighestFrame )
    {
      char szTmp[256];
      sprintf(szTmp, "Fixed replay with %u frames. Desired: %u frames.", replayHeader.dwFrameCount, g_dwHighestFrame);
      MessageBox(NULL, szTmp, "Fixed", 0);

      //replayHeader.dwFrameCount = g_dwHighestFrame + 10;
    }

    FileWriter fw;
    fw.Open(pszFilename);

    // write rep resource id
    dwRepResourceID = mmioFOURCC('r','e','R','S');
    CompressWrite(&dwRepResourceID, sizeof(dwRepResourceID), fw);

    // write header
    CompressWrite(&replayHeader, sizeof(replayHeader), fw);

    // write actions
    CompressWrite(&dwActionBufferSize, sizeof(dwActionBufferSize), fw);
    if ( dwActionBufferSize )
      CompressWrite(pActionBuffer, dwActionBufferSize, fw);
    
    // write chk
    CompressWrite(&dwChkBufferSize, sizeof(dwChkBufferSize), fw);
    if ( dwChkBufferSize )
      CompressWrite(pChkBuffer, dwChkBufferSize, fw);
  }

  return true;
}