aboutsummaryrefslogtreecommitdiff
blob: 334356575a708081289d32b309430a7d53aa3c9b (plain)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
module Struct.UI exposing
   (
      Type,
      Tab(..),
      Action(..),
      default,
      -- Zoom
      get_zoom_level,
      reset_zoom_level,
      mod_zoom_level,
      -- Tab
      try_getting_displayed_tab,
      set_displayed_tab,
      reset_displayed_tab,
      to_string,
      get_all_tabs,
      -- Manual Controls
      has_manual_controls_enabled,
      -- Previous Action
      has_focus,
      get_previous_action,
      set_previous_action
   )

-- Battlemap -------------------------------------------------------------------
import Struct.Location

import Struct.Character

--------------------------------------------------------------------------------
-- TYPES -----------------------------------------------------------------------
--------------------------------------------------------------------------------
type Tab =
   StatusTab
   | CharactersTab
   | SettingsTab
   | TimelineTab

type Action =
   UsedManualControls
   | SelectedLocation Struct.Location.Ref
   | SelectedCharacter Struct.Character.Ref
   | AttackedCharacter Struct.Character.Ref

type alias Type =
   {
      zoom_level : Float,
      show_manual_controls : Bool,
      displayed_tab : (Maybe Tab),
      previous_action : (Maybe Action)
   }

--------------------------------------------------------------------------------
-- LOCAL -----------------------------------------------------------------------
--------------------------------------------------------------------------------

--------------------------------------------------------------------------------
-- EXPORTED --------------------------------------------------------------------
--------------------------------------------------------------------------------
default : Type
default =
   {
      zoom_level = 1.0,
      show_manual_controls = True,
      displayed_tab = (Just StatusTab),
      previous_action = Nothing
   }

-- Zoom ------------------------------------------------------------------------
get_zoom_level : Type -> Float
get_zoom_level ui = ui.zoom_level

reset_zoom_level : Type -> Type
reset_zoom_level ui = {ui | zoom_level = 1.0}

mod_zoom_level : Type -> Float -> Type
mod_zoom_level ui mod = {ui | zoom_level = (mod * ui.zoom_level)}

-- Tab -------------------------------------------------------------------------
try_getting_displayed_tab : Type -> (Maybe Tab)
try_getting_displayed_tab ui = ui.displayed_tab

set_displayed_tab : Type -> Tab -> Type
set_displayed_tab ui tab = {ui | displayed_tab = (Just tab)}

reset_displayed_tab : Type -> Type
reset_displayed_tab ui = {ui | displayed_tab = Nothing}

to_string : Tab -> String
to_string tab =
   case tab of
      StatusTab -> "Status"
      CharactersTab -> "Characters"
      SettingsTab -> "Settings"
      TimelineTab -> "Timeline"

get_all_tabs : (List Tab)
get_all_tabs =
   [StatusTab, CharactersTab, SettingsTab, TimelineTab]

-- ManualControls --------------------------------------------------------------
has_manual_controls_enabled : Type -> Bool
has_manual_controls_enabled ui = ui.show_manual_controls

toggle_manual_controls : Type -> Type
toggle_manual_controls ui =
   if (ui.show_manual_controls)
   then
      {ui | show_manual_controls = False}
   else
      {ui | show_manual_controls = True}

set_enable_manual_controls : Type -> Bool -> Type
set_enable_manual_controls ui val = {ui | show_manual_controls = val}

-- Previous Action -------------------------------------------------------------
has_focus : Type -> Bool
has_focus ui = True

set_previous_action : Type -> (Maybe Action) -> Type
set_previous_action ui act = {ui | previous_action = act}

get_previous_action : Type -> (Maybe Action)
get_previous_action ui = ui.previous_action