MCPcopy
hub / github.com/KilledByAPixel/LittleJS / uiUpdate

Method uiUpdate

plugins/uiSystem.js:157–263  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

155 // setup recursive update and render
156 // update in reverse order to detect mouse enter/leave
157 function uiUpdate()
158 {
159 if (uiSystem.activeObject && !uiSystem.activeObject.visible)
160 uiSystem.activeObject = undefined;
161
162 // reset hover object at start of update
163 uiSystem.lastHoverObject = uiSystem.hoverObject;
164 uiSystem.hoverObject = undefined;
165
166 if (mouseWasPressed(0))
167 {
168 // exit navigation mode on mouse press
169 uiSystem.navigationMode = false;
170 uiSystem.navigationObject = undefined;
171 }
172 if (uiSystem.keyInputObject)
173 {
174 // handle text input
175 uiSystem.activeObject = uiSystem.keyInputObject;
176 uiSystem.hoverObject = uiSystem.keyInputObject;
177 uiSystem.navigationMode = false;
178 uiSystem.navigationObject = undefined;
179 }
180
181 // navigation with gamepad/keyboard
182 const navigableObjects = uiSystem.getNavigableObjects();
183 if (!navigableObjects.length)
184 uiSystem.navigationObject = undefined;
185 else if (!uiSystem.keyInputObject)
186 {
187 // unselect object if it is no longer navigable
188 if (!navigableObjects.includes(uiSystem.navigationObject))
189 uiSystem.navigationObject = undefined;
190
191 if (!isTouchDevice)
192 if (uiSystem.navigationMode && !uiSystem.navigationObject)
193 {
194 // select first auto focus object
195 uiSystem.navigationObject = navigableObjects.find(o=>o.navigationAutoSelect);
196 }
197
198 // navigate with dpad or left stick
199 if (!uiSystem.navigationTimer.active())
200 {
201 // navigate through list with gamepad or keyboard
202 const direction = sign(uiSystem.getNavigationDirection());
203 if (direction)
204 {
205 let newNavigationObject;
206 if (!uiSystem.navigationObject)
207 {
208 // use auto select object
209 newNavigationObject = navigableObjects.find(o=>o.navigationAutoSelect);
210
211 if (!newNavigationObject)
212 {
213 // try first or last object
214 const newIndex = direction > 0 ? 0 : navigableObjects.length-1;

Callers

nothing calls this directly

Calls 10

mouseWasPressedFunction · 0.85
signFunction · 0.85
modFunction · 0.85
getNavigableObjectsMethod · 0.80
activeMethod · 0.80
setMethod · 0.45
playMethod · 0.45
navigatePressedMethod · 0.45

Tested by

no test coverage detected