void CGuiHandler::MenuChoice(string s)
{
	game->showList=0;
	delete list;
	if(inCommand>=0 && inCommand<commands.size())
	{
		CommandDescription& cd=commands[inCommand];
		switch(cd.type)
		{
		case CMDTYPE_COMBO_BOX:
			{
				inCommand=-1;
				vector<string>::iterator pi;
				int a=0;
				for(pi=++cd.params.begin();pi!=cd.params.end();++pi)
				{
					if(*pi==s)
					{
						Command c;
						c.id=cd.id;
						c.params.push_back(a);
						CreateOptions(c,0);
						selectedUnits.GiveCommand(c);
						break;
					}
					++a;
				}
			}
				break;
		}
	}
}
Example #2
0
/* Constructor. */
DIALOGUE::DIALOGUE(const CMarkup * original_script) : SCENE(original_script){
	Gdiplus::Font temp_font(fontFamily, text_size, Gdiplus::FontStyleRegular, Gdiplus::UnitPixel);
	line_height = static_cast<int>(temp_font.GetHeight(BMP_mix)); // sets the difference between two lines, in pixels
	line_top = video_height - 25; // sets top of the zero line 25 pixels beyond the bottom of the window

	highlited_option = 0;

	if(!scene_created)
		return;
	if(!CreateOptions())
		return;
	if(!DrawOptions())
		return;
	if(Play() != S_OK)
		return;
	PostSceneCreated();
}
Example #3
0
//---------------------------------------------------------------------------
void __fastcall TMainForm::FormCreate(TObject *Sender)
{
	Log::d("Main form alive");
	CreateOptions();
	FInAppPurchase = new TInAppPurchase(this);
    // Set the license Key for Android only
	// You can get this license from your Google Dev. Console.
	FInAppPurchase->ApplicationLicenseKey = "";
	FInAppPurchase->ProductIDs->Add(NoAdsID);
	FInAppPurchase->ProductIDs->Add(EuropeID);
	Log::d("Setting up IAP");
	FInAppPurchase->OnSetupComplete = &InAppPurchaseOnSetupComplete;
	FInAppPurchase->OnProductsRequestResponse = &InAppPurchaseProductsRequestResponse;
	FInAppPurchase->OnError = &InAppPurchaseError;
	FInAppPurchase->OnPurchaseCompleted = &InAppPurchasePurchaseCompleted;
	FInAppPurchase->SetupInAppPurchase();
	East = true;
	West = true;
	Central = true;
	CreateQuiz();
	CreateScore(QuizForm);
	CreateAnswer(QuizForm);
}
bool CGuiHandler::KeyPressed(unsigned short key)
{
	if(key==SDLK_ESCAPE && activeMousePress){
		activeMousePress=false;
		inCommand=-1;
		if(showingMetal){
			showingMetal=false;
			groundDrawer->SetExtraTexture(0,0,false);
		}
		return true;
	}
	if(key==SDLK_ESCAPE && inCommand>0){
		inCommand=-1;
		if(showingMetal){
			showingMetal=false;
			groundDrawer->SetExtraTexture(0,0,false);
		}
		return true;
	}
	unsigned char keyOptions=0;
	if(keys[SDLK_LSHIFT])
		keyOptions|=SHIFT_KEY;
	if(keys[SDLK_LCTRL])
		keyOptions|=CONTROL_KEY;
	if(keys[SDLK_LALT])
		keyOptions|=ALT_KEY;
	
	if (key >= SDLK_a && key <= SDLK_z)
		key = 'A' + (key - SDLK_a);

	int a;
	for(a=0;a<commands.size();++a){
		if(commands[a].key==key && (keyOptions==commands[a].switchKeys || keyOptions==(commands[a].switchKeys|SHIFT_KEY))){
			switch(commands[a].type){
			case CMDTYPE_ICON:{
				Command c;
				c.id=commands[a].id;
				CreateOptions(c,0);
				selectedUnits.GiveCommand(c);
				inCommand=-1;
				break;}
			case CMDTYPE_ICON_MODE:{
				int newMode=atoi(commands[a].params[0].c_str())+1;
				if(newMode>commands[a].params.size()-2)
					newMode=0;

				char t[10];
				SNPRINTF(t, 10, "%d", newMode);
				commands[a].params[0]=t;

				Command c;
				c.id=commands[a].id;
				c.params.push_back(newMode);
				CreateOptions(c,0);
				selectedUnits.GiveCommand(c);
				inCommand=-1;
				break;}
			case CMDTYPE_COMBO_BOX:{
				inCommand=a;
				CommandDescription& cd=commands[a];
				list=new CglList(cd.name.c_str(),MenuSelection);
				vector<string>::iterator pi;
				for(pi=++cd.params.begin();pi!=cd.params.end();++pi)
					list->AddItem(pi->c_str(),"");
				list->place=atoi(cd.params[0].c_str());
				game->showList=list;
				break;}
			default:
				inCommand=a;
			}
			return true;
		}
	}
	return false;
}
void CGuiHandler::MouseRelease(int x,int y,int button)
{
	if(activeMousePress)
		activeMousePress=false;
	else 
		return;

	if(needShift && !keys[SDLK_LSHIFT]){
		if(showingMetal){
			showingMetal=false;
			groundDrawer->SetExtraTexture(0,0,false);
		}
		inCommand=-1;
		needShift=false;
	}

	int icon=IconAtPos(x,y);

//	(*info) << x << " " << y << " " << mouse->lastx << " " << mouse->lasty << "\n";

	if (button == SDL_BUTTON_RIGHT && icon==-1) { // right click -> default cmd
		inCommand=defaultCmdMemory;//GetDefaultCommand(x,y);
		defaultCmdMemory=0;
	} 

	if(icon>=0 && icon<commands.size()){
		if(showingMetal){
			showingMetal=false;
			groundDrawer->SetExtraTexture(0,0,false);
		}
		switch(commands[icon].type){
			case CMDTYPE_ICON:{
				Command c;
				c.id=commands[icon].id;
				CreateOptions(c,(button==SDL_BUTTON_LEFT?0:1));
				selectedUnits.GiveCommand(c);
				inCommand=-1;
				break;}
			case CMDTYPE_ICON_MODE:{
				int newMode=atoi(commands[icon].params[0].c_str())+1;
				if(newMode>commands[icon].params.size()-2)
					newMode=0;

				char t[10];
				SNPRINTF(t, 10, "%d", newMode);
				commands[icon].params[0]=t;

				Command c;
				c.id=commands[icon].id;
				c.params.push_back(newMode);
				CreateOptions(c,(button==SDL_BUTTON_LEFT?0:1));
				selectedUnits.GiveCommand(c);
				inCommand=-1;
				break;}
			case CMDTYPE_ICON_MAP:
			case CMDTYPE_ICON_AREA:
			case CMDTYPE_ICON_UNIT:
			case CMDTYPE_ICON_UNIT_OR_MAP:
			case CMDTYPE_ICON_FRONT:
			case CMDTYPE_ICON_UNIT_OR_AREA:
			case CMDTYPE_ICON_UNIT_FEATURE_OR_AREA:
				inCommand=icon;
				break;

			case CMDTYPE_ICON_BUILDING:{
				UnitDef* ud=unitDefHandler->GetUnitByID(-commands[icon].id);
				if(ud->extractsMetal>0 && !groundDrawer->drawMetalMap && autoShowMetal){
					groundDrawer->SetMetalTexture(readmap->metalMap->metalMap,readmap->metalMap->extractionMap,readmap->metalMap->metalPal,false);
					showingMetal=true;
				}
				inCommand=icon;
				break;}

			case CMDTYPE_COMBO_BOX:
				{
					inCommand=icon;
					CommandDescription& cd=commands[icon];
					list=new CglList(cd.name.c_str(),MenuSelection);
					for(vector<string>::iterator pi=++cd.params.begin();pi!=cd.params.end();++pi)
						list->AddItem(pi->c_str(),"");
					list->place=atoi(cd.params[0].c_str());
					game->showList=list;
					return;
				}
				inCommand=-1;
				break;
			case CMDTYPE_NEXT:
				{
					++activePage;
					if(activePage>maxPages)
						activePage=0;
				}
				selectedUnits.SetCommandPage(activePage);
				inCommand=-1;
				break;

			case CMDTYPE_PREV:
				{
					--activePage;
					if(activePage<0)
						activePage=maxPages;
				}
				selectedUnits.SetCommandPage(activePage);
				inCommand=-1;
				break;
		}
		return;
	}

	Command c=GetCommand(x,y,button,false);

	if(c.id!=CMD_STOP)	//if cmd_stop is returned it indicates that no good command could be found
	selectedUnits.GiveCommand(c);
	FinishCommand(button);
}
Command CGuiHandler::GetCommand(int mousex, int mousey, int buttonHint, bool preview)
{
	Command defaultRet;
	defaultRet.id=CMD_STOP;

	int button;
	if(buttonHint>=SDL_BUTTON_LEFT)
		button=buttonHint;
	else if(inCommand!=-1)
		button=SDL_BUTTON_LEFT;
	else if(mouse->buttons[SDL_BUTTON_RIGHT].pressed)
		button=SDL_BUTTON_RIGHT;
	else
		return defaultRet;

	int tempInCommand=inCommand;

	if (button == SDL_BUTTON_RIGHT && preview) { // right click -> default cmd, in preview we might not have default cmd memory set
		if(mouse->buttons[SDL_BUTTON_RIGHT].pressed)
			tempInCommand=defaultCmdMemory;
		else
			tempInCommand=GetDefaultCommand(mousex,mousey);
	} 

	if(tempInCommand>=0 && tempInCommand<commands.size()){
		switch(commands[tempInCommand].type){

		case CMDTYPE_ICON:{
			Command c;
			c.id=commands[tempInCommand].id;
			CreateOptions(c,(button==SDL_BUTTON_LEFT?0:1));
			if(button==SDL_BUTTON_LEFT && !preview)
				info->AddLine("CMDTYPE_ICON left button press in incommand test? This shouldnt happen");
			return c;}

		case CMDTYPE_ICON_MAP:{
			float dist=ground->LineGroundCol(camera->pos,camera->pos+mouse->dir*9000);
			if(dist<0){
				return defaultRet;
			}
			float3 pos=camera->pos+mouse->dir*dist;
			Command c;
			c.id=commands[tempInCommand].id;
			c.params.push_back(pos.x);
			c.params.push_back(pos.y);
			c.params.push_back(pos.z);
			CreateOptions(c,(button==SDL_BUTTON_LEFT?0:1));
			return c;}

		case CMDTYPE_ICON_BUILDING:{
			float dist=ground->LineGroundCol(camera->pos,camera->pos+mouse->dir*9000);
			if(dist<0){
				return defaultRet;
			}
			string s=commands[guihandler->inCommand].name;
			UnitDef *unitdef = unitDefHandler->GetUnitByName(s);

			if(!unitdef){
				return defaultRet;
			}
			float3 pos=camera->pos+mouse->dir*dist;
			std::vector<float3> buildPos;
			if(keys[SDLK_LSHIFT] && button==SDL_BUTTON_LEFT){
				float dist=ground->LineGroundCol(mouse->buttons[SDL_BUTTON_LEFT].camPos,mouse->buttons[SDL_BUTTON_LEFT].camPos+mouse->buttons[SDL_BUTTON_LEFT].dir*9000);
				float3 pos2=mouse->buttons[SDL_BUTTON_LEFT].camPos+mouse->buttons[SDL_BUTTON_LEFT].dir*dist;
				buildPos=GetBuildPos(pos2,pos,unitdef);
			} else {
				buildPos=GetBuildPos(pos,pos,unitdef);
			}

			int a=0;		//limit the number of max commands possible to send to avoid overflowing the network buffer
			for(std::vector<float3>::iterator bpi=buildPos.begin();bpi!=--buildPos.end() && a<200;++bpi){
				++a;
				float3 pos=*bpi;
				Command c;
				c.id=commands[tempInCommand].id;
				c.params.push_back(pos.x);
				c.params.push_back(pos.y);
				c.params.push_back(pos.z);
				CreateOptions(c,(button==SDL_BUTTON_LEFT?0:1));
				if(!preview)
					selectedUnits.GiveCommand(c);
			}
			pos=*(--buildPos.end());
			Command c;
			c.id=commands[tempInCommand].id;
			c.params.push_back(pos.x);
			c.params.push_back(pos.y);
			c.params.push_back(pos.z);
			CreateOptions(c,(button==SDL_BUTTON_LEFT?0:1));
			return c;}

		case CMDTYPE_ICON_UNIT: {
			CUnit* unit=0;
			Command c;

			c.id=commands[tempInCommand].id;
			float dist2=helper->GuiTraceRay(camera->pos,mouse->dir,9000,unit,20,true);
			if (!unit){
				return defaultRet;
			}
			c.params.push_back(unit->id);
			CreateOptions(c,(button==SDL_BUTTON_LEFT?0:1));
			return c;}
		
		case CMDTYPE_ICON_UNIT_OR_MAP: {
			
			Command c;
			c.id=commands[tempInCommand].id;

			CUnit* unit=0;
			float dist2=helper->GuiTraceRay(camera->pos,mouse->dir,9000,unit,20,true);
			if(dist2>8900){
				return defaultRet;
			}

			if (unit!=0) {  // clicked on unit
				c.params.push_back(unit->id);
			} else { // clicked in map
				float3 pos=camera->pos+mouse->dir*dist2;
				c.params.push_back(pos.x);
				c.params.push_back(pos.y);
				c.params.push_back(pos.z);
			}
			CreateOptions(c,(button==SDL_BUTTON_LEFT?0:1));
			return c;}

		case CMDTYPE_ICON_FRONT:{
			Command c;

			float dist=ground->LineGroundCol(mouse->buttons[button].camPos,mouse->buttons[button].camPos+mouse->buttons[button].dir*9000);
			if(dist<0){
				return defaultRet;
			}
			float3 pos=mouse->buttons[button].camPos+mouse->buttons[button].dir*dist;
			c.id=commands[tempInCommand].id;
			c.params.push_back(pos.x);
			c.params.push_back(pos.y);
			c.params.push_back(pos.z);

			if(mouse->buttons[button].movement>30){		//only create the front if the mouse has moved enough
				dist=ground->LineGroundCol(camera->pos,camera->pos+mouse->dir*9000);
				if(dist<0){
					return defaultRet;
				}
				float3 pos2=camera->pos+mouse->dir*dist;
				if(!commands[tempInCommand].params.empty() && pos.distance2D(pos2)>atoi(commands[tempInCommand].params[0].c_str())){
					float3 dif=pos2-pos;
					dif.Normalize();
					pos2=pos+dif*atoi(commands[tempInCommand].params[0].c_str());
				}

				c.params.push_back(pos2.x);
				c.params.push_back(pos2.y);
				c.params.push_back(pos2.z);
			}
			CreateOptions(c,(button==SDL_BUTTON_LEFT?0:1));
			return c;}

		case CMDTYPE_ICON_UNIT_OR_AREA:
		case CMDTYPE_ICON_UNIT_FEATURE_OR_AREA:
		case CMDTYPE_ICON_AREA:{
			float maxRadius=100000;
			if(commands[tempInCommand].params.size()==1)
				maxRadius=atof(commands[tempInCommand].params[0].c_str());

			Command c;
			c.id=commands[tempInCommand].id;

			if(mouse->buttons[button].movement<4){
				CUnit* unit=0;
				CFeature* feature=0;
				float dist2=helper->GuiTraceRay(camera->pos,mouse->dir,9000,unit,20,true);
				float dist3=helper->GuiTraceRayFeature(camera->pos,mouse->dir,9000,feature);

				if(dist2>8900 && (commands[tempInCommand].type!=CMDTYPE_ICON_UNIT_FEATURE_OR_AREA || dist3>8900)){
					return defaultRet;
				}

				if (feature!=0 && dist3<dist2 && commands[tempInCommand].type==CMDTYPE_ICON_UNIT_FEATURE_OR_AREA) {  // clicked on feature
					c.params.push_back(MAX_UNITS+feature->id);
				} else if (unit!=0 && commands[tempInCommand].type!=CMDTYPE_ICON_AREA) {  // clicked on unit
					c.params.push_back(unit->id);
				} else { // clicked in map
					float3 pos=camera->pos+mouse->dir*dist2;
					c.params.push_back(pos.x);
					c.params.push_back(pos.y);
					c.params.push_back(pos.z);
					c.params.push_back(0);//zero radius
				}
			} else {	//created area
				float dist=ground->LineGroundCol(mouse->buttons[button].camPos,mouse->buttons[button].camPos+mouse->buttons[button].dir*9000);
				if(dist<0){
					return defaultRet;
				}
				float3 pos=mouse->buttons[button].camPos+mouse->buttons[button].dir*dist;
				c.params.push_back(pos.x);
				c.params.push_back(pos.y);
				c.params.push_back(pos.z);
				dist=ground->LineGroundCol(camera->pos,camera->pos+mouse->dir*9000);
				if(dist<0){
					return defaultRet;
				}
				float3 pos2=camera->pos+mouse->dir*dist;
				c.params.push_back(min(maxRadius,pos.distance2D(pos2)));
			}
			CreateOptions(c,(button==SDL_BUTTON_LEFT?0:1));
			return c;}

		default:
			return defaultRet;
		}
	} else {
		if(!preview)
			inCommand=-1;
	}
	return defaultRet;
}
// NodeTree
Offset<NodeTree> FlatBuffersSerialize::createNodeTree(const tinyxml2::XMLElement *objectData,
                                                      std::string classType)
{
    std::string classname = classType.substr(0, classType.find("ObjectData"));
    CCLOG("classname = %s", classname.c_str());
    
    std::string name = "";
    
    Offset<Options> options;
    std::vector<Offset<NodeTree>> children;
    
    if (classname == "ProjectNode")
    {
        auto reader = ProjectNodeReader::getInstance();
        options = CreateOptions(*_builder, reader->createOptionsWithFlatBuffers(objectData, _builder));
    }
    else if (classname == "SimpleAudio")
    {
        auto reader = ComAudioReader::getInstance();
        options = CreateOptions(*_builder, reader->createOptionsWithFlatBuffers(objectData, _builder));
    }
    else
    {
        std::string readername = getGUIClassName(classname);
        readername.append("Reader");
        
        NodeReaderProtocol* reader = dynamic_cast<NodeReaderProtocol*>(ObjectFactory::getInstance()->createObject(readername));
        options = CreateOptions(*_builder, reader->createOptionsWithFlatBuffers(objectData, _builder));
    }
    
    
    // children
    bool containChildrenElement = false;
    const tinyxml2::XMLElement* child = objectData->FirstChildElement();
    
    while (child)
    {
        CCLOG("child name = %s", child->Name());
        
        if (strcmp("Children", child->Name()) == 0)
        {
            containChildrenElement = true;
            break;
        }
        
        child = child->NextSiblingElement();
    }
    
    if (containChildrenElement)
    {
        child = child->FirstChildElement();
        CCLOG("element name = %s", child->Name());
        
        while (child)
        {
            const tinyxml2::XMLAttribute* attribute = child->FirstAttribute();
            bool bHasType = false;
            while (attribute)
            {
                std::string attriname = attribute->Name();
                std::string value = attribute->Value();
                
                if (attriname == "ctype")
                {
                    children.push_back(createNodeTree(child, value));
                    
                    bHasType = true;
                    break;
                }
                
                attribute = attribute->Next();
            }
            
            if(!bHasType)
            {
                children.push_back(createNodeTree(child, "NodeObjectData"));
            }
            
            child = child->NextSiblingElement();
        }
    }
    //
    
    std::string customClassName = "";
    const tinyxml2::XMLAttribute* attribute = objectData->FirstAttribute();
    while (attribute)
    {
        std::string attriname = attribute->Name();
        std::string value = attribute->Value();
        
        if (attriname == "CustomClassName")
        {
            customClassName = value;
            break;
        }
        
        attribute = attribute->Next();
    }
    
    return CreateNodeTree(*_builder,
                          _builder->CreateString(classname),
                          _builder->CreateVector(children),
                          options,
                          _builder->CreateString(customClassName));
}