- the keybinding control works again, this time fully scripted.

This commit is contained in:
Christoph Oelckers 2017-02-12 18:38:23 +01:00
commit dbf3530696
19 changed files with 161 additions and 162 deletions

View file

@ -282,6 +282,7 @@ void C_NameKeys (char *str, int first, int second)
int c = 0;
*str = 0;
if (second == first) second = 0;
if (first)
{
c++;
@ -478,7 +479,7 @@ DEFINE_ACTION_FUNCTION(FKeyBindings, GetKeysForCommand)
int k1, k2, c;
self->GetKeysForCommand(cmd.GetChars(), &k1, &k2);
if (numret > 0) ret[0].SetInt(k1);
if (numret > 1) ret[1].SetInt(k1);
if (numret > 1) ret[1].SetInt(k2);
return MIN(numret, 2);
}

View file

@ -2830,3 +2830,10 @@ void FStartupScreen::NetMessage(char const *,...) {}
void FStartupScreen::NetDone(void) {}
bool FStartupScreen::NetLoop(bool (*)(void *),void *) { return false; }
DEFINE_FIELD_X(InputEvent, event_t, type)
DEFINE_FIELD_X(InputEvent, event_t, subtype)
DEFINE_FIELD_X(InputEvent, event_t, data1)
DEFINE_FIELD_X(InputEvent, event_t, data2)
DEFINE_FIELD_X(InputEvent, event_t, data3)
DEFINE_FIELD_X(InputEvent, event_t, x)
DEFINE_FIELD_X(InputEvent, event_t, y)

View file

@ -204,6 +204,7 @@ enum EObjectFlags
OF_Sentinel = 1 << 10, // Object is serving as the sentinel in a ring list
OF_Transient = 1 << 11, // Object should not be archived (references to it will be nulled on disk)
OF_Released = 1 << 12, // Object was released from the GC system and should not be processed by GC function
OF_Abstract = 1 << 13, // Marks a class that cannot be created with CreateNew
};
template<class T> class TObjPtr;

View file

@ -101,7 +101,7 @@ EXTERN_CVAR (Float, snd_musicvolume) // maximum volume for music
// Status flags for refresh.
//
enum EMenuState
enum EMenuState : int
{
MENU_Off, // Menu is closed
MENU_On, // Menu is opened

View file

@ -48,9 +48,6 @@
#include "d_event.h"
#include "d_gui.h"
#define NO_IMP
#include "menu/optionmenuitems.h"
class DColorPickerMenu : public DOptionMenu
{
DECLARE_CLASS(DColorPickerMenu, DOptionMenu)

View file

@ -51,10 +51,6 @@
#include "i_music.h"
#include "m_joy.h"
#define NO_IMP
#include "optionmenuitems.h"
static TArray<IJoystickConfig *> Joysticks;
IJoystickConfig *SELECTED_JOYSTICK;

View file

@ -191,6 +191,26 @@ bool DMenu::Responder (event_t *ev)
return false;
}
DEFINE_ACTION_FUNCTION(DMenu, Responder)
{
PARAM_SELF_PROLOGUE(DMenu);
PARAM_POINTER(ev, event_t);
ACTION_RETURN_BOOL(self->Responder(ev));
}
bool DMenu::CallResponder(event_t *ev)
{
IFVIRTUAL(DMenu, Responder)
{
VMValue params[] = { (DObject*)this, ev};
int retval;
VMReturn ret(&retval);
GlobalVMStack.Call(func, params, 2, &ret, 1, nullptr);
return !!retval;
}
else return Responder(ev);
}
//=============================================================================
//
//
@ -386,6 +406,20 @@ void DMenu::CallDrawer()
else Drawer();
}
DEFINE_ACTION_FUNCTION(DMenu, Close)
{
PARAM_SELF_PROLOGUE(DMenu);
self->Close();
return 0;
}
DEFINE_ACTION_FUNCTION(DMenu, GetItem)
{
PARAM_SELF_PROLOGUE(DMenu);
PARAM_NAME(name);
ACTION_RETURN_POINTER(self->GetItem(name));
}
bool DMenu::DimAllowed()
@ -395,6 +429,14 @@ bool DMenu::DimAllowed()
bool DMenu::TranslateKeyboardEvents()
{
IFVIRTUAL(DMenu, TranslateKeyboardEvents)
{
VMValue params[] = { (DObject*)this };
int retval;
VMReturn ret(&retval);
GlobalVMStack.Call(func, params, countof(params), &ret, 1, nullptr);
return !!retval;
}
return true;
}
@ -444,6 +486,13 @@ void M_ActivateMenu(DMenu *menu)
GC::WriteBarrier(DMenu::CurrentMenu);
}
DEFINE_ACTION_FUNCTION(DMenu, ActivateMenu)
{
PARAM_SELF_PROLOGUE(DMenu);
M_ActivateMenu(self);
return 0;
}
//=============================================================================
//
//
@ -631,7 +680,7 @@ bool M_Responder (event_t *ev)
}
// pass everything else on to the current menu
return DMenu::CurrentMenu->Responder(ev);
return DMenu::CurrentMenu->CallResponder(ev);
}
else if (DMenu::CurrentMenu->TranslateKeyboardEvents())
{
@ -652,7 +701,7 @@ bool M_Responder (event_t *ev)
default:
if (!keyup)
{
return DMenu::CurrentMenu->Responder(ev);
return DMenu::CurrentMenu->CallResponder(ev);
}
break;
}
@ -739,7 +788,7 @@ bool M_Responder (event_t *ev)
return true;
}
}
return DMenu::CurrentMenu->Responder(ev) || !keyup;
return DMenu::CurrentMenu->CallResponder(ev) || !keyup;
}
else if (MenuEnabled)
{
@ -1094,6 +1143,8 @@ CCMD(reset2saved)
//native void OptionMenuDescriptor.CalcIndent();
//native OptionMenuItem OptionMenuDescriptor.GetItem(Name iname);
DEFINE_FIELD(DMenu, mParentMenu)
DEFINE_FIELD(DMenuDescriptor, mMenuName)
DEFINE_FIELD(DMenuDescriptor, mNetgameMessage)
DEFINE_FIELD(DMenuDescriptor, mClass)

View file

@ -269,7 +269,7 @@ public:
virtual void Ticker ();
virtual void Drawer ();
virtual bool DimAllowed ();
virtual bool TranslateKeyboardEvents();
/*virtual */bool TranslateKeyboardEvents();
virtual void Close();
virtual bool MouseEvent(int type, int x, int y);
@ -277,7 +277,9 @@ public:
virtual bool CheckFocus(DMenuItemBase *fc) { return false; }
virtual void ReleaseFocus() {}
virtual DMenuItemBase *GetItem(FName name) { return nullptr; }
bool CallResponder(event_t *ev);
bool CallMenuEvent(int mkey, bool fromcontroller);
bool CallMouseEvent(int type, int x, int y);
void CallDrawer();
@ -466,7 +468,7 @@ public:
void Drawer ();
bool MenuEvent (int mkey, bool fromcontroller);
bool Responder(event_t *ev);
bool TranslateKeyboardEvents();
//bool TranslateKeyboardEvents();
bool MouseEvent(int type, int x, int y);
};

View file

@ -52,8 +52,6 @@
#include "i_sound.h"
#include "cmdlib.h"
#include "optionmenuitems.h"
void ClearSaveGames();

View file

@ -96,10 +96,12 @@ DTextEnterMenu::DTextEnterMenu(DMenu *parent, char *textbuffer, int maxlen, int
//
//=============================================================================
/*
bool DTextEnterMenu::TranslateKeyboardEvents()
{
return mInputGridOkay;
}
*/
//=============================================================================
//

View file

@ -1,104 +0,0 @@
/*
** optionmenuitems.h
** Control items for option menus
**
**---------------------------------------------------------------------------
** Copyright 2010 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.
**---------------------------------------------------------------------------
**
*/
#include "v_text.h"
#include "gstrings.h"
void M_DrawConText (int color, int x, int y, const char *str);
void M_SetVideoMode();
//=============================================================================
//
// This class is used to capture the key to be used as the new key binding
// for a control item
//
//=============================================================================
class DEnterKey : public DMenu
{
DECLARE_CLASS(DEnterKey, DMenu)
int *pKey;
public:
DEnterKey(DMenu *parent, int *keyptr)
: DMenu(parent)
{
pKey = keyptr;
SetMenuMessage(1);
menuactive = MENU_WaitKey; // There should be a better way to disable GUI capture...
}
bool TranslateKeyboardEvents()
{
return false;
}
void SetMenuMessage(int which)
{
if (mParentMenu->IsKindOf(RUNTIME_CLASS(DOptionMenu)))
{
DOptionMenu *m = barrier_cast<DOptionMenu*>(mParentMenu);
DMenuItemBase *it = m->GetItem(NAME_Controlmessage);
if (it != NULL)
{
it->SetValue(0, which);
}
}
}
bool Responder(event_t *ev)
{
if (ev->type == EV_KeyDown)
{
*pKey = ev->data1;
menuactive = MENU_On;
SetMenuMessage(0);
Close();
mParentMenu->CallMenuEvent((ev->data1 == KEY_ESCAPE)? MKEY_Abort : MKEY_Input, 0);
return true;
}
return false;
}
void Drawer()
{
mParentMenu->CallDrawer();
}
};
#ifndef NO_IMP
IMPLEMENT_CLASS(DEnterKey, true, false)
#endif

View file

@ -54,10 +54,6 @@
#include "sbar.h"
#include "hardware.h"
#define NO_IMP
#include "optionmenuitems.h"
/*=======================================
*
* Video Modes Menu

View file

@ -5069,7 +5069,6 @@ FxExpression *FxNew::Resolve(FCompileContext &ctx)
ExpEmit FxNew::Emit(VMFunctionBuilder *build)
{
assert(ValueType == val->ValueType);
ExpEmit from = val->Emit(build);
from.Free(build);
ExpEmit to(build, REGT_POINTER);
@ -10167,6 +10166,8 @@ FxExpression *FxClassTypeCast::Resolve(FCompileContext &ctx)
ScriptPosition.Message(MSG_OPTERROR,
"Unknown class name '%s' of type '%s'",
clsname.GetChars(), desttype->TypeName.GetChars());
delete this;
return nullptr;
}
else
{

View file

@ -882,6 +882,9 @@ void InitThingdef()
fieldptr = new PField("CleanHeight_1", TypeSInt32, VARF_Native | VARF_Static | VARF_ReadOnly, (intptr_t)&CleanHeight_1);
Namespaces.GlobalNamespace->Symbols.AddSymbol(fieldptr);
fieldptr = new PField("menuactive", TypeSInt32, VARF_Native | VARF_Static, (intptr_t)&menuactive);
Namespaces.GlobalNamespace->Symbols.AddSymbol(fieldptr);
fieldptr = new PField("OptionMenuSettings", NewStruct("FOptionMenuSettings", nullptr), VARF_Native | VARF_Static | VARF_ReadOnly, (intptr_t)&OptionSettings);
Namespaces.GlobalNamespace->Symbols.AddSymbol(fieldptr);

View file

@ -785,8 +785,11 @@ begin:
OP(NEW_K):
OP(NEW):
{
PClass *cls = (PClass*)(pc->op == OP_NEW ? reg.a[C] : konsta[C].v);
reg.a[B] = cls->CreateNew();
b = B;
PClass *cls = (PClass*)(pc->op == OP_NEW ? reg.a[b] : konsta[b].v);
if (cls->ObjectFlags & OF_Abstract) ThrowAbortException(X_OTHER, "Cannot instantiate abstract class %s", cls->TypeName.GetChars());
reg.a[a] = cls->CreateNew();
reg.atag[a] = ATAG_OBJECT;
NEXTOP;
}

View file

@ -597,6 +597,10 @@ void ZCCCompiler::CreateClassTypes()
c->cls->Type = nullptr;
}
}
if (c->cls->Flags & ZCC_Abstract)
{
c->Type()->ObjectFlags |= OF_Abstract;
}
if (c->Type() == nullptr) c->cls->Type = parent->FindClassTentative(c->NodeName());
c->Type()->bExported = true; // this class is accessible to script side type casts. (The reason for this flag is that types like PInt need to be skipped.)
c->cls->Symbol = new PSymbolType(c->NodeName(), c->Type());