From bb6def820f6e7af5dbd0131a28078246fa4866c6 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sun, 12 Feb 2017 14:04:48 +0100 Subject: [PATCH] - everything compiles and mostly works again. --- src/CMakeLists.txt | 1 - src/dobjtype.cpp | 18 +++--- src/menu/listmenu.cpp | 2 +- src/menu/menu.cpp | 9 +-- src/menu/menudef.cpp | 59 ++++++++----------- src/menu/playerdisplay.cpp | 0 src/scripting/thingdef_data.cpp | 7 +++ wadsrc/static/zscript/menu/listmenuitems.txt | 28 ++++++--- wadsrc/static/zscript/menu/menuitembase.txt | 6 ++ .../static/zscript/menu/optionmenuitems.txt | 56 ++++++++++++++---- wadsrc/static/zscript/menu/playerdisplay.txt | 2 +- wadsrc/static/zscript/menu/playermenu.txt | 8 +-- 12 files changed, 119 insertions(+), 77 deletions(-) delete mode 100644 src/menu/playerdisplay.cpp diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index d079c68b2..9448006e4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -848,7 +848,6 @@ set( FASTMATH_PCH_SOURCES menu/menuinput.cpp menu/messagebox.cpp menu/optionmenu.cpp - menu/playerdisplay.cpp menu/playermenu.cpp menu/readthis.cpp menu/videomenu.cpp diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index 1e6211976..53ca1f335 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -1985,7 +1985,7 @@ void PDynArray::DestroyValue(void *addr) const void PDynArray::SetDefaultValue(void *base, unsigned offset, TArray *special) const { - memset((char*)base + offset, 0, sizeof(FArray)); // same as constructing an empty array. + if (base != nullptr) memset((char*)base + offset, 0, sizeof(FArray)); // same as constructing an empty array. if (special != nullptr) { special->Push(std::make_pair(this, offset)); @@ -3047,6 +3047,10 @@ DObject *PClass::CreateNew() const else memset (mem, 0, Size); + if (ConstructNative == nullptr) + { + I_Error("Attempt to instantiate abstract class %s.", TypeName.GetChars()); + } ConstructNative (mem); ((DObject *)mem)->SetClass (const_cast(this)); InitializeSpecials(mem, Defaults); @@ -3165,16 +3169,12 @@ void PClass::InitializeDefaults() { // Copy parent values from the parent defaults. assert(ParentClass != nullptr); - ParentClass->InitializeSpecials(Defaults, ParentClass->Defaults); - - if (Defaults != nullptr) + if (Defaults != nullptr) ParentClass->InitializeSpecials(Defaults, ParentClass->Defaults); + for (const PField *field : Fields) { - for (const PField *field : Fields) + if (!(field->Flags & VARF_Native)) { - if (!(field->Flags & VARF_Native)) - { - field->Type->SetDefaultValue(Defaults, unsigned(field->Offset), &SpecialInits); - } + field->Type->SetDefaultValue(Defaults, unsigned(field->Offset), &SpecialInits); } } } diff --git a/src/menu/listmenu.cpp b/src/menu/listmenu.cpp index adb630375..18c627359 100644 --- a/src/menu/listmenu.cpp +++ b/src/menu/listmenu.cpp @@ -278,4 +278,4 @@ void DListMenu::Drawer () // base class for menu items // //============================================================================= -IMPLEMENT_CLASS(DMenuItemBase, true, false) +IMPLEMENT_CLASS(DMenuItemBase, false, false) diff --git a/src/menu/menu.cpp b/src/menu/menu.cpp index 720a327dd..6b137d12a 100644 --- a/src/menu/menu.cpp +++ b/src/menu/menu.cpp @@ -1130,9 +1130,6 @@ DEFINE_FIELD(DOptionMenuDescriptor, mIndent) DEFINE_FIELD(DOptionMenuDescriptor, mPosition) DEFINE_FIELD(DOptionMenuDescriptor, mDontDim) -//DEFINE_FIELD(DMenuItemBase, mLabel) -//DEFINE_FIELD(DMenuItemBase, mCentered) - DEFINE_FIELD(DOptionMenu, CanScrollUp) DEFINE_FIELD(DOptionMenu, CanScrollDown) DEFINE_FIELD(DOptionMenu, VisBottom) @@ -1272,7 +1269,7 @@ DMenuItemBase * CreateOptionMenuItemControl(const char *label, FName cmd, FKeyBi DMenuItemBase * CreateListMenuItemPatch(int x, int y, int height, int hotkey, FTextureID tex, FName command, int param) { - auto c = PClass::FindClass("ListMenuItemPatch"); + auto c = PClass::FindClass("ListMenuItemPatchItem"); auto p = c->CreateNew(); VMValue params[] = { p, x, y, height, tex.GetIndex(), hotkey, command.GetIndex(), param }; auto f = dyn_cast(c->Symbols.FindSymbol("InitDirect", false)); @@ -1282,7 +1279,7 @@ DMenuItemBase * CreateListMenuItemPatch(int x, int y, int height, int hotkey, FT DMenuItemBase * CreateListMenuItemText(int x, int y, int height, int hotkey, const char *text, FFont *font, PalEntry color1, PalEntry color2, FName command, int param) { - auto c = PClass::FindClass("ListMenuItemText"); + auto c = PClass::FindClass("ListMenuItemTextItem"); auto p = c->CreateNew(); VMValue params[] = { p, x, y, height, hotkey, text, font, int(color1.d), int(color2.d), command.GetIndex(), param }; auto f = dyn_cast(c->Symbols.FindSymbol("InitDirect", false)); @@ -1314,7 +1311,7 @@ void DMenuItemBase::Ticker() void DMenuItemBase::Drawer(bool selected) { - IFVIRTUAL(DMenuItemBase, Ticker) + IFVIRTUAL(DMenuItemBase, Drawer) { VMValue params[] = { (DObject*)this, selected }; GlobalVMStack.Call(func, params, countof(params), nullptr, 0, nullptr); diff --git a/src/menu/menudef.cpp b/src/menu/menudef.cpp index fe0314c1b..aec60af91 100644 --- a/src/menu/menudef.cpp +++ b/src/menu/menudef.cpp @@ -384,12 +384,12 @@ static void ParseListMenuBody(FScanner &sc, DListMenuDescriptor *desc) } auto TypeCVar = NewPointer(NewNativeStruct("CVar", nullptr)); - for (unsigned i = 1; i < args.Size(); i++) + for (unsigned i = start; i < args.Size(); i++) { sc.MustGetString(); if (args[i] == TypeString) { - params.Push(sc.String); + params.Push(FString(sc.String)); } else if (args[i] == TypeName) { @@ -401,7 +401,21 @@ static void ParseListMenuBody(FScanner &sc, DListMenuDescriptor *desc) } else if (args[i] == TypeFont) { - params.Push(FFont::FindFont(sc.String)); + auto f = FFont::FindFont(sc.String); + if (f == nullptr) + { + sc.ScriptError("Unknown font %s", sc.String); + } + params.Push(f); + } + else if (args[i] == TypeTextureID) + { + auto f = TexMan.CheckForTexture(sc.String, FTexture::TEX_MiscPatch); + if (!f.isValid()) + { + sc.ScriptError("Unknown texture %s", sc.String); + } + params.Push(f.GetIndex()); } else if (args[i]->IsKindOf(RUNTIME_CLASS(PInt))) { @@ -459,12 +473,11 @@ static void ParseListMenuBody(FScanner &sc, DListMenuDescriptor *desc) break; } } - /* DMenuItemBase *item = (DMenuItemBase*)cls->CreateNew(); params[0] = item; GlobalVMStack.Call(func->Variants[0].Implementation, ¶ms[0], params.Size(), nullptr, 0); desc->mItems.Push((DMenuItemBase*)item); - */ + if (cls->IsDescendantOf("ListMenuItemSelectable")) { desc->mYpos += desc->mLinespacing; @@ -477,11 +490,6 @@ static void ParseListMenuBody(FScanner &sc, DListMenuDescriptor *desc) { sc.ScriptError("Unknown keyword '%s'", sc.String); } - - } - - { - sc.ScriptError("Unknown keyword '%s'", sc.String); } } for (auto &p : desc->mItems) @@ -664,21 +672,6 @@ static void ParseOptionSettings(FScanner &sc) // //============================================================================= -static EColorRange ParseOptionColor(FScanner &sc, DOptionMenuDescriptor *desc) -{ - EColorRange cr = OptionSettings.mFontColor; - if (sc.CheckString(",")) - { - sc.MustGetString(); - cr = V_FindFontColor(sc.String); - if (cr == CR_UNTRANSLATED && !sc.Compare("untranslated") && isdigit(sc.String[0])) - { - if (strtoll(sc.String, nullptr, 0)) cr = OptionSettings.mFontColorHeader; - } - } - return cr; -} - static void ParseOptionMenuBody(FScanner &sc, DOptionMenuDescriptor *desc) { sc.MustGetStringName("{"); @@ -745,7 +738,6 @@ static void ParseOptionMenuBody(FScanner &sc, DOptionMenuDescriptor *desc) bool success = false; FStringf buildname("OptionMenuItem%s", sc.String); // Handle one special case: MapControl maps to Control with one parameter different - FKeyBindings *bind = sc.Compare("MapControl") ? &AutomapBindings : &Bindings; PClass *cls = PClass::FindClass(buildname); if (cls != nullptr && cls->IsDescendantOf("OptionMenuItem")) { @@ -757,13 +749,12 @@ static void ParseOptionMenuBody(FScanner &sc, DOptionMenuDescriptor *desc) params.Push(0); auto TypeCVar = NewPointer(NewNativeStruct("CVar", nullptr)); - auto TypeBind = NewPointer(NewNativeStruct("KeyBindings", nullptr)); for (unsigned i = 1; i < args.Size(); i++) { sc.MustGetString(); if (args[i] == TypeString) { - params.Push(sc.String); + params.Push(FString(sc.String)); } else if (args[i] == TypeName) { @@ -786,6 +777,8 @@ static void ParseOptionMenuBody(FScanner &sc, DOptionMenuDescriptor *desc) // todo: check other data types that may get used. sc.ScriptError("Integer expected, got %s", sc.String); } + // Color ranges need to be marked for option menu items to support an older feature where a boolean number could be passed instead. + v |= 0x12340000; } if (args[i] == TypeBool) v = !!v; params.Push(v); @@ -822,12 +815,6 @@ static void ParseOptionMenuBody(FScanner &sc, DOptionMenuDescriptor *desc) } else { - if (args[i + 1] == TypeBind) - { - // Bindings are not parsed, they just get tacked on. - params.Push(bind); - i++; - } if (i < args.Size() - 1 && !(func->Variants[0].ArgFlags[i + 1] & VARF_Optional)) { sc.ScriptError("Insufficient parameters for %s", cls->TypeName.GetChars()); @@ -835,12 +822,12 @@ static void ParseOptionMenuBody(FScanner &sc, DOptionMenuDescriptor *desc) break; } } - /* + DMenuItemBase *item = (DMenuItemBase*)cls->CreateNew(); params[0] = item; GlobalVMStack.Call(func->Variants[0].Implementation, ¶ms[0], params.Size(), nullptr, 0); desc->mItems.Push((DMenuItemBase*)item); - */ + success = true; } } diff --git a/src/menu/playerdisplay.cpp b/src/menu/playerdisplay.cpp deleted file mode 100644 index e69de29bb..000000000 diff --git a/src/scripting/thingdef_data.cpp b/src/scripting/thingdef_data.cpp index c736b5487..1aa35895d 100644 --- a/src/scripting/thingdef_data.cpp +++ b/src/scripting/thingdef_data.cpp @@ -55,6 +55,7 @@ #include "r_sky.h" #include "v_font.h" #include "v_video.h" +#include "c_bind.h" #include "menu/menu.h" static TArray properties; @@ -797,6 +798,12 @@ void InitThingdef() PField *plrclsf = new PField("PlayerClasses", plrcls, VARF_Native | VARF_Static | VARF_ReadOnly, (intptr_t)&PlayerClasses); Namespaces.GlobalNamespace->Symbols.AddSymbol(plrclsf); + auto bindcls = NewNativeStruct("KeyBindings", nullptr); + PField *binding = new PField("Bindings", bindcls, VARF_Native | VARF_Static, (intptr_t)&Bindings); + Namespaces.GlobalNamespace->Symbols.AddSymbol(binding); + binding = new PField("AutomapBindings", bindcls, VARF_Native | VARF_Static, (intptr_t)&AutomapBindings); + Namespaces.GlobalNamespace->Symbols.AddSymbol(binding); + // set up a variable for the DEH data PStruct *dstruct = NewNativeStruct("DehInfo", nullptr); PField *dehf = new PField("deh", dstruct, VARF_Native | VARF_Static, (intptr_t)&deh); diff --git a/wadsrc/static/zscript/menu/listmenuitems.txt b/wadsrc/static/zscript/menu/listmenuitems.txt index eae172e73..8920e617b 100644 --- a/wadsrc/static/zscript/menu/listmenuitems.txt +++ b/wadsrc/static/zscript/menu/listmenuitems.txt @@ -98,7 +98,7 @@ class ListMenuItemStaticPatch : ListMenuItem } } -class ListMenuItemStatucPatchCentered : ListMenuItemStaticPatch +class ListMenuItemStaticPatchCentered : ListMenuItemStaticPatch { void Init(int x, int y, TextureID patch) { @@ -119,7 +119,16 @@ class ListMenuItemStaticText : ListMenuItem int mColor; bool mCentered; - void Init(int x, int y, String text, Font font, int color, bool centered = false) + void Init(ListMenuDescriptor desc, int x, int y, String text, int color = Font.CR_UNTRANSLATED) + { + Super.Init(x, y); + mText = text; + mFont = desc.mFont; + mColor = color >= 0? color : desc.mFontColor; + mCentered = false; + } + + void InitDirect(int x, int y, String text, Font font, int color = Font.CR_UNTRANSLATED, bool centered = false) { Super.Init(x, y); mText = text; @@ -149,11 +158,12 @@ class ListMenuItemStaticText : ListMenuItem } } -class ListMenuItemStatucTextCentered : ListMenuItemStaticText +class ListMenuItemStaticTextCentered : ListMenuItemStaticText { - void Init(int x, int y, String text, Font font, int color) + void Init(ListMenuDescriptor desc, int x, int y, String text, int color = -1) { - Super.Init(x, y, text, font, color, true); + Super.Init(desc, x, y, text, color); + mCentered = true; } } @@ -237,7 +247,7 @@ class ListMenuItemTextItem : ListMenuItemSelectable mFont = desc.mFont; mColor = desc.mFontColor; mColorSelected = desc.mFontcolor2; - mHotkey = hotkey.CharAt(0); + mHotkey = hotkey.CharCodeAt(0); } void InitDirect(int x, int y, int height, String hotkey, String text, Font font, int color, int color2, Name child, int param = 0) @@ -247,7 +257,7 @@ class ListMenuItemTextItem : ListMenuItemSelectable mFont = font; mColor = color; mColorSelected = color2; - mHotkey = hotkey.CharAt(0); + mHotkey = hotkey.CharCodeAt(0); } override void Drawer(bool selected) @@ -274,14 +284,14 @@ class ListMenuItemPatchItem : ListMenuItemSelectable void Init(ListMenuDescriptor desc, TextureID patch, String hotkey, Name child, int param = 0) { Super.Init(desc.mXpos, desc.mYpos, desc.mLinespacing, child, param); - mHotkey = hotkey.CharAt(0); + mHotkey = hotkey.CharCodeAt(0); mTexture = patch; } void InitDirect(int x, int y, int height, TextureID patch, String hotkey, Name child, int param = 0) { Super.Init(x, y, height, child, param); - mHotkey = hotkey.CharAt(0); + mHotkey = hotkey.CharCodeAt(0); mTexture = patch; } diff --git a/wadsrc/static/zscript/menu/menuitembase.txt b/wadsrc/static/zscript/menu/menuitembase.txt index cdc67b611..de5f05a42 100644 --- a/wadsrc/static/zscript/menu/menuitembase.txt +++ b/wadsrc/static/zscript/menu/menuitembase.txt @@ -33,6 +33,7 @@ class MenuItemBase : Object native virtual bool MouseEvent(int type, int x, int y) { return false; } virtual bool CheckHotkey(int c) { return false; } virtual int GetWidth() { return 0; } + virtual int GetIndent() { return 0; } virtual int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected) { return indent; } void OffsetPositionY(int ydelta) { mYpos += ydelta; } @@ -41,3 +42,8 @@ class MenuItemBase : Object native void SetX(int x) { mXpos = x; } } +// this is only used to parse font color ranges in MENUDEF +enum MenudefColorRange +{ + NO_COLOR = -1 +} \ No newline at end of file diff --git a/wadsrc/static/zscript/menu/optionmenuitems.txt b/wadsrc/static/zscript/menu/optionmenuitems.txt index c3e6e0bd1..89cdbdd3c 100644 --- a/wadsrc/static/zscript/menu/optionmenuitems.txt +++ b/wadsrc/static/zscript/menu/optionmenuitems.txt @@ -32,11 +32,10 @@ ** */ -class OptionMenuItem : MenuItemBase native +class OptionMenuItem : MenuItemBase { - - native String mLabel; - native bool mCentered; + String mLabel; + bool mCentered; void Init(String label, String command, bool center = false) { @@ -67,7 +66,7 @@ class OptionMenuItem : MenuItemBase native return true; } - virtual int GetIndent() + override int GetIndent() { if (mCentered) return 0; return SmallFont.StringWidth(Stringtable.Localize(mLabel)); @@ -145,7 +144,7 @@ class OptionMenuItemSafeCommand : OptionMenuItemCommand String mPrompt; - void Init(String label, Name command, String prompt) + void Init(String label, Name command, String prompt = "") { Super.Init(label, command); mPrompt = prompt; @@ -420,7 +419,7 @@ IMPLEMENT_CLASS(DEnterKey, true, false) // //============================================================================= -class OptionMenuItemControl : OptionMenuItem +class OptionMenuItemControlBase : OptionMenuItem { KeyBindings mBindings; int mInput; @@ -487,6 +486,22 @@ class OptionMenuItemControl : OptionMenuItem } } +class OptionMenuItemControl : OptionMenuItemControlBase +{ + void Init(String label, Name command) + { + Super.Init(label, command, Bindings); + } +} + +class OptionMenuItemMapControl : OptionMenuItemControlBase +{ + void Init(String label, Name command) + { + Super.Init(label, command, AutomapBindings); + } +} + //============================================================================= // // @@ -497,10 +512,19 @@ class OptionMenuItemStaticText : OptionMenuItem { int mColor; - void Init(String label, int cr = -1, bool header = false) + // this function is only for use from MENUDEF, it needs to do some strange things with the color for backwards compatibility. + void Init(String label, int cr = -1) { Super.Init(label, 'None', true); - mColor = cr >= 0? cr : header ? OptionMenuSettings.mFontColorHeader : OptionMenuSettings.mFontColor; + mColor = OptionMenuSettings.mFontColor; + if ((cr & 0xffff0000) == 0x12340000) mColor = cr & 0xffff; + else if (cr > 0) mColor = OptionMenuSettings.mFontColorHeader; + } + + void InitDirect(String label, int cr) + { + Super.Init(label, 'None', true); + mColor = cr; } override int Draw(OptionMenuDescriptor desc, int y, int indent, bool selected) @@ -528,7 +552,19 @@ class OptionMenuItemStaticTextSwitchable : OptionMenuItem String mAltText; int mCurrent; - void Init(String label, String label2, Name command, int cr) + // this function is only for use from MENUDEF, it needs to do some strange things with the color for backwards compatibility. + void Init(String label, String label2, Name command, int cr = -1) + { + Super.Init(label, command, true); + mAltText = label2; + mCurrent = 0; + + mColor = OptionMenuSettings.mFontColor; + if ((cr & 0xffff0000) == 0x12340000) mColor = cr & 0xffff; + else if (cr > 0) mColor = OptionMenuSettings.mFontColorHeader; + } + + void InitDirect(String label, String label2, Name command, int cr) { Super.Init(label, command, true); mColor = cr; diff --git a/wadsrc/static/zscript/menu/playerdisplay.txt b/wadsrc/static/zscript/menu/playerdisplay.txt index 18d81bb19..e13e9fb54 100644 --- a/wadsrc/static/zscript/menu/playerdisplay.txt +++ b/wadsrc/static/zscript/menu/playerdisplay.txt @@ -68,7 +68,7 @@ class ListMenuItemPlayerDisplay : ListMenuItem // // //============================================================================= - void Init(ListMenuDescriptor menu, Name command, int x, int y, Color c1, Color c2, bool np = false) + void Init(ListMenuDescriptor menu, int x, int y, Color c1, Color c2, bool np = false, Name command = 'None' ) { Super.Init(x, y, command); mOwner = menu; diff --git a/wadsrc/static/zscript/menu/playermenu.txt b/wadsrc/static/zscript/menu/playermenu.txt index 9a21530d6..6b055e0a0 100644 --- a/wadsrc/static/zscript/menu/playermenu.txt +++ b/wadsrc/static/zscript/menu/playermenu.txt @@ -59,8 +59,8 @@ class ListMenuItemPlayerNameBox : ListMenuItemSelectable { Super.Init(desc.mXpos, desc.mYpos, desc.mLinespacing, command); mText = text; - mFont = font; - mFontColor = color; + mFont = desc.mFont; + mFontColor = desc.mFontColor; mFrameSize = frameofs; mPlayerName = ""; mEntering = false; @@ -72,7 +72,7 @@ class ListMenuItemPlayerNameBox : ListMenuItemSelectable // //============================================================================= - void Init(int x, int y, int height, int frameofs, String text, Font font, int color, Name command) + void InitDirect(int x, int y, int height, int frameofs, String text, Font font, int color, Name command) { Super.Init(x, y, height, command); mText = text; @@ -371,7 +371,7 @@ class ListMenuItemSlider : ListMenuItemSelectable // //============================================================================= - void Init(ListMenuItemDescriptor desc, String text, Name command, int min, int max, int step) + void Init(ListMenuDescriptor desc, String text, Name command, int min, int max, int step) { Super.Init(desc.mXpos, desc.mYpos, desc.mLinespacing, command); mText = text;