MCPcopy Create free account
hub / github.com/OpenStarbound/OpenStarbound / MerchantPane

Method MerchantPane

source/frontend/StarMerchantInterface.cpp:24–111  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22namespace Star {
23
24MerchantPane::MerchantPane(
25 WorldClientPtr worldClient, PlayerPtr player, Json const& settings, EntityId sourceEntityId) {
26 m_worldClient = std::move(worldClient);
27 m_player = std::move(player);
28 m_sourceEntityId = sourceEntityId;
29
30 auto assets = Root::singleton().assets();
31 auto baseConfig = settings.get("config", "/interface/windowconfig/merchant.config");
32 m_settings = jsonMerge(assets->fetchJson(baseConfig), settings);
33
34 m_refreshTimer = GameTimer(assets->json("/merchant.config:autoRefreshRate").toFloat());
35
36 m_buyFactor = m_settings.getFloat("buyFactor", assets->json("/merchant.config:defaultBuyFactor").toFloat());
37 m_sellFactor = m_settings.getFloat("sellFactor", assets->json("/merchant.config:defaultSellFactor").toFloat());
38
39 m_itemBag = make_shared<ItemBag>(m_settings.getUInt("sellContainerSize"));
40
41 m_maxBuyCount = m_settings.getUInt("maxSpinCount", assets->json("/interface/windowconfig/crafting.config:default").getUInt("maxSpinCount", 1000));
42
43 GuiReader reader;
44 reader.registerCallback("spinCount.up", [=](Widget*) {
45 if (m_selectedIndex != NPos) {
46 if (m_buyCount < maxBuyCount())
47 m_buyCount++;
48 else
49 m_buyCount = 1;
50 } else {
51 m_buyCount = 0;
52 }
53 countChanged();
54 });
55
56 reader.registerCallback("spinCount.down", [=](Widget*) {
57 if (m_selectedIndex != NPos) {
58 if (m_buyCount > 1)
59 m_buyCount--;
60 else
61 m_buyCount = std::max(maxBuyCount(), 1);
62 } else {
63 m_buyCount = 0;
64 }
65 countChanged();
66 });
67
68 reader.registerCallback("countChanged", [=](Widget*) { countChanged(); });
69 reader.registerCallback("parseCountText", [=](Widget*) { countTextChanged(); });
70
71 reader.registerCallback("buy", [=](Widget*) { buy(); });
72
73 reader.registerCallback("sell", [=](Widget*) { sell(); });
74
75 reader.registerCallback("close", [=](Widget*) { dismiss(); });
76
77 reader.registerCallback("itemGrid",
78 [=](Widget*) {
79 swapSlot();
80 updateSellTotal();
81 });

Callers

nothing calls this directly

Calls 15

singletonClass · 0.85
GameTimerClass · 0.85
assetsMethod · 0.80
fetchJsonMethod · 0.80
toFloatMethod · 0.80
jsonMethod · 0.80
getFloatMethod · 0.80
getUIntMethod · 0.80
selectedTabMethod · 0.80
getStringMethod · 0.80
setItemBagMethod · 0.80
jsonMergeFunction · 0.50

Tested by

no test coverage detected