Tweak camera movement
This commit is contained in:
@@ -100,7 +100,6 @@ tryAssignHotkey w sc = fromMaybe w $ do
|
||||
cr <- w ^? cWorld . lWorld . creatures . ix 0
|
||||
invid <- cr ^? crManipulation . manObject . imSelectedItem
|
||||
itid <- cr ^? crInv . ix invid . itID
|
||||
--return $ w & cWorld . lWorld . creatures . ix 0 %~ assignHotkey itid (scancodeToHotkey sc)
|
||||
return $ w & cWorld . lWorld %~ assignHotkey itid (scancodeToHotkey sc)
|
||||
|
||||
{- | The order of these MAY be important, in particular the setting of crMvAim
|
||||
@@ -180,17 +179,9 @@ pressedMBEffectsTopInventory pkeys w
|
||||
, Just rtime <- pkeys ^? ix SDL.ButtonRight
|
||||
, ltime <= rtime && inTopInv
|
||||
= youhammerdown $ useSelectedItem 0 w
|
||||
| Just _ <- pkeys ^? ix SDL.ButtonLeft
|
||||
, Just _ <- pkeys ^? ix SDL.ButtonRight
|
||||
= w & wCam . camRot -~ rotation
|
||||
| otherwise = w
|
||||
where
|
||||
youhammerdown = set (cWorld . lWorld . creatures . ix 0 . crHammerPosition) HammerDown
|
||||
inTopInv = case w ^. hud . hudElement of
|
||||
DisplayInventory{_subInventory = NoSubInventory{}} -> True
|
||||
_ -> False
|
||||
rotation =
|
||||
maybe
|
||||
0
|
||||
(angleBetween $ w ^. input . mousePos)
|
||||
(w ^. input . heldPos . at SDL.ButtonRight)
|
||||
|
||||
@@ -180,9 +180,13 @@ updateDisplaySections w cfig =
|
||||
IM.fromDistinctAscList . zip [0 ..] $
|
||||
mapMaybe (closeItemToSelectionItem w) (w ^. hud . closeItems)
|
||||
invitems =
|
||||
IM.mapWithKey
|
||||
(\k (indent, x) -> invSelectionItem indent (w ^. cWorld . lWorld)
|
||||
k (x ^. locLDT . ldtValue))
|
||||
IM.map
|
||||
( \(indent, x) ->
|
||||
invSelectionItem
|
||||
indent
|
||||
(w ^. cWorld . lWorld)
|
||||
(x ^. locLDT . ldtValue)
|
||||
)
|
||||
(fmap (first removeindentiffiltering) . allInvLocs $ _crInv cr)
|
||||
removeindentiffiltering =
|
||||
if maybe False (not . null) (w ^? hud . hudElement . diInvFilter . _Just)
|
||||
@@ -309,8 +313,9 @@ updateSection indent mcsel sis availablelines oldoffset =
|
||||
SelectionSection
|
||||
{ _ssItems = sis
|
||||
, _ssOffset = offset
|
||||
, _ssShownItems = tweakfirst . tweaklast . map snd
|
||||
$ take availablelines shownstrings
|
||||
, _ssShownItems =
|
||||
tweakfirst . tweaklast . map snd $
|
||||
take availablelines shownstrings
|
||||
, _ssIndent = indent
|
||||
}
|
||||
where
|
||||
@@ -331,12 +336,13 @@ updateSection indent mcsel sis availablelines oldoffset =
|
||||
| length allstrings - oldoffset < availablelines ->
|
||||
length allstrings - availablelines
|
||||
_ -> oldoffsetbounded
|
||||
tweakfirst
|
||||
tweakfirst
|
||||
| offset > 0 = ix 0 .~ color moreupcolor (text (replicate 15 (toEnum 30)))
|
||||
| otherwise = id
|
||||
moreupcolor = fromMaybe white $ allstrings ^? ix offset . _1
|
||||
tweaklast
|
||||
| length shownstrings > availablelines = ix (availablelines - 1)
|
||||
| length shownstrings > availablelines =
|
||||
ix (availablelines - 1)
|
||||
.~ color moredowncolor (text . replicate 15 $ toEnum 31)
|
||||
| otherwise = id
|
||||
moredowncolor = fromMaybe white $ allstrings ^? ix (offset + availablelines - 1) . _1
|
||||
|
||||
+6
-5
@@ -2,19 +2,20 @@ module Dodge.Hotkey (
|
||||
assignHotkey,
|
||||
) where
|
||||
|
||||
import NewInt
|
||||
import Control.Lens
|
||||
import Data.Maybe
|
||||
import Dodge.Data.World
|
||||
import NewInt
|
||||
|
||||
-- it is not obvious to me whether hotkeys should belong to LWorld, CWorld or
|
||||
-- World
|
||||
|
||||
assignHotkey :: NewInt ItmInt -> Hotkey -> LWorld -> LWorld
|
||||
assignHotkey (NInt itid) hk lw = lw
|
||||
& handleoldposition
|
||||
& hotkeys . at hk ?~ NInt itid
|
||||
& imHotkeys . unNIntMap . at itid ?~ hk
|
||||
assignHotkey (NInt itid) hk lw =
|
||||
lw
|
||||
& handleoldposition
|
||||
& hotkeys . at hk ?~ NInt itid
|
||||
& imHotkeys . unNIntMap . at itid ?~ hk
|
||||
where
|
||||
handleoldposition = fromMaybe id $ do
|
||||
olditid <- lw ^? hotkeys . ix hk . unNInt
|
||||
|
||||
@@ -19,8 +19,8 @@ import NewInt
|
||||
import Padding
|
||||
import Picture.Base
|
||||
|
||||
invSelectionItem :: Int -> LWorld -> Int -> ComposedItem -> SelectionItem ()
|
||||
invSelectionItem indent lw i ci =
|
||||
invSelectionItem :: Int -> LWorld -> ComposedItem -> SelectionItem ()
|
||||
invSelectionItem indent lw ci =
|
||||
SelectionItem
|
||||
{ _siPictures = pics & ix 0 %~ (++ anyequippos ++ anyhotkey)
|
||||
, _siHeight = itInvHeight $ ci ^. _1
|
||||
|
||||
+27
-19
@@ -31,7 +31,7 @@ update where your avatar's view is from. -}
|
||||
updateCamera :: Configuration -> World -> World
|
||||
updateCamera cfig w = case w ^. wCam . camControl of
|
||||
CamInGame {} -> updateInGameCamera cfig w
|
||||
CamFloat -> rotateCamera cfig $ updateFloatingCamera cfig w
|
||||
CamFloat -> updateFloatingCamera cfig w
|
||||
|
||||
updateFloatingCamera :: Configuration -> World -> World
|
||||
updateFloatingCamera cfig w =
|
||||
@@ -46,15 +46,20 @@ updateFloatingCamera cfig w =
|
||||
|
||||
translateFloatingCamera :: Input -> Camera -> Camera
|
||||
translateFloatingCamera theinput cam = fromMaybe cam $ do
|
||||
presstime <- theinput ^. mouseButtons . at ButtonLeft
|
||||
guard $ presstime > 0
|
||||
hpos <- theinput ^? heldPos . ix ButtonLeft
|
||||
let thetran =
|
||||
screenToWorldPos cam hpos
|
||||
-.- screenToWorldPos cam (theinput ^. mousePos)
|
||||
return $
|
||||
cam & camCenter +~ thetran
|
||||
& camViewFrom +~ thetran
|
||||
lpresstime <- theinput ^. mouseButtons . at ButtonLeft
|
||||
rpresstime <- theinput ^. mouseButtons . at ButtonRight
|
||||
if lpresstime > rpresstime
|
||||
then do
|
||||
hpos <- theinput ^? heldPos . ix ButtonLeft
|
||||
let thetran =
|
||||
screenToWorldPos cam hpos
|
||||
-.- screenToWorldPos cam (theinput ^. mousePos)
|
||||
return $
|
||||
cam & camCenter +~ thetran
|
||||
& camViewFrom +~ thetran
|
||||
else do
|
||||
a <- (theinput ^. heldPos . at SDL.ButtonRight)
|
||||
return $ cam & camRot -~ angleBetween (theinput ^. mousePos) a
|
||||
|
||||
translateFloatingCameraKeys :: Input -> Camera -> Camera
|
||||
translateFloatingCameraKeys theinput = (camCenter -~ thetran) . (camViewFrom -~ thetran)
|
||||
@@ -157,17 +162,20 @@ doWallRotate wl w = rotateUsing $ (argV . uncurry (-.-) $ _wlLine wl) - (w ^. wC
|
||||
b = a * (4 / pi)
|
||||
b' = fromIntegral (round b :: Int)
|
||||
|
||||
--rotateCameraBy :: Float -> World -> World
|
||||
--rotateCameraBy x = wCam . camRot +~ x
|
||||
|
||||
rotateCamera :: Configuration -> World -> World
|
||||
rotateCamera cfig w
|
||||
-- | keydown SDL.ScancodeQ && keydown SDL.ScancodeE = w
|
||||
-- | keydown SDL.ScancodeQ = rotateCameraBy 0.025 w
|
||||
-- | keydown SDL.ScancodeE = rotateCameraBy (-0.025) w
|
||||
rotateCamera cfig w
|
||||
| Just ltime <- pkeys ^? ix SDL.ButtonLeft
|
||||
, Just rtime <- pkeys ^? ix SDL.ButtonRight
|
||||
, rtime > ltime = w & wCam . camRot -~ rotation
|
||||
| otherwise = ifConfigWallRotate cfig (w ^. input . mouseButtons) w
|
||||
-- where
|
||||
-- keydown scode = scode `M.member` _pressedKeys (_input w) && not (inTextInputFocus w)
|
||||
where
|
||||
pkeys = w ^. input . mouseButtons
|
||||
rotation =
|
||||
maybe
|
||||
0
|
||||
(angleBetween $ w ^. input . mousePos)
|
||||
(w ^. input . heldPos . at SDL.ButtonRight)
|
||||
|
||||
|
||||
zoomFromItem :: ItZoom -> Float
|
||||
zoomFromItem ItZoom{_izMax = zMax, _izMin = zMin, _izFac = zFac} =
|
||||
|
||||
Reference in New Issue
Block a user