ServerSaveActivity::ServerSaveActivity(SaveInfo save, bool saveNow, ServerSaveActivity::SaveUploadedCallback * callback) :
	WindowActivity(ui::Point(-1, -1), ui::Point(200, 50)),
	thumbnailRenderer(nullptr),
	save(save),
	callback(callback),
	saveUploadTask(NULL)
{
	ui::Label * titleLabel = new ui::Label(ui::Point(0, 0), Size, "Saving to server...");
	titleLabel->SetTextColour(style::Colour::InformationTitle);
	titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignCentre;
	titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(titleLabel);

	AddAuthorInfo();

	saveUploadTask = new SaveUploadTask(this->save);
	saveUploadTask->AddTaskListener(this);
	saveUploadTask->Start();
}
Beispiel #2
0
void test::TestEntityComponentAttachment() {
    auto entities = new stoked::EntityPool(2);
    auto componentPoolA = new stoked::ComponentPool<ComponentA>(4);
    auto componentPoolB = new stoked::ComponentPool<ComponentB>(4);

    while (entities->Available()) {
        auto e1 = entities->Create();
        auto a = componentPoolA->Get();
        auto b = componentPoolB->Get();

        bool resA = e1->AddComponent(a);
        bool resB = e1->AddComponent(b);

        assert(resA);
        assert(resB);
    }

    PASSED();
}
Beispiel #3
0
			int Storage::AddRepo (const RepoInfo& ri)
			{
				Util::DBLock lock (DB_);
				try
				{
					lock.Init ();
				}
				catch (const std::runtime_error& e)
				{
					qWarning () << Q_FUNC_INFO
							<< "could not acquire DB lock";
					throw;
				}

				QueryAddRepo_.bindValue (":url", Slashize (ri.GetUrl ()).toEncoded ());
				QueryAddRepo_.bindValue (":name", ri.GetName ());
				QueryAddRepo_.bindValue (":description", ri.GetShortDescr ());
				QueryAddRepo_.bindValue (":longdescr", ri.GetLongDescr ());
				QueryAddRepo_.bindValue (":maint_name", ri.GetMaintainer ().Name_);
				QueryAddRepo_.bindValue (":maint_email", ri.GetMaintainer ().Email_);
				if (!QueryAddRepo_.exec ())
				{
					Util::DBLock::DumpError (QueryAddRepo_);
					throw std::runtime_error ("Query execution failed.");
				}

				QueryAddRepo_.finish ();

				int repoId = FindRepo (Slashize (ri.GetUrl ()));
				if (repoId == -1)
				{
					qWarning () << Q_FUNC_INFO
							<< "OH SHI~, just inserted repo cannot be found!";
					throw std::runtime_error ("Just inserted repo cannot be found.");
				}

				Q_FOREACH (const QString& component, ri.GetComponents ())
					AddComponent (repoId, component);

				lock.Good ();

				return repoId;
			}
 void CDirectionalLEDEquippedEntity::Init(TConfigurationNode& t_tree) {
    try {
       /* Init parent */
       CComposableEntity::Init(t_tree);
       /* Go through the led entries */
       TConfigurationNodeIterator itLED("directional_led");
       for(itLED = itLED.begin(&t_tree);
           itLED != itLED.end();
           ++itLED) {
          /* Initialise the LED using the XML */
          CDirectionalLEDEntity* pcLED = new CDirectionalLEDEntity(this);
          pcLED->Init(*itLED);
          CVector3 cPositionOffset;
          GetNodeAttribute(*itLED, "position", cPositionOffset);
          CQuaternion cOrientationOffset;
          GetNodeAttribute(*itLED, "orientation", cOrientationOffset);
          /* Parse and look up the anchor */
          std::string strAnchorId;
          GetNodeAttribute(*itLED, "anchor", strAnchorId);
          /*
           * NOTE: here we get a reference to the embodied entity
           * This line works under the assumption that:
           * 1. the DirectionalLEDEquippedEntity has a parent;
           * 2. the parent has a child whose id is "body"
           * 3. the "body" is an embodied entity
           * If any of the above is false, this line will bomb out.
           */
          CEmbodiedEntity& cBody =
             GetParent().GetComponent<CEmbodiedEntity>("body");
          /* Add the LED to this container */
          m_vecInstances.emplace_back(*pcLED,
                                      cBody.GetAnchor(strAnchorId),
                                      cPositionOffset,
                                      cOrientationOffset);
          AddComponent(*pcLED);
       }
       UpdateComponents();
    }
    catch(CARGoSException& ex) {
       THROW_ARGOSEXCEPTION_NESTED("Failed to initialize directional LED equipped entity \"" <<
                                   GetContext() + GetId() << "\".", ex);
    }
 }
void GameState::InitFunction()
{
  // Add target component
  VisTriggerTargetComponent_cl *pTargetComp = new VisTriggerTargetComponent_cl();
  AddComponent(pTargetComp);

  // Get trigger box entity
  VisBaseEntity_cl *pTriggerBoxEntity = Vision::Game.SearchEntity("TriggerBox");
  VASSERT(pTriggerBoxEntity);

  // Find source component
  VisTriggerSourceComponent_cl* pSourceComp = vstatic_cast<VisTriggerSourceComponent_cl*>(
    pTriggerBoxEntity->Components().GetComponentOfTypeAndName(VisTriggerSourceComponent_cl::GetClassTypeId(), "OnObjectEnter"));
  VASSERT(pSourceComp != NULL);

  // Link source and target component 
  IVisTriggerBaseComponent_cl::OnLink(pSourceComp, pTargetComp);
  
  m_eState = GAME_STATE_RUN;
}
    PlayerProjectile::PlayerProjectile(const float direction, const float speed)
        : uth::GameObject(),
          m_timer(0.f),
          m_direction()
    {
        // Load a texture and create a sprite component.
        auto tex = uthRS.LoadTexture("enemy.png");
        AddComponent(new uth::Sprite(tex));

        SetActive(true);

        // Compute a rotation vector from the given angle. (This doesn't currently work for some reason)
        const float sine = pmath::sin(direction);
        m_direction.x = sine * 1.f;
        m_direction.y = sine * m_direction.x + pmath::cos(direction) * 1.f;

        m_direction.normalize();
        m_direction.x *= speed;
        m_direction.y *= speed;
    }
Beispiel #7
0
	void GameObject::LoadFloor()
	{
		SetName("Floor");
		auto meshComponent = MeshComponentPtr(
			new MeshComponent(
				MeshManager::Get().GetMesh("floor.mm"),
				PngManager::Get().GetPngTexture("MartEngine.png")
			)
		);

		SetScale(10.f);

		SetRotation(Quaternion(Vector3(0.0f, 0.0f, 0.0f), 0.0f));

		SetTranslation(Vector3(0.0f, 5.0f, 0.0f));

		AddComponent(meshComponent);

		//AddComponent(std::make_shared<Plane>(Vector3(0,0,0),Vector3(0,1,0)));
	}
Beispiel #8
0
bool PackAnimation::CreateFramePart(const ee::SprConstPtr& spr, Frame& frame)
{	
	const IPackNode* node = PackNodeFactory::Instance()->Create(spr);

	PackAnimation::Part part;

	CU_STR name;
	s2::SprNameMap::Instance()->IDToStr(spr->GetName(), name);
	if (Utility::IsNameValid(name.c_str())) {
		name = name;
	}

	bool force_mat = false;
	bool new_comp = AddComponent(node, name.c_str(), part.comp_idx, force_mat);
	PackAnimation::LoadSprTrans(spr, part.t, force_mat);

	frame.parts.push_back(part);

	return new_comp;
}
SelectionWindow::SelectionWindow(Rect dimensions):UIBase(){
    UI_REGISTER(SelectionWindow);
    box = dimensions;
    optionCounter = 0;
    mother = nullptr;
    box.x = dimensions.x;
    box.y = dimensions.y;
    OnMousePress = [=](UIBase*w,int button,Point pos){
        SetFocused(true);
    };
    selectedOption = -1;
    arrow = Text(style.fontfile,style.fontSize,style.txtstyle,">", {style.fg[0],style.fg[1],style.fg[2]} );
    Back = [=](UIBase *b){
    };
    title = new Label(Point(dimensions.w/2 -16,2),std::string(""),this);
    title->style.fg[0] = 255;
    title->style.txtstyle = TEXT_BLENDED;
    AddComponent(title);


}
void UIDiscreteSlider::AddCells( unsigned int maxValue, unsigned int startValue, float cellSpacing )
{
	MaxValue = maxValue;
	StartValue = startValue;

	DiscreteSliderComponent = new UIDiscreteSliderComponent( *this, StartValue );
	OVR_ASSERT( DiscreteSliderComponent );
	AddComponent( DiscreteSliderComponent );

	float cellOffset = 0.0f;
	const float pixelCellSpacing = cellSpacing * VRMenuObject::DEFAULT_TEXEL_SCALE;

	VRMenuFontParms fontParms( HORIZONTAL_CENTER, VERTICAL_CENTER, false, false, false, 1.0f );
	Vector3f defaultScale( 1.0f );
	
	for ( unsigned int cellIndex = 0; cellIndex <= MaxValue; ++cellIndex )
	{
		const Posef pose( Quatf( Vector3f( 0.0f, 1.0f, 0.0f ), 0.0f ),
			Vector3f( cellOffset, 0.f, 0.0f ) );

		cellOffset += pixelCellSpacing;

		VRMenuObjectParms cellParms( VRMENU_BUTTON, Array< VRMenuComponent* >(), VRMenuSurfaceParms(),
			"", pose, defaultScale, fontParms, Menu->AllocId(),
			VRMenuObjectFlags_t(), VRMenuObjectInitFlags_t( VRMENUOBJECT_INIT_FORCE_POSITION ) );

		UICell * cellObject = new UICell( GuiSys );
		cellObject->AddToDiscreteSlider( Menu, this, cellParms );
		cellObject->SetImage( 0, SURFACE_TEXTURE_DIFFUSE, CellOffTexture );
		UICellComponent * cellComp = new UICellComponent( *DiscreteSliderComponent, cellIndex );

		VRMenuObject * object = cellObject->GetMenuObject();
		OVR_ASSERT( object );
		object->AddComponent( cellComp );

		DiscreteSliderComponent->AddCell( cellObject );
	}

	DiscreteSliderComponent->HighlightCells( StartValue );
}
ConsoleView::ConsoleView():
	ui::Window(ui::Point(0, 0), ui::Point(WINDOWW, 150)),
	commandField(NULL)
{
	class CommandHighlighter: public ui::TextboxAction
	{
		ConsoleView * v;
	public:
		CommandHighlighter(ConsoleView * v_) { v = v_; }
		virtual void TextChangedCallback(ui::Textbox * sender)
		{
			sender->SetDisplayText(v->c->FormatCommand(sender->GetText()));
		}
	};
	commandField = new ui::Textbox(ui::Point(7, Size.Y-16), ui::Point(Size.X, 16), "");
	commandField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
	commandField->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	commandField->SetActionCallback(new CommandHighlighter(this));
	AddComponent(commandField);
	FocusComponent(commandField);
	commandField->SetBorder(false);
}
 void CDirectionalLEDEquippedEntity::AddLED(const CVector3& c_position,
                                            const CQuaternion& c_orientation,
                                            SAnchor& s_anchor,
                                            const CRadians& c_observable_angle,
                                            const CColor& c_color) {
    /* create the new directional LED entity */
    CDirectionalLEDEntity* pcLED =
       new CDirectionalLEDEntity(this,
                                 "directional_led_" + std::to_string(m_vecInstances.size()),
                                 c_position,
                                 c_orientation,
                                 c_observable_angle,
                                 c_color);
    /* add it to the instances vector */
    m_vecInstances.emplace_back(*pcLED,
                                s_anchor,
                                c_position,
                                c_orientation);
    /* inform the base class about the new entity */
    AddComponent(*pcLED);
    UpdateComponents();
 }
/**
 * Load the sphere configuration from its XML tag
 */
void CSphereEntity::Init(TConfigurationNode &t_tree)
{
	try
	{
		// Init parent
		CComposableEntity::Init(t_tree);

		// Parse XML to get the radius (required)
		GetNodeAttribute(t_tree, "radius", m_fRadius);

		// Parse XML to get the movable attribute (optional: defaults to true)
		bool bMovable;
		GetNodeAttributeOrDefault(t_tree, "movable", bMovable, true);

		// Get the mass from XML if the sphere is movable
		if (bMovable)
		{
			// Parse XML to get the mass (optional, defaults to 1)
			GetNodeAttributeOrDefault(t_tree, "mass", m_fMass, 1.0f);
		}
		else
		{
			m_fMass = 0.0f;
		}

		// Create embodied entity using parsed data
		m_pcEmbodiedEntity = new CEmbodiedEntity(this);

		m_pcEmbodiedEntity->Init(GetNode(t_tree, "body"));
		m_pcEmbodiedEntity->SetMovable(bMovable);
		AddComponent(*m_pcEmbodiedEntity);

		UpdateComponents();
	}
	catch (CARGoSException &ex)
	{
		THROW_ARGOSEXCEPTION_NESTED("Failed to initialize the ball entity.", ex);
	}
}
Beispiel #14
0
HRESULT CBaseUI::Initialize(void)
{
	FAILED_CHECK(AddComponent());

	m_fX = 150.f;
	m_fY = 50.f;
	m_fSizeX = 140.f;
	m_fSizeY = 42.f;

	//
	CRenderMgr::GetInstance()->AddRenderGroup(TYPE_UI, this);

	m_pFont->m_eType = FONT_TYPE_OUTLINE;
	m_pFont->m_wstrText = L" ";//여기에 아이디 넣자고하면 수정.
	m_pFont->m_fSize = 20.f;
	m_pFont->m_nColor = 0xFF008AFF;
	m_pFont->m_nFlag = FW1_CENTER | FW1_VCENTER | FW1_RESTORESTATE;
	m_pFont->m_vPos = D3DXVECTOR2(m_fX, m_fY + 150);
	m_pFont->m_fOutlineSize = 1.f;
	m_pFont->m_nOutlineColor = 0xFF000000 /*0xFFFFFFFF*/;

	return S_OK;
}
Beispiel #15
0
void CubesGame::Initialize()
{
	Game::Initialize();

	MediaManager::Instance().AddSearchPath("../../examples/resources");
	MediaManager::Instance().AddSearchPath("../../examples/resources/textures");
	MediaManager::Instance().AddSearchPath("../../examples/resources/models");
	MediaManager::Instance().AddSearchPath("../../examples/resources/shaders");
	MediaManager::Instance().AddSearchPath("../../examples/resources/spriteSheet");
	MediaManager::Instance().AddSearchPath("../../examples/resources/script");
	MediaManager::Instance().AddSearchPath("../../examples/resources/fonts");


// 	Line2DRendererComponent *m_pLine2DRenderer = NEW_AO Line2DRendererComponent(this);
// 	Line3DRendererComponent *m_pLine3DRenderer = NEW_AO Line3DRendererComponent(this);
	MeshRendererGameComponent *m_pModelRenderer = NEW_AO MeshRendererGameComponent(this);
	//DebugSystem *m_pDebugSystem = NEW_AO DebugSystem(this);

// 	AddComponent(m_pLine2DRenderer);
// 	AddComponent(m_pLine3DRenderer);	
	AddComponent(m_pModelRenderer);
	//AddComponent(m_pDebugSystem);
}
void SkyBoxTestScene::Initialize(const GameContext& gameContext)
{
    UNREFERENCED_PARAMETER(gameContext);

    auto skinnedDiffuseMaterial = new SkinnedDiffuseMaterial();
    skinnedDiffuseMaterial->SetDiffuseTexture(L"./Resources/Textures/Knight.jpg");
    gameContext.pMaterialManager->AddMaterial(skinnedDiffuseMaterial, 115);

    m_pModel = new ModelComponent(L"./Resources/Meshes/Knight.ovm");
    m_pModel->SetMaterial(115);
    auto obj = new GameObject();
    obj->AddComponent(m_pModel);
    AddChild(obj);

    obj->GetTransform()->Scale(0.1f, 0.1f, 0.1f);

    auto myMaterial = new SkyBoxMaterial();
    myMaterial->SetDiffuseTexture(L"./Resources/Textures/SkyBox.dds");
    gameContext.pMaterialManager->AddMaterial(myMaterial, 110);
    auto skycube = new SkyBoxPrefab(110);
    AddChild(skycube);

}
void BG_DarkWarriorEntity::InitFunction()
{
	BG_WarriorEntity::InitFunction();

	m_havokBehavior = new vHavokBehaviorComponent();
	m_havokBehavior->m_projectName = "HavokAnimation/BG_Warriors.hkt";
	m_havokBehavior->m_characterName = "Dark_Warrior.hkt";
	m_havokBehavior->m_behaviorName = "Dark_Warrior.hkt";
	AddComponent(m_havokBehavior);

	VTextureObject *textureHandler = Vision::TextureManager.Load2DTexture("Assets/Models/Textures/Dark_Warrior/Dark_Warrior_cloth_d.png");
	GetMesh()->GetSurface(3)->SetTexture(VisSurfaceTextures_cl::VTextureType_e::VTT_Diffuse, textureHandler);
	textureHandler = Vision::TextureManager.Load2DTexture("Assets/Models/Textures/Dark_Warrior/Dark_Warrior_cloth_n.png");
	GetMesh()->GetSurface(3)->SetTexture(VisSurfaceTextures_cl::VTextureType_e::VTT_NormalMap, textureHandler);

	textureHandler = Vision::TextureManager.Load2DTexture("Assets/Models/Textures/Dark_Warrior/Dark_Warrior_bones_d.png");
	GetMesh()->GetSurface(1)->SetTexture(VisSurfaceTextures_cl::VTextureType_e::VTT_Diffuse, textureHandler);
	textureHandler = Vision::TextureManager.Load2DTexture("Assets/Models/Textures/Dark_Warrior/Dark_Warrior_bones_n.png");
	GetMesh()->GetSurface(1)->SetTexture(VisSurfaceTextures_cl::VTextureType_e::VTT_NormalMap, textureHandler);

	textureHandler = Vision::TextureManager.Load2DTexture("Assets/Models/Textures/Dark_Warrior/Dark_Warrior_wepons_d.tga");
	GetMesh()->GetSurface(2)->SetTexture(VisSurfaceTextures_cl::VTextureType_e::VTT_Diffuse, textureHandler);
	GetMesh()->GetSurface(0)->SetTexture(VisSurfaceTextures_cl::VTextureType_e::VTT_Diffuse, textureHandler);
	textureHandler = Vision::TextureManager.Load2DTexture("Assets/Models/Textures/Dark_Warrior/Dark_Warrior_wepons_n.tga");
	GetMesh()->GetSurface(2)->SetTexture(VisSurfaceTextures_cl::VTextureType_e::VTT_NormalMap, textureHandler);
	GetMesh()->GetSurface(0)->SetTexture(VisSurfaceTextures_cl::VTextureType_e::VTT_NormalMap, textureHandler);

	m_collisionRadius = 30;
	m_collisionHeight = 160;
	m_sensorSize = 64;
	m_desiredSpeed = 80;

	PostInitialize();

	SetDirection(hkvVec3(-1,0,0));
}
Beispiel #18
0
	//! called when the HQ has taken damage
	bool HQ::OnDamage(float fDamage)
	{
		if (m_fExplosionTimer > 0.0f)
			return true;

		m_fHitPoints -= fDamage;

		m_HealthBG->SetVisible(true);
		m_HealthBar->SetProgress(m_fHitPoints / m_fMaxHitPoints);

		if(m_fHitPoints < 0.0f)
		{
			auto explosionVisitor = static_cast<ExplosionVisitor*>(m_ExplosionVisitor->Copy());
			auto explosionEntity = static_cast<Entity3D*>(m_ExplosionEntity->Copy());
			explosionEntity->SetScale(Vector3::One * 2.0f);

			// add explosion visitor
			explosionVisitor->SetDefaultIntensity(m_fExplosionIntensity);
			explosionVisitor->SetDefaultDuration(m_fExplosionDuration);
			auto mesh = static_cast<Entity3D*>(GetChildByName("HQMesh"));
			mesh->AddComponent(explosionVisitor);

			// add explosion entity
			AddChild(explosionEntity);
			explosionEntity->SetPosition(mesh->GetPosition());

			AUDIOMGR->Play(AudioManager::S_ExplosionNuclear);
			m_fExplosionTimer = m_fExplosionDuration;
			m_HealthBG->SetVisible(false);

			GAMECAM->Shake(.5f, .02f, m_fExplosionDuration / 2.0f);
			return true;
		}

		return false;
	}
Beispiel #19
0
LoginView::LoginView():
	ui::Window(ui::Point(-1, -1), ui::Point(200, 87)),
	loginButton(new ui::Button(ui::Point(200-100, 87-17), ui::Point(100, 17), "Sign in")),
	cancelButton(new ui::Button(ui::Point(0, 87-17), ui::Point(101, 17), "Cancel")),
	titleLabel(new ui::Label(ui::Point(4, 5), ui::Point(200-16, 16), "Server login")),
	usernameField(new ui::Textbox(ui::Point(8, 25), ui::Point(200-16, 17), Client::Ref().GetAuthUser().Username, "[username]")),
	passwordField(new ui::Textbox(ui::Point(8, 46), ui::Point(200-16, 17), "", "[password]")),
	infoLabel(new ui::Label(ui::Point(8, 67), ui::Point(200-16, 16), "")),
	targetSize(0, 0)
{
	targetSize = Size;
	FocusComponent(usernameField);
	
	infoLabel->Appearance.HorizontalAlign = ui::Appearance::AlignCentre;	infoLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	infoLabel->Visible = false;
	AddComponent(infoLabel);
	
	AddComponent(loginButton);
	SetOkayButton(loginButton);
	loginButton->Appearance.HorizontalAlign = ui::Appearance::AlignRight;
	loginButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	loginButton->Appearance.TextInactive = style::Colour::ConfirmButton;
	loginButton->SetActionCallback(new LoginAction(this));
	AddComponent(cancelButton);
	SetCancelButton(cancelButton);
	cancelButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
	cancelButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	cancelButton->SetActionCallback(new CancelAction(this));
	AddComponent(titleLabel);
	titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;	titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	
	AddComponent(usernameField);
	usernameField->Appearance.icon = IconUsername;
	usernameField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;	usernameField->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(passwordField);
	passwordField->Appearance.icon = IconPassword;
	passwordField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;	passwordField->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	passwordField->SetHidden(true);
}
ServerSaveActivity::ServerSaveActivity(SaveInfo save, ServerSaveActivity::SaveUploadedCallback * callback) :
	WindowActivity(ui::Point(-1, -1), ui::Point(440, 200)),
	thumbnail(NULL),
	save(save),
	callback(callback),
	saveUploadTask(NULL)
{
	titleLabel = new ui::Label(ui::Point(4, 5), ui::Point((Size.X/2)-8, 16), "");
	titleLabel->SetTextColour(style::Colour::InformationTitle);
	titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
	titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(titleLabel);
	CheckName(save.GetName()); //set titleLabel text

	ui::Label * previewLabel = new ui::Label(ui::Point((Size.X/2)+4, 5), ui::Point((Size.X/2)-8, 16), "Preview:");
	previewLabel->SetTextColour(style::Colour::InformationTitle);
	previewLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
	previewLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(previewLabel);

	nameField = new ui::Textbox(ui::Point(8, 25), ui::Point((Size.X/2)-16, 16), save.GetName(), "[save name]");
	nameField->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	nameField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
	nameField->SetActionCallback(new NameChangedAction(this));
	AddComponent(nameField);
	FocusComponent(nameField);

	descriptionField = new ui::Textbox(ui::Point(8, 65), ui::Point((Size.X/2)-16, Size.Y-(65+16+4)), save.GetDescription(), "[save description]");
	descriptionField->SetMultiline(true);
	descriptionField->SetLimit(254);
	descriptionField->Appearance.VerticalAlign = ui::Appearance::AlignTop;
	descriptionField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
	AddComponent(descriptionField);

	publishedCheckbox = new ui::Checkbox(ui::Point(8, 45), ui::Point((Size.X/2)-80, 16), "Publish", "");
	if(Client::Ref().GetAuthUser().Username != save.GetUserName())
	{
		//Save is not owned by the user, disable by default
		publishedCheckbox->SetChecked(false);	
	}
	else
	{
		//Save belongs to the current user, use published state already set
		publishedCheckbox->SetChecked(save.GetPublished());
	}
	AddComponent(publishedCheckbox);

	pausedCheckbox = new ui::Checkbox(ui::Point(160, 45), ui::Point(55, 16), "Paused", "");
	pausedCheckbox->SetChecked(save.GetGameSave()->paused);
	AddComponent(pausedCheckbox);

	ui::Button * cancelButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point((Size.X/2)-75, 16), "Cancel");
	cancelButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
	cancelButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	cancelButton->Appearance.BorderInactive = ui::Colour(200, 200, 200);
	cancelButton->SetActionCallback(new CancelAction(this));
	AddComponent(cancelButton);
	SetCancelButton(cancelButton);

	ui::Button * okayButton = new ui::Button(ui::Point((Size.X/2)-76, Size.Y-16), ui::Point(76, 16), "Save");
	okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
	okayButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	okayButton->Appearance.TextInactive = style::Colour::InformationTitle;
	okayButton->SetActionCallback(new SaveAction(this));
	AddComponent(okayButton);
	SetOkayButton(okayButton);

	ui::Button * PublishingInfoButton = new ui::Button(ui::Point((Size.X*3/4)-75, Size.Y-42), ui::Point(150, 16), "Publishing Info");
	PublishingInfoButton->Appearance.HorizontalAlign = ui::Appearance::AlignCentre;
	PublishingInfoButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	PublishingInfoButton->Appearance.TextInactive = style::Colour::InformationTitle;
	PublishingInfoButton->SetActionCallback(new PublishingAction(this));
	AddComponent(PublishingInfoButton);

	ui::Button * RulesButton = new ui::Button(ui::Point((Size.X*3/4)-75, Size.Y-22), ui::Point(150, 16), "Save Uploading Rules");
	RulesButton->Appearance.HorizontalAlign = ui::Appearance::AlignCentre;
	RulesButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	RulesButton->Appearance.TextInactive = style::Colour::InformationTitle;
	RulesButton->SetActionCallback(new RulesAction(this));
	AddComponent(RulesButton);

	if(save.GetGameSave())
		RequestBroker::Ref().RenderThumbnail(save.GetGameSave(), false, true, (Size.X/2)-16, -1, this);
}
void SearchView::NotifySaveListChanged(SearchModel * sender)
{
	int i = 0;
	int buttonWidth, buttonHeight, saveX = 0, saveY = 0, savesX = 5, savesY = 4, buttonPadding = 1;
	int buttonAreaWidth, buttonAreaHeight, buttonXOffset, buttonYOffset;

	int tagWidth, tagHeight, tagX = 0, tagY = 0, tagsX = 6, tagsY = 4, tagPadding = 1;
	int tagAreaWidth, tagAreaHeight, tagXOffset, tagYOffset;

	vector<SaveInfo*> saves = sender->GetSaveList();
	//string messageOfTheDay = sender->GetMessageOfTheDay();

	if(sender->GetShowFavourite())
		favouriteSelected->SetText("Unfavourite");
	else
		favouriteSelected->SetText("Favourite");

	Client::Ref().ClearThumbnailRequests();
	for(i = 0; i < saveButtons.size(); i++)
	{
		RemoveComponent(saveButtons[i]);
	}
	if(!sender->GetSavesLoaded())
	{
		nextButton->Enabled = false;
		previousButton->Enabled = false;
		favButton->Enabled = false;
	}
	else
	{
		nextButton->Enabled = true;
		previousButton->Enabled = true;
		if (Client::Ref().GetAuthUser().ID)
			favButton->Enabled = true;
	}
	if (!sender->GetSavesLoaded() || favButton->GetToggleState())
	{
		ownButton->Enabled = false;
		sortButton->Enabled = false;
	}
	else
	{
		if (Client::Ref().GetAuthUser().ID)
			ownButton->Enabled = true;
		sortButton->Enabled = true;
	}
	if(!saves.size())
	{
		loadingSpinner->Visible = false;
		if(!errorLabel)
		{
			errorLabel = new ui::Label(ui::Point(((XRES+BARSIZE)/2)-100, ((YRES+MENUSIZE)/2)-6), ui::Point(200, 12), "Error");
			AddComponent(errorLabel);
		}
		if(!sender->GetSavesLoaded())
		{
			errorLabel->SetText("Loading...");
			loadingSpinner->Visible = true;
		}
		else
		{
			if(sender->GetLastError().length())
				errorLabel->SetText("\bo" + sender->GetLastError());
			else
				errorLabel->SetText("\boNo saves found");
		}
	}
	else
	{
		loadingSpinner->Visible = false;
		if(errorLabel)
		{
			RemoveComponent(errorLabel);
			delete errorLabel;
			errorLabel = NULL;
		}
		for(i = 0; i < saveButtons.size(); i++)
		{
			delete saveButtons[i];
		}
		saveButtons.clear();

		buttonYOffset = 28;
		buttonXOffset = buttonPadding;
		buttonAreaWidth = Size.X;
		buttonAreaHeight = Size.Y - buttonYOffset - 18;

		if(sender->GetShowTags())
		{
			buttonYOffset += (buttonAreaHeight/savesY) - buttonPadding*2;
			buttonAreaHeight = Size.Y - buttonYOffset - 18;
			savesY--;

			tagXOffset = tagPadding;
			tagYOffset = 60;
			tagAreaWidth = Size.X;
			tagAreaHeight = ((buttonAreaHeight/savesY) - buttonPadding*2)-(tagYOffset-28)-5;
			tagWidth = (tagAreaWidth/tagsX) - tagPadding*2;
			tagHeight = (tagAreaHeight/tagsY) - tagPadding*2;
		}

		buttonWidth = (buttonAreaWidth/savesX) - buttonPadding*2;
		buttonHeight = (buttonAreaHeight/savesY) - buttonPadding*2;



		class SaveOpenAction: public ui::SaveButtonAction
		{
			SearchView * v;
		public:
			SaveOpenAction(SearchView * _v) { v = _v; }
			virtual void ActionCallback(ui::SaveButton * sender)
			{
				v->c->OpenSave(sender->GetSave()->GetID(), sender->GetSave()->GetVersion());
			}
			virtual void SelectedCallback(ui::SaveButton * sender)
			{
				v->c->Selected(sender->GetSave()->GetID(), sender->GetSelected());
			}
			virtual void AltActionCallback(ui::SaveButton * sender)
			{
				stringstream search;
				search << "history:" << sender->GetSave()->GetID();
				v->Search(search.str());
			}
			virtual void AltActionCallback2(ui::SaveButton * sender)
			{
				v->Search("user:"+sender->GetSave()->GetUserName());
			}
		};
		for(i = 0; i < saves.size(); i++)
		{
			if(saveX == savesX)
			{
				if(saveY == savesY-1)
					break;
				saveX = 0;
				saveY++;
			}
			ui::SaveButton * saveButton;
			saveButton = new ui::SaveButton(
						ui::Point(
							buttonXOffset + buttonPadding + saveX*(buttonWidth+buttonPadding*2),
							buttonYOffset + buttonPadding + saveY*(buttonHeight+buttonPadding*2)
							),
						ui::Point(buttonWidth, buttonHeight),
						saves[i]);
			saveButton->AddContextMenu(0);
			saveButton->SetActionCallback(new SaveOpenAction(this));
			if(Client::Ref().GetAuthUser().ID)
				saveButton->SetSelectable(true);
			if (saves[i]->GetUserName() == Client::Ref().GetAuthUser().Username || Client::Ref().GetAuthUser().UserElevation == User::ElevationAdmin || Client::Ref().GetAuthUser().UserElevation == User::ElevationModerator)
				saveButton->SetShowVotes(true);
			saveButtons.push_back(saveButton);
			AddComponent(saveButton);
			saveX++;
		}
	}
}
void SearchView::NotifyTagListChanged(SearchModel * sender)
{
	int i = 0;
	int buttonWidth, buttonHeight, saveX = 0, saveY = 0, savesX = 5, savesY = 4, buttonPadding = 1;
	int buttonAreaWidth, buttonAreaHeight, buttonXOffset, buttonYOffset;

	int tagWidth, tagHeight, tagX = 0, tagY = 0, tagsX = 6, tagsY = 4, tagPadding = 1;
	int tagAreaWidth, tagAreaHeight, tagXOffset, tagYOffset;

	vector<pair<string, int> > tags = sender->GetTagList();

	RemoveComponent(motdLabel);
	motdLabel->SetParentWindow(NULL);

	RemoveComponent(tagsLabel);
	tagsLabel->SetParentWindow(NULL);

	for(i = 0; i < tagButtons.size(); i++)
	{
		RemoveComponent(tagButtons[i]);
		delete tagButtons[i];
	}
	tagButtons.clear();

	buttonYOffset = 28;
	buttonXOffset = buttonPadding;
	buttonAreaWidth = Size.X;
	buttonAreaHeight = Size.Y - buttonYOffset - 18;

	if(sender->GetShowTags())
	{
		buttonYOffset += (buttonAreaHeight/savesY) - buttonPadding*2;
		buttonAreaHeight = Size.Y - buttonYOffset - 18;
		savesY--;

		tagXOffset = tagPadding;
		tagYOffset = 60;
		tagAreaWidth = Size.X;
		tagAreaHeight = ((buttonAreaHeight/savesY) - buttonPadding*2)-(tagYOffset-28)-5;
		tagWidth = (tagAreaWidth/tagsX) - tagPadding*2;
		tagHeight = (tagAreaHeight/tagsY) - tagPadding*2;

		AddComponent(tagsLabel);
		tagsLabel->Position.Y = tagYOffset-16;

		AddComponent(motdLabel);
		motdLabel->Position.Y = tagYOffset-30;
	}

	class TagAction: public ui::ButtonAction
	{
		SearchView * v;
		std::string tag;
	public:
		TagAction(SearchView * v, std::string tag) : v(v), tag(tag) {}
		virtual void ActionCallback(ui::Button * sender)
		{
			v->Search(tag);
		}
	};
	if(sender->GetShowTags())
	{
		for(i = 0; i < tags.size(); i++)
		{
			int maxTagVotes = tags[0].second;

			pair<string, int> tag = tags[i];
			
			if(tagX == tagsX)
			{
				if(tagY == tagsY-1)
					break;
				tagX = 0;
				tagY++;
			}

			int tagAlpha = 192;
			if (maxTagVotes)
				tagAlpha = 127+(128*tag.second)/maxTagVotes;

			ui::Button * tagButton;
			tagButton = new ui::Button(
				ui::Point(
						tagXOffset + tagPadding + tagX*(tagWidth+tagPadding*2),
						tagYOffset + tagPadding + tagY*(tagHeight+tagPadding*2)
					),
				ui::Point(tagWidth, tagHeight),
				tag.first
				);
			tagButton->SetActionCallback(new TagAction(this, tag.first));
			tagButton->Appearance.BorderInactive = ui::Colour(0, 0, 0);
			tagButton->Appearance.BorderHover = ui::Colour(0, 0, 0);
			tagButton->Appearance.BorderActive = ui::Colour(0, 0, 0);
			tagButton->Appearance.BackgroundHover = ui::Colour(0, 0, 0);

			tagButton->Appearance.TextInactive = ui::Colour(tagAlpha, tagAlpha, tagAlpha);
			tagButton->Appearance.TextHover = ui::Colour((tagAlpha*5)/6, (tagAlpha*5)/6, tagAlpha);
			AddComponent(tagButton);
			tagButtons.push_back(tagButton);
			tagX++;

		}
	}
}
SearchView::SearchView():
	ui::Window(ui::Point(0, 0), ui::Point(XRES+BARSIZE, YRES+MENUSIZE)),
	saveButtons(vector<ui::SaveButton*>()),
	errorLabel(NULL),
	c(NULL)
{

	Client::Ref().AddListener(this);

	nextButton = new ui::Button(ui::Point(XRES+BARSIZE-52, YRES+MENUSIZE-18), ui::Point(50, 16), "Next \x95");
	previousButton = new ui::Button(ui::Point(1, YRES+MENUSIZE-18), ui::Point(50, 16), "\x96 Prev");
	infoLabel  = new ui::Label(ui::Point(260, YRES+MENUSIZE-18), ui::Point(XRES+BARSIZE-520, 16), "Page 1 of 1");
	tagsLabel  = new ui::Label(ui::Point(270, YRES+MENUSIZE-18), ui::Point(XRES+BARSIZE-540, 16), "\boPopular Tags:");
	motdLabel  = new ui::RichLabel(ui::Point(51, YRES+MENUSIZE-18), ui::Point(XRES+BARSIZE-102, 16), Client::Ref().GetMessageOfTheDay());

	class SearchAction : public ui::TextboxAction
	{
		SearchView * v;
	public:
		SearchAction(SearchView * _v) { v = _v; }
		void TextChangedCallback(ui::Textbox * sender)
		{
			v->doSearch();
		}
	};
	searchField = new ui::Textbox(ui::Point(60, 10), ui::Point((XRES+BARSIZE)-238, 17), "", "[search]");
	searchField->Appearance.icon = IconSearch;
	searchField->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
	searchField->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	searchField->SetActionCallback(new SearchAction(this));


	class SortAction : public ui::ButtonAction
	{
		SearchView * v;
	public:
		SortAction(SearchView * _v) { v = _v; }
		void ActionCallback(ui::Button * sender)
		{
			v->c->ChangeSort();
		}
	};
	sortButton = new ui::Button(ui::Point(XRES+BARSIZE-140, 10), ui::Point(61, 17), "Sort");
	sortButton->SetIcon(IconVoteSort);
	sortButton->SetTogglable(true);
	sortButton->SetActionCallback(new SortAction(this));
	sortButton->Appearance.HorizontalAlign = ui::Appearance::AlignCentre;
	sortButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(sortButton);

	class MyOwnAction : public ui::ButtonAction
	{
		SearchView * v;
	public:
		MyOwnAction(SearchView * _v) { v = _v; }
		void ActionCallback(ui::Button * sender)
		{
			v->c->ShowOwn(sender->GetToggleState());
		}
	};
	ownButton = new ui::Button(ui::Point(XRES+BARSIZE-70, 10), ui::Point(61, 17), "My Own");
	ownButton->SetIcon(IconMyOwn);
	ownButton->SetTogglable(true);
	ownButton->SetActionCallback(new MyOwnAction(this));
	ownButton->Appearance.HorizontalAlign = ui::Appearance::AlignCentre;
	ownButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(ownButton);

	class FavAction : public ui::ButtonAction
	{
		SearchView * v;
	public:
		FavAction(SearchView * _v) { v = _v; }
		void ActionCallback(ui::Button * sender)
		{
			v->c->ShowFavourite(sender->GetToggleState());
		}
	};
	favButton = new ui::Button(searchField->Position+ui::Point(searchField->Size.X+15, 0), ui::Point(17, 17), "");
	favButton->SetIcon(IconFavourite);
	favButton->SetTogglable(true);
	favButton->Appearance.Margin.Left+=2;
	favButton->SetActionCallback(new FavAction(this));
	favButton->Appearance.HorizontalAlign = ui::Appearance::AlignCentre;
	favButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	favButton->Appearance.BorderInactive = ui::Colour(170,170,170);
	AddComponent(favButton);
	
	class ClearSearchAction : public ui::ButtonAction
	{
		SearchView * v;
	public:
		ClearSearchAction(SearchView * _v) { v = _v; }
		void ActionCallback(ui::Button * sender)
		{
			v->clearSearch();
		}
	};
	ui::Button * clearSearchButton = new ui::Button(searchField->Position+ui::Point(searchField->Size.X-1, 0), ui::Point(17, 17), "");
	clearSearchButton->SetIcon(IconClose);
	clearSearchButton->SetActionCallback(new ClearSearchAction(this));
	clearSearchButton->Appearance.Margin.Left+=2;
	clearSearchButton->Appearance.Margin.Top+=2;
	clearSearchButton->Appearance.HorizontalAlign = ui::Appearance::AlignCentre;
	clearSearchButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	clearSearchButton->Appearance.BorderInactive = ui::Colour(170,170,170);
	AddComponent(clearSearchButton);

	class NextPageAction : public ui::ButtonAction
	{
		SearchView * v;
	public:
		NextPageAction(SearchView * _v) { v = _v; }
		void ActionCallback(ui::Button * sender)
		{
			v->c->NextPage();
		}
	};
	nextButton->SetActionCallback(new NextPageAction(this));
	nextButton->Appearance.HorizontalAlign = ui::Appearance::AlignRight;
	nextButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	class PrevPageAction : public ui::ButtonAction
	{
		SearchView * v;
	public:
		PrevPageAction(SearchView * _v) { v = _v; }
		void ActionCallback(ui::Button * sender)
		{
			v->c->PrevPage();
		}
	};
	previousButton->SetActionCallback(new PrevPageAction(this));
	previousButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
	previousButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(nextButton);
	AddComponent(previousButton);
	AddComponent(searchField);
	AddComponent(infoLabel);

	loadingSpinner = new ui::Spinner(ui::Point(((XRES+BARSIZE)/2)-12, ((YRES+MENUSIZE)/2)+12), ui::Point(24, 24));
	AddComponent(loadingSpinner);

	ui::Label * searchPrompt = new ui::Label(ui::Point(10, 10), ui::Point(50, 16), "Search:");
	searchPrompt->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
	searchPrompt->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(searchPrompt);

	class RemoveSelectedAction : public ui::ButtonAction
	{
		SearchView * v;
	public:
		RemoveSelectedAction(SearchView * _v) { v = _v; }
		void ActionCallback(ui::Button * sender)
		{
			v->c->RemoveSelected();
		}
	};

	class UnpublishSelectedAction : public ui::ButtonAction
	{
		SearchView * v;
	public:
		UnpublishSelectedAction(SearchView * _v) { v = _v; }
		void ActionCallback(ui::Button * sender)
		{
			v->c->UnpublishSelected();
		}
	};

	class FavouriteSelectedAction : public ui::ButtonAction
	{
		SearchView * v;
	public:
		FavouriteSelectedAction(SearchView * _v) { v = _v; }
		void ActionCallback(ui::Button * sender)
		{
			v->c->FavouriteSelected();
		}
	};

	class ClearSelectionAction : public ui::ButtonAction
	{
		SearchView * v;
	public:
		ClearSelectionAction(SearchView * _v) { v = _v; }
		void ActionCallback(ui::Button * sender)
		{
			v->c->ClearSelection();
		}
	};

	removeSelected = new ui::Button(ui::Point((((XRES+BARSIZE)-415)/2), YRES+MENUSIZE-18), ui::Point(100, 16), "Delete");
	removeSelected->Visible = false;
	removeSelected->SetActionCallback(new RemoveSelectedAction(this));
	AddComponent(removeSelected);

	unpublishSelected = new ui::Button(ui::Point((((XRES+BARSIZE)-415)/2)+105, YRES+MENUSIZE-18), ui::Point(100, 16), "Unpublish");
	unpublishSelected->Visible = false;
	unpublishSelected->SetActionCallback(new UnpublishSelectedAction(this));
	AddComponent(unpublishSelected);

	favouriteSelected = new ui::Button(ui::Point((((XRES+BARSIZE)-415)/2)+210, YRES+MENUSIZE-18), ui::Point(100, 16), "Favourite");
	favouriteSelected->Visible = false;
	favouriteSelected->SetActionCallback(new FavouriteSelectedAction(this));
	AddComponent(favouriteSelected);

	clearSelection = new ui::Button(ui::Point((((XRES+BARSIZE)-415)/2)+315, YRES+MENUSIZE-18), ui::Point(100, 16), "Clear selection");
	clearSelection->Visible = false;
	clearSelection->SetActionCallback(new ClearSelectionAction(this));
	AddComponent(clearSelection);

	CheckAccess();
}
Beispiel #24
0
 Entity::Entity(vector<Component*> _components) {
     for (vector<Component*>::iterator it = _components.begin(); it != _components.end(); ++it) {
         AddComponent((*it));
     }
 }
Beispiel #25
0
OptionsView::OptionsView():
	ui::Window(ui::Point(-1, -1), ui::Point(300, 310)){

	ui::Label * tempLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 14), "Simulation Options");
	tempLabel->SetTextColour(style::Colour::InformationTitle);
	tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;	tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(tempLabel);

	class HeatSimulationAction: public ui::CheckboxAction
	{
		OptionsView * v;
	public:
		HeatSimulationAction(OptionsView * v_){	v = v_;	}
		virtual void ActionCallback(ui::Checkbox * sender){	v->c->SetHeatSimulation(sender->GetChecked()); }
	};

	heatSimulation = new ui::Checkbox(ui::Point(8, 23), ui::Point(Size.X-6, 16), "Heat simulation \bgIntroduced in version 34", "");
	heatSimulation->SetActionCallback(new HeatSimulationAction(this));
	AddComponent(heatSimulation);
	tempLabel = new ui::Label(ui::Point(24, heatSimulation->Position.Y+14), ui::Point(Size.X-28, 16), "\bgCan cause odd behaviour with very old saves");
	tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;	tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(tempLabel);

	class AmbientHeatSimulationAction: public ui::CheckboxAction
	{
		OptionsView * v;
	public:
		AmbientHeatSimulationAction(OptionsView * v_){	v = v_;	}
		virtual void ActionCallback(ui::Checkbox * sender){	v->c->SetAmbientHeatSimulation(sender->GetChecked()); }
	};

	ambientHeatSimulation = new ui::Checkbox(ui::Point(8, 53), ui::Point(Size.X-6, 16), "Ambient heat simulation \bgIntroduced in version 50", "");
	ambientHeatSimulation->SetActionCallback(new AmbientHeatSimulationAction(this));
	AddComponent(ambientHeatSimulation);
	tempLabel = new ui::Label(ui::Point(24, ambientHeatSimulation->Position.Y+14), ui::Point(Size.X-28, 16), "\bgCan cause odd behaviour with old saves");
	tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;	tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(tempLabel);

	class NewtonianGravityAction: public ui::CheckboxAction
	{
		OptionsView * v;
	public:
		NewtonianGravityAction(OptionsView * v_){	v = v_;	}
		virtual void ActionCallback(ui::Checkbox * sender){	v->c->SetNewtonianGravity(sender->GetChecked()); }
	};

	newtonianGravity = new ui::Checkbox(ui::Point(8, 83), ui::Point(Size.X-6, 16), "Newtonian gravity \bgIntroduced in version 48", "");
	newtonianGravity->SetActionCallback(new NewtonianGravityAction(this));
	AddComponent(newtonianGravity);
	tempLabel = new ui::Label(ui::Point(24, newtonianGravity->Position.Y+14), ui::Point(Size.X-28, 16), "\bgMay cause poor performance on older computers");
	tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;	tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(tempLabel);

	class WaterEqualisationAction: public ui::CheckboxAction
		{
			OptionsView * v;
		public:
			WaterEqualisationAction(OptionsView * v_){	v = v_;	}
			virtual void ActionCallback(ui::Checkbox * sender){	v->c->SetWaterEqualisation(sender->GetChecked()); }
		};

	waterEqualisation = new ui::Checkbox(ui::Point(8, 113), ui::Point(Size.X-6, 16), "Water equalisation \bgIntroduced in version 61", "");
	waterEqualisation->SetActionCallback(new WaterEqualisationAction(this));
	AddComponent(waterEqualisation);
	tempLabel = new ui::Label(ui::Point(24, waterEqualisation->Position.Y+14), ui::Point(Size.X-28, 16), "\bgMay cause poor performance with a lot of water");
	tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;	tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(tempLabel);

	class AirModeChanged: public ui::DropDownAction
	{
		OptionsView * v;
	public:
		AirModeChanged(OptionsView * v): v(v) { }
		virtual void OptionChanged(ui::DropDown * sender, std::pair<std::string, int> option) { v->c->SetAirMode(option.second); }
	};
	airMode = new ui::DropDown(ui::Point(Size.X-88, 146), ui::Point(80, 16));
	AddComponent(airMode);
	airMode->AddOption(std::pair<std::string, int>("On", 0));
	airMode->AddOption(std::pair<std::string, int>("Pressure off", 1));
	airMode->AddOption(std::pair<std::string, int>("Velocity off", 2));
	airMode->AddOption(std::pair<std::string, int>("Off", 3));
	airMode->AddOption(std::pair<std::string, int>("No Update", 4));
	airMode->SetActionCallback(new AirModeChanged(this));
		
	tempLabel = new ui::Label(ui::Point(8, 146), ui::Point(Size.X-96, 16), "Air Simulation Mode");
	tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;	tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(tempLabel);
		
	class GravityModeChanged: public ui::DropDownAction
	{
		OptionsView * v;
	public:
		GravityModeChanged(OptionsView * v): v(v) { }
		virtual void OptionChanged(ui::DropDown * sender, std::pair<std::string, int> option) { v->c->SetGravityMode(option.second); }
	};	
		
	gravityMode = new ui::DropDown(ui::Point(Size.X-88, 166), ui::Point(80, 16));
	AddComponent(gravityMode);
	gravityMode->AddOption(std::pair<std::string, int>("Vertical", 0));
	gravityMode->AddOption(std::pair<std::string, int>("Off", 1));
	gravityMode->AddOption(std::pair<std::string, int>("Radial", 2));
	gravityMode->SetActionCallback(new GravityModeChanged(this));

	tempLabel = new ui::Label(ui::Point(8, 166), ui::Point(Size.X-96, 16), "Gravity Simulation Mode");
	tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;	tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(tempLabel);

	class EdgeModeChanged: public ui::DropDownAction
	{
		OptionsView * v;
	public:
		EdgeModeChanged(OptionsView * v): v(v) { }
		virtual void OptionChanged(ui::DropDown * sender, std::pair<std::string, int> option) { v->c->SetEdgeMode(option.second); }
	};	

	edgeMode = new ui::DropDown(ui::Point(Size.X-88, 186), ui::Point(80, 16));
	AddComponent(edgeMode);
	edgeMode->AddOption(std::pair<std::string, int>("Void", 0));
	edgeMode->AddOption(std::pair<std::string, int>("Solid", 1));
	edgeMode->SetActionCallback(new EdgeModeChanged(this));

	tempLabel = new ui::Label(ui::Point(8, 186), ui::Point(Size.X-96, 16), "Edge Mode");
	tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;	tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(tempLabel);

	class ScaleAction: public ui::CheckboxAction
	{
		OptionsView * v;
	public:
		ScaleAction(OptionsView * v_){	v = v_;	}
		virtual void ActionCallback(ui::Checkbox * sender){	v->c->SetScale(sender->GetChecked()); }
	};

	scale = new ui::Checkbox(ui::Point(8, 210), ui::Point(Size.X-6, 16), "Large screen", "");
	scale->SetActionCallback(new ScaleAction(this));
	tempLabel = new ui::Label(ui::Point(scale->Position.X+Graphics::textwidth(scale->GetText().c_str())+20, scale->Position.Y), ui::Point(Size.X-28, 16), "\bg- Double window size for smaller screen");
	tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;	tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(tempLabel);
	AddComponent(scale);


	class FullscreenAction: public ui::CheckboxAction
	{
		OptionsView * v;
	public:
		FullscreenAction(OptionsView * v_){	v = v_;	}
		virtual void ActionCallback(ui::Checkbox * sender){	v->c->SetFullscreen(sender->GetChecked()); }
	};

	fullscreen = new ui::Checkbox(ui::Point(8, 230), ui::Point(Size.X-6, 16), "Fullscreen", "");
	fullscreen->SetActionCallback(new FullscreenAction(this));
	tempLabel = new ui::Label(ui::Point(fullscreen->Position.X+Graphics::textwidth(fullscreen->GetText().c_str())+20, fullscreen->Position.Y), ui::Point(Size.X-28, 16), "\bg- Use the entire screen");
	tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;	tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(tempLabel);
	AddComponent(fullscreen);


	class FastQuitAction: public ui::CheckboxAction
	{
		OptionsView * v;
	public:
		FastQuitAction(OptionsView * v_){	v = v_;	}
		virtual void ActionCallback(ui::Checkbox * sender){	v->c->SetFastQuit(sender->GetChecked()); }
	};

	fastquit = new ui::Checkbox(ui::Point(8, 250), ui::Point(Size.X-6, 16), "Fast Quit", "");
	fastquit->SetActionCallback(new FastQuitAction(this));
	tempLabel = new ui::Label(ui::Point(fastquit->Position.X+Graphics::textwidth(fastquit->GetText().c_str())+20, fastquit->Position.Y), ui::Point(Size.X-28, 16), "\bg- Always exit completely when hitting close");
	tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;	tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(tempLabel);
	AddComponent(fastquit);

	class ShowAvatarsAction: public ui::CheckboxAction
	{
		OptionsView * v;
	public:
		ShowAvatarsAction(OptionsView * v_){	v = v_;	}
		virtual void ActionCallback(ui::Checkbox * sender){	v->c->SetShowAvatars(sender->GetChecked()); }
	};

	showAvatars = new ui::Checkbox(ui::Point(8, 270), ui::Point(Size.X-6, 16), "Show Avatars", "");
	showAvatars->SetActionCallback(new ShowAvatarsAction(this));
	tempLabel = new ui::Label(ui::Point(showAvatars->Position.X+Graphics::textwidth(showAvatars->GetText().c_str())+20, showAvatars->Position.Y), ui::Point(Size.X-28, 16), "\bg- Disable if you have a slow connection");
	tempLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;	tempLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(tempLabel);
	AddComponent(showAvatars);

	class CloseAction: public ui::ButtonAction
	{
	public:
		OptionsView * v;
		CloseAction(OptionsView * v_) { v = v_; }
		void ActionCallback(ui::Button * sender)
		{
			v->c->Exit();
		}
	};

	ui::Button * tempButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X, 16), "OK");
	tempButton->SetActionCallback(new CloseAction(this));
	AddComponent(tempButton);
	SetCancelButton(tempButton);
	SetOkayButton(tempButton);
}
Beispiel #26
0
void FixedLayouter::AddWindow(Window* window, int r, int rc, int c, int cw, int cc) {
	AddComponent(window, r, rc, c, cw, cc);
	window->SetRoundedRadius(window->GetPreferredHeight() / 3);
}
void InterpretArchetype(FILE * fpArch)
{
    char buffer[MAX_LENGTH];
    ARCHETYPE * pNewArchetype = malloc(sizeof(ARCHETYPE));
    COMPONENT * pCurrComp = NULL;
    pNewArchetype->Name = "Untitled";
    pNewArchetype->nextArchetype = NULL;
    pNewArchetype->nextComponent = NULL;
    pNewArchetype->pGame = pTheGame;
    pNewArchetype->pUnit = NULL;
    pNewArchetype->nextArchetype = pTheGame->nextArchetype;
    pTheGame->nextArchetype = pNewArchetype;
    while (!feof(fpArch))
    {
        if (fgets(buffer, MAX_LENGTH, fpArch))
        {
            char question[MAX_LENGTH];
            int inputInt = 0;
            float inputFloat = 0.0f;
            VECTOR inputVector = NewVector(0, 0);
            AddNull(buffer);
            if (buffer[0] != '#' && strlen(buffer) > 2)
            {
                sscanf(buffer, "%s", &question);
                if (myStrCmp(question, "Name") <= 0)
                {
                    char nameInput[MAX_LENGTH];
                    sscanf(buffer, "Name = %s", nameInput);
                    pNewArchetype->Name = myStrCpy(nameInput);
                    continue;
                }

                if (myStrCmp(question, "Tag") <= 0)
                {
                    char tagInput[MAX_LENGTH];
                    sscanf(buffer, "Tag = %s", tagInput);
                    pNewArchetype->Tag = GetTagFromString(tagInput);
                    continue;
                }

                if (myStrCmp(question, "COMPONENT") <= 0)
                {
                    COMPONENTTYPE theType;
                    char typeInput[MAX_LENGTH];
                    sscanf(buffer, "COMPONENT |%s|", &typeInput);
                    if (myStrCmp(typeInput, "Sprite") <= 0) theType = Sprite;
                    if (myStrCmp(typeInput, "Mesh") <= 0) theType = Mesh;
                    if (myStrCmp(typeInput, "Behavior") <= 0) theType = Behavior;
                    if (myStrCmp(typeInput, "Physics") <= 0) theType = Physics;
                    if (myStrCmp(typeInput, "Collider") <= 0) theType = Collider;
                    if (myStrCmp(typeInput, "KSound") <= 0) theType = KSound;


                    pCurrComp = AddComponent(pNewArchetype, theType);
                    continue;
                }

                if (pCurrComp)
                {
                    if (pCurrComp->Type == Mesh)
                    {
                        MESH * pMesh = (MESH*)pCurrComp->pStruct;
                        if (myStrCmp(question, "Size") <= 0)
                        {
                            sscanf(buffer, "\tSize = (%f, %f)", &inputVector.x, &inputVector.y);
                            pMesh->Size = inputVector;
                            continue;
                        }

                        if (myStrCmp(question, "Color") <= 0)
                        {
                            COLOR inputColor;
                            sscanf(buffer, "\tColor = (%f, %f, %f, %f)", &inputColor.r, &inputColor.g, &inputColor.b, &inputColor.a);
                            pMesh->Color = inputColor;
                            continue;
                        }

                        if (myStrCmp(question, "Opacity") <= 0)
                        {
                            sscanf(buffer, "\tOpacity = %f", &inputFloat);
                            pMesh->Opacity = inputFloat;
                            continue;
                        }
                    }

                    if (pCurrComp->Type == Behavior)
                    {
                        BEHAVIOR * pBehavior = (BEHAVIOR*)pCurrComp->pStruct;
                        if (myStrCmp(question, "BehaviorScript") <= 0)
                        {
                            char scriptInput[MAX_LENGTH];
                            sscanf(buffer, "\tBehaviorScript = %s", &scriptInput);
                            pBehavior->BehaviorScript = GetBehaviorFromString(scriptInput);
                            continue;
                        }
                    }

                    if (pCurrComp->Type == Physics)
                    {
                        PHYSICS * pPhysics = (PHYSICS*)pCurrComp->pStruct;
                        if (myStrCmp(question, "Gravity") <= 0)
                        {
                            sscanf(buffer, "\tGravity = %f", &inputFloat);
                            pPhysics->Gravity = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "MaxSpeed") <= 0)
                        {
                            sscanf(buffer, "\tMaxSpeed = %f", &inputFloat);
                            pPhysics->MaxSpeed = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "Friction") <= 0)
                        {
                            sscanf(buffer, "\tFriction = %f", &inputFloat);
                            pPhysics->Friction = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "Velocity") <= 0)
                        {
                            sscanf(buffer, "\tVelocity = (%f, %f)", &inputVector.x, &inputVector.y);
                            pPhysics->Velocity = inputVector;
                            continue;
                        }

                        if (myStrCmp(question, "Acceleration") <= 0)
                        {
                            sscanf(buffer, "\tAcceleration = (%f, %f)", &inputVector.x, &inputVector.y);
                            pPhysics->Acceleration = inputVector;
                            continue;
                        }
                    }

                    if (pCurrComp->Type == Collider)
                    {
                        COLLIDER * pCollider = (COLLIDER*)pCurrComp->pStruct;

                        if (myStrCmp(question, "Offset") <= 0)
                        {
                            sscanf(buffer, "\tOffset = (%f, %f)", &inputVector.x, &inputVector.y);
                            pCollider->Offset = inputVector;
                            continue;
                        }

                        if (myStrCmp(question, "Height") <= 0)
                        {
                            sscanf(buffer, "\tHeight = %f", &inputFloat);
                            pCollider->Height = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "Width") <= 0)
                        {
                            sscanf(buffer, "\tWidth = %f", &inputFloat);
                            pCollider->Width = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "IsGhosted") <= 0)
                        {
                            sscanf(buffer, "\tIsGhosted = %i", &inputInt);
                            pCollider->IsGhosted = inputInt;
                            continue;
                        }
                    }

                    if (pCurrComp->Type == KSound)
                    {
                        KSOUND * pSound = (KSOUND*)pCurrComp->pStruct;

                        if (myStrCmp(question, "Volume") <= 0)
                        {
                            sscanf(buffer, "\tVolume = %f", &inputFloat);
                            pSound->Volume = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "Positional") <= 0)
                        {
                            sscanf(buffer, "\tPositional = %i", &inputInt);
                            pSound->Positional = inputInt;
                            continue;
                        }

                        if (myStrCmp(question, "MaxReach") <= 0)
                        {
                            sscanf(buffer, "\tMaxReach = %f", &inputFloat);
                            pSound->MaxReach = inputFloat;
                            continue;
                        }

                        if (myStrCmp(question, "SoundFile") <= 0)
                        {
                            char scriptInput[MAX_LENGTH];
                            sscanf(buffer, "\tSoundFile = %s", &scriptInput);
                            pSound->SoundFile = scriptInput;
                            continue;
                        }

                        if (myStrCmp(question, "PlayOnStart") <= 0)
                        {
                            sscanf(buffer, "\tPlayOnStart = %i", &inputInt);
                            pSound->PlayOnStart = inputInt;
                            continue;
                        }

                        // TODO : Add the rest of the params.
                    }

                    if (pCurrComp->Type == Sprite)
                    {
                        SPRITE * pSprite = (SPRITE*)pCurrComp->pStruct;
                        if (myStrCmp(question, "TextureFile") <= 0)
                        {
                            int temp;
                            char textureInput[MAX_LENGTH];
                            sscanf(buffer, "\tTextureFile = %i , ", &temp);
                            MultipleAnimations(buffer, temp, pSprite);
                            continue;
                        }

                        if (myStrCmp(question, "Animated") <= 0)
                        {
                            sscanf(buffer, "\tAnimated = %i", &inputInt);
                            pSprite->Animated = inputInt;
                            continue;
                        }

                        if (myStrCmp(question, "RowCol") <= 0)
                        {
                            sscanf(buffer, "\tRowCol = (%f, %f)", &inputVector.x, &inputVector.y);
                            pSprite->RowCol = inputVector;
                            continue;
                        }

                        if (myStrCmp(question, "Offset") <= 0)
                        {
                            sscanf(buffer, "\tOffset = (%f, %f)", &inputVector.x, &inputVector.y);
                            pSprite->Offset = inputVector;
                            continue;
                        }

                        if (myStrCmp(question, "AnimationSpeed") <= 0)
                        {
                            sscanf(buffer, "\tAnimationSpeed = %f", &inputFloat);
                            pSprite->AnimationSpeed = inputFloat;
                            continue;
                        }
                    }

                    if (myStrCmp(question, "EndComponent") <= 0)
                    {
                        pCurrComp = NULL;
                        continue;
                    }
                }
            }
        }
    }
}
Beispiel #28
0
	template <typename Type> inline GameObject& GameObject::AddComponent(void) {
		AddComponent(new Type());
		return *this;
	}
Beispiel #29
0
TreeTablePath::TreeTablePath(const TreeTablePath& other, int32 childIndex)
{
	*this = other;
	AddComponent(childIndex);
}
ConfirmPrompt::ConfirmPrompt(std::string title, std::string message, ConfirmDialogueCallback * callback_):
	ui::Window(ui::Point(-1, -1), ui::Point(250, 35)),
	callback(callback_)
{
	ui::Label * titleLabel = new ui::Label(ui::Point(4, 5), ui::Point(Size.X-8, 15), title);
	titleLabel->SetTextColour(style::Colour::WarningTitle);
	titleLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
	titleLabel->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	AddComponent(titleLabel);


	ui::ScrollPanel *messagePanel = new ui::ScrollPanel(ui::Point(4, 24), ui::Point(Size.X-8, 206));
	AddComponent(messagePanel);

	ui::Label * messageLabel = new ui::Label(ui::Point(4, 0), ui::Point(Size.X-28, -1), message);
	messageLabel->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
	messageLabel->Appearance.VerticalAlign = ui::Appearance::AlignTop;
	messageLabel->SetMultiline(true);
	messagePanel->AddChild(messageLabel);

	messagePanel->InnerSize = ui::Point(messagePanel->Size.X, messageLabel->Size.Y+4);

	if (messageLabel->Size.Y < messagePanel->Size.Y)
		messagePanel->Size.Y = messageLabel->Size.Y+4;
	Size.Y += messagePanel->Size.Y+12;
	Position.Y = (ui::Engine::Ref().GetHeight()-Size.Y)/2;

	class CloseAction: public ui::ButtonAction
	{
	public:
		ConfirmPrompt * prompt;
		DialogueResult result;
		CloseAction(ConfirmPrompt * prompt_, DialogueResult result_) { prompt = prompt_; result = result_; }
		void ActionCallback(ui::Button * sender)
		{
			prompt->CloseActiveWindow();
			if(prompt->callback)
				prompt->callback->ConfirmCallback(result);
			prompt->SelfDestruct();
		}
	};


	ui::Button * cancelButton = new ui::Button(ui::Point(0, Size.Y-16), ui::Point(Size.X-75, 16), "Cancel");
	cancelButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
	cancelButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	cancelButton->Appearance.BorderInactive = ui::Colour(200, 200, 200);
	cancelButton->SetActionCallback(new CloseAction(this, ResultCancel));
	AddComponent(cancelButton);
	SetCancelButton(cancelButton);

	ui::Button * okayButton = new ui::Button(ui::Point(Size.X-76, Size.Y-16), ui::Point(76, 16), "Continue");
	okayButton->Appearance.HorizontalAlign = ui::Appearance::AlignLeft;
	okayButton->Appearance.VerticalAlign = ui::Appearance::AlignMiddle;
	okayButton->Appearance.TextInactive = style::Colour::WarningTitle;
	okayButton->SetActionCallback(new CloseAction(this, ResultOkay));
	AddComponent(okayButton);
	SetOkayButton(okayButton);

	MakeActiveWindow();
}