From 2b977f70e6981980daa4e8171987b9c13ac37a33 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 12 Feb 2017 23:05:39 +0100 Subject: [PATCH] - scriptified the video mode menu (only the part that extends the actual menu class, the entire thing is basically non-modifiable but this code would otherwise stand in the way of properly handling the rest of the menus.) --- src/menu/menu.cpp | 7 +++ src/menu/videomenu.cpp | 80 ++++++++---------------- wadsrc/static/zscript.txt | 1 + wadsrc/static/zscript/base.txt | 31 ++++++++- wadsrc/static/zscript/menu/videomenu.txt | 73 +++++++++++++++++++++ 5 files changed, 137 insertions(+), 55 deletions(-) create mode 100644 wadsrc/static/zscript/menu/videomenu.txt diff --git a/src/menu/menu.cpp b/src/menu/menu.cpp index 1b93083e1..a64f7b6df 100644 --- a/src/menu/menu.cpp +++ b/src/menu/menu.cpp @@ -93,6 +93,8 @@ int BackbuttonTime; float BackbuttonAlpha; static bool MenuEnabled = true; +void M_InitVideoModes(); + #define KEY_REPEAT_DELAY (TICRATE*5/12) #define KEY_REPEAT_RATE (3) @@ -568,6 +570,11 @@ void M_SetMenu(FName menu, int param) M_StartMessage (GStrings("SAVEDEAD"), 1); return; } + + case NAME_VideoModeMenu: + M_InitVideoModes(); + break; + } // End of special checks diff --git a/src/menu/videomenu.cpp b/src/menu/videomenu.cpp index 1dc3a5c0e..dfb08f13c 100644 --- a/src/menu/videomenu.cpp +++ b/src/menu/videomenu.cpp @@ -138,60 +138,6 @@ struct OptionMenuItemScreenResolution // temporary workaround SRL_HIGHLIGHT = 0x30004, }; }; -class DVideoModeMenu : public DOptionMenu -{ - DECLARE_CLASS(DVideoModeMenu, DOptionMenu) - -public: - - DVideoModeMenu() - { - SetModesMenu (screen->VideoWidth, screen->VideoHeight, DisplayBits); - } - - bool MenuEvent(int mkey, bool fromcontroller) - { - if ((mkey == MKEY_Up || mkey == MKEY_Down) && mDesc->mSelectedItem >= 0 && - mDesc->mSelectedItem < (int)mDesc->mItems.Size()) - { - int sel; - bool selected = mDesc->mItems[mDesc->mSelectedItem]->GetValue(OptionMenuItemScreenResolution::SRL_SELECTION, &sel); - bool res = Super::MenuEvent(mkey, fromcontroller); - if (selected) mDesc->mItems[mDesc->mSelectedItem]->SetValue(OptionMenuItemScreenResolution::SRL_SELECTION, sel); - return res; - } - return Super::MenuEvent(mkey, fromcontroller); - } - - bool Responder(event_t *ev) - { - if (ev->type == EV_GUI_Event && ev->subtype == EV_GUI_KeyDown && - (ev->data1 == 't' || ev->data1 == 'T')) - { - if (!GetSelectedSize (&NewWidth, &NewHeight)) - { - NewWidth = screen->VideoWidth; - NewHeight = screen->VideoHeight; - } - else - { - OldWidth = screen->VideoWidth; - OldHeight = screen->VideoHeight; - OldBits = DisplayBits; - NewBits = BitTranslate[DummyDepthCvar]; - setmodeneeded = true; - testingmode = I_GetTime(false) + 5 * TICRATE; - S_Sound (CHAN_VOICE | CHAN_UI, "menu/choose", snd_menuvolume, ATTN_NONE); - SetModesMenu (NewWidth, NewHeight, NewBits); - return true; - } - } - return Super::Responder(ev); - } -}; - -IMPLEMENT_CLASS(DVideoModeMenu, false, false) - //============================================================================= // @@ -382,6 +328,27 @@ static bool GetSelectedSize (int *width, int *height) return false; } +DEFINE_ACTION_FUNCTION(DVideoModeMenu, SetSelectedSize) +{ + if (!GetSelectedSize (&NewWidth, &NewHeight)) + { + NewWidth = screen->VideoWidth; + NewHeight = screen->VideoHeight; + ACTION_RETURN_BOOL(false); + } + else + { + OldWidth = screen->VideoWidth; + OldHeight = screen->VideoHeight; + OldBits = DisplayBits; + NewBits = BitTranslate[DummyDepthCvar]; + setmodeneeded = true; + testingmode = I_GetTime(false) + 5 * TICRATE; + SetModesMenu (NewWidth, NewHeight, NewBits); + ACTION_RETURN_BOOL(true); + } +} + //============================================================================= // // @@ -460,3 +427,8 @@ static void SetModesMenu (int w, int h, int bits) } BuildModesList (w, h, bits); } + +void M_InitVideoModes() +{ + SetModesMenu (screen->VideoWidth, screen->VideoHeight, DisplayBits); +} \ No newline at end of file diff --git a/wadsrc/static/zscript.txt b/wadsrc/static/zscript.txt index ba5c3d19b..c108b6623 100644 --- a/wadsrc/static/zscript.txt +++ b/wadsrc/static/zscript.txt @@ -15,6 +15,7 @@ #include "zscript/menu/playerdisplay.txt" #include "zscript/menu/playermenu.txt" #include "zscript/menu/textentermenu.txt" +#include "zscript/menu/videomenu.txt" #include "zscript/inventory/inventory.txt" #include "zscript/inventory/inv_misc.txt" diff --git a/wadsrc/static/zscript/base.txt b/wadsrc/static/zscript/base.txt index 2d79a2916..eee20a04f 100644 --- a/wadsrc/static/zscript/base.txt +++ b/wadsrc/static/zscript/base.txt @@ -18,6 +18,35 @@ struct InputEvent native DeviceChange,// a device has been connected or removed } + enum EGUIEvent + { + GUI_None, + GUI_KeyDown, // data1: unshifted ASCII, data2: shifted ASCII, data3: modifiers + GUI_KeyRepeat, // same + GUI_KeyUp, // same + GUI_Char, // data1: translated character (for user text input), data2: alt down? + GUI_FirstMouseEvent, + GUI_MouseMove, + GUI_LButtonDown, + GUI_LButtonUp, + GUI_LButtonDblClick, + GUI_MButtonDown, + GUI_MButtonUp, + GUI_MButtonDblClick, + GUI_RButtonDown, + GUI_RButtonUp, + GUI_RButtonDblClick, + GUI_WheelUp, // data3: shift/ctrl/alt + GUI_WheelDown, // " + GUI_WheelRight, // " + GUI_WheelLeft, // " + GUI_BackButtonDown, + GUI_BackButtonUp, + GUI_FwdButtonDown, + GUI_FwdButtonUp, + GUI_LastMouseEvent, + }; + const KEY_ESCAPE = 0x01; } @@ -580,7 +609,7 @@ class Floor : Thinker native waitStair, resetStair, - // Not to be used as parameters to EV_DoFloor() + // Not to be used as parameters to DoFloor() genFloorChg0, genFloorChgT, genFloorChg diff --git a/wadsrc/static/zscript/menu/videomenu.txt b/wadsrc/static/zscript/menu/videomenu.txt new file mode 100644 index 000000000..a162781eb --- /dev/null +++ b/wadsrc/static/zscript/menu/videomenu.txt @@ -0,0 +1,73 @@ +/* +** videomenu.txt +** The video modes menu +** +**--------------------------------------------------------------------------- +** Copyright 2001-2010 Randy Heit +** Copyright 2010-2017 Christoph Oelckers +** All rights reserved. +** +** Redistribution and use in source and binary forms, with or without +** modification, are permitted provided that the following conditions +** are met: +** +** 1. Redistributions of source code must retain the above copyright +** notice, this list of conditions and the following disclaimer. +** 2. Redistributions in binary form must reproduce the above copyright +** notice, this list of conditions and the following disclaimer in the +** documentation and/or other materials provided with the distribution. +** 3. The name of the author may not be used to endorse or promote products +** derived from this software without specific prior written permission. +** +** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES +** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. +** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, +** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT +** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF +** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +**--------------------------------------------------------------------------- +** +*/ + +//============================================================================= +// +// +// +//============================================================================= + +class VideoModeMenu : OptionMenu +{ + native static bool SetSelectedSize(); + + override bool MenuEvent(int mkey, bool fromcontroller) + { + if ((mkey == MKEY_Up || mkey == MKEY_Down) && mDesc.mSelectedItem >= 0 && mDesc.mSelectedItem < mDesc.mItems.Size()) + { + int sel; + bool selected; + [selected, sel] = mDesc.mItems[mDesc.mSelectedItem].GetValue(OptionMenuItemScreenResolution.SRL_SELECTION); + bool res = Super.MenuEvent(mkey, fromcontroller); + if (selected) mDesc.mItems[mDesc.mSelectedItem].SetValue(OptionMenuItemScreenResolution.SRL_SELECTION, sel); + return res; + } + return Super.MenuEvent(mkey, fromcontroller); + } + + override bool Responder(InputEvent ev) + { + if (ev.type == InputEvent.GUI_Event && ev.subtype == InputEvent.GUI_KeyDown && (ev.data1 == 0x54 || ev.data1 == 0x74)) + { + if (SetSelectedSize()) + { + MenuSound ("menu/choose"); + return true; + } + } + return Super.Responder(ev); + } +} +