载入中...
搜索中...
未找到
PcgControllerSelection.cpp
浏览该文件的文档.
3#include <simplesquirrel/simplesquirrel.hpp>
4namespace eve::ui {namespace {}
5Result<void> PcgControllerSelection::add(const std::string&name,int type,const std::string&id){if(name.empty()||id.empty())return Result<void>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"controller name and widget id are required","ui.pcgControllerSelection"));rows_.push_back({name,id,type,false});return Result<void>::success();}
6Result<bool> PcgControllerSelection::refresh(int current){int found=-1;for(size_t i=0;i<rows_.size();++i)if(rows_[i].controllerType==current){found=int(i);break;}if(found<0)return Result<bool>::success(false);for(size_t i=0;i<rows_.size();++i)rows_[i].visible=int(i)==found;selected_=found;return Result<bool>::success(true);}
7Result<bool> PcgControllerSelection::getVisible(int i)const{if(i<0||i>=int(rows_.size()))return Result<bool>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"controller row index is out of range","ui.pcgControllerSelection"));return Result<bool>::success(rows_[size_t(i)].visible);}
8Result<std::string> PcgControllerSelection::getWidgetId(int i)const{if(i<0||i>=int(rows_.size()))return Result<std::string>::failure(Diagnostic::error(DiagnosticCode::InvalidArgument,"controller row index is out of range","ui.pcgControllerSelection"));return Result<std::string>::success(rows_[size_t(i)].widgetId);}
9void exposePcgControllerSelectionBindings(ssq::Table&t){auto c=t.addClass("PcgControllerSelection",ssq::Class::Ctor<PcgControllerSelection()>());auto vm=t.getHandle();c.addFunc("add",[vm](PcgControllerSelection*s,const std::string&n,int type,const std::string&id){return eve::script::projectResult(vm,s->add(n,type,id));});c.addFunc("refresh",[vm](PcgControllerSelection*s,int type){return eve::script::projectResult(vm,s->refresh(type),[](bool v){return v;});});c.addFunc("getCount",[](const PcgControllerSelection*s){return s->getCount();});c.addFunc("getSelectedIndex",[](const PcgControllerSelection*s){return s->getSelectedIndex();});c.addFunc("getVisible",[vm](const PcgControllerSelection*s,int i){return eve::script::projectResult(vm,s->getVisible(i),[](bool v){return v;});});c.addFunc("getWidgetId",[vm](const PcgControllerSelection*s,int i){return eve::script::projectResult(vm,s->getWidgetId(i),[](std::string v){return v;});});}
10}
const std::string & s
HSQUIRRELVM vm
Definition ECS.cpp:20
glm::vec3 n
Definition Grass.cpp:63
float v
std::int32_t c
std::string name
std::string id
Definition PlayHost.cpp:108
float t
bool found
double current
The single Squirrel projection for common Result, Status and Value.
bool visible
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={}, DiagnosticDetails details={}, std::string source={})
Construct an error diagnostic with the standard error severity.
Definition Diagnostic.h:125
Move-only operation result carrying either a value or Status.
Definition Result.h:155
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:164
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:175
Caller-owned visibility selection ported from Pcg UIControllerSelection.
Result< bool > refresh(int currentController)
Select first matching type; no match preserves the previous visibility snapshot.
Result< bool > getVisible(int index) const
Return row visibility.
Result< void > add(const std::string &name, int controllerType, const std::string &widgetId)
Append one controller type and its stable UI widget id.
Result< std::string > getWidgetId(int index) const
Return stable widget id.
ssq::Table projectResult(HSQUIRRELVM vm, Result< void > &&result)
Consume and project a void native Result using the common schema.
void exposePcgControllerSelectionBindings(ssq::Table &t)
Register Pcg controller-selection bindings.