forked from teamnwah/openmw-tes3coop
Implemented all MW window layouts
parent
3896fd218a
commit
b2d54a619e
@ -0,0 +1,125 @@
|
|||||||
|
#ifndef ENGINE_MYGUI_LAYOUT_H
|
||||||
|
#define ENGINE_MYGUI_LAYOUT_H
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <MyGUI.h>
|
||||||
|
|
||||||
|
namespace GUI
|
||||||
|
{
|
||||||
|
/** The Layout class is an utility class used to load MyGUI layouts
|
||||||
|
from xml files, and to manipulate member widgets.
|
||||||
|
*/
|
||||||
|
class Layout
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
Layout(const std::string & _layout, MyGUI::WidgetPtr _parent = nullptr)
|
||||||
|
: mMainWidget(nullptr)
|
||||||
|
{ initialise(_layout, _parent); }
|
||||||
|
virtual ~Layout() { shutdown(); }
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void getWidget(T * & _widget, const std::string & _name, bool _throw = true)
|
||||||
|
{
|
||||||
|
_widget = nullptr;
|
||||||
|
for (MyGUI::VectorWidgetPtr::iterator iter=mListWindowRoot.begin();
|
||||||
|
iter!=mListWindowRoot.end(); ++iter)
|
||||||
|
{
|
||||||
|
MyGUI::WidgetPtr find = (*iter)->findWidget(mPrefix + _name);
|
||||||
|
if (nullptr != find)
|
||||||
|
{
|
||||||
|
T * cast = find->castType<T>(false);
|
||||||
|
if (nullptr != cast)
|
||||||
|
_widget = cast;
|
||||||
|
else if (_throw)
|
||||||
|
{
|
||||||
|
MYGUI_EXCEPT("Error cast : dest type = '" << T::getClassTypeName()
|
||||||
|
<< "' source name = '" << find->getName()
|
||||||
|
<< "' source type = '" << find->getTypeName() << "' in layout '" << mLayoutName << "'");
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MYGUI_ASSERT( ! _throw, "widget name '" << _name << "' in layout '" << mLayoutName << "' not found.");
|
||||||
|
}
|
||||||
|
|
||||||
|
void initialise(const std::string & _layout,
|
||||||
|
MyGUI::WidgetPtr _parent = nullptr)
|
||||||
|
{
|
||||||
|
const std::string MAIN_WINDOW = "_Main";
|
||||||
|
mLayoutName = _layout;
|
||||||
|
|
||||||
|
if (mLayoutName.empty())
|
||||||
|
mMainWidget = _parent;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mPrefix = MyGUI::utility::toString(this, "_");
|
||||||
|
mListWindowRoot = MyGUI::LayoutManager::getInstance().loadLayout(mLayoutName, mPrefix, _parent);
|
||||||
|
|
||||||
|
const std::string main_name = mPrefix + MAIN_WINDOW;
|
||||||
|
for (MyGUI::VectorWidgetPtr::iterator iter=mListWindowRoot.begin(); iter!=mListWindowRoot.end(); ++iter)
|
||||||
|
{
|
||||||
|
if ((*iter)->getName() == main_name)
|
||||||
|
{
|
||||||
|
mMainWidget = (*iter);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
MYGUI_ASSERT(mMainWidget, "root widget name '" << MAIN_WINDOW << "' in layout '" << mLayoutName << "' not found.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void shutdown()
|
||||||
|
{
|
||||||
|
for (VectorBasePtr::iterator iter=mListBase.begin(); iter!=mListBase.end(); ++iter) {
|
||||||
|
delete (*iter);
|
||||||
|
}
|
||||||
|
mListBase.clear();
|
||||||
|
|
||||||
|
MyGUI::LayoutManager::getInstance().unloadLayout(mListWindowRoot);
|
||||||
|
mListWindowRoot.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
void setCoord(int x, int y, int w, int h)
|
||||||
|
{
|
||||||
|
mMainWidget->setCoord(x,y,w,h);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setVisible(bool b)
|
||||||
|
{
|
||||||
|
mMainWidget->setVisible(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setText(const std::string& name, const std::string& caption)
|
||||||
|
{
|
||||||
|
MyGUI::WidgetPtr pt;
|
||||||
|
getWidget(pt, name);
|
||||||
|
pt->setCaption(caption);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setTextColor(const std::string& name, float r, float g, float b)
|
||||||
|
{
|
||||||
|
MyGUI::WidgetPtr pt;
|
||||||
|
getWidget(pt, name);
|
||||||
|
MyGUI::StaticText *st = dynamic_cast<MyGUI::StaticText*>(pt);
|
||||||
|
if(st != NULL)
|
||||||
|
st->setTextColour(MyGUI::Colour(b,g,r));
|
||||||
|
}
|
||||||
|
|
||||||
|
void setImage(const std::string& name, const std::string& imgName)
|
||||||
|
{
|
||||||
|
MyGUI::StaticImagePtr pt;
|
||||||
|
getWidget(pt, name);
|
||||||
|
pt->setImageTexture(imgName);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
MyGUI::WidgetPtr mMainWidget;
|
||||||
|
std::string mPrefix;
|
||||||
|
std::string mLayoutName;
|
||||||
|
MyGUI::VectorWidgetPtr mListWindowRoot;
|
||||||
|
typedef std::vector<Layout*> VectorBasePtr;
|
||||||
|
VectorBasePtr mListBase;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
@ -0,0 +1,58 @@
|
|||||||
|
#ifndef ENGINE_MYGUI_MANAGER_H
|
||||||
|
#define ENGINE_MYGUI_MANAGER_H
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <MyGUI.h>
|
||||||
|
#include <MyGUI_OgrePlatform.h>
|
||||||
|
|
||||||
|
namespace GUI
|
||||||
|
{
|
||||||
|
class MyGUIManager
|
||||||
|
{
|
||||||
|
MyGUI::OgrePlatform *mPlatform;
|
||||||
|
MyGUI::Gui *mGui;
|
||||||
|
|
||||||
|
public:
|
||||||
|
MyGUIManager() : mPlatform(NULL), mGui(NULL) {}
|
||||||
|
MyGUIManager(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool logging=false)
|
||||||
|
{ setup(wnd,mgr,logging); }
|
||||||
|
~MyGUIManager() { shutdown(); }
|
||||||
|
|
||||||
|
void setup(Ogre::RenderWindow *wnd, Ogre::SceneManager *mgr, bool logging=false)
|
||||||
|
{
|
||||||
|
assert(wnd);
|
||||||
|
assert(mgr);
|
||||||
|
|
||||||
|
using namespace MyGUI;
|
||||||
|
|
||||||
|
// Enable/disable MyGUI logging to stdout. (Logging to MyGUI.log
|
||||||
|
// is still enabled.) In order to do this we have to initialize
|
||||||
|
// the log manager before the main gui system itself, otherwise
|
||||||
|
// the main object will get the chance to spit out a few messages
|
||||||
|
// before we can able to disable it.
|
||||||
|
LogManager::initialise();
|
||||||
|
LogManager::setSTDOutputEnabled(logging);
|
||||||
|
|
||||||
|
// Set up OGRE platform. We might make this more generic later.
|
||||||
|
mPlatform = new OgrePlatform();
|
||||||
|
mPlatform->initialise(wnd, mgr);
|
||||||
|
|
||||||
|
// Create GUI
|
||||||
|
mGui = new Gui();
|
||||||
|
mGui->initialise();
|
||||||
|
}
|
||||||
|
|
||||||
|
void shutdown()
|
||||||
|
{
|
||||||
|
if(mGui) delete mGui;
|
||||||
|
if(mPlatform)
|
||||||
|
{
|
||||||
|
mPlatform->shutdown();
|
||||||
|
delete mPlatform;
|
||||||
|
}
|
||||||
|
mGui = NULL;
|
||||||
|
mPlatform = NULL;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
@ -0,0 +1,188 @@
|
|||||||
|
#ifndef MWGUI_LAYOUTS_H
|
||||||
|
#define MWGUI_LAYOUTS_H
|
||||||
|
|
||||||
|
#include "layout.hpp"
|
||||||
|
|
||||||
|
namespace MWGUI
|
||||||
|
{
|
||||||
|
class HUD : public GUI::Layout
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
HUD(int width, int height)
|
||||||
|
: Layout("openmw_hud_layout.xml")
|
||||||
|
{
|
||||||
|
setCoord(0,0, width, height);
|
||||||
|
|
||||||
|
// Energy bars
|
||||||
|
getWidget(health, "Health");
|
||||||
|
getWidget(magicka, "Magicka");
|
||||||
|
getWidget(stamina, "Stamina");
|
||||||
|
|
||||||
|
// Item and spell images and status bars
|
||||||
|
getWidget(weapImage, "WeapImage");
|
||||||
|
getWidget(weapStatus, "WeapStatus");
|
||||||
|
getWidget(spellImage, "SpellImage");
|
||||||
|
getWidget(spellStatus, "SpellStatus");
|
||||||
|
|
||||||
|
getWidget(effectBox, "EffectBox");
|
||||||
|
getWidget(effect1, "Effect1");
|
||||||
|
|
||||||
|
getWidget(minimap, "MiniMap");
|
||||||
|
getWidget(compass, "Compass");
|
||||||
|
|
||||||
|
getWidget(crosshair, "Crosshair");
|
||||||
|
|
||||||
|
compass->setImageTexture("compass.dds");
|
||||||
|
crosshair->setImageTexture("target.dds");
|
||||||
|
|
||||||
|
// These are just demo values, you should replace these with
|
||||||
|
// real calls from outside the class later.
|
||||||
|
setStats(60, 100,
|
||||||
|
30, 100,
|
||||||
|
80, 100);
|
||||||
|
setWeapIcon("icons\\w\\tx_knife_iron.dds");
|
||||||
|
setWeapStatus(90, 100);
|
||||||
|
setSpellIcon("icons\\s\\b_tx_s_rstor_health.dds");
|
||||||
|
setSpellStatus(65, 100);
|
||||||
|
setEffect("icons\\s\\tx_s_chameleon.dds");
|
||||||
|
}
|
||||||
|
|
||||||
|
void setStats(int h, int hmax, int m, int mmax, int s, int smax)
|
||||||
|
{
|
||||||
|
health->setProgressRange(hmax);
|
||||||
|
health->setProgressPosition(h);
|
||||||
|
magicka->setProgressRange(mmax);
|
||||||
|
magicka->setProgressPosition(m);
|
||||||
|
stamina->setProgressRange(smax);
|
||||||
|
stamina->setProgressPosition(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setWeapIcon(const char *str)
|
||||||
|
{ weapImage->setImageTexture(str); }
|
||||||
|
void setSpellIcon(const char *str)
|
||||||
|
{ spellImage->setImageTexture(str); }
|
||||||
|
|
||||||
|
void setWeapStatus(int s, int smax)
|
||||||
|
{
|
||||||
|
weapStatus->setProgressRange(smax);
|
||||||
|
weapStatus->setProgressPosition(s);
|
||||||
|
}
|
||||||
|
void setSpellStatus(int s, int smax)
|
||||||
|
{
|
||||||
|
spellStatus->setProgressRange(smax);
|
||||||
|
spellStatus->setProgressPosition(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
void setEffect(const char *img)
|
||||||
|
{ effect1->setImageTexture(img); }
|
||||||
|
|
||||||
|
MyGUI::ProgressPtr health, magicka, stamina;
|
||||||
|
|
||||||
|
MyGUI::StaticImagePtr weapImage, spellImage;
|
||||||
|
MyGUI::ProgressPtr weapStatus, spellStatus;
|
||||||
|
|
||||||
|
MyGUI::WidgetPtr effectBox;
|
||||||
|
MyGUI::StaticImagePtr effect1;
|
||||||
|
|
||||||
|
MyGUI::StaticImagePtr minimap;
|
||||||
|
MyGUI::StaticImagePtr compass;
|
||||||
|
|
||||||
|
MyGUI::StaticImagePtr crosshair;
|
||||||
|
};
|
||||||
|
|
||||||
|
class MapWindow : public GUI::Layout
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MapWindow()
|
||||||
|
: Layout("openmw_map_window_layout.xml")
|
||||||
|
{
|
||||||
|
setCoord(500,0,320,300);
|
||||||
|
setText("WorldButton", "World");
|
||||||
|
setImage("Compass", "compass.dds");
|
||||||
|
|
||||||
|
// Obviously you should override this later on
|
||||||
|
setCellName("No Cell Loaded");
|
||||||
|
}
|
||||||
|
|
||||||
|
void setCellName(const std::string& cellName)
|
||||||
|
{
|
||||||
|
mMainWidget->setCaption(cellName);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class MainMenu : public GUI::Layout
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
MainMenu(int w, int h)
|
||||||
|
: Layout("openmw_mainmenu_layout.xml")
|
||||||
|
{
|
||||||
|
setCoord(0,0,w,h);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
class StatsWindow : public GUI::Layout
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void setBar(const char* name, const char* tname, int val, int max)
|
||||||
|
{
|
||||||
|
MyGUI::ProgressPtr pt;
|
||||||
|
getWidget(pt, name);
|
||||||
|
pt->setProgressRange(max);
|
||||||
|
pt->setProgressPosition(val);
|
||||||
|
|
||||||
|
std::stringstream out;
|
||||||
|
out << val << "/" << max;
|
||||||
|
setText(tname, out.str().c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
StatsWindow()
|
||||||
|
: Layout("openmw_stats_window_layout.xml")
|
||||||
|
{
|
||||||
|
setCoord(0,0,498, 342);
|
||||||
|
|
||||||
|
setText("Health_str", "Health");
|
||||||
|
setText("Magicka_str", "Magicka");
|
||||||
|
setText("Fatigue_str", "Fatigue");
|
||||||
|
|
||||||
|
setText("Level_str", "Level");
|
||||||
|
setText("Race_str", "Race");
|
||||||
|
setText("Class_str", "Class");
|
||||||
|
|
||||||
|
setText("Attrib1", "Strength");
|
||||||
|
setText("Attrib2", "Intelligence");
|
||||||
|
setText("Attrib3", "Willpower");
|
||||||
|
setText("Attrib4", "Agility");
|
||||||
|
setText("Attrib5", "Speed");
|
||||||
|
setText("Attrib6", "Endurance");
|
||||||
|
setText("Attrib7", "Personality");
|
||||||
|
setText("Attrib8", "Luck");
|
||||||
|
|
||||||
|
// These are just demo values, you should replace these with
|
||||||
|
// real calls from outside the class later.
|
||||||
|
setPlayerName("ThePlayer");
|
||||||
|
|
||||||
|
setText("LevelText", "5");
|
||||||
|
setText("RaceText", "Wood Elf");
|
||||||
|
setText("ClassText", "Pilgrim");
|
||||||
|
|
||||||
|
setBar("HBar", "HBarT", 60, 100);
|
||||||
|
setBar("MBar", "MBarT", 30, 100);
|
||||||
|
setBar("FBar", "FBarT", 80, 100);
|
||||||
|
|
||||||
|
setText("AttribVal1", "30");
|
||||||
|
setText("AttribVal2", "40");
|
||||||
|
setText("AttribVal3", "30");
|
||||||
|
setText("AttribVal4", "75");
|
||||||
|
setText("AttribVal5", "50");
|
||||||
|
setText("AttribVal6", "40");
|
||||||
|
setText("AttribVal7", "50");
|
||||||
|
setText("AttribVal8", "40");
|
||||||
|
}
|
||||||
|
|
||||||
|
void setPlayerName(const std::string& playerName)
|
||||||
|
{
|
||||||
|
mMainWidget->setCaption(playerName);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
#endif
|
@ -1,62 +0,0 @@
|
|||||||
/*
|
|
||||||
OpenMW - The completely unofficial reimplementation of Morrowind
|
|
||||||
Copyright (C) 2008 Nicolay Korslund
|
|
||||||
Email: < korslund@gmail.com >
|
|
||||||
WWW: http://openmw.snaptoad.com/
|
|
||||||
|
|
||||||
This file (bindings.d) is part of the OpenMW package.
|
|
||||||
|
|
||||||
OpenMW is distributed as free software: you can redistribute it
|
|
||||||
and/or modify it under the terms of the GNU General Public License
|
|
||||||
version 3, as published by the Free Software Foundation.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, but
|
|
||||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
version 3 along with this program. If not, see
|
|
||||||
http://www.gnu.org/licenses/ .
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
module gui.bindings;
|
|
||||||
|
|
||||||
extern(C):
|
|
||||||
|
|
||||||
// GUI functions. Under development. The corresponding C++ functions
|
|
||||||
// are in cpp_mygui.cpp
|
|
||||||
|
|
||||||
typedef void* WidgetPtr;
|
|
||||||
void gui_setupGUI(int debugOut);
|
|
||||||
void gui_toggleGui();
|
|
||||||
void gui_setCellName(char *str);
|
|
||||||
void gui_showHUD();
|
|
||||||
|
|
||||||
// Console stuff
|
|
||||||
void gui_toggleConsole();
|
|
||||||
void gui_setConsoleFont(char*);
|
|
||||||
void gui_clearConsole();
|
|
||||||
|
|
||||||
// Get the widget type, as a string
|
|
||||||
char *gui_widgetType(WidgetPtr);
|
|
||||||
|
|
||||||
// Get the guiMode flag
|
|
||||||
int *gui_getGuiModePtr();
|
|
||||||
|
|
||||||
// Get the height or width of a widget. If the argument is null,
|
|
||||||
// return the size of the screen.
|
|
||||||
int gui_getHeight(WidgetPtr);
|
|
||||||
int gui_getWidth(WidgetPtr);
|
|
||||||
|
|
||||||
// Set various properties of a given widget
|
|
||||||
void gui_setCaption(WidgetPtr, char*);
|
|
||||||
void gui_setNeedMouseFocus(WidgetPtr, int);
|
|
||||||
void gui_setTextColor(WidgetPtr, float,float,float);
|
|
||||||
void gui_setCoord(WidgetPtr, int,int,int,int);
|
|
||||||
|
|
||||||
// Various ways to get or create widgets
|
|
||||||
WidgetPtr gui_loadLayout(char *file, char *prefix, WidgetPtr parent);
|
|
||||||
WidgetPtr gui_getChild(WidgetPtr, char*);
|
|
||||||
WidgetPtr gui_createText(char *skin, int x, int y, int w, int h, char *layer);
|
|
@ -1,321 +0,0 @@
|
|||||||
/*
|
|
||||||
OpenMW - The completely unofficial reimplementation of Morrowind
|
|
||||||
Copyright (C) 2008-2009 Nicolay Korslund
|
|
||||||
Email: < korslund@gmail.com >
|
|
||||||
WWW: http://openmw.snaptoad.com/
|
|
||||||
|
|
||||||
This file (gui.d) is part of the OpenMW package.
|
|
||||||
|
|
||||||
OpenMW is distributed as free software: you can redistribute it
|
|
||||||
and/or modify it under the terms of the GNU General Public License
|
|
||||||
version 3, as published by the Free Software Foundation.
|
|
||||||
|
|
||||||
This program is distributed in the hope that it will be useful, but
|
|
||||||
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
||||||
General Public License for more details.
|
|
||||||
|
|
||||||
You should have received a copy of the GNU General Public License
|
|
||||||
version 3 along with this program. If not, see
|
|
||||||
http://www.gnu.org/licenses/ .
|
|
||||||
|
|
||||||
*/
|
|
||||||
|
|
||||||
module gui.gui;
|
|
||||||
|
|
||||||
import monster.monster;
|
|
||||||
import monster.vm.mclass;
|
|
||||||
import monster.modules.console;
|
|
||||||
import gui.bindings;
|
|
||||||
import bullet.bindings;
|
|
||||||
import std.string;
|
|
||||||
import std.stdio;
|
|
||||||
|
|
||||||
// Widget class and gui module
|
|
||||||
MonsterClass
|
|
||||||
gmc, // GUI module
|
|
||||||
wid_mc, // Widget
|
|
||||||
but_mc, // Button
|
|
||||||
tex_mc, // StaticText
|
|
||||||
img_mc, // StaticImage
|
|
||||||
pro_mc, // Progress
|
|
||||||
win_mc; // Window
|
|
||||||
|
|
||||||
MWidget[WidgetPtr] gui_store;
|
|
||||||
|
|
||||||
class MWidget
|
|
||||||
{
|
|
||||||
WidgetPtr widget;
|
|
||||||
MonsterObject *mo;
|
|
||||||
|
|
||||||
// Used for layouts
|
|
||||||
bool isLayout;
|
|
||||||
char[] prefix;
|
|
||||||
|
|
||||||
// For layouts
|
|
||||||
this(char[] layout, WidgetPtr parent = null)
|
|
||||||
{
|
|
||||||
assert(layout.length);
|
|
||||||
|
|
||||||
isLayout = true;
|
|
||||||
prefix = format("%s", cast(void*)this);
|
|
||||||
|
|
||||||
widget = gui_loadLayout(layout.toStringz(), prefix.toStringz(), parent);
|
|
||||||
if(widget is null)
|
|
||||||
fail("Layout " ~ layout ~ " is empty");
|
|
||||||
|
|
||||||
this();
|
|
||||||
}
|
|
||||||
|
|
||||||
// For normal widgets
|
|
||||||
this(WidgetPtr w)
|
|
||||||
{
|
|
||||||
isLayout = false;
|
|
||||||
widget = w;
|
|
||||||
assert(widget !is null);
|
|
||||||
this();
|
|
||||||
}
|
|
||||||
|
|
||||||
private this()
|
|
||||||
{
|
|
||||||
assert(widget !is null);
|
|
||||||
|
|
||||||
// Create the object from the right class
|
|
||||||
mo = toClass(widget).createObject();
|
|
||||||
// But store the pointer in the Widget's pointer slot
|
|
||||||
mo.getExtra(wid_mc).obj = this;
|
|
||||||
// Also store a lookup for later
|
|
||||||
gui_store[widget] = this;
|
|
||||||
}
|
|
||||||
|
|
||||||
MWidget getChild(char[] name)
|
|
||||||
{
|
|
||||||
if(prefix.length)
|
|
||||||
name = prefix ~ name;
|
|
||||||
|
|
||||||
// Get the child widget
|
|
||||||
auto pt = gui_getChild(widget, name.toStringz());
|
|
||||||
|
|
||||||
if(pt is null)
|
|
||||||
fail("Widget has no child named " ~ name);
|
|
||||||
|
|
||||||
// Return the MWidget
|
|
||||||
return get(pt);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return the MonsterClass corresponding to a given widget.
|
|
||||||
private static MonsterClass toClass(WidgetPtr p)
|
|
||||||
{
|
|
||||||
switch(widgetType(p))
|
|
||||||
{
|
|
||||||
/*
|
|
||||||
case "Button": return but_mc;
|
|
||||||
case "StaticText": return tex_mc;
|
|
||||||
case "StaticImage": return img_mc;
|
|
||||||
case "Progress": return pro_mc;
|
|
||||||
case "Window": return win_mc;
|
|
||||||
*/
|
|
||||||
default:
|
|
||||||
// Use "Widget" for all unimplemented types
|
|
||||||
case "Widget": return wid_mc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the MWidget (and associatied MonsterObject) corresponding to
|
|
||||||
// a given Widget.
|
|
||||||
static MWidget get(WidgetPtr wid)
|
|
||||||
{
|
|
||||||
// First, check if the instance exists
|
|
||||||
auto p = wid in gui_store;
|
|
||||||
if(p) return *p;
|
|
||||||
|
|
||||||
// No MWidget exists. We have to create one.
|
|
||||||
return new MWidget(wid);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
char[] widgetType(WidgetPtr p)
|
|
||||||
{
|
|
||||||
return toString(gui_widgetType(p));
|
|
||||||
}
|
|
||||||
|
|
||||||
MWidget getMWOwner(MonsterObject *mo)
|
|
||||||
{
|
|
||||||
return (cast(MWidget)mo.getExtra(wid_mc).obj);
|
|
||||||
}
|
|
||||||
MWidget getMWOwner()
|
|
||||||
{
|
|
||||||
return getMWOwner(params.obj());
|
|
||||||
}
|
|
||||||
WidgetPtr getOwner(MonsterObject *mo)
|
|
||||||
{
|
|
||||||
return getMWOwner(mo).widget;
|
|
||||||
}
|
|
||||||
WidgetPtr getOwner()
|
|
||||||
{
|
|
||||||
return getMWOwner().widget;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Widget functions
|
|
||||||
void setCaption()
|
|
||||||
{
|
|
||||||
AIndex[] args = stack.popAArray();
|
|
||||||
|
|
||||||
char[] res;
|
|
||||||
|
|
||||||
foreach(AIndex ind; args)
|
|
||||||
res ~= format("%s", arrays.getRef(ind).carr);
|
|
||||||
|
|
||||||
gui_setCaption(getOwner(), toStringz(res));
|
|
||||||
}
|
|
||||||
void setNeedMouseFocus()
|
|
||||||
{ gui_setNeedMouseFocus(getOwner(), stack.popBool); }
|
|
||||||
void setTextColor()
|
|
||||||
{
|
|
||||||
float b = stack.popFloat();
|
|
||||||
float g = stack.popFloat();
|
|
||||||
float r = stack.popFloat();
|
|
||||||
gui_setTextColor(getOwner(), r,g,b);
|
|
||||||
}
|
|
||||||
void setCoord()
|
|
||||||
{
|
|
||||||
int h = stack.popInt();
|
|
||||||
int w = stack.popInt();
|
|
||||||
int y = stack.popInt();
|
|
||||||
int x = stack.popInt();
|
|
||||||
gui_setCoord(getOwner(), x,y,w,h);
|
|
||||||
}
|
|
||||||
|
|
||||||
void get()
|
|
||||||
{
|
|
||||||
// Get the owner MWidget
|
|
||||||
auto mw = getMWOwner();
|
|
||||||
// Get the child
|
|
||||||
mw = mw.getChild(stack.popString8());
|
|
||||||
// Push the object
|
|
||||||
stack.pushObject(mw.mo);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: These are all written to be used with the 'gui' module. Later
|
|
||||||
// they should be part of Widget, and create child widgets. When used
|
|
||||||
// with 'gui' they create root widgets.
|
|
||||||
|
|
||||||
void loadLayout()
|
|
||||||
{
|
|
||||||
MWidget mw = new MWidget(stack.popString8());
|
|
||||||
stack.pushObject(mw.mo);
|
|
||||||
}
|
|
||||||
|
|
||||||
void text()
|
|
||||||
{
|
|
||||||
char[] layer = stack.popString8();
|
|
||||||
int h = stack.popInt();
|
|
||||||
int w = stack.popInt();
|
|
||||||
int y = stack.popInt();
|
|
||||||
int x = stack.popInt();
|
|
||||||
char[] skin = stack.popString8();
|
|
||||||
WidgetPtr ptr = gui_createText(skin.toStringz(),
|
|
||||||
x,y,w,h,
|
|
||||||
layer.toStringz());
|
|
||||||
assert(widgetType(ptr) == "StaticText");
|
|
||||||
MWidget mw = new MWidget(ptr);
|
|
||||||
stack.pushObject(mw.mo);
|
|
||||||
}
|
|
||||||
|
|
||||||
void getWidth()
|
|
||||||
{
|
|
||||||
stack.pushInt(gui_getWidth(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
void getHeight()
|
|
||||||
{
|
|
||||||
stack.pushInt(gui_getHeight(null));
|
|
||||||
}
|
|
||||||
|
|
||||||
void initGUI(bool debugOut)
|
|
||||||
{
|
|
||||||
// Load the GUI system
|
|
||||||
gui_setupGUI(debugOut);
|
|
||||||
}
|
|
||||||
|
|
||||||
void startGUI()
|
|
||||||
{
|
|
||||||
gui_showHUD();
|
|
||||||
|
|
||||||
// Run GUI scripts
|
|
||||||
// Create the HUD and windows
|
|
||||||
vm.run("makegui.mn");
|
|
||||||
|
|
||||||
// Run the fps ticker
|
|
||||||
vm.run("fpsticker.mn");
|
|
||||||
}
|
|
||||||
|
|
||||||
void setupGUIScripts()
|
|
||||||
{
|
|
||||||
vm.addPath("mscripts/guiscripts/");
|
|
||||||
vm.addPath("mscripts/guiscripts/module/");
|
|
||||||
gmc = vm.load("gui", "gui.mn");
|
|
||||||
wid_mc = vm.load("Widget", "widget.mn");
|
|
||||||
/*
|
|
||||||
but_mc = new MonsterClass("Button", "button.mn");
|
|
||||||
tex_mc = new MonsterClass("Text", "text.mn");
|
|
||||||
img_mc = new MonsterClass("Image", "image.mn");
|
|
||||||
pro_mc = new MonsterClass("Progress", "progress.mn");
|
|
||||||
win_mc = new MonsterClass("Window", "window.mn");
|
|
||||||
*/
|
|
||||||
|
|
||||||
wid_mc.bind("setCaption", &setCaption);
|
|
||||||
wid_mc.bind("setNeedMouseFocus", &setNeedMouseFocus);
|
|
||||||
wid_mc.bind("setTextColor", &setTextColor);
|
|
||||||
wid_mc.bind("setCoord", &setCoord);
|
|
||||||
wid_mc.bind("get", &get);
|
|
||||||
|
|
||||||
gmc.bind("text", &text);
|
|
||||||
gmc.bind("loadLayout", &loadLayout);
|
|
||||||
gmc.bind("getWidth", &getWidth);
|
|
||||||
gmc.bind("getHeight", &getHeight);
|
|
||||||
|
|
||||||
// Set up the console
|
|
||||||
auto cmc = vm.load("Console");
|
|
||||||
auto cmo = cmc.createObject;
|
|
||||||
cons = new Console(cmo);
|
|
||||||
|
|
||||||
// Bind native functions
|
|
||||||
cmc.bind("walk", { bullet_walk(); cons.putln("Walk mode enabled");});
|
|
||||||
cmc.bind("fly", { bullet_fly(); cons.putln("Fly mode enabled");});
|
|
||||||
cmc.bind("ghost", { bullet_ghost(); cons.putln("Ghost mode enabled");});
|
|
||||||
cmc.bind("setfont",
|
|
||||||
{
|
|
||||||
char[] fnt = stack.popString8();
|
|
||||||
gui_setConsoleFont(toStringz(fnt));
|
|
||||||
cons.putln("Setting font " ~ fnt);
|
|
||||||
});
|
|
||||||
cmc.bind("clear", { gui_clearConsole(); });
|
|
||||||
cmc.bind("exit", { exitProgram(); });
|
|
||||||
cmc.bind("wireframe", { cons.putln("Wireframe mode not implemented yet"); });
|
|
||||||
}
|
|
||||||
|
|
||||||
Console cons;
|
|
||||||
|
|
||||||
// Checked from input/events.d. Shouldn't really be here, but it's a
|
|
||||||
// workaround for a DMD import issue.
|
|
||||||
bool doExit = false;
|
|
||||||
void exitProgram()
|
|
||||||
{
|
|
||||||
doExit = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Some glue code that will go away later when we use the C++
|
|
||||||
// interface to Monster directly.
|
|
||||||
extern(C):
|
|
||||||
int console_input(char* str)
|
|
||||||
{
|
|
||||||
char[] dstr = toString(str);
|
|
||||||
return cons.input(dstr);
|
|
||||||
}
|
|
||||||
|
|
||||||
char* console_output()
|
|
||||||
{
|
|
||||||
char[] dstr = cons.output();
|
|
||||||
return toStringz(dstr);
|
|
||||||
}
|
|
Loading…
Reference in New Issue