示例#1
0
文件: ui_node.cpp 项目: ufoai/ufoai
void UI_NodeSetPropertyFromRAW (uiNode_t* node, const value_t* property, const void* rawValue, int rawType)
{
	if (property->type != rawType) {
		Com_Printf("UI_NodeSetPropertyFromRAW: type %i expected, but @%s type %i found. Property setter to '%s@%s' skipped\n", rawType, property->string, property->type, UI_GetPath(node), property->string);
		return;
	}

	if ((property->type & V_UI_MASK) == V_NOT_UI)
		Com_SetValue(node, rawValue, property->type, property->ofs, property->size);
	else if ((property->type & V_UI_MASK) == V_UI_CVAR) {
		UI_FreeStringProperty(Com_GetValue<void*>(node, property));
		switch (property->type & V_BASETYPEMASK) {
		case V_FLOAT: *Com_GetValue<float*     >(node, property) = *static_cast<float const*>(rawValue); break;
		case V_INT:   *Com_GetValue<int*       >(node, property) = *static_cast<int   const*>(rawValue); break;
		default:       Com_GetValue<byte const*>(node, property) =  static_cast<byte  const*>(rawValue); break;
		}
	} else if (property->type == V_UI_ACTION) {
		Com_GetValue<uiAction_t const*>(node, property) = static_cast<uiAction_t const*>(rawValue);
	} else if (property->type == V_UI_SPRITEREF) {
		Com_GetValue<uiSprite_t const*>(node, property) = static_cast<uiSprite_t const*>(rawValue);
	} else {
		Com_Error(ERR_FATAL, "UI_NodeSetPropertyFromRAW: Property type '%d' unsupported", property->type);
	}
	UI_Node_PropertyChanged(node, property);
}
示例#2
0
static void UI_ReleaseVariable (uiValue_t *variable)
{
	/** @todo most of cases here are useless, it only should be EA_VALUE_STRING */
	switch (variable->type) {
	case EA_VALUE_STRING:
		UI_FreeStringProperty(variable->value.string);
		break;
	case EA_VALUE_FLOAT:
	case EA_VALUE_NODE:
	case EA_VALUE_CVAR:
		/* nothing */
		break;
	default:
		Com_Error(ERR_FATAL, "UI_ReleaseVariable: Variable type \"%d\" unsupported", variable->type);
	}

	/* bug safe, but useless */
	OBJZERO(*variable);
}
示例#3
0
/**
 * Delete the node and remove it from his parent
 * @param node The node we want to delete
 */
void UI_DeleteNode (uiNode_t* node)
{
	uiBehaviour_t *behaviour;

	if (!node->dynamic)
		return;

	UI_BeforeDeletingNode(node);

	UI_DeleteAllChild(node);
	if (node->firstChild != NULL) {
		Com_Printf("UI_DeleteNode: Node '%s' contain static nodes. We can't delete it.", UI_GetPath(node));
		return;
	}

	if (node->parent)
		UI_RemoveNode(node->parent, node);

	/* delete all allocated properties */
	for (behaviour = node->behaviour; behaviour; behaviour = behaviour->super) {
		const value_t *property = behaviour->properties;
		if (property == NULL)
			continue;
		while (property->string != NULL) {
			if ((property->type & V_UI_MASK) == V_UI_CVAR) {
				void *mem = ((byte *) node + property->ofs);
				if (*(void**)mem != NULL) {
					UI_FreeStringProperty(*(void**)mem);
					*(void**)mem = NULL;
				}
			}

			/** @todo We must delete all EA_LISTENER too */

			property++;
		}
	}

	if (node->behaviour->deleteNode)
		node->behaviour->deleteNode(node);
}
示例#4
0
/**
 * Delete the node and remove it from his parent
 * @param node The node we want to delete
 */
void UI_DeleteNode (uiNode_t* node)
{
	uiBehaviour_t *behaviour;

	if (!node->dynamic)
		return;

	UI_BeforeDeletingNode(node);

	UI_DeleteAllChild(node);
	if (node->firstChild != nullptr) {
		Com_Printf("UI_DeleteNode: Node '%s' contain static nodes. We can't delete it.\n", UI_GetPath(node));
		return;
	}

	if (node->parent)
		UI_RemoveNode(node->parent, node);

	/* delete all allocated properties */
	for (behaviour = node->behaviour; behaviour; behaviour = behaviour->super) {
		const value_t **property = behaviour->localProperties;
		if (property == nullptr)
			continue;
		while (*property) {
			if (((*property)->type & V_UI_MASK) == V_UI_CVAR) {
				if (void*& mem = Com_GetValue<void*>(node, *property)) {
					UI_FreeStringProperty(mem);
					mem = 0;
				}
			}

			/** @todo We must delete all EA_LISTENER too */

			property++;
		}
	}

	UI_Node_DeleteNode(node);
}
示例#5
0
void UI_Sequence_SetSource(uiNode_t* node, const char* name) {
	UI_FreeStringProperty(const_cast<char*>(EXTRADATA(node).source));
	EXTRADATA(node).source = Mem_PoolStrDup(name, ui_dynStringPool, 0);
}
示例#6
0
文件: ui_node.cpp 项目: ufoai/ufoai
/**
 * @brief Set node property
 */
bool UI_NodeSetProperty (uiNode_t* node, const value_t* property, const char* value)
{
	const int specialType = property->type & V_UI_MASK;
	int result;
	size_t bytes;

	switch (specialType) {
	case V_NOT_UI:	/* common type */
		result = Com_ParseValue(node, value, property->type, property->ofs, property->size, &bytes);
		if (result != RESULT_OK) {
			Com_Printf("UI_NodeSetProperty: Invalid value for property '%s': %s\n", property->string, Com_GetLastParseError());
			return false;
		}
		UI_Node_PropertyChanged(node, property);
		return true;

	case V_UI_CVAR:	/* cvar */
		switch ((int)property->type) {
		case V_UI_CVAR:
			if (Q_strstart(value, "*cvar:")) {
				char*& b = Com_GetValue<char*>(node, property);
				UI_FreeStringProperty(b);
				b = Mem_PoolStrDup(value, ui_dynStringPool, 0);
				UI_Node_PropertyChanged(node, property);
				return true;
			}
			break;
		case V_CVAR_OR_FLOAT:
			{
				float f;

				if (Q_strstart(value, "*cvar:")) {
					char*& b = Com_GetValue<char*>(node, property);
					UI_FreeStringProperty(b);
					b = Mem_PoolStrDup(value, ui_dynStringPool, 0);
					UI_Node_PropertyChanged(node, property);
					return true;
				}

				result = Com_ParseValue(&f, value, V_FLOAT, 0, sizeof(f), &bytes);
				if (result != RESULT_OK) {
					Com_Printf("UI_NodeSetProperty: Invalid value for property '%s': %s\n", property->string, Com_GetLastParseError());
					return false;
				}

				void* const b = Com_GetValue<void*>(node, property);
				if (char const* const cvar = Q_strstart((char const*)b, "*cvar:"))
					Cvar_SetValue(cvar, f);
				else
					*(float*) b = f;
				UI_Node_PropertyChanged(node, property);
				return true;
			}
		case V_CVAR_OR_LONGSTRING:
		case V_CVAR_OR_STRING:
			{
				char*& b = Com_GetValue<char*>(node, property);
				UI_FreeStringProperty(b);
				b = Mem_PoolStrDup(value, ui_dynStringPool, 0);
				UI_Node_PropertyChanged(node, property);
				return true;
			}
		}
		break;

	case V_UI:
		switch ((int)property->type) {
		case V_UI_SPRITEREF:
			{
				uiSprite_t* sprite = UI_GetSpriteByName(value);
				Com_GetValue<uiSprite_t const*>(node, property) = sprite;
				UI_Node_PropertyChanged(node, property);
				return true;
			}
		}
		break;
	}

	Com_Printf("UI_NodeSetProperty: Unimplemented type for property '%s@%s'\n", UI_GetPath(node), property->string);
	return false;
}
示例#7
0
文件: ui_node.cpp 项目: ufoai/ufoai
void UI_Node_SetTooltip (uiNode_t* node, const char* tooltip) {
	UI_FreeStringProperty((void*)node->tooltip);
	node->tooltip = Mem_PoolStrDup(tooltip, ui_dynStringPool, 0);
}
示例#8
0
文件: ui_node.cpp 项目: ufoai/ufoai
void UI_Node_SetImage (uiNode_t* node, const char* name) {
	UI_FreeStringProperty(node->image);
	node->image = Mem_PoolStrDup(name, ui_dynStringPool, 0);
}
示例#9
0
文件: ui_node.cpp 项目: ufoai/ufoai
void UI_Node_SetFont (uiNode_t* node, const char* name) {
	UI_FreeStringProperty(node->font);
	node->font = Mem_PoolStrDup(name, ui_dynStringPool, 0);
}
示例#10
0
文件: ui_node.cpp 项目: ufoai/ufoai
void UI_Node_SetText (uiNode_t* node, const char* text) {
	UI_FreeStringProperty(node->text);
	node->text = Mem_PoolStrDup(text, ui_dynStringPool, 0);
}