MCPcopy Create free account
hub / github.com/GlobedGD/globed2 / init

Method init

src/ui/admin/ModRoleModifyPopup.cpp:16–76  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

14static const float WIDTH_PER_ROLE = ROLE_ICON_SIZE.width + 3.f;
15
16bool ModRoleModifyPopup::init(int32_t accountId, std::vector<uint8_t> roleIds) {
17 auto ret = new ModRoleModifyPopup;
18 size_t allCnt = NetworkManagerImpl::get().getAllRoles().size();
19
20 float width = std::max(150.f, 50.f + allCnt * WIDTH_PER_ROLE);
21 float height = 120.f;
22
23 if (!BasePopup::init(width, height)) return false;
24
25 m_accountId = accountId;
26 m_roleIds = std::move(roleIds);
27
28 this->setTitle("Edit user roles");
29
30 auto* buttonLayout = Build<CCMenu>::create()
31 .pos(this->center())
32 .layout(RowLayout::create()->setGap(3.f))
33 .parent(m_mainLayer)
34 .collect();
35
36 auto allRoles = NetworkManagerImpl::get().getAllRoles();
37
38 for (const auto& role : allRoles) {
39 auto* spr1 = globed::createBadge(role.icon);
40 if (!spr1) continue;
41
42 bool present = std::find_if(m_roleIds.begin(), m_roleIds.end(), [&](uint8_t k) { return k == role.id; }) != m_roleIds.end();
43 cue::rescaleToMatch(spr1, ROLE_ICON_SIZE);
44
45 Build(spr1)
46 .intoMenuItem([this, roleid = role.id](auto btn) {
47 auto it = std::find_if(m_roleIds.begin(), m_roleIds.end(), [&](uint8_t k) { return k == roleid; });
48
49 bool present = it != m_roleIds.end();
50
51 if (present) {
52 btn->setOpacity(69);
53 m_roleIds.erase(it);
54 } else {
55 btn->setOpacity(255);
56 m_roleIds.push_back(roleid);
57 }
58 })
59 .opacity(present ? 255 : 69)
60 .parent(buttonLayout);
61 }
62
63 Build<ButtonSprite>::create("Update", "bigFont.fnt", "GJ_button_01.png", 0.9f)
64 .scale(0.8f)
65 .intoMenuItem([this] {
66 this->submit();
67 })
68 .pos(this->fromBottom(28.f))
69 .intoNewParent(CCMenu::create())
70 .pos(0.f, 0.f)
71 .parent(m_mainLayer);
72
73 buttonLayout->updateLayout();

Callers 1

createMethod · 0.45

Calls 10

submitMethod · 0.95
createBadgeFunction · 0.85
setTitleMethod · 0.80
layoutMethod · 0.80
eraseMethod · 0.80
getFunction · 0.50
initFunction · 0.50
sizeMethod · 0.45
getAllRolesMethod · 0.45
setOpacityMethod · 0.45

Tested by

no test coverage detected