bool LoadScene(const std::string &sceneName) { std::string fullPath; fullPath = "Scenes/"; fullPath += sceneName; fullPath += ".lua"; LuaPlus::LuaStateAuto state; state = LuaPlus::LuaState::Create(); int retVal = state->DoFile(fullPath.c_str()); _ASSERT(retVal==0); LuaPlus::LuaObject meshList = state->GetGlobals()["MeshList"]; _ASSERT(meshList.IsTable()); int numMeshes = meshList.GetCount(); for(int meshIndex=1;meshIndex <= meshList.GetCount(); meshIndex++) { LuaPlus::LuaObject meshObj = meshList[meshIndex]; LuaPlus::LuaObject nameObj = meshObj["Name"]; _ASSERT(nameObj.IsString()); std::string meshName = nameObj.GetString(); MeshManager::GetInstance().Load(meshName,meshObj); Instance *inst = InstanceManager::GetInstance().CreateInstance(meshName); inst->SetMeshName(meshName); } return true; }
// ///////////////////////////////////////////////////////////////// // // ///////////////////////////////////////////////////////////////// bool SetStringFromLua(const LuaPlus::LuaObject &stringData, std::string &str) { if(!stringData.IsString()) { return (false); } str.assign(stringData.GetString()); return (true); }
// ///////////////////////////////////////////////////////////////// // // ///////////////////////////////////////////////////////////////// bool BallActorParams::VInit(LuaPlus::LuaObject srcData, TErrorMessageList &errorMessages) { if (!Pool3dActorParams::VInit(srcData, errorMessages)) { return (false); } VSetType(AT_Ball); LuaPlus::LuaObject rObj = srcData["Radius"]; if(rObj.IsNumber()) { m_radius = static_cast<F32>(rObj.GetNumber()); } LuaPlus::LuaObject slObj = srcData["Slices"]; if(slObj.IsInteger()) { m_slices = slObj.GetInteger(); } LuaPlus::LuaObject stObj = srcData["Stacks"]; if(stObj.IsInteger()) { m_stacks = stObj.GetInteger(); } LuaPlus::LuaObject groupObj = srcData["Group"]; if(groupObj.IsString()) { const char *groupStr = groupObj.GetString(); if(strcmp(groupStr, "cue") == 0) { m_group = eCue; } else if(strcmp(groupStr, "stripes") == 0) { m_group = eStripes; } else if(strcmp(groupStr, "plain") == 0) { m_group = ePlain; } else if(strcmp(groupStr, "black") == 0) { m_group = eBlack; } else { m_group = eCue; } } return (true); }
void LuaScriptEventManager::RemoveListener(LuaPlus::LuaObject listener, EventType type) { auto it = m_listenerMap.find(type); for(auto itt = it->second.begin(); itt != it->second.end(); ++itt) { LuaEventListener* l = itt->get(); if(listener.GetString() == l->GetFunction().GetString()) { itt = it->second.erase(itt); chimera::EventListener elistener = fastdelegate::MakeDelegate(l, &LuaEventListener::EventListenerDelegate); chimera::IEventManager::Get()->VRemoveEventListener(elistener, type); } } }
// ///////////////////////////////////////////////////////////////// // // ///////////////////////////////////////////////////////////////// SliderControl::SliderControl(const LuaPlus::LuaObject &widgetScriptData, \ boost::shared_ptr<ModelViewProjStackManager> mvpStackManPtr, \ const boost::shared_ptr<GLSLShader> shaderFlatObj, \ const boost::shared_ptr<GLSLShader> shaderTexObj, \ boost::shared_ptr<FTFont> fontPtr, \ const ScreenElementId id) throw(GameException &)\ : ControlWidget(widgetScriptData, mvpStackManPtr, shaderFlatObj, shaderTexObj, fontPtr, id) , m_sliderPos(0.5f) , m_sliderButPtr() , m_sliderLineBatch() , m_sliding(false) , m_eventTypeId(0) , m_lineColor(0.0f, 0.0f, 0.0f, 1.0f) { SetLuaSliderPosition(widgetScriptData.GetByName("SliderPosition")); SetLuaEventId(widgetScriptData.GetByName("EventTypeId")); std::string buttonTableName; LuaPlus::LuaObject tableName = widgetScriptData.GetByName("ButtonTableId"); if(tableName.IsString()) { LuaPlus::LuaObject buttonData = widgetScriptData.GetByName(tableName.GetString()); if(buttonData.IsTable()) { m_sliderButPtr.reset(GCC_NEW ButtonControl(buttonData, mvpStackManPtr, shaderFlatObj, shaderTexObj, fontPtr, 0)); m_sliderButPtr->VSetPosition(CalculateButtonPositionFromSlider()); m_sliderButPtr->VSetText(""); m_sliderButPtr->VSetWidth(GetProjectedButtonWidth()); m_sliderButPtr->VSetHeight(GetProjectedButtonHeight()); m_sliderButPtr->VSetVisible(VIsVisible()); m_sliderButPtr->VSetEnabled(VIsEnabled()); m_sliderButPtr->SetSendEvent(false); } else { GF_LOG_TRACE_ERR("SliderControl::SliderControl()", "Creation of scripted slider button failed. Creating default button"); CreateDefaultButton(VGetColor(), mvpStackManPtr, fontPtr, shaderFlatObj, shaderTexObj, VIsVisible(), VIsEnabled()); } } else { GF_LOG_TRACE_ERR("SliderControl::SliderControl()", "Missing slider button information from script so creating default button"); CreateDefaultButton(VGetColor(), mvpStackManPtr, fontPtr, shaderFlatObj, shaderTexObj, VIsVisible(), VIsEnabled()); } RebuildSliderLine(); }
// ///////////////////////////////////////////////////////////////// // // ///////////////////////////////////////////////////////////////// void ListButtonControl::SetLuaTextList(const LuaPlus::LuaObject &table) { bool error = true; if(table.IsTable()) { I64 size = table.GetTableCount(); // LUA table indices start at 1!! for(I64 i = 1; i <= size; ++i) { LuaPlus::LuaObject currTable = table[i]; if(currTable.IsString()) { error = false; m_list.push_back(std::string(currTable.GetString())); } } } #if DEBUG if(error) { GF_LOG_TRACE_ERR("ListButtonControl::SetLuaTextList()", "No List of text strings got from lua data"); } #endif }
// ///////////////////////////////////////////////////////////////// // // ///////////////////////////////////////////////////////////////// bool TableActorParams::VInit(LuaPlus::LuaObject srcData, TErrorMessageList &errorMessages) { if (!Pool3dActorParams::VInit(srcData, errorMessages)) { return (false); } VSetType(AT_Table); // Table Panels data. LuaPlus::LuaObject obj = srcData["FrontPanelMeshName"]; if(obj.IsString()) { SetFrontPanelMeshName(obj.GetString()); } obj = srcData["SidePanelMeshName"]; if(obj.IsString()) { SetSidePanelMeshName(obj.GetString()); } obj = srcData["PanelTextureName"]; if(obj.IsString()) { SetPanelTextureName(obj.GetString()); } obj = srcData["PanelMaterial"]; if(obj.IsTable()) { GameColor tmp; if(SetColorFromLua(obj["Ambient"], tmp)) { m_panelMaterial.SetAmbient(tmp); } if(SetColorFromLua(obj["Diffuse"], tmp)) { m_panelMaterial.SetDiffuse(tmp); } if(SetColorFromLua(obj["Specular"], tmp)) { m_panelMaterial.SetSpecular(tmp); } if(SetColorFromLua(obj["Emissive"], tmp)) { m_panelMaterial.SetEmissive(tmp); } F32 tmp2; if(SetFloatFromLua(obj["Shininess"], tmp2)) { m_panelMaterial.SetSpecularPower(tmp2); } } // Table pockets data. obj = srcData["MiddlePocketMeshName"]; if(obj.IsString()) { SetMiddlePocketMeshName(obj.GetString()); } obj = srcData["CornerPocketMeshName"]; if(obj.IsString()) { SetCornerPocketMeshName(obj.GetString()); } obj = srcData["PocketMaterial"]; if(obj.IsTable()) { GameColor tmp; if(SetColorFromLua(obj["Ambient"], tmp)) { m_pocketsMaterial.SetAmbient(tmp); } if(SetColorFromLua(obj["Diffuse"], tmp)) { m_pocketsMaterial.SetDiffuse(tmp); } if(SetColorFromLua(obj["Specular"], tmp)) { m_pocketsMaterial.SetSpecular(tmp); } if(SetColorFromLua(obj["Emissive"], tmp)) { m_pocketsMaterial.SetEmissive(tmp); } F32 tmp2; if(SetFloatFromLua(obj["Shininess"], tmp2)) { m_pocketsMaterial.SetSpecularPower(tmp2); } } obj = srcData["PocketTexture"]; if(obj.IsString()) { SetPocketTextureName(obj.GetString()); } obj = srcData["Width"]; if(obj.IsNumber()) { SetFloatFromLua(obj, m_width); } obj = srcData["Height"]; if(obj.IsNumber()) { SetFloatFromLua(obj, m_height); } obj = srcData["Depth"]; if(obj.IsNumber()) { SetFloatFromLua(obj, m_depth); } obj = srcData["PocketRadius"]; if(obj.IsNumber()) { SetFloatFromLua(obj, m_pocketRadius); } obj = srcData["TopLeftPocketTriggerPos"]; if(obj.IsTable()) { SetPoint3FromLua(obj, m_tlpTriggerPos); } obj = srcData["TopLeftPocketTriggerId"]; if(obj.IsInteger()) { SetIntFromLua(obj, m_tlPocketId); } obj = srcData["TopRightPocketTriggerPos"]; if(obj.IsTable()) { SetPoint3FromLua(obj, m_trpTriggerPos); } obj = srcData["TopRightPocketTriggerId"]; if(obj.IsInteger()) { SetIntFromLua(obj, m_trPocketId); } obj = srcData["BottomLeftPocketTriggerPos"]; if(obj.IsTable()) { SetPoint3FromLua(obj, m_blpTriggerPos); } obj = srcData["BottomLeftPocketTriggerId"]; if(obj.IsInteger()) { SetIntFromLua(obj, m_blPocketId); } obj = srcData["BottomRightPocketTriggerPos"]; if(obj.IsTable()) { SetPoint3FromLua(obj, m_brpTriggerPos); } obj = srcData["BottomRightPocketTriggerId"]; if(obj.IsInteger()) { SetIntFromLua(obj, m_brPocketId); } obj = srcData["MiddleLeftPocketTriggerPos"]; if(obj.IsTable()) { SetPoint3FromLua(obj, m_mlpTriggerPos); } obj = srcData["MiddleLeftPocketTriggerId"]; if(obj.IsInteger()) { SetIntFromLua(obj, m_mlPocketId); } obj = srcData["MiddleRightPocketTriggerPos"]; if(obj.IsTable()) { SetPoint3FromLua(obj, m_mrpTriggerPos); } obj = srcData["MiddleRightPocketTriggerId"]; if(obj.IsInteger()) { SetIntFromLua(obj, m_mrPocketId); } return (true); }