-
Notifications
You must be signed in to change notification settings - Fork 1
/
Status.hs
65 lines (46 loc) · 1.84 KB
/
Status.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
{-# LANGUAGE OverloadedStrings #-}
module Status where
import HGamer3D
import qualified Data.Traversable as Tr
import Control.Monad.Trans.Reader
import Control.Monad.Trans.State
import Control.Monad.IO.Class
import Control.Monad.Trans.Class
import qualified Data.Text as T
import Data
import Actor
-- STATUS BAR ACTOR
-- ----------------
type SbaR = HG3D
type SbaS = (Int, Entity, Entity, Entity)
newStatusBarActor :: HG3D -> Int -> T.Text -> T.Text -> IO Actor
newStatusBarActor hg3d count name status = do
eL <- liftIO $ newE hg3d [
ctStaticText #: ("hero: " `T.append` name),
ctScreenRect #: ScreenRect 10 10 100 25
]
eM <- liftIO $ newE hg3d [
ctStaticText #: (T.pack ("count: " ++ (show count))),
ctScreenRect #: ScreenRect 350 10 100 25
]
eR <- liftIO $ newE hg3d [
ctStaticText #: status,
ctScreenRect #: ScreenRect 590 10 100 25
]
actor <- newActor
runActor actor statusBarActorF hg3d (count, eL, eM, eR)
return actor
statusBarActorF :: Actor -> Message -> ReaderStateIO SbaR SbaS ()
statusBarActorF statusA msg = do
hg3d <- lift ask
(count, textLeft, textMiddle, textRight) <- get
let setY y' e = do
r@(ScreenRect x y w h) <- readC e ctScreenRect
setC e ctScreenRect (ScreenRect x y' w h)
return ()
case msg of
DisplayStatus -> liftIO (mapM (\e -> setY 10 e) [textLeft, textMiddle, textRight]) >> return ()
HideStatus -> liftIO (mapM (\e -> setY (-1000) e) [textLeft, textMiddle, textRight]) >> return ()
AddCount count' -> put (count + count', textLeft, textMiddle, textRight) >> liftIO (setC textMiddle ctStaticText (T.pack ("count: " ++ (show (count + count'))))) >> return ()
SetMode mode -> liftIO (setC textRight ctStaticText mode) >> return ()
_ -> return ()