Пример #1
0
/// Creates the relevant children. Separate function in order to not have everything allocated in the constructor.
void UIQueryDialogue::CreateChildren()
{
	if (childrenCreated)
		return;

	/// Clear any children if we had any first.
	if (children.Size())
		children.ClearAndDelete();
	/// Create the "box"
	UIList * box = new UIList();
	box->sizeRatioX = box->sizeRatioY = 0.5f;
	box->alignmentX = box->alignmentY = 0.5f;
	box->textureSource = "80Gray50Alpha";
	AddChild(box);

	/// Title
	UILabel * label = new UILabel();
	label->text = headerText;
	label->textureSource = "80Gray50Alpha";
	label->sizeRatioY = 0.15f;
	box->AddChild(label);

	/// Body
	label = new UILabel();
	label->text = textToPresent;
	label->textSizeRatio = 0.3f;
	label->sizeRatioY = 0.4f;
	box->AddChild(label);

	UIColumnList * cList = new UIColumnList();
	cList->sizeRatioY = 0.2f;
	box->AddChild(cList);

	/// Cancel/Decline-button
	UIButton * button;
	button = new UIButton("CancelButton");
	button->text = "Cancel";
	button->sizeRatioX = 0.5f;
	if (popUponContinuing)
		button->activationMessage += "&PopUI("+this->name+")&";
	button->activationMessage += actionToBeTakenIfDeclining;
	cList->AddChild(button);
	cancelButton = button;

	/// OK/Continue-button
	button = new UIButton("OKButton");
	button->text = "OK";
	button->sizeRatioX = 0.5f;
	if (popUponContinuing)
		button->activationMessage += "&PopUI("+this->name+")&";
	button->activationMessage += actionToBeTakenIfProceeding;
	cList->AddChild(button);
	okButton = button;

	childrenCreated = true;
}
Пример #2
0
UIList* UIFactory::createList(vec2 pos, float rot, vec2 scale, float displayElementsCount, const char* filename, UIController* uiController){
	UIList* list = new UIList(filename, displayElementsCount, scale.y, uiController);
	//Le seteo la posicion al scrollBar en X para que se ajuste al ancho de la lista
	list->setScrollBarPositionX(scale.x);
	//Creo un estado externo
	UIState* externalState = UIFactory::createState(pos, rot, scale, 1.0f, NULL);
	//Informo que debe destruirse el estado luego de efectuar una transicion
	externalState->setDestroyedAfterTransition(true);
	//Asigno el estado
	list->getExternalState()->makeStateTransition(externalState);
	//Habemus boton
	return list;
}
Пример #3
0
void UIListMetadata::InitializeControl(const String& controlName, const Vector2& position)
{
	BaseMetadata::InitializeControl(controlName, position);
	
	int paramsCount = this->GetParamsCount();
    for (BaseMetadataParams::METADATAPARAMID i = 0; i < paramsCount; i ++)
    {
		// Initialize UIList
        UIList* list = dynamic_cast<UIList*>(this->treeNodeParams[i].GetUIControl());
		if (list)
		{
			EditorListDelegate *editorList = new EditorListDelegate(list->GetRect(), list->GetOrientation());
			list->SetDelegate(editorList);
			list->GetBackground()->SetDrawType(UIControlBackground::DRAW_SCALE_TO_RECT);
		}
    }	
}
Пример #4
0
/// Creates the relevant children. Separate function in order to not have everything allocated in the constructor.
void UIStringDialogue::CreateChildren()
{
	if (childrenCreated)
		return;

	/// Clear any children if we had any first.
	if (children.Size())
		children.ClearAndDelete();
	/// Create the "box"
	UIList * box = new UIList();
	box->sizeRatioX = box->sizeRatioY = 0.5f;
	box->alignmentX = box->alignmentY = 0.5f;
	box->textureSource = "80Gray50Alpha";
	box->padding = 0.01f;
	AddChild(box);

	/// Title
	UILabel * label = new UILabel();
	label->text = headerText;
	label->textureSource = "80Gray50Alpha";
	label->sizeRatioY = 0.15f;
	box->AddChild(label);

	/// Body
	label = new UILabel();
	label->text = textToPresent;
	label->textSizeRatio = 0.3f;
	label->sizeRatioY = 0.4f;
	box->AddChild(label);

	/// Add the input.
	input = new UIInput("StringInput");
	input->text = initialText;
	input->sizeRatioY = 0.2f;
	box->AddChild(input);

	/// And the ok-button.
	UIElement * okButton = new UIButton("OK");
	okButton->activationMessage = "UIProceed("+this->name+")";
	okButton->sizeRatioY = 0.2f;
	okButton->sizeRatioX = 0.4f;
	okButton->alignmentX = 0.2f;
	box->AddChild(okButton);
	childrenCreated = true;
}
HierarchyTreeControlNode::HierarchyTreeControlNode(HierarchyTreeNode* parent,
        UIControl* uiObject,
        const QString& name) :
    HierarchyTreeNode(name),
    listDelegate(NULL)
{
    this->parent = parent;

    this->uiObject = uiObject;
    this->parentUIObject = NULL;
    this->needReleaseUIObjects = false;

    // All UIList controls should always have a delegate
    // We set a delegate here to avoid inappropriate loading of saved list
    UIList *list = dynamic_cast<UIList*>(uiObject);
    if (list)
    {
        listDelegate = new EditorListDelegate(list->GetRect(), list->GetOrientation());
        list->SetDelegate(listDelegate);
    }

    AddControlToParent();
}
Пример #6
0
void CN3UIBase::ArrangeZOrder()
{
	// 보통 image가 배경그림이 되므로 child list에서 맨 뒤로 보낸다.
	// 왜냐하면 맨 뒤에 있는것이 맨 먼저 그려지므로
	UIList tempList;
	for(UIListItor itor = m_Children.begin(); m_Children.end() != itor;)
	{
		CN3UIBase* pChild = (*itor);
		if(UI_TYPE_IMAGE == pChild->UIType())
		{
			itor = m_Children.erase(itor);	// 현재 위치에서 지우고
			tempList.push_back(pChild);		// 임시 버퍼에 저장
		}
		else ++itor;
	}

	for(itor = tempList.begin(); tempList.end() != itor; ++itor)
	{
		CN3UIBase* pChild = (*itor);
		m_Children.push_back(pChild);		// child list맨 뒤에 넣기
	}
	tempList.clear();
}
HierarchyTreeControlNode::HierarchyTreeControlNode(HierarchyTreeNode* parent,
        const HierarchyTreeControlNode* node):
    HierarchyTreeNode(node),
    listDelegate(NULL)
{
    this->parent = parent;
    this->uiObject = node->GetUIObject()->Clone();
    this->needReleaseUIObjects = false;

    // All UIList controls should always have a delegate
    // We set a delegate here to avoid inappropriate loading of saved list
    UIList *list = dynamic_cast<UIList*>(this->uiObject);
    UIList *srcList = dynamic_cast<UIList*>(node->GetUIObject());
    if (list)
    {
        listDelegate = new EditorListDelegate(list->GetRect(), list->GetOrientation());
        EditorListDelegate *srcListDelegate = dynamic_cast<EditorListDelegate*>(srcList->GetDelegate());
        if (srcListDelegate)
        {
            listDelegate->SetAggregatorID(srcListDelegate->GetAggregatorID());
        }
        list->SetDelegate(listDelegate);
    }

    // Remove real children & subcontrols - each control is responsible for its
    // subcontrols by itself.
    const List<UIControl* > &realChildren = GetUIObject()->GetRealChildren();
    for (List<UIControl* >::const_iterator iter = realChildren.begin();
            iter != realChildren.end();
            ++iter)
    {
        GetUIObject()->RemoveControl(*iter);
    }

    AddControlToParent();

    const HierarchyTreeNode::HIERARCHYTREENODESLIST& child = node->GetChildNodes();
    for (HierarchyTreeNode::HIERARCHYTREENODESLIST::const_iterator iter = child.begin();
            iter != child.end();
            ++iter)
    {
        const HierarchyTreeControlNode* controlNode = dynamic_cast<const HierarchyTreeControlNode*>((*iter));
        if (!controlNode)
            continue;

        AddTreeNode(controlNode->CreateControlCopy(parent ? this : NULL));
    }
}
Пример #8
0
void Script::EvaluateLine(String & line)
{
	/// Default line processed once?
	lineProcessed = true;

	line.SetComparisonMode(String::NOT_CASE_SENSITIVE);
	// "80Gray50Alpha.png"
#define DEFAULT_TEXTURE_SOURCE	"black50Alpha.png"
#define DEFAULT_TEXT_SIZE_RATIO	0.3f
	
	/// Some state began, take not of it?
	if (line.Contains("Wait("))
	{
		WaitScript * wait = new WaitScript(line, this);
		wait->SetDeleteOnEnd(true);
		ScriptMan.PlayScript(wait);
	}
	else if (line.StartsWith("Key:"))
	{
		String keyStr = line.Tokenize(":")[1];
		keyStr.RemoveSurroundingWhitespaces();
		int keyCode = GetKeyForString(keyStr);
		assert(keyCode != 0);
		InputMan.KeyDown(MainWindow(), keyCode, false);
		InputMan.KeyUp(MainWindow(), keyCode);
		lineFinished = true;
	}
	else if (line.Contains("PlayScript("))
	{
		List<String> tokens = line.Tokenize("(),");
		// Source of script within the parenthesis.
		String source = tokens[1];
		bool wait = true;
		Script * scriptParent = this;
		if (tokens.Size() >= 3)
		{
			wait = tokens[2].ParseBool();
			if (!wait)
			{
				scriptParent = NULL;
				this->lineFinished = true;
			}
		}
		Script * script = new Script(source, scriptParent);
		script->source = source;
		bool loaded = script->Load();
		assert(loaded);
		ScriptMan.PlayScript(script);
	}
	else if (line == "DisableActiveUI")
	{
		InputMan.DisableActiveUI();
		lineFinished = true;
		uiDisabled = true;
	}
	else if (line == "EnableActiveUI")
	{
		InputMan.EnableActiveUI();
		lineFinished = true;
	}
	else if (line.Contains("PreloadTexturesInDirectory("))
	{
		// Fetch the stuff, do the buff
		String dir = line.Tokenize("()")[1];
		List<String> files;
		int num = GetFilesInDirectory(dir, files);
		for (int i = 0; i < files.Size(); ++i)
		{
			String path = dir + "/" + files[i];
			Texture * tex = TexMan.LoadTexture(path);
			Graphics.QueueMessage(new GMBufferTexture(tex));
		}
		lineFinished = true;
	}
	else if (line.Contains("Begin("))
	{
		String stateBeginning = line.Tokenize("()")[1];
		if (stateBeginning == "Cutscene")
		{
			BeginCutscene();
		}
		lineFinished = true;
	}
	else if (line.Contains("End("))
	{
		String stateEnding = line.Tokenize("()")[1];
		if (stateEnding == "Cutscene")
		{
			EndCutscene();
		}
		lineFinished = true;
	}
	else if (line.Contains("EndScript"))
	{
		// End it.
		scriptState = ENDING;
	}
	else if (line.Contains("EnterGameState("))
	{
		String name = line.Tokenize("()")[1];		
		StateChanger * changer = new StateChanger(line, this);
		ScriptMan.PlayScript(changer);
	}
	else if (line.Contains("FadeTo(") || line.Contains("FadeIn("))
	{
		FadeInEffect * fade = new FadeInEffect(line, this);
		ScriptMan.PlayScript(fade);
	}
	else if (line.Contains("FadeInBackground("))
	{
		FadeInBackground * fade = new FadeInBackground(line, this);
		ScriptMan.PlayScript(fade);
	}
	else if (line.Contains("FadeOutBackground("))
	{
		FadeOutBackground * fade = new FadeOutBackground(line, this);
		ScriptMan.PlayScript(fade);
	}
	else if (line.Contains("FadeOut"))
	{
		FadeOutEffect * fade = new FadeOutEffect(line, this);
		ScriptMan.PlayScript(fade);
	}
	else if (line.Contains("FadeText("))
	{
		FadeTextEffect * text = new FadeTextEffect(line, this);
		ScriptMan.PlayScript(text);
		lineFinished = true;
	}
	else if (line.Contains("PlaySong("))
	{
		// Just play it.
		String song = line.Tokenize("()")[1];
		TrackMan.PlayTrack(song);
		// Line finished straight away.
		lineFinished = true;
	}
	else if (line.Contains("Dialogue")){
		/// If raw string, output it straight away! (should later be queued to some kind of dialogue-manager?)
		if (line.Contains("\"")){
			/// Create dialogue UI and append it to the current UI!
			String text = line.Tokenize("\"")[1];
			std::cout<<"\n"<<text;
			UIButton * dialogue = new UIButton("Dialogue");
			dialogue->exitable = false;
			dialogue->text = text;
			dialogue->activationMessage = "PopFromStack(this)&Remove(this)&ContinueEvent("+this->name+")";
			dialogue->textureSource = DEFAULT_TEXTURE_SOURCE;
			dialogue->textSizeRatio = DEFAULT_TEXT_SIZE_RATIO;
			dialogue->sizeRatioY = 0.3f;
			dialogue->alignmentY = 0.15f;
			dialogue->state |= UIState::DIALOGUE;  // Flag the dialogue-state flag to signify importance!
			Graphics.QueueMessage(new GMAddUI(dialogue, "root"));
			Graphics.QueueMessage(GMPushUI::ToUI("Dialogue", ActiveUI()));
		}
		/// If no quotes, load the specified dialogue-file and begin processing that instead, waiting until it is finished.!
		else {
			/// Give the npc a dialogue?
		//	assert(false);
			// Send it tot he state too, to attach to the appropriate thingymajig.
			Message * message = new Message(line);
			/// Set this event as
			message->scriptOrigin = this;
			MesMan.QueueMessage(message);
			/// Instant thingies.
			lineFinished = true;
		}
	}
	else if (line.Contains("Answer")){
		///  Go to EndAnswers..!
		lineFinished = true;
		for (int i = currentLine; i < lines.Size(); ++i){
			String line = lines[i];
			if (line.Contains("EndAnswers")){
				currentLine = i;
				lineFinished = true;
				return;
			}
		}
		assert(false && "No EndAnswers found? No good, jaow ;___;");
	}
	else if (line.Contains("BeginAlternatives") || line.Contains("BeginQuestion")){
		/// Create dialogue UI and append it to the current UI!
		String text = line.Tokenize("\"")[1];
		std::cout<<"\n"<<text;
		UIElement * dialogue = new UIElement();
		dialogue->exitable = false;
		dialogue->name = "AlternativesDialogue";
	//	dialogue->activationMessage = "Remove(this)&ContinueEvent("+this->name+")";
		dialogue->textureSource = DEFAULT_TEXTURE_SOURCE;
		dialogue->sizeRatioY = 0.3f;
		dialogue->alignmentY = 0.15f;
		dialogue->state |= UIState::DIALOGUE;  // Flag the dialogue-state flag to signify importance!

		UILabel * dialogueText = new UILabel();
		dialogueText->text = text;
		dialogueText->textSizeRatio = DEFAULT_TEXT_SIZE_RATIO;
		dialogueText->sizeRatioX = 0.5f;
		dialogueText->alignmentX = 0.25f;
		dialogue->AddChild(dialogueText);

		UIList * dialogueAnswerList = new UIList();
		dialogueAnswerList->sizeRatioX = 0.5f;
		dialogueAnswerList->alignmentX = 0.75f;
		dialogue->AddChild(dialogueAnswerList);

		int answers = 0;
		List<UIElement*> answerList;
		// Parse and add answers
		for (int i = currentLine+1; i < lines.Size(); ++i){
			String l = lines[i];
			l.SetComparisonMode(String::NOT_CASE_SENSITIVE);
			List<String> tokens = l.Tokenize(" ");
			String token1 = tokens[0];
			token1.SetComparisonMode(String::NOT_CASE_SENSITIVE);

			if (token1 == "text"){
				l.Remove(token1);
				dialogueText->text = l;
				dialogueText->text.RemoveInitialWhitespaces();
				dialogueText->text.Remove("\"");
				dialogueText->text.Remove("\"");
			}
			else if (l.Contains("Answer")){
				++answers;
				UIButton * answerButton = new UIButton();
				answerButton->name = token1;
				l.Remove("Answer");
				l.RemoveInitialWhitespaces();
				l.Remove("\"");
				l.Remove("\"");
				answerButton->textureSource = DEFAULT_TEXTURE_SOURCE;
				answerButton->text = l;
				answerButton->sizeRatioY = 0.2f;
				answerButton->activationMessage = "ActivateDialogueAlternative("+name+","+answerButton->name+")&PopFromStack("+dialogue->name+")&Remove("+dialogue->name+")";
				answerList.Add(answerButton);
			}
			else if (l.Contains("EndAlternatives")){
				// Donelir. o-o
				break;
			}
			else {
				assert(false && "Bad line! Should only be Answer before EndAlternatives!");
			}
		}
		assert(answers);
		float sizeRatioY = 0.95f / answers;
		for (int i = 0; i < answers; ++i){
			UIElement * ans = answerList[i];
		//	ans->sizeRatioY = sizeRatioY; // Stupid to set the sizeRatioY to be this dynamic, yo.
			dialogueAnswerList->AddChild(ans);
		}
		isInAlternativeDialogue = true;
		Graphics.QueueMessage(new GMAddUI(dialogue, "root"));
		Graphics.QueueMessage(GMPushUI::ToUI(dialogue, ActiveUI()));
	}
	else if (line.Contains("elsif") || line.Contains("elseif") || line.Contains("else if"))
	{
		/// Should be in an if-stack, check if we already evaluated.
		ScriptLevel sl = stack.Last();
		assert(sl.type == ScriptLevel::IF_CLAUSE);
		/// If already evaluated, jump to endif.
		if (sl.evaluatedAtLine > 0)
		{
			// Jump to endif.
			JumpToEndif();
			return;
		}
		/// If not, handle the conditional first.
		HandleConditional(line);
	}
	else if (line.Contains("if(") || line.Contains("if ("))
	{
		// Add to stack.
		stack.AddItem(ScriptLevel(ScriptLevel::IF_CLAUSE, currentLine));
		HandleConditional(line);
	}
	else if (line.Contains("else"))
	{
//		if (ifProcessed)
		//	JumpToEndif();
		ScriptLevel sl = stack.Last();
		assert(sl.type == ScriptLevel::IF_CLAUSE);
		if (sl.evaluatedAtLine > 0)
		{
			JumpToEndif();
			return;
		}
		lineFinished = true;
		return;
	}
	else if (line.Contains("endif"))
	{
		ScriptLevel sl = stack.Last();
		assert(sl.type == ScriptLevel::IF_CLAUSE);
		stack.RemoveLast();
		lineFinished = true;
	}
	else if (line.Contains("endwhile"))
	{
		// Go to start!
		ScriptLevel sl = stack.Last();
		assert(sl.type == ScriptLevel::WHILE_LOOP);
		currentLine = sl.evaluatedAtLine;
		String startLine = lines[currentLine];
		HandleConditional(startLine);
//		lineFinished = true;
		// Evaluate?
//		stack.RemoveLast();
	}
	else if (line.Contains("while"))
	{
		stack.AddItem(ScriptLevel(ScriptLevel::WHILE_LOOP, currentLine));
		HandleConditional(line);
	}
/*	else if (line.Contains("CreateInt")){
		List<String> tokens = line.Tokenize(" \t");
		String varName = tokens[1];
		int initialValue = 0;
		if (tokens.Size() >= 3)
			initialValue = tokens[2].ParseInt();
		if (!GameVars.Get(varName)){
			GameVars.CreateInt(varName, initialValue);
		}
		lineFinished = true;
	}
	/*
	else if (line.Contains("SetInt ")){
		List<String> tokens = line.Tokenize(" \t");
		String varName = tokens[1];
		int value = tokens[2].ParseInt();
		GameVars.SetInt(varName, value);
		lineFinished = true;
	}*/
	else if (line.Contains("Repeatable")){
		/// Flag the event as repeatable.
		repeatable = true;
		lineFinished = true;
	}
	// Consider just making an else-clause for all remaining events to be processed by the specific game instead?
	else if (
		line.Contains("SpawnEntity") ||
		line.Contains("OnApproach") ||
		line.Contains("OnInteract") ||
		line.Contains("DisableMovement") ||
		line.Contains("EnableMovement") ||
		line.Contains("Zone(") ||
		line.Contains("PlacePlayer(") ||
		line.Contains("TrackPlayer")
		)
	{
		Message * message = new Message(line);
		/// Set this event as
		message->scriptOrigin = this;
		MesMan.QueueMessage(message);
		/// Instant thingies.
		lineFinished = true;
	}
	else {
		/// Try evaluate it as an expression.
		Expression exp;
		List<Variable> allVars = GameVars.GetAllExpressionVariables() + variables;
		exp.functionEvaluators = functionEvaluators; // Set evaluators.
		bool parseOK = exp.ParseExpression(line);
		if (line.Contains("SetMovementPattern"))
			int p = 4;;
		if (parseOK)
		{
			ExpressionResult res = exp.Evaluate(allVars);
			/// Continue until it returns true! o.o
			if (res.type != DataType::NO_TYPE)
			{
				if (res.GetBool() == true)
				{
					lineFinished = true;
					return;
				}
			}
		}


//		std::cout<<"\nUndefined event command: "<<line;
//		std::cout<<"\nPassing it as a custom command to the game states for further processing.";
		Message * message = new Message(line);
		/// Set this event as source of it.
		message->scriptOrigin = this;
		MesMan.QueueMessage(message);
		lineFinished = true;
	//	assert(false && "Undefined event command!");
	};
}