added missing button implementation for MessageBox

actorid
Marc Zinnschlag 15 years ago
parent 72cc0a3983
commit 276a9db6f7

@ -196,7 +196,7 @@ namespace MWGui
Compiler::Locals locals; Compiler::Locals locals;
Compiler::Output output (locals); Compiler::Output output (locals);
if (compile (cm, output)) if (compile (cm + "\n", output))
{ {
try try
{ {
@ -216,4 +216,3 @@ namespace MWGui
command->setCaption(""); command->setCaption("");
} }
} }

@ -505,8 +505,6 @@ namespace Compiler
void message (CodeContainer& code, Literals& literals, const std::string& message, void message (CodeContainer& code, Literals& literals, const std::string& message,
int buttons) int buttons)
{ {
assert (buttons==0);
int index = literals.addString (message); int index = literals.addString (message);
opPushInt (code, index); opPushInt (code, index);
@ -773,4 +771,3 @@ namespace Compiler
} }
} }
} }

@ -168,13 +168,19 @@ namespace Compiler
mExprParser.parseArguments (arguments, scanner, mCode, true); mExprParser.parseArguments (arguments, scanner, mCode, true);
} }
// for now skip buttons mName = name;
SkipParser skip (getErrorHandler(), getContext()); mButtons = 0;
scanner.scan (skip);
Generator::message (mCode, mLiterals, name, 0); mState = MessageButtonState;
mState = EndState; return true;
return false; }
if (mState==MessageButtonState || mState==MessageButtonCommaState)
{
Generator::pushString (mCode, mLiterals, name);
mState = MessageButtonState;
++mButtons;
return true;
} }
if (mState==BeginState && mAllowExpression) if (mState==BeginState && mAllowExpression)
@ -360,6 +366,18 @@ namespace Compiler
return true; return true;
} }
if (code==Scanner::S_newline && mState==MessageButtonState)
{
Generator::message (mCode, mLiterals, mName, mButtons);
return false;
}
if (code==Scanner::S_comma && mState==MessageButtonState)
{
mState = MessageButtonCommaState;
return true;
}
if (mAllowExpression && mState==BeginState && if (mAllowExpression && mState==BeginState &&
(code==Scanner::S_open || code==Scanner::S_minus)) (code==Scanner::S_open || code==Scanner::S_minus))
{ {
@ -378,4 +396,3 @@ namespace Compiler
mExplicit.clear(); mExplicit.clear();
} }
} }

@ -22,7 +22,7 @@ namespace Compiler
BeginState, BeginState,
ShortState, LongState, FloatState, ShortState, LongState, FloatState,
SetState, SetLocalVarState, SetGlobalVarState, SetState, SetLocalVarState, SetGlobalVarState,
MessageState, MessageCommaState, MessageState, MessageCommaState, MessageButtonState, MessageButtonCommaState,
EndState, EndState,
PotentialExplicitState, ExplicitState PotentialExplicitState, ExplicitState
}; };
@ -32,6 +32,7 @@ namespace Compiler
std::vector<Interpreter::Type_Code>& mCode; std::vector<Interpreter::Type_Code>& mCode;
State mState; State mState;
std::string mName; std::string mName;
int mButtons;
std::string mExplicit; std::string mExplicit;
char mType; char mType;
ExprParser mExprParser; ExprParser mExprParser;

@ -6,6 +6,7 @@
#include <vector> #include <vector>
#include <string> #include <string>
#include <sstream> #include <sstream>
#include <algorithm>
#include "opcodes.hpp" #include "opcodes.hpp"
#include "runtime.hpp" #include "runtime.hpp"
@ -18,8 +19,17 @@ namespace Interpreter
virtual void execute (Runtime& runtime, unsigned int arg0) virtual void execute (Runtime& runtime, unsigned int arg0)
{ {
if (arg0!=0) // buttons
throw std::logic_error ("message box buttons not implemented yet"); std::vector<std::string> buttons;
for (std::size_t i=0; i<arg0; ++i)
{
int index = runtime[0].mInteger;
runtime.pop();
buttons.push_back (runtime.getStringLiteral (index));
}
std::reverse (buttons.begin(), buttons.end());
// message // message
int index = runtime[0].mInteger; int index = runtime[0].mInteger;
@ -82,9 +92,6 @@ namespace Interpreter
} }
} }
// buttons (not implemented)
std::vector<std::string> buttons;
runtime.getContext().messageBox (formattedMessage, buttons); runtime.getContext().messageBox (formattedMessage, buttons);
} }
}; };
@ -206,4 +213,3 @@ namespace Interpreter
} }
#endif #endif

Loading…
Cancel
Save