Skip to content

Commit 41a77d9

Browse files
committed
Added random image and rotation
1 parent 8f71872 commit 41a77d9

File tree

7 files changed

+88
-19
lines changed

7 files changed

+88
-19
lines changed

config.js

+14
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@ CONFIG = {
66
active: true, // If you want an image background make this flag true (but make sure youtube/video is false)
77
source: "url('nui://bcc-loadscreen/ui/assets/background.png')",
88
backgroundcolor: "#4d4d4d",
9+
random: {
10+
active: false, //If set to true, a random image from Sources will be chosed on player connection. Warning: The image.source will be ignored if set to true.
11+
sources: [
12+
"url('nui://bcc-loadscreen/ui/assets/background.png')",
13+
"url('nui://bcc-loadscreen/ui/assets/images/background1.jpg')",
14+
"url('nui://bcc-loadscreen/ui/assets/images/background2.jpg')",
15+
"url('nui://bcc-loadscreen/ui/assets/images/background3.jpeg')"
16+
],
17+
rotate: {
18+
active: false, // If true, the loadscreen will rotate between images every x seconds
19+
sequenced: false, // Images show in order, if false, random image will be chosen each time.
20+
time: 5, // Roate image every x seconds
21+
}
22+
},
923
},
1024
video: {
1125
active: false, //If you want a local video make this flag true (but make sure image/youtube is false)

fxmanifest.lua

+2-1
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@ files {
1515
'ui/assets/*',
1616
'ui/assets/fonts/*',
1717
'ui/assets/styles/*',
18+
'ui/assets/images/*',
1819
'config.js'
1920
}
2021

2122
ui_page 'ui/index.html'
2223

23-
version '1.1.2'
24+
version '1.1.3'

ui/app.js

+70-18
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ let vueApp = createApp({
1717
elapsedtime: null,
1818
elapsedtimer: null,
1919
starttime: null,
20-
player: null
20+
player: null,
21+
backgroundimage: null,
22+
rotations: {
23+
interval: null,
24+
},
2125
};
2226
},
2327
mounted() {
@@ -64,6 +68,41 @@ let vueApp = createApp({
6468
var vid = document.getElementById("audiocomp");
6569
vid.volume = this.config.audio.volume;
6670
}
71+
72+
this.backgroundimage = this.config.image.source;
73+
74+
if (this.config.image.random.rotate.active == true) {
75+
let position = 0;
76+
77+
if (this.config.image.random.rotate.sequenced !== true) {
78+
let min = Math.ceil(0);
79+
let max = Math.floor(this.config.image.random.sources.length - 1);
80+
position = Math.floor(Math.random() * (max - min + 1)) + min;
81+
}
82+
83+
this.backgroundimage = this.config.image.random.sources[position];
84+
85+
this.rotations.interval = setInterval(() => {
86+
if (this.config.image.random.rotate.sequenced == true) {
87+
if (position < this.config.image.random.sources.length - 1) {
88+
position++;
89+
} else {
90+
position = 0;
91+
}
92+
this.backgroundimage = this.config.image.random.sources[position];
93+
} else {
94+
let min = Math.ceil(0);
95+
let max = Math.floor(this.config.image.random.sources.length - 1);
96+
let randindex = Math.floor(Math.random() * (max - min + 1)) + min;
97+
this.backgroundimage = this.config.image.random.sources[randindex];
98+
}
99+
}, this.config.image.random.rotate.time * 1000);
100+
} else if (this.config.image.random.active == true) {
101+
let min = Math.ceil(0);
102+
let max = Math.floor(this.config.image.random.sources.length - 1);
103+
let randindex = Math.floor(Math.random() * (max - min + 1)) + min;
104+
this.backgroundimage = this.config.image.random.sources[randindex];
105+
}
67106
},
68107
destroyed() {
69108
this.yt = false;
@@ -78,13 +117,17 @@ let vueApp = createApp({
78117
if (video) {
79118
video.pause();
80119
}
120+
121+
if (this.rotations.interval) {
122+
clearInterval(this.rotations.interval);
123+
}
81124
},
82125
computed: {
83126
cssvars() {
84127
return {
85128
"--color": "#fff",
86129
"--backgroundcolor": this.config.image.backgroundcolor,
87-
"--backgroundimage": this.config.image.source,
130+
"--backgroundimage": this.backgroundimage || this.config.image.source,
88131
"--loadingcolor": this.config.loading.color,
89132
};
90133
},
@@ -99,15 +142,15 @@ let vueApp = createApp({
99142
height: window.innerHeight,
100143
videoId: this.config.youtube.source,
101144
playerVars: {
102-
'playsinline': 1,
103-
'controls': 0,
104-
'mute': this.config.youtube.mute,
105-
'autoplay': 1
145+
playsinline: 1,
146+
controls: 0,
147+
mute: this.config.youtube.mute,
148+
autoplay: 1,
106149
},
107150
events: {
108151
onReady: that.onPlayerReady,
109-
onStateChange: that.onPlayerStateChange
110-
}
152+
onStateChange: that.onPlayerStateChange,
153+
},
111154
});
112155
}
113156
},
@@ -118,7 +161,7 @@ let vueApp = createApp({
118161
onPlayerStateChange(evt) {
119162
if (evt.data === 0) {
120163
if (this.config.youtube.looped) {
121-
this.player.playVideo();
164+
this.player.playVideo();
122165
} else if (this.visible) {
123166
this.visible = false;
124167
clearInterval(this.timer);
@@ -127,12 +170,17 @@ let vueApp = createApp({
127170
},
128171
startCallback() {
129172
this.timer = setInterval(() => {
130-
fetch(this.config.feathercore.active ? `https://feather-core/isgameinitiated` : `https://bcc-loadscreen-helper/isgameinitiated`, {
131-
method: "POST",
132-
headers: {
133-
"Content-Type": "application/json; charset=UTF-8",
134-
},
135-
})
173+
fetch(
174+
this.config.feathercore.active
175+
? `https://feather-core/isgameinitiated`
176+
: `https://bcc-loadscreen-helper/isgameinitiated`,
177+
{
178+
method: "POST",
179+
headers: {
180+
"Content-Type": "application/json; charset=UTF-8",
181+
},
182+
}
183+
)
136184
.then((resp) => resp.json())
137185
.then((resp) => {
138186
this.loading = false;
@@ -142,8 +190,12 @@ let vueApp = createApp({
142190
} else if (resp.online) {
143191
this.loading = false;
144192

145-
let isvideolooped = this.config.video.looped == false && this.config.video.active == true
146-
let isYTlooped = this.config.youtube.looped == false && this.config.youtube.active == true
193+
let isvideolooped =
194+
this.config.video.looped == false &&
195+
this.config.video.active == true;
196+
let isYTlooped =
197+
this.config.youtube.looped == false &&
198+
this.config.youtube.active == true;
147199

148200
if (!(isvideolooped || isYTlooped)) {
149201
this.visible = false;
@@ -159,5 +211,5 @@ let vueApp = createApp({
159211

160212
// Youtube API Shim for vue
161213
window.onYouTubeIframeAPIReady = () => {
162-
vueApp.initYoutube()
214+
vueApp.initYoutube();
163215
};

ui/assets/images/background1.jpg

387 KB
Loading

ui/assets/images/background2.jpg

1.1 MB
Loading

ui/assets/images/background3.jpeg

1.19 MB
Loading

ui/assets/styles/style.css

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@ video {
5050
background-image: var(--backgroundimage);
5151
background-repeat: no-repeat;
5252
background-position: center;
53+
-webkit-transition: all 0.5s ease-in-out;
54+
transition: all 0.5s ease-in-out;
5355
}
5456

5557
.wrapper {

0 commit comments

Comments
 (0)