Skip to content

Commit 4b55bd9

Browse files
committed
simple tab list
1 parent 33fa9c2 commit 4b55bd9

File tree

7 files changed

+64
-0
lines changed

7 files changed

+64
-0
lines changed

src/html/index.html

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,16 @@ <h1 class="loadingText">Loading assets...</h1>
4141
<!-- Inventory window -->
4242
<div class="inv_window"></div>
4343

44+
<!-- Tab List -->
45+
<div class="tab_list text-light">
46+
<div class="tab_player clearfix">
47+
<span class="float-left">xd</span>
48+
<span class="float-right">OK</span>
49+
</div>
50+
<div class="tab_player">lol</div>
51+
<div class="tab_player">xd</div>
52+
</div>
53+
4454
<!-- MENU -->
4555
<div class="gameMenu">
4656
<div class="w-100 text-center p-3 gameMenuX">

src/scripts/EventHandler.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ class EventHandler {
4343
focus = i - 1
4444
}
4545
}
46+
if (z.code === 'Tab' && this.gameState === 'gameLock') {
47+
$('.tab_list').show()
48+
z.preventDefault()
49+
}
4650
if (z.code === 'KeyQ') {
4751
this.game.socket.emit('drop')
4852
}
@@ -124,6 +128,9 @@ class EventHandler {
124128
})
125129
$(document).on('keyup', (z) => {
126130
delete this.keys[z.code]
131+
if (z.code === 'Tab') {
132+
$('.tab_list').hide()
133+
}
127134
if (this.controls[z.code] !== undefined) {
128135
this.game.socket.emit('move', this.controls[z.code], false)
129136
const to = {

src/scripts/Setup.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { BlockBreak } from './rendering/BlockBreak.js'
1414
import { BlockPlace } from './rendering/BlockPlace.js'
1515
import { EventHandler } from './EventHandler.js'
1616
import { Socket } from './proxy/Socket.js'
17+
import { TabList } from './gui/TabList.js'
1718
import $ from 'jquery'
1819

1920
async function Setup (game) {
@@ -51,6 +52,7 @@ async function Setup (game) {
5152
game.ent = new Entities(game)
5253
game.chat = new Chat(game)
5354
game.inv_bar = new InventoryBar(game)
55+
game.tl = new TabList(game)
5456
game.distanceBasedFog.addShaderToMaterial(game.world.material)
5557
game.distanceBasedFog.addShaderToMaterial(game.ent.mobMaterial)
5658
game.distanceBasedFog.addShaderToMaterial(game.ent.playerMaterial)

src/scripts/gui/TabList.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import $ from 'jquery'
2+
3+
class TabList {
4+
constructor (game) {
5+
this.game = game
6+
this.lastHTML
7+
}
8+
9+
update (players) {
10+
let newHTML = ''
11+
if (players !== undefined && JSON.stringify(players) !== '{}') {
12+
for (const i in players) {
13+
newHTML += `<div class="tab_player clearfix">
14+
<span class="float-left">${i}</span>
15+
<span class="float-right">${players[i].ping}ms</span>
16+
</div>`
17+
}
18+
if (newHTML != this.lastHTML) {
19+
// console.log(players)
20+
this.lastHTML = newHTML
21+
$('.tab_list').html(this.lastHTML)
22+
}
23+
}
24+
}
25+
}
26+
export { TabList }

src/scripts/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class Game {
5050
this.camera.rotation.y = yaw
5151
this.camera.rotation.x = pitch
5252
})
53+
this.socket.on('players', (players) => {
54+
this.tl.update(players)
55+
})
5356
this.socket.on('dimension', (dim) => {
5457
this.dimension = dim
5558
console.log(`Player dimension has been changed: ${dim}`)

src/scripts/proxy/Proxy.worker.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ addEventListener('message', function (e) {
9393
emit('game', bot.game)
9494
})
9595
setInterval(function () {
96+
emit('players', bot.players)
9697
if (bot.inventory !== undefined) {
9798
const invNew = JSON.stringify(bot.inventory.slots)
9899
if (inv !== invNew) {

src/styles/style.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,21 @@
55
src: url(../assets/fonts/MinecraftRegular-Bmg3.otf);
66
}
77

8+
.tab_player{
9+
padding:3px;
10+
}
11+
12+
.tab_list{
13+
display:none;
14+
position:fixed;
15+
top:20px;
16+
left:50%;
17+
width:300px;
18+
margin-left:-150px;
19+
border:1px solid black;
20+
background:rgba(0,0,0,0.5);
21+
}
22+
823
.dg.ac {
924
z-index: 98;
1025
}

0 commit comments

Comments
 (0)