Skip to content

Commit 77d5684

Browse files
committed
better Chat and pause blur
1 parent eaf686c commit 77d5684

File tree

8 files changed

+249
-130
lines changed

8 files changed

+249
-130
lines changed

coffee/client/module/FirstPersonControls.coffee

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ class FirstPersonControls
1717
@socket=options.socket
1818
@gameState="menu"
1919
@listen()
20-
$("#commandx").blur()
21-
$(".command").hide()
20+
$(".com_i").blur()
21+
$(".com").hide()
2222
updatePosition: (e)->
2323
#Updatowanie kursora
2424
if @gameState is "gameLock"
@@ -38,28 +38,28 @@ class FirstPersonControls
3838

3939
#Klawisz Enter
4040
if z.keyCode is 13 and _this.gameState is "chat"
41-
_this.socket.emit "command",commandx.value
42-
commandx.value=""
41+
_this.socket.emit "command",$(".com_i").val()
42+
$(".com_i").val("")
4343

4444
#Klawisz T lub /
4545
if (z.keyCode is 84 or z.keyCode is 191) and _this.gameState is "gameLock"
4646
if z.keyCode is 191
47-
commandx.value="/"
47+
$(".com_i").val("/")
4848
_this._Chat()
4949
z.preventDefault()
5050

5151
#Klawisz `
5252
if z.keyCode is 192
53-
$("#commandx").blur()
54-
$(".command").hide()
53+
$(".com_i").blur()
54+
$(".com").hide()
5555
z.preventDefault()
5656
if (_this.gameState is "menu") or (_this.gameState is "chat")
5757
_this._Game()
5858
else
5959
_this._Menu()
6060
if z.keyCode is 27 and _this.gameState is "chat"
61-
$("#commandx").blur()
62-
$(".command").hide()
61+
$(".com_i").blur()
62+
$(".com").hide()
6363
_this._Menu()
6464

6565
#Wysyłanie state'u do serwera
@@ -82,15 +82,15 @@ class FirstPersonControls
8282
if document.pointerLockElement is _this.canvas or document.mozPointerLockElement is _this.canvas
8383
#Lock
8484
if _this.gameState is "game"
85-
$("#commandx").blur()
86-
$(".command").hide()
85+
$(".com_i").blur()
86+
$(".com").hide()
8787
_this.state "gameLock"
8888
$(".gameMenu").css "display", "none"
8989
else
9090
#Unlock
9191
if (_this.gameState is "menu") or (_this.gameState is "gameLock")
92-
$("#commandx").blur()
93-
$(".command").hide()
92+
$(".com_i").blur()
93+
$(".com").hide()
9494
_this._Menu()
9595
return
9696
document.addEventListener 'pointerlockchange', lockChangeAlert, false
@@ -101,12 +101,21 @@ class FirstPersonControls
101101
return @
102102
state:(state)->
103103
@gameState=state
104+
if @gameState is "chat"
105+
$(".chat").addClass("focus")
106+
$(".chat").removeClass("blur")
107+
else
108+
$(".chat").removeClass("focus")
109+
$(".chat").addClass("blur")
110+
if @gameState isnt "menu"
111+
$(".winbl").removeClass("blur")
104112
console.log "Game state: "+state
105113
_Game:()->
106114
@state "game"
107115
@canvas.requestPointerLock()
108116
_Menu:()->
109117
@state "menu"
118+
$(".winbl").addClass("blur")
110119
$(".gameMenu").css "display", "block"
111120
document.exitPointerLock = document.exitPointerLock or document.mozExitPointerLock
112121
document.exitPointerLock();
@@ -116,8 +125,8 @@ class FirstPersonControls
116125
$(".gameMenu").css "display", "none"
117126
document.exitPointerLock = document.exitPointerLock or document.mozExitPointerLock
118127
document.exitPointerLock()
119-
$(".command").show()
120-
$("#commandx").focus()
128+
$(".com").show()
129+
$(".com_i").focus()
121130

122131

123132

coffee/client/module/index.coffee

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,20 @@ init = ()->
7676
world._computeSections sections,x,z,biomes
7777
socket.on "hp",(points)->
7878
inv_bar.setHp(points)
79+
socket.on "inventory",(inv)->
80+
console.log inv
7981
socket.on "food",(points)->
8082
inv_bar.setFood(points)
8183
socket.on "msg",(msg)->
84+
atBottom = isElementScrolledToBottom(consoleDiv)
8285
$(".chat").append(msg+"<br>")
86+
if atBottom
87+
scrollToBottom(consoleDiv)
88+
socket.on "kicked",(reason)->
89+
atBottom = isElementScrolledToBottom(consoleDiv)
90+
$(".chat").append("You have been kicked!<br>")
91+
if atBottom
92+
scrollToBottom(consoleDiv)
8393
socket.on "xp",(xp)->
8494
inv_bar.setXp xp.level,xp.progress
8595
socket.on "move", (pos)->
@@ -136,6 +146,19 @@ init = ()->
136146
gui.add( world.material, 'wireframe' ).name( 'Wireframe' ).listen()
137147
gui.add( params, 'chunkdist',0,10,1).name( 'Render distance' ).listen()
138148

149+
#Autoscrollowanie chatu
150+
consoleDiv = document.querySelector(".chat")
151+
152+
window.addEventListener "wheel", (e)->
153+
if FPC.gameState isnt "chat"
154+
e.preventDefault()
155+
, {passive: false}
156+
isElementScrolledToBottom=(el)->
157+
if el.scrollTop >= (el.scrollHeight - el.offsetHeight)
158+
return true
159+
return false
160+
scrollToBottom=(el)->
161+
el.scrollTop = el.scrollHeight
139162
#Wprawienie w ruch funkcji animate
140163
animate()
141164
return

coffee/server.coffee

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,21 @@ module.exports=(type)->
7171
io.to(socket.id).emit "hp",socketInfo[socket.id].bot.health
7272
io.to(socket.id).emit "food",socketInfo[socket.id].bot.food
7373
return
74+
inv=""
75+
socketInfo[socket.id].int=setInterval ()->
76+
inv_new=JSON.stringify(socketInfo[socket.id].bot.inventory.slots)
77+
if inv isnt inv_new
78+
inv=inv_new
79+
io.to(socket.id).emit "inventory",socketInfo[socket.id].bot.inventory.slots
80+
,100
7481
socketInfo[socket.id].bot.on 'spawn',()->
7582
try
7683
io.to(socket.id).emit "spawn"
7784
return
85+
socketInfo[socket.id].bot.on 'kicked',(reason,loggedIn)->
86+
try
87+
io.to(socket.id).emit "kicked",reason
88+
return
7889
socketInfo[socket.id].bot.on 'message',(msg)->
7990
try
8091
io.to(socket.id).emit "msg",convert.toHtml(msg.toAnsi());
@@ -103,6 +114,7 @@ module.exports=(type)->
103114
return
104115
socket.on "disconnect", ->
105116
try
117+
clearInterval socketInfo[socket.id].int
106118
console.log "[-] "+socketInfo[socket.id].nick
107119
socketInfo[socket.id].bot.end()
108120
delete socketInfo[socket.id]

src/client/css/style.css

Lines changed: 38 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
body { margin: 0; background:black;}
21

2+
body { margin: 0; background:black;}
33
canvas {
44
display: block;
55
width:100%;
@@ -33,7 +33,7 @@ canvas {
3333
}
3434

3535
.initLoading{
36-
z-index:11;
36+
z-index:99;
3737
position:fixed;
3838
top:0px;
3939
left:0px;
@@ -86,9 +86,15 @@ canvas {
8686
font-size:20px;
8787
font-weight:bold;
8888
}
89-
.con{
90-
overflow:auto;
91-
display:flex; flex-direction:column-reverse;
89+
.chat{
90+
position:fixed;
91+
bottom:100px;
92+
left:0px;
93+
width:60%;
94+
overflow-x:hidden;
95+
overflow:scroll;
96+
/* display:flex; */
97+
/* flex-direction:column-reverse; */
9298
-webkit-text-stroke: 1px black;
9399
color: white;
94100
text-shadow:
@@ -97,21 +103,26 @@ canvas {
97103
1px -1px 0 #000,
98104
-1px 1px 0 #000,
99105
1px 1px 0 #000;
100-
height:70%;
106+
height:45%;
101107
font-weight:bold;
102108
font-size:20px;
103109
}
104-
.console{
110+
.chat.focus{
111+
background:rgba(0,0,0,0.5);
112+
}
113+
.chat.blur{
114+
background:rgba(0,0,0,0);
115+
}
116+
.com{
105117
position:fixed;
106-
height:30%;
107-
bottom:110px;
118+
bottom:-30px;
119+
padding:5px;
108120
left:0px;
109-
width:60%;
110-
}
111-
.command{
112-
font-size:40px;
121+
width:100%;
122+
background:rgba(0,0,0,0.5);
123+
z-index:11;
113124
}
114-
.con::-webkit-scrollbar {
125+
.chat::-webkit-scrollbar {
115126
display: none;
116127
}
117128
.inv_bar{
@@ -131,7 +142,7 @@ canvas {
131142
}
132143
.player_hp{
133144
position:fixed;
134-
bottom:80px;
145+
bottom:70px;
135146
left:calc(50vw - 250px);
136147
display:block;
137148
}
@@ -189,7 +200,18 @@ canvas {
189200
}
190201
.player_food{
191202
position:fixed;
192-
bottom:80px;
203+
bottom:70px;
193204
right:calc(50vw - 245px);
194205
display:block;
195206
}
207+
.winbl{
208+
z-index:13;
209+
position:fixed;
210+
top:0px;
211+
left:0px;
212+
width:100%;
213+
height:100%;
214+
}
215+
.winbl.blur{
216+
background:rgba(0,0,0,0.5);
217+
}

0 commit comments

Comments
 (0)