| summaryrefslogtreecommitdiff | 
diff options
| author | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2021-12-27 22:32:32 +0100 | 
|---|---|---|
| committer | Nathanael Sensfelder <SpamShield0@MultiAgentSystems.org> | 2021-12-27 22:32:32 +0100 | 
| commit | 18ebe6e6ca4299b7f903426502c5a5fb73747c81 (patch) | |
| tree | 7a310a4c8330b04c0d61a69e11650452896851eb /src/View | |
| parent | 7c727df4fb7e15e396959f59048f22bb346aef13 (diff) | |
...
Diffstat (limited to 'src/View')
| -rw-r--r-- | src/View/PlayerInput.elm | 152 | 
1 files changed, 152 insertions, 0 deletions
| diff --git a/src/View/PlayerInput.elm b/src/View/PlayerInput.elm new file mode 100644 index 0000000..01d926c --- /dev/null +++ b/src/View/PlayerInput.elm @@ -0,0 +1,152 @@ +module View.PlayerInput exposing (get_html) + +-- Elm ------------------------------------------------------------------------- +import List +import Html +import Html.Attributes +import Html.Events + +-- Local Module ---------------------------------------------------------------- +import Struct.Event +import Struct.Model +import Struct.UI + +-------------------------------------------------------------------------------- +-- TYPES ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_choice_html : ( +      (Int, (Html.Html Struct.Event.Type)) -> +      (Html.Html Struct.Event.Type) +   ) +get_choice_html data = +   let (ix, html) = data in +   (Html.div +      [ +         (Html.Attributes.class "tonkadur-choice"), +         (Html.Events.onClick (Struct.Event.ChoiceSelected ix)) +      ] +      [html] +   ) + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +get_html : Struct.Model.Type -> (Html.Html Struct.Event.Type) +get_html model = +   if (List.isEmpty model.ui.displayed_choices) +   then +      case model.ui.input of +         Struct.UI.NoInput -> (Html.div [] []) +         Struct.UI.IntegerInput -> +            (Html.div +               [ +                  (Html.Attributes.class "tonkadur-input") +               ] +               [ +                  (Html.div +                     [ +                        (Html.Attributes.class "tonkadur-input-instruction") +                     ] +                     [ +                        (Html.text +                           ( +                              "A number between " +                              ++ (String.fromInt model.ui.min) +                              ++ " and " +                              ++ (String.fromInt model.ui.max) +                              ++ " is expected:" +                           ) +                        ) +                     ] +                  ), +                  (Html.input +                     [ +                        (Html.Attributes.class "tonkadur-input-field"), +                        (Html.Attributes.min (String.fromInt model.ui.min)), +                        (Html.Attributes.max (String.fromInt model.ui.max)) +                     ] +                     [ +                     ] +                  ) +               ] +            ) + +         Struct.UI.StringInput -> +            (Html.div +               [ +                  (Html.Attributes.class "tonkadur-input") +               ] +               [ +                  (Html.div +                     [ +                        (Html.Attributes.class "tonkadur-input-instruction") +                     ] +                     [ +                        (Html.text +                           ( +                              "A string of size between " +                              ++ (String.fromInt model.ui.min) +                              ++ " and " +                              ++ (String.fromInt model.ui.max) +                              ++ " characters is expected:" +                           ) +                        ) +                     ] +                  ), +                  (Html.input +                     [ +                        (Html.Attributes.class "tonkadur-input-field"), +                        (Html.Attributes.minlength model.ui.min), +                        (Html.Attributes.maxlength model.ui.max) +                     ] +                     [ +                     ] +                  ) +               ] +            ) + +         Struct.UI.CommandInput -> +            (Html.div +               [ +                  (Html.Attributes.class "tonkadur-input") +               ] +               [ +                  (Html.div +                     [ +                        (Html.Attributes.class "tonkadur-input-instruction") +                     ] +                     [ +                        (Html.text +                           ( +                              "A space-separated list of strings (total size " +                              ++ " between " +                              ++ (String.fromInt model.ui.min) +                              ++ " and " +                              ++ (String.fromInt model.ui.max) +                              ++ " characters) is expected:" +                           ) +                        ) +                     ] +                  ), +                  (Html.input +                     [ +                        (Html.Attributes.class "tonkadur-input-field"), +                        (Html.Attributes.minlength model.ui.min), +                        (Html.Attributes.maxlength model.ui.max) +                     ] +                     [ +                     ] +                  ) +               ] +            ) +   else +      (Html.div +         [ +            (Html.Attributes.class "tonkadur-choice-list") +         ] +         (List.map (get_choice_html) model.ui.displayed_choices) +      ) | 


