Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function gridSwitchPage(page, container, ignore, dontMoveSlider){
- var slots = container.slots;
- var slotsKeys = gridData.slotsKeys;
- var slots_count = gridData.slots_count;
- var x_count = gridData.x_count;
- var pages1 = gridFuncs.getPages(slotsKeys.length);
- var pages = Math.max(1, pages1 + 1 - gridData.y_count);
- page = Math.max(1, Math.min(page, pages)) - 1;
- if(page == gridData.lastPage - 1 && !ignore) return false;
- gridData.lastPage = page + 1;
- var pages = gridFuncs.getPages(slotsKeys.length);
- var ___y = gridFuncs.getCoordsFromPage(page + 1, pages);
- if(!dontMoveSlider)container.getUiAdapter().getElement("slider_button").setPosition(_elementsGUI_grid['slider_button'].x, ___y);
- if (!gridData.isWorkAllowed) {
- for (var i = 0; i < slots_count; i++) {
- container.setSlot("slot" + i, 0, 0, 0, null);
- container.setText("slot" + i, "0");
- }
- return false;
- }
- for (var i = page * x_count; i < page * x_count + slots_count; i++) {
- var a = i - (page * x_count);
- var item = slots[slotsKeys[i]] || { id: 0, data: 0, count: 0, extra: null };
- container.setSlot("slot" + a, item.id, item.count, item.data, item.extra || null);
- container.setText("slot" + a, cutNumber(item.count));
- }
- return true;
- }
- containerEvents: {
- openGui: function(container, window, content, eventData){
- Object.assign(gridData, eventData);
- gridData.updateGui = function(refresh, updateFilters, nonlocal){
- if(!content || !window || !window.isOpened()) return;
- if(Config.dev)Logger.Log((nonlocal ? 'Server ' : 'Local ') + (refresh ? 'Updating' : 'Openning') + ' window: ' + JSON.stringify(eventData), 'RefinedStorageDebug');
- delete container.slots.bindings;
- delete container.slots.slots;
- gridData.networkData = SyncedNetworkData.getClientSyncedData(eventData.name);
- if(updateFilters){
- var _slotKeys = [];
- for(var i in container.slots)if(i[0] != 's')_slotKeys.push(i);
- gridData.slotsKeys = _slotKeys;//Object.keys(container.slots).splice(0, eventData.slotsLength);
- //alert(gridData.slotsKeys);
- //if(Config.dev)Logger.Log('Pre items: ' + _slotKeys.map(function(value){return JSON.stringify(container.slots[value].asScriptable())}), 'RefinedStorageDebug');
- if(!refresh)gridData.textSearch = false;
- if(gridData.textSearch){
- var textSearch = new RegExp(gridData.textSearch, "i");
- gridData.slotsKeys = gridData.slotsKeys.filter(function (value, index) {
- var slot = container.slots[value];
- if (getItemName(slot.id, slot.data).match(textSearch)) {
- return true;
- }
- })
- };
- gridData.slotsKeys.sort(gridFuncs.sort(eventData.sort, eventData.reverse_filter, container.slots));
- //if(Config.dev)Logger.Log('Post items: ' + _slotKeys.map(function(value){return JSON.stringify(container.slots[value].asScriptable())}), 'RefinedStorageDebug');
- }
- content.elements["image_filter"].bitmap = 'RS_filter' + (eventData.sort + 1);
- content.elements["image_filter"].x = content.elements["filter_button"].x + (content.elements["filter_button"].scale * 20 - filter_size_map[eventData.sort]) / 2;
- if (eventData.reverse_filter) {
- content.elements["image_reverse_filter"].bitmap = 'RS_arrow_up';
- } else {
- content.elements["image_reverse_filter"].bitmap = 'RS_arrow_down';
- }
- content.elements["search_text"].text = gridData.textSearch ? gridData.textSearch : Translation.translate('Search');
- content.elements["image_redstone"].bitmap = 'redstone_GUI_' + (eventData.redstone_mode || 0);
- var slots_count = content.elements.slots_count;
- content.elements["slider_button"].bitmap = gridData.slotsKeys.length <= gridData.slots_count ? 'slider_buttonOff' : 'slider_buttonOn';
- //if(refresh)window.getWindow('main').getElements().get("slider_button").setPosition(content.elements['slider_button'].x, gridFuncs.getCoordsFromPage(gridData.lastPage, gridFuncs.getPages(gridData.slotsKeys.length)));
- if (!eventData.isWorkAllowed) {
- for (var i = 0; i < slots_count; i++) {
- content.elements['slot' + i].bitmap = 'classic_darken_slot';
- }
- content.elements["slider_button"].bitmap = 'slider_buttonOff';
- } else if (content.elements['slot0'].bitmap == 'classic_darken_slot') {
- for (var i = 0; i < slots_count; i++) {
- content.elements['slot' + i].bitmap = 'classic_slot';
- }
- }
- gridSwitchPage(refresh ? gridData.lastPage : 1, container, true);
- }
- if(gridData.lowPriority){
- gridData.lowPriority = false;
- var craftsThread = java.lang.Thread({
- run: function(){
- try {
- gridData.updateGui(eventData.refresh, eventData.updateFilters, true);
- } catch(err){
- alert('Sorry, i broke :_(' + JSON.stringify(err));
- }
- }
- });
- craftsThread.setPriority(java.lang.Thread.MIN_PRIORITY);
- craftsThread.start();
- } else {
- gridData.updateGui(eventData.refresh, eventData.updateFilters, true);
- }
- }
- }
Add Comment
Please, Sign In to add comment