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

Method sendEvent

source/frontend/StarActionBar.cpp:118–196  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

116}
117
118bool ActionBar::sendEvent(InputEvent const& event) {
119 if (Pane::sendEvent(event))
120 return true;
121
122 auto inventory = m_player->inventory();
123
124 auto customBarIndexes = inventory->customBarIndexes();
125 if (auto mouseWheel = event.ptr<MouseWheelEvent>()) {
126 auto abl = inventory->selectedActionBarLocation();
127
128 int index = 0;
129 if (!abl) {
130 if (mouseWheel->mouseWheel == MouseWheel::Down)
131 index = 0;
132 else
133 index = customBarIndexes + EssentialItemCount - 1;
134 } else {
135 if (auto cbi = abl.ptr<CustomBarIndex>()) {
136 if (*cbi < customBarIndexes / 2)
137 index = *cbi;
138 else
139 index = *cbi + EssentialItemCount;
140 } else {
141 index = customBarIndexes / 2 + (int)abl.get<EssentialItem>();
142 }
143
144 if (mouseWheel->mouseWheel == MouseWheel::Down)
145 index = pmod(index + 1, customBarIndexes + EssentialItemCount);
146 else
147 index = pmod(index - 1, customBarIndexes + EssentialItemCount);
148 }
149
150 if (index < customBarIndexes / 2)
151 abl = (CustomBarIndex)index;
152 else if (index < customBarIndexes / 2 + EssentialItemCount)
153 abl = (EssentialItem)(index - customBarIndexes / 2);
154 else
155 abl = (CustomBarIndex)(index - EssentialItemCount);
156
157 inventory->selectActionBarLocation(abl);
158 context()->playAudio(RandomSource().randFrom(m_switchSounds));
159
160 return true;
161 }
162
163 if (event.is<MouseMoveEvent>()) {
164 m_customBarHover.reset();
165 Vec2I screenPosition = *GuiContext::singleton().mousePosition(event);
166 for (uint8_t i = 0; i < customBarIndexes; ++i) {
167 if (m_customBarWidgets[i].left->screenBoundRect().contains(screenPosition))
168 m_customBarHover = make_pair((CustomBarIndex)i, false);
169 else if (m_customBarWidgets[i].right->screenBoundRect().contains(screenPosition))
170 m_customBarHover = make_pair((CustomBarIndex)i, true);
171 }
172 }
173
174 for (auto action : context()->actions(event)) {
175 if (action >= InterfaceAction::InterfaceBar1 && action <= InterfaceAction::InterfaceBar10

Callers

nothing calls this directly

Calls 14

pmodFunction · 0.85
RandomSourceClass · 0.85
singletonClass · 0.85
takeFunction · 0.85
inventoryMethod · 0.80
customBarIndexesMethod · 0.80
playAudioMethod · 0.80
resetMethod · 0.45
mousePositionMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected