From ab2a37813d6c2cd6554c4a6b0e5b93b3214d61e7 Mon Sep 17 00:00:00 2001 From: Nathanael Sensfelder Date: Wed, 5 Sep 2018 22:29:44 +0200 Subject: Adds "Main Menu" buttons. --- src/battle/src/ElmModule/Update.elm | 4 ++++ src/battle/src/Struct/Event.elm | 1 + src/battle/src/Update/GoToMainMenu.elm | 24 ++++++++++++++++++++++++ src/battle/src/View/MainMenu.elm | 22 +++++++++++++++------- src/battle/www/index.html | 2 ++ src/login/src/Action/Session.elm | 8 -------- src/login/src/ElmModule/Subscriptions.elm | 4 ++-- src/login/src/Update/HandleConnected.elm | 4 ++-- src/login/src/Update/HandleServerReply.elm | 4 ++-- src/map-editor/src/ElmModule/Update.elm | 7 ++++++- src/map-editor/src/Struct/Event.elm | 1 + src/map-editor/src/Struct/UI.elm | 2 +- src/map-editor/src/Update/GoToMainMenu.elm | 24 ++++++++++++++++++++++++ src/map-editor/src/View/MainMenu.elm | 22 +++++++++++++++++++--- src/map-editor/src/View/SubMenu/Settings.elm | 6 +----- src/map-editor/www/index.html | 2 ++ src/shared/elm/Action/Ports.elm | 6 ++++++ 17 files changed, 112 insertions(+), 31 deletions(-) create mode 100644 src/battle/src/Update/GoToMainMenu.elm delete mode 100644 src/login/src/Action/Session.elm create mode 100644 src/map-editor/src/Update/GoToMainMenu.elm create mode 100644 src/shared/elm/Action/Ports.elm diff --git a/src/battle/src/ElmModule/Update.elm b/src/battle/src/ElmModule/Update.elm index eafac01..998d327 100644 --- a/src/battle/src/ElmModule/Update.elm +++ b/src/battle/src/ElmModule/Update.elm @@ -11,6 +11,7 @@ import Update.AttackWithoutMoving import Update.ChangeScale import Update.DisplayCharacterInfo import Update.EndTurn +import Update.GoToMainMenu import Update.HandleAnimationEnded import Update.HandleServerReply import Update.LookForCharacter @@ -104,3 +105,6 @@ update event model = (Struct.Event.RequestedHelp help_request) -> (Update.SetRequestedHelp.apply_to new_model help_request) + + Struct.Event.GoToMainMenu -> + (Update.GoToMainMenu.apply_to new_model) diff --git a/src/battle/src/Struct/Event.elm b/src/battle/src/Struct/Event.elm index dedb606..6d3c133 100644 --- a/src/battle/src/Struct/Event.elm +++ b/src/battle/src/Struct/Event.elm @@ -35,6 +35,7 @@ type Type = | TurnEnded | RequestedHelp Struct.HelpRequest.Type | WeaponSwitchRequest + | GoToMainMenu attempted : (Result.Result err val) -> Type attempted act = diff --git a/src/battle/src/Update/GoToMainMenu.elm b/src/battle/src/Update/GoToMainMenu.elm new file mode 100644 index 0000000..f2ec989 --- /dev/null +++ b/src/battle/src/Update/GoToMainMenu.elm @@ -0,0 +1,24 @@ +module Update.GoToMainMenu exposing (apply_to) +-- Elm ------------------------------------------------------------------------- + +-- Battle ---------------------------------------------------------------------- +import Action.Ports + +import Constants.IO + +import Struct.Model +import Struct.Event + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +apply_to : Struct.Model.Type -> (Struct.Model.Type, (Cmd Struct.Event.Type)) +apply_to model = + ( + model, + (Action.Ports.go_to (Constants.IO.base_url ++"/main-menu/")) + ) diff --git a/src/battle/src/View/MainMenu.elm b/src/battle/src/View/MainMenu.elm index 9f3099b..96bf539 100644 --- a/src/battle/src/View/MainMenu.elm +++ b/src/battle/src/View/MainMenu.elm @@ -12,16 +12,20 @@ import Struct.UI -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- -get_menu_button_html : ( - Struct.UI.Tab -> - (Html.Html Struct.Event.Type) - ) +get_menu_button_html : Struct.UI.Tab -> (Html.Html Struct.Event.Type) get_menu_button_html tab = (Html.button [ (Html.Events.onClick (Struct.Event.TabSelected tab)) ] [ (Html.text (Struct.UI.to_string tab)) ] ) +get_main_menu_button_html : (Html.Html Struct.Event.Type) +get_main_menu_button_html = + (Html.button + [ (Html.Events.onClick Struct.Event.GoToMainMenu) ] + [ (Html.text "Main Menu") ] + ) + -------------------------------------------------------------------------------- -- EXPORTED -------------------------------------------------------------------- -------------------------------------------------------------------------------- @@ -31,8 +35,12 @@ get_html = [ (Html.Attributes.class "battle-main-menu") ] - (List.map - (get_menu_button_html) - (Struct.UI.get_all_tabs) + ( + (get_main_menu_button_html) + :: + (List.map + (get_menu_button_html) + (Struct.UI.get_all_tabs) + ) ) ) diff --git a/src/battle/www/index.html b/src/battle/www/index.html index 942de3b..2c69952 100644 --- a/src/battle/www/index.html +++ b/src/battle/www/index.html @@ -11,6 +11,7 @@ + diff --git a/src/login/src/Action/Session.elm b/src/login/src/Action/Session.elm deleted file mode 100644 index 1074cd7..0000000 --- a/src/login/src/Action/Session.elm +++ /dev/null @@ -1,8 +0,0 @@ -port module Action.Session exposing (..) - -import Struct.Event - -port store_new_session : (String, String) -> (Cmd msg) -port reset_session : () -> (Cmd msg) -port connected: (() -> msg) -> (Sub msg) -port go_to : (String) -> (Cmd msg) diff --git a/src/login/src/ElmModule/Subscriptions.elm b/src/login/src/ElmModule/Subscriptions.elm index 08ba697..9376f89 100644 --- a/src/login/src/ElmModule/Subscriptions.elm +++ b/src/login/src/ElmModule/Subscriptions.elm @@ -3,7 +3,7 @@ module ElmModule.Subscriptions exposing (..) -- Elm ------------------------------------------------------------------------- -- Main Menu ------------------------------------------------------------------- -import Action.Session +import Action.Ports import Struct.Model import Struct.Event @@ -16,4 +16,4 @@ import Struct.Event -------------------------------------------------------------------------------- subscriptions : Struct.Model.Type -> (Sub Struct.Event.Type) subscriptions model = - (Action.Session.connected (always Struct.Event.Connected)) + (Action.Ports.connected (always Struct.Event.Connected)) diff --git a/src/login/src/Update/HandleConnected.elm b/src/login/src/Update/HandleConnected.elm index 5d1284d..62fd243 100644 --- a/src/login/src/Update/HandleConnected.elm +++ b/src/login/src/Update/HandleConnected.elm @@ -2,7 +2,7 @@ module Update.HandleConnected exposing (apply_to) -- Elm ------------------------------------------------------------------------- -- Login ----------------------------------------------------------------------- -import Action.Session +import Action.Ports import Constants.IO @@ -21,5 +21,5 @@ apply_to : Struct.Model.Type -> (Struct.Model.Type, (Cmd Struct.Event.Type)) apply_to model = ( model, - (Action.Session.go_to (Constants.IO.base_url ++"/main-menu/")) + (Action.Ports.go_to (Constants.IO.base_url ++"/main-menu/")) ) diff --git a/src/login/src/Update/HandleServerReply.elm b/src/login/src/Update/HandleServerReply.elm index 8720457..f079b33 100644 --- a/src/login/src/Update/HandleServerReply.elm +++ b/src/login/src/Update/HandleServerReply.elm @@ -8,7 +8,7 @@ import Dict import Http -- Map ------------------------------------------------------------------- -import Action.Session +import Action.Ports import Struct.Error import Struct.Event @@ -49,7 +49,7 @@ set_session pid stk current_state = }, Nothing, ( - (Action.Session.store_new_session (pid, stk)) + (Action.Ports.store_new_session (pid, stk)) :: cmd_list ) ) diff --git a/src/map-editor/src/ElmModule/Update.elm b/src/map-editor/src/ElmModule/Update.elm index bc84f5b..850e659 100644 --- a/src/map-editor/src/ElmModule/Update.elm +++ b/src/map-editor/src/ElmModule/Update.elm @@ -8,15 +8,17 @@ import Struct.Model import Update.ChangeScale import Update.ClearToolboxSelection +import Update.GoToMainMenu import Update.HandleServerReply import Update.PrettifySelectedTiles -import Update.SendMapUpdate import Update.SelectTab import Update.SelectTile +import Update.SendMapUpdate import Update.SetRequestedHelp import Update.SetToolboxMode import Update.SetToolboxShape import Update.SetToolboxTemplate + -------------------------------------------------------------------------------- -- LOCAL ----------------------------------------------------------------------- -------------------------------------------------------------------------------- @@ -75,3 +77,6 @@ update event model = Struct.Event.SendMapUpdateRequested -> (Update.SendMapUpdate.apply_to new_model) + + Struct.Event.GoToMainMenu -> + (Update.GoToMainMenu.apply_to new_model) diff --git a/src/map-editor/src/Struct/Event.elm b/src/map-editor/src/Struct/Event.elm index d0d84e1..449f590 100644 --- a/src/map-editor/src/Struct/Event.elm +++ b/src/map-editor/src/Struct/Event.elm @@ -28,6 +28,7 @@ type Type = | TemplateRequested (Int, Int) | PrettifySelectionRequested | SendMapUpdateRequested + | GoToMainMenu attempted : (Result.Result err val) -> Type attempted act = diff --git a/src/map-editor/src/Struct/UI.elm b/src/map-editor/src/Struct/UI.elm index fe7b700..b35a60a 100644 --- a/src/map-editor/src/Struct/UI.elm +++ b/src/map-editor/src/Struct/UI.elm @@ -51,7 +51,7 @@ default : Type default = { zoom_level = 1.0, - displayed_tab = Nothing, + displayed_tab = (Just TilesTab), previous_action = Nothing } diff --git a/src/map-editor/src/Update/GoToMainMenu.elm b/src/map-editor/src/Update/GoToMainMenu.elm new file mode 100644 index 0000000..f2ec989 --- /dev/null +++ b/src/map-editor/src/Update/GoToMainMenu.elm @@ -0,0 +1,24 @@ +module Update.GoToMainMenu exposing (apply_to) +-- Elm ------------------------------------------------------------------------- + +-- Battle ---------------------------------------------------------------------- +import Action.Ports + +import Constants.IO + +import Struct.Model +import Struct.Event + +-------------------------------------------------------------------------------- +-- LOCAL ----------------------------------------------------------------------- +-------------------------------------------------------------------------------- + +-------------------------------------------------------------------------------- +-- EXPORTED -------------------------------------------------------------------- +-------------------------------------------------------------------------------- +apply_to : Struct.Model.Type -> (Struct.Model.Type, (Cmd Struct.Event.Type)) +apply_to model = + ( + model, + (Action.Ports.go_to (Constants.IO.base_url ++"/main-menu/")) + ) diff --git a/src/map-editor/src/View/MainMenu.elm b/src/map-editor/src/View/MainMenu.elm index b9a8922..fd5801e 100644 --- a/src/map-editor/src/View/MainMenu.elm +++ b/src/map-editor/src/View/MainMenu.elm @@ -31,8 +31,24 @@ get_html = [ (Html.Attributes.class "map-main-menu") ] - (List.map - (get_menu_button_html) - (Struct.UI.get_all_tabs) + ( + ( + (Html.button + [ (Html.Events.onClick Struct.Event.GoToMainMenu) ] + [ (Html.text "Main Menu") ] + ) + :: + (List.map + (get_menu_button_html) + (Struct.UI.get_all_tabs) + ) + ) + ++ + [ + (Html.button + [ (Html.Events.onClick Struct.Event.SendMapUpdateRequested) ] + [ (Html.text "Save Map") ] + ) + ] ) ) diff --git a/src/map-editor/src/View/SubMenu/Settings.elm b/src/map-editor/src/View/SubMenu/Settings.elm index 98405d0..1661053 100644 --- a/src/map-editor/src/View/SubMenu/Settings.elm +++ b/src/map-editor/src/View/SubMenu/Settings.elm @@ -36,10 +36,6 @@ get_html model = [ (scale_button (0.75) "Zoom -"), (scale_button 0 "Zoom Reset"), - (scale_button (1.15) "Zoom +"), - (Html.button - [ (Html.Events.onClick Struct.Event.SendMapUpdateRequested) ] - [ (Html.text "Save Map") ] - ) + (scale_button (1.15) "Zoom +") ] ) diff --git a/src/map-editor/www/index.html b/src/map-editor/www/index.html index 80b147d..3828b22 100644 --- a/src/map-editor/www/index.html +++ b/src/map-editor/www/index.html @@ -9,6 +9,7 @@ + diff --git a/src/shared/elm/Action/Ports.elm b/src/shared/elm/Action/Ports.elm new file mode 100644 index 0000000..8da9bac --- /dev/null +++ b/src/shared/elm/Action/Ports.elm @@ -0,0 +1,6 @@ +port module Action.Ports exposing (..) + +port store_new_session : (String, String) -> (Cmd msg) +port reset_session : () -> (Cmd msg) +port connected: (() -> msg) -> (Sub msg) +port go_to : (String) -> (Cmd msg) -- cgit v1.2.3-70-g09d2