some refactoring
This commit is contained in:
parent
8ef1b28546
commit
571801ae39
|
@ -52,13 +52,11 @@ SET(SOURCES
|
||||||
src/protocollogin.cpp
|
src/protocollogin.cpp
|
||||||
|
|
||||||
# framework core
|
# framework core
|
||||||
src/framework/core/global.cpp
|
|
||||||
src/framework/core/dispatcher.cpp
|
src/framework/core/dispatcher.cpp
|
||||||
src/framework/core/configs.cpp
|
src/framework/core/configs.cpp
|
||||||
src/framework/core/resources.cpp
|
src/framework/core/resources.cpp
|
||||||
src/framework/core/engine.cpp
|
src/framework/core/engine.cpp
|
||||||
src/framework/core/modules.cpp
|
src/framework/core/modules.cpp
|
||||||
src/framework/core/allocator.cpp
|
|
||||||
|
|
||||||
# framework otml
|
# framework otml
|
||||||
src/framework/otml/otmlemitter.cpp
|
src/framework/otml/otmlemitter.cpp
|
||||||
|
@ -66,9 +64,9 @@ SET(SOURCES
|
||||||
src/framework/otml/otmlnode.cpp
|
src/framework/otml/otmlnode.cpp
|
||||||
|
|
||||||
# framework script
|
# framework script
|
||||||
src/framework/script/scriptable.cpp
|
src/framework/script/scriptobject.cpp
|
||||||
src/framework/script/luascript.cpp
|
src/framework/script/scriptcontext.cpp
|
||||||
src/framework/script/luafunctions.cpp
|
src/framework/script/scriptfunctions.cpp
|
||||||
|
|
||||||
# framework utilities
|
# framework utilities
|
||||||
src/framework/util/color.cpp
|
src/framework/util/color.cpp
|
||||||
|
@ -76,6 +74,7 @@ SET(SOURCES
|
||||||
src/framework/util/convert.cpp
|
src/framework/util/convert.cpp
|
||||||
src/framework/util/logger.cpp
|
src/framework/util/logger.cpp
|
||||||
src/framework/util/apngloader.cpp
|
src/framework/util/apngloader.cpp
|
||||||
|
src/framework/util/allocator.cpp
|
||||||
|
|
||||||
# framework graphics
|
# framework graphics
|
||||||
src/framework/graphics/image.cpp
|
src/framework/graphics/image.cpp
|
||||||
|
|
|
@ -1,46 +0,0 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef CONSTANTS_H
|
|
||||||
#define CONSTANTS_H
|
|
||||||
|
|
||||||
enum AlignmentFlag {
|
|
||||||
AlignLeft = 1,
|
|
||||||
AlignRight = 2,
|
|
||||||
AlignTop = 4,
|
|
||||||
AlignBottom = 8,
|
|
||||||
AlignHorizontalCenter = 16,
|
|
||||||
AlignVerticalCenter = 32,
|
|
||||||
AlignTopLeft = AlignTop | AlignLeft,
|
|
||||||
AlignTopRight = AlignTop | AlignRight,
|
|
||||||
AlignBottomLeft = AlignBottom | AlignLeft,
|
|
||||||
AlignBottomRight = AlignBottom | AlignRight,
|
|
||||||
AlignLeftCenter = AlignLeft | AlignVerticalCenter,
|
|
||||||
AlignRightCenter = AlignRight | AlignVerticalCenter,
|
|
||||||
AlignTopCenter = AlignTop | AlignHorizontalCenter,
|
|
||||||
AlignBottomCenter = AlignBottom | AlignHorizontalCenter,
|
|
||||||
AlignCenter = AlignVerticalCenter | AlignHorizontalCenter
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif // CONSTANTS_H
|
|
|
@ -1,30 +1,6 @@
|
||||||
/* The MIT License
|
#include "configs.h"
|
||||||
*
|
#include "resources.h"
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <global.h>
|
|
||||||
#include <core/configs.h>
|
|
||||||
#include <core/resources.h>
|
|
||||||
#include <otml/otml.h>
|
#include <otml/otml.h>
|
||||||
|
|
||||||
Configs g_configs;
|
Configs g_configs;
|
||||||
|
@ -59,4 +35,3 @@ void Configs::save()
|
||||||
g_resources.saveFile(m_fileName, emitter.emitDocument());
|
g_resources.saveFile(m_fileName, emitter.emitDocument());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef CONFIGS_H
|
#ifndef CONFIGS_H
|
||||||
#define CONFIGS_H
|
#define CONFIGS_H
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,5 @@
|
||||||
/* The MIT License
|
#include "dispatcher.h"
|
||||||
*
|
#include "engine.h"
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <global.h>
|
|
||||||
#include <core/dispatcher.h>
|
|
||||||
#include <core/engine.h>
|
|
||||||
|
|
||||||
Dispatcher g_dispatcher;
|
Dispatcher g_dispatcher;
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef DISPATCHER_H
|
#ifndef DISPATCHER_H
|
||||||
#define DISPATCHER_H
|
#define DISPATCHER_H
|
||||||
|
|
||||||
|
@ -31,17 +7,15 @@
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
#include <boost/function.hpp>
|
#include <boost/function.hpp>
|
||||||
|
|
||||||
class ScheduledTask {
|
struct ScheduledTask {
|
||||||
public:
|
ScheduledTask(const boost::function<void()>& _callback) : ticks(0), callback(_callback) { }
|
||||||
inline ScheduledTask(const boost::function<void()>& _callback) : ticks(0), callback(_callback) { }
|
ScheduledTask(int _ticks, const boost::function<void()>& _callback) : ticks(_ticks), callback(_callback) { }
|
||||||
inline ScheduledTask(int _ticks, const boost::function<void()>& _callback) : ticks(_ticks), callback(_callback) { }
|
bool operator<(const ScheduledTask& other) const { return ticks > other.ticks; }
|
||||||
inline bool operator<(const ScheduledTask& other) const { return ticks > other.ticks; }
|
|
||||||
int ticks;
|
int ticks;
|
||||||
boost::function<void()> callback;
|
boost::function<void()> callback;
|
||||||
};
|
};
|
||||||
|
|
||||||
class lessScheduledTask : public std::binary_function<ScheduledTask*&, ScheduledTask*&, bool> {
|
struct lessScheduledTask : public std::binary_function<ScheduledTask*&, ScheduledTask*&, bool> {
|
||||||
public:
|
|
||||||
bool operator()(ScheduledTask*& t1,ScheduledTask*& t2) { return (*t1) < (*t2); }
|
bool operator()(ScheduledTask*& t1,ScheduledTask*& t2) { return (*t1) < (*t2); }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -1,38 +1,13 @@
|
||||||
/* The MIT License
|
#include "engine.h"
|
||||||
*
|
#include "platform.h"
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
#include "dispatcher.h"
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <global.h>
|
|
||||||
#include <core/engine.h>
|
|
||||||
#include <core/platform.h>
|
|
||||||
#include <core/dispatcher.h>
|
|
||||||
#include <graphics/graphics.h>
|
#include <graphics/graphics.h>
|
||||||
#include <graphics/fonts.h>
|
#include <graphics/fonts.h>
|
||||||
#include <ui/uicontainer.h>
|
|
||||||
#include <net/connection.h>
|
|
||||||
#include <script/luascript.h>
|
|
||||||
#include <ui/uiskins.h>
|
|
||||||
#include <graphics/textures.h>
|
#include <graphics/textures.h>
|
||||||
|
#include <ui/uicontainer.h>
|
||||||
|
#include <ui/uiskins.h>
|
||||||
|
#include <script/scriptcontext.h>
|
||||||
|
#include <net/connection.h>
|
||||||
|
|
||||||
Engine g_engine;
|
Engine g_engine;
|
||||||
|
|
||||||
|
@ -138,7 +113,7 @@ void Engine::stop()
|
||||||
|
|
||||||
void Engine::onClose()
|
void Engine::onClose()
|
||||||
{
|
{
|
||||||
g_dispatcher.addTask(boost::bind(&LuaScript::callModuleField, &g_lua, "App", "onClose"));
|
g_dispatcher.addTask(boost::bind(&ScriptContext::callModuleField, &g_lua, "App", "onClose"));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Engine::onResize(const Size& size)
|
void Engine::onResize(const Size& size)
|
||||||
|
|
|
@ -1,32 +1,8 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef ENGINE_H
|
#ifndef ENGINE_H
|
||||||
#define ENGINE_H
|
#define ENGINE_H
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <core/input.h>
|
#include "input.h"
|
||||||
|
|
||||||
class Engine
|
class Engine
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "global.h"
|
|
|
@ -1,31 +1,8 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef INPUT_H
|
#ifndef INPUT_H
|
||||||
#define INPUT_H
|
#define INPUT_H
|
||||||
|
|
||||||
#include <global.h>
|
#include <util/types.h>
|
||||||
|
#include <util/point.h>
|
||||||
|
|
||||||
enum EKeyCode {
|
enum EKeyCode {
|
||||||
KC_UNKNOWN = 0x00,
|
KC_UNKNOWN = 0x00,
|
||||||
|
|
|
@ -1,26 +1,2 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "modules.h"
|
#include "modules.h"
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef MODULES_H
|
#ifndef MODULES_H
|
||||||
#define MODULES_H
|
#define MODULES_H
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef PLATFORM_H
|
#ifndef PLATFORM_H
|
||||||
#define PLATFORM_H
|
#define PLATFORM_H
|
||||||
|
|
||||||
|
|
|
@ -1,30 +1,6 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <core/resources.h>
|
#include "resources.h"
|
||||||
#include <core/platform.h>
|
#include "platform.h"
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <physfs.h>
|
#include <physfs.h>
|
||||||
|
@ -170,7 +146,6 @@ std::list<std::string> Resources::listDirectoryFiles(const std::string& director
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Resources::pushCurrentPath(const std::string ¤tPath)
|
void Resources::pushCurrentPath(const std::string ¤tPath)
|
||||||
{
|
{
|
||||||
m_currentPaths.push(currentPath);
|
m_currentPaths.push(currentPath);
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef RESOURCES_H
|
#ifndef RESOURCES_H
|
||||||
#define RESOURCES_H
|
#define RESOURCES_H
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@
|
||||||
#include <boost/enable_shared_from_this.hpp>
|
#include <boost/enable_shared_from_this.hpp>
|
||||||
|
|
||||||
// constants
|
// constants
|
||||||
#include "const.h"
|
#include <const.h>
|
||||||
|
|
||||||
// easy types
|
// easy types
|
||||||
#include <util/types.h>
|
#include <util/types.h>
|
||||||
|
|
|
@ -37,33 +37,6 @@ BorderedImage::BorderedImage(TexturePtr texture,
|
||||||
const Rect& bottomLeft,
|
const Rect& bottomLeft,
|
||||||
const Rect& bottomRight,
|
const Rect& bottomRight,
|
||||||
const Rect& center) : Image(texture)
|
const Rect& center) : Image(texture)
|
||||||
{
|
|
||||||
setTexCoords(left, right, top, bottom, topLeft, topRight, bottomLeft, bottomRight, center);
|
|
||||||
}
|
|
||||||
|
|
||||||
BorderedImage::BorderedImage(const std::string& texture,
|
|
||||||
const Rect& left,
|
|
||||||
const Rect& right,
|
|
||||||
const Rect& top,
|
|
||||||
const Rect& bottom,
|
|
||||||
const Rect& topLeft,
|
|
||||||
const Rect& topRight,
|
|
||||||
const Rect& bottomLeft,
|
|
||||||
const Rect& bottomRight,
|
|
||||||
const Rect& center) : Image(texture)
|
|
||||||
{
|
|
||||||
setTexCoords(left, right, top, bottom, topLeft, topRight, bottomLeft, bottomRight, center);
|
|
||||||
}
|
|
||||||
|
|
||||||
void BorderedImage::setTexCoords(const Rect& left,
|
|
||||||
const Rect& right,
|
|
||||||
const Rect& top,
|
|
||||||
const Rect& bottom,
|
|
||||||
const Rect& topLeft,
|
|
||||||
const Rect& topRight,
|
|
||||||
const Rect& bottomLeft,
|
|
||||||
const Rect& bottomRight,
|
|
||||||
const Rect& center)
|
|
||||||
{
|
{
|
||||||
m_leftBorderTexCoords = left;
|
m_leftBorderTexCoords = left;
|
||||||
m_rightBorderTexCoords = right;
|
m_rightBorderTexCoords = right;
|
||||||
|
@ -86,6 +59,73 @@ void BorderedImage::setTexCoords(const Rect& left,
|
||||||
center.height());
|
center.height());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BorderedImagePtr BorderedImage::loadFromOTMLNode(OTMLNode* node, TexturePtr defaultTexture)
|
||||||
|
{
|
||||||
|
Rect leftBorder;
|
||||||
|
Rect rightBorder;
|
||||||
|
Rect topBorder;
|
||||||
|
Rect bottomBorder;
|
||||||
|
Rect topLeftCorner;
|
||||||
|
Rect topRightCorner;
|
||||||
|
Rect bottomLeftCorner;
|
||||||
|
Rect bottomRightCorner;
|
||||||
|
Rect center;
|
||||||
|
Rect subRect;
|
||||||
|
int top, bottom, left, right, border;
|
||||||
|
Size size;
|
||||||
|
Point offset;
|
||||||
|
|
||||||
|
TexturePtr texture;
|
||||||
|
std::string textureSource = node->readAt("source", std::string());
|
||||||
|
if(!textureSource.empty())
|
||||||
|
texture = g_textures.get(textureSource);
|
||||||
|
else
|
||||||
|
texture = defaultTexture;
|
||||||
|
|
||||||
|
if(!texture)
|
||||||
|
return BorderedImagePtr();
|
||||||
|
|
||||||
|
size = texture->getSize();
|
||||||
|
size = node->readAt("size", size);
|
||||||
|
offset = node->readAt("offset", offset);
|
||||||
|
subRect = Rect(offset, size);
|
||||||
|
border = node->readAt("border", 0);
|
||||||
|
top = bottom = left = right = border;
|
||||||
|
top = node->readAt("top", top);
|
||||||
|
bottom = node->readAt("bottom", bottom);
|
||||||
|
left = node->readAt("left", left);
|
||||||
|
right = node->readAt("right", right);
|
||||||
|
leftBorder = Rect(subRect.left(), subRect.top() + top, left, subRect.height() - top - bottom);
|
||||||
|
rightBorder = Rect(subRect.right() - right, subRect.top() + top, right, subRect.height() - top - bottom);
|
||||||
|
topBorder = Rect(subRect.left() + left, subRect.top(), subRect.width() - right - left, top);
|
||||||
|
bottomBorder = Rect(subRect.left() + left, subRect.bottom() - bottom, subRect.width() - right - left, bottom);
|
||||||
|
topLeftCorner = Rect(subRect.left(), subRect.top(), left, top);
|
||||||
|
topRightCorner = Rect(subRect.right() - right, subRect.top(), right, top);
|
||||||
|
bottomLeftCorner = Rect(subRect.left(), subRect.bottom() - bottom, left, bottom);
|
||||||
|
bottomRightCorner = Rect(subRect.right() - right, subRect.bottom() - bottom, right, bottom);
|
||||||
|
center = Rect(subRect.left() + left, subRect.top() + top, subRect.width() - right - left, subRect.height() - top - bottom);
|
||||||
|
leftBorder = node->readAt("left border", leftBorder);
|
||||||
|
rightBorder = node->readAt("right border", rightBorder);
|
||||||
|
topBorder = node->readAt("top border", topBorder);
|
||||||
|
bottomBorder = node->readAt("bottom border", bottomBorder);
|
||||||
|
topLeftCorner = node->readAt("top left corner", topLeftCorner);
|
||||||
|
topRightCorner = node->readAt("top right corner", topRightCorner);
|
||||||
|
bottomLeftCorner = node->readAt("bottom left corner", bottomLeftCorner);
|
||||||
|
bottomRightCorner = node->readAt("bottom right corner", bottomRightCorner);
|
||||||
|
center = node->readAt("center", center);
|
||||||
|
|
||||||
|
return BorderedImagePtr(new BorderedImage(texture,
|
||||||
|
leftBorder,
|
||||||
|
rightBorder,
|
||||||
|
topBorder,
|
||||||
|
bottomBorder,
|
||||||
|
topLeftCorner,
|
||||||
|
topRightCorner,
|
||||||
|
bottomLeftCorner,
|
||||||
|
bottomRightCorner,
|
||||||
|
center));
|
||||||
|
}
|
||||||
|
|
||||||
void BorderedImage::draw(const Rect& screenCoords)
|
void BorderedImage::draw(const Rect& screenCoords)
|
||||||
{
|
{
|
||||||
Rect rectCoords;
|
Rect rectCoords;
|
||||||
|
|
|
@ -28,6 +28,10 @@
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <graphics/image.h>
|
#include <graphics/image.h>
|
||||||
#include <graphics/texture.h>
|
#include <graphics/texture.h>
|
||||||
|
#include <otml/otmlnode.h>
|
||||||
|
|
||||||
|
class BorderedImage;
|
||||||
|
typedef boost::shared_ptr<BorderedImage> BorderedImagePtr;
|
||||||
|
|
||||||
class BorderedImage : public Image
|
class BorderedImage : public Image
|
||||||
{
|
{
|
||||||
|
@ -43,31 +47,12 @@ public:
|
||||||
const Rect& bottomRight,
|
const Rect& bottomRight,
|
||||||
const Rect& center);
|
const Rect& center);
|
||||||
|
|
||||||
BorderedImage(const std::string& texture,
|
|
||||||
const Rect& left,
|
|
||||||
const Rect& right,
|
|
||||||
const Rect& top,
|
|
||||||
const Rect& bottom,
|
|
||||||
const Rect& topLeft,
|
|
||||||
const Rect& topRight,
|
|
||||||
const Rect& bottomLeft,
|
|
||||||
const Rect& bottomRight,
|
|
||||||
const Rect& center);
|
|
||||||
|
|
||||||
void setTexCoords(const Rect& left,
|
|
||||||
const Rect& right,
|
|
||||||
const Rect& top,
|
|
||||||
const Rect& bottom,
|
|
||||||
const Rect& topLeft,
|
|
||||||
const Rect& topRight,
|
|
||||||
const Rect& bottomLeft,
|
|
||||||
const Rect& bottomRight,
|
|
||||||
const Rect& center);
|
|
||||||
|
|
||||||
void draw(const Rect& screenCoords);
|
void draw(const Rect& screenCoords);
|
||||||
|
|
||||||
Size getDefaultSize() const { return m_defaultSize; }
|
Size getDefaultSize() const { return m_defaultSize; }
|
||||||
|
|
||||||
|
static BorderedImagePtr loadFromOTMLNode(OTMLNode *node, TexturePtr defaultTexture = TexturePtr());
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Rect m_leftBorderTexCoords;
|
Rect m_leftBorderTexCoords;
|
||||||
Rect m_rightBorderTexCoords;
|
Rect m_rightBorderTexCoords;
|
||||||
|
@ -85,6 +70,4 @@ private:
|
||||||
Size m_defaultSize;
|
Size m_defaultSize;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef boost::shared_ptr<BorderedImage> BorderedImagePtr;
|
|
||||||
|
|
||||||
#endif // BORDEREDIMAGE_H
|
#endif // BORDEREDIMAGE_H
|
||||||
|
|
|
@ -101,7 +101,7 @@ bool Font::load(const std::string& file)
|
||||||
calculateGlyphsWidthsAutomatically(glyphSize);
|
calculateGlyphsWidthsAutomatically(glyphSize);
|
||||||
|
|
||||||
// read custom widths
|
// read custom widths
|
||||||
if(doc->hasNode("glyph widths")) {
|
if(doc->hasChild("glyph widths")) {
|
||||||
std::map<int, int> glyphWidths;
|
std::map<int, int> glyphWidths;
|
||||||
doc->readAt("glyph widths", &glyphWidths);
|
doc->readAt("glyph widths", &glyphWidths);
|
||||||
foreach(const auto& pair, glyphWidths)
|
foreach(const auto& pair, glyphWidths)
|
||||||
|
|
|
@ -37,9 +37,9 @@ void Fonts::init()
|
||||||
// load all fonts
|
// load all fonts
|
||||||
std::list<std::string> files = g_resources.listDirectoryFiles();
|
std::list<std::string> files = g_resources.listDirectoryFiles();
|
||||||
foreach(const std::string& file, files) {
|
foreach(const std::string& file, files) {
|
||||||
if(boost::ends_with(file, ".yml")) {
|
if(boost::ends_with(file, ".otml")) {
|
||||||
std::string name = file;
|
std::string name = file;
|
||||||
boost::erase_first(name, ".yml");
|
boost::erase_first(name, ".otml");
|
||||||
FontPtr font(new Font(name));
|
FontPtr font(new Font(name));
|
||||||
if(font->load(file))
|
if(font->load(file))
|
||||||
m_fonts.push_back(font);
|
m_fonts.push_back(font);
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
#include <net/connection.h>
|
#include <net/connection.h>
|
||||||
#include <net/inputmessage.h>
|
#include <net/inputmessage.h>
|
||||||
#include <net/outputmessage.h>
|
#include <net/outputmessage.h>
|
||||||
#include <script/scriptable.h>
|
#include <script/scriptobject.h>
|
||||||
|
|
||||||
#define CIPSOFT_PUBLIC_RSA "1321277432058722840622950990822933849527763264961655079678763618" \
|
#define CIPSOFT_PUBLIC_RSA "1321277432058722840622950990822933849527763264961655079678763618" \
|
||||||
"4334395343554449668205332383339435179772895415509701210392836078" \
|
"4334395343554449668205332383339435179772895415509701210392836078" \
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
|
|
||||||
//#define RSA "109120132967399429278860960508995541528237502902798129123468757937266291492576446330739696001110603907230888610072655818825358503429057592827629436413108566029093628212635953836686562675849720620786279431090218017681061521755056710823876476444260558147179707119674283982419152118103759076030616683978566631413"
|
//#define RSA "109120132967399429278860960508995541528237502902798129123468757937266291492576446330739696001110603907230888610072655818825358503429057592827629436413108566029093628212635953836686562675849720620786279431090218017681061521755056710823876476444260558147179707119674283982419152118103759076030616683978566631413"
|
||||||
|
|
||||||
class Protocol : public Scriptable
|
class Protocol : public ScriptObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Protocol();
|
Protocol();
|
||||||
|
@ -49,7 +49,7 @@ public:
|
||||||
virtual void onRecv(InputMessage *inputMessage);
|
virtual void onRecv(InputMessage *inputMessage);
|
||||||
virtual void onError(const boost::system::error_code& err);
|
virtual void onError(const boost::system::error_code& err);
|
||||||
|
|
||||||
virtual const char *getScriptableName() const { return "Protocol"; }
|
virtual const char *getScriptObjectType() const { return "Protocol"; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
uint32 m_xteaKey[4];
|
uint32 m_xteaKey[4];
|
||||||
|
|
|
@ -6,4 +6,3 @@
|
||||||
#include "otmlparser.h"
|
#include "otmlparser.h"
|
||||||
|
|
||||||
#endif // OTML_H
|
#endif // OTML_H
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ public:
|
||||||
bool hasTag() const { return !m_tag.empty(); }
|
bool hasTag() const { return !m_tag.empty(); }
|
||||||
bool hasChildren() const { return size() > 0; }
|
bool hasChildren() const { return size() > 0; }
|
||||||
bool hasValue() const { return !m_value.empty(); }
|
bool hasValue() const { return !m_value.empty(); }
|
||||||
bool hasNode(const std::string ctag) const { return at(ctag) != 0; }
|
bool hasChild(const std::string ctag) const { return at(ctag) != 0; }
|
||||||
|
|
||||||
void setTag(std::string tag) { m_tag = tag; }
|
void setTag(std::string tag) { m_tag = tag; }
|
||||||
void setLine(int line) { m_line = line; }
|
void setLine(int line) { m_line = line; }
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
#ifndef OTMLPARSER_H
|
#ifndef OTMLPARSER_H
|
||||||
#define OTMLPARSER_H
|
#define OTMLPARSER_H
|
||||||
|
|
||||||
#include <global.h>
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
#include <istream>
|
||||||
|
|
||||||
class OTMLNode;
|
class OTMLNode;
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <core/platform.h>
|
#include <core/platform.h>
|
||||||
#include <core/engine.h>
|
#include <core/engine.h>
|
||||||
|
|
|
@ -1,95 +0,0 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef PREREQUISITES_H
|
|
||||||
#define PREREQUISITES_H
|
|
||||||
|
|
||||||
// easy typing
|
|
||||||
#include <stdint.h>
|
|
||||||
typedef unsigned char uchar;
|
|
||||||
typedef unsigned short ushort;
|
|
||||||
typedef unsigned int uint;
|
|
||||||
typedef unsigned long ulong;
|
|
||||||
typedef uint64_t uint64;
|
|
||||||
typedef uint32_t uint32;
|
|
||||||
typedef uint16_t uint16;
|
|
||||||
typedef uint8_t uint8;
|
|
||||||
typedef int32_t int32;
|
|
||||||
typedef int16_t int16;
|
|
||||||
typedef int8_t int8;
|
|
||||||
|
|
||||||
// C headers
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstdlib>
|
|
||||||
#include <cstring>
|
|
||||||
#include <cassert>
|
|
||||||
#include <ctime>
|
|
||||||
#include <cmath>
|
|
||||||
#include <csignal>
|
|
||||||
|
|
||||||
// STL headers
|
|
||||||
#include <iostream>
|
|
||||||
#include <fstream>
|
|
||||||
#include <sstream>
|
|
||||||
#include <algorithm>
|
|
||||||
#include <string>
|
|
||||||
#include <vector>
|
|
||||||
#include <stack>
|
|
||||||
#include <map>
|
|
||||||
#include <string>
|
|
||||||
#include <list>
|
|
||||||
#include <queue>
|
|
||||||
#include <iterator>
|
|
||||||
|
|
||||||
// OpenGL
|
|
||||||
#include <GL/gl.h>
|
|
||||||
#include <GL/glu.h>
|
|
||||||
#include <GL/glext.h>
|
|
||||||
|
|
||||||
// boost utilities
|
|
||||||
#include <boost/algorithm/string.hpp>
|
|
||||||
#include <boost/foreach.hpp>
|
|
||||||
#include <boost/bind.hpp>
|
|
||||||
#include <boost/function.hpp>
|
|
||||||
#include <boost/shared_ptr.hpp>
|
|
||||||
#include <boost/scoped_ptr.hpp>
|
|
||||||
#include <boost/enable_shared_from_this.hpp>
|
|
||||||
#include <boost/signals.hpp>
|
|
||||||
#define foreach BOOST_FOREACH
|
|
||||||
|
|
||||||
typedef boost::function<void()> SimpleCallback;
|
|
||||||
|
|
||||||
// constants
|
|
||||||
#include <constants.h>
|
|
||||||
|
|
||||||
// common utilities
|
|
||||||
#include <util/util.h>
|
|
||||||
#include <util/fml.h>
|
|
||||||
#include <util/logger.h>
|
|
||||||
#include <util/color.h>
|
|
||||||
#include <util/point.h>
|
|
||||||
#include <util/size.h>
|
|
||||||
#include <util/rect.h>
|
|
||||||
|
|
||||||
#endif // PREREQUISITES_H
|
|
|
@ -1,78 +0,0 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <global.h>
|
|
||||||
#include <script/scriptable.h>
|
|
||||||
#include <script/luascript.h>
|
|
||||||
#include <core/dispatcher.h>
|
|
||||||
|
|
||||||
int Scriptable::getLuaTableRef()
|
|
||||||
{
|
|
||||||
if(m_luaTableRef == -1) {
|
|
||||||
g_lua.newTable();
|
|
||||||
m_luaTableRef = g_lua.popRef();
|
|
||||||
}
|
|
||||||
return m_luaTableRef;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Scriptable::releaseLuaTableRef()
|
|
||||||
{
|
|
||||||
if(m_luaTableRef != -1) {
|
|
||||||
g_lua.releaseRef(m_luaTableRef);
|
|
||||||
m_luaTableRef = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Scriptable::callLuaTableField(const std::string& field, int numArgs)
|
|
||||||
{
|
|
||||||
// set self
|
|
||||||
g_lua.pushClassInstance(shared_from_this());
|
|
||||||
g_lua.setGlobal("self");
|
|
||||||
|
|
||||||
// push field
|
|
||||||
g_lua.getScriptableField(shared_from_this(), field);
|
|
||||||
|
|
||||||
// call it if its a function
|
|
||||||
if(g_lua.isFunction()) {
|
|
||||||
g_lua.insert(-numArgs-1);
|
|
||||||
g_lua.callFunction(numArgs);
|
|
||||||
// if its an array call each element
|
|
||||||
} else if(g_lua.isTable()) {
|
|
||||||
//TODO: call here with arguments
|
|
||||||
g_lua.pushNil();
|
|
||||||
while(g_lua.next()) {
|
|
||||||
// call it if its a function
|
|
||||||
if(g_lua.isFunction())
|
|
||||||
g_lua.callFunction();
|
|
||||||
g_lua.pop();
|
|
||||||
}
|
|
||||||
} else if(!g_lua.isNil()) {
|
|
||||||
g_lua.reportError(make_string("field '", field, "' for '", getScriptableName(), "' is not a valid function or array of functions"));
|
|
||||||
}
|
|
||||||
|
|
||||||
// release self
|
|
||||||
g_lua.pushNil();
|
|
||||||
g_lua.setGlobal("self");
|
|
||||||
}
|
|
||||||
|
|
|
@ -1,49 +0,0 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef SCRIPTABLE_H
|
|
||||||
#define SCRIPTABLE_H
|
|
||||||
|
|
||||||
#include <global.h>
|
|
||||||
|
|
||||||
class Scriptable : public boost::enable_shared_from_this<Scriptable>
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Scriptable() : m_luaTableRef(-1) { }
|
|
||||||
virtual ~Scriptable() { releaseLuaTableRef(); }
|
|
||||||
|
|
||||||
//TODO: global destroy
|
|
||||||
virtual const char *getScriptableName() const { return NULL; }
|
|
||||||
|
|
||||||
int getLuaTableRef();
|
|
||||||
void releaseLuaTableRef();
|
|
||||||
void callLuaTableField(const std::string& field, int numArgs = 0);
|
|
||||||
|
|
||||||
private:
|
|
||||||
int m_luaTableRef;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef boost::shared_ptr<Scriptable> ScriptablePtr;
|
|
||||||
|
|
||||||
#endif
|
|
|
@ -1,38 +1,14 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <script/luascript.h>
|
#include <script/scriptcontext.h>
|
||||||
#include <script/luafunctions.h>
|
#include <script/scriptfunctions.h>
|
||||||
#include <core/resources.h>
|
#include <core/resources.h>
|
||||||
#include <lua.hpp>
|
#include <lua.hpp>
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
LuaScript g_lua;
|
ScriptContext g_lua;
|
||||||
|
|
||||||
void LuaScript::init()
|
void ScriptContext::init()
|
||||||
{
|
{
|
||||||
L = luaL_newstate();
|
L = luaL_newstate();
|
||||||
if(!L)
|
if(!L)
|
||||||
|
@ -44,17 +20,17 @@ void LuaScript::init()
|
||||||
// setup custom package loader
|
// setup custom package loader
|
||||||
setupPackageLoader();
|
setupPackageLoader();
|
||||||
|
|
||||||
registerLuaFunctions();
|
registerScriptFunctions();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::terminate()
|
void ScriptContext::terminate()
|
||||||
{
|
{
|
||||||
collectGarbage();
|
collectGarbage();
|
||||||
lua_close(L);
|
lua_close(L);
|
||||||
L = NULL;
|
L = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::loadAllModules()
|
void ScriptContext::loadAllModules()
|
||||||
{
|
{
|
||||||
std::list<std::string> modules = g_resources.listDirectoryFiles("modules");
|
std::list<std::string> modules = g_resources.listDirectoryFiles("modules");
|
||||||
foreach(const std::string& module, modules) {
|
foreach(const std::string& module, modules) {
|
||||||
|
@ -66,7 +42,7 @@ void LuaScript::loadAllModules()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaScript::loadFile(const std::string& fileName)
|
bool ScriptContext::loadFile(const std::string& fileName)
|
||||||
{
|
{
|
||||||
std::stringstream fin;
|
std::stringstream fin;
|
||||||
if(g_resources.loadFile(fileName, fin))
|
if(g_resources.loadFile(fileName, fin))
|
||||||
|
@ -76,14 +52,14 @@ bool LuaScript::loadFile(const std::string& fileName)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaScript::loadBuffer(const std::string& text, const std::string& what)
|
bool ScriptContext::loadBuffer(const std::string& text, const std::string& what)
|
||||||
{
|
{
|
||||||
if(loadBufferAsFunction(text, what) && callFunction())
|
if(loadBufferAsFunction(text, what) && callFunction())
|
||||||
return true;
|
return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaScript::loadBufferAsFunction(const std::string& text, const std::string& what)
|
bool ScriptContext::loadBufferAsFunction(const std::string& text, const std::string& what)
|
||||||
{
|
{
|
||||||
int ret = luaL_loadbuffer(L, text.c_str(), text.length(), ("@" + what).c_str());
|
int ret = luaL_loadbuffer(L, text.c_str(), text.length(), ("@" + what).c_str());
|
||||||
if(ret != 0){
|
if(ret != 0){
|
||||||
|
@ -98,7 +74,7 @@ bool LuaScript::loadBufferAsFunction(const std::string& text, const std::string&
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::reportError(const std::string& errorDesc, const char *funcName)
|
void ScriptContext::reportError(const std::string& errorDesc, const char *funcName)
|
||||||
{
|
{
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
ss << "LUA Script ERROR: ";
|
ss << "LUA Script ERROR: ";
|
||||||
|
@ -108,73 +84,73 @@ void LuaScript::reportError(const std::string& errorDesc, const char *funcName)
|
||||||
error(ss.str());
|
error(ss.str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::reportErrorWithTraceback(const std::string& errorDesc, const char* funcName)
|
void ScriptContext::reportErrorWithTraceback(const std::string& errorDesc, const char* funcName)
|
||||||
{
|
{
|
||||||
pushString(errorDesc);
|
pushString(errorDesc);
|
||||||
luaErrorHandler(L);
|
luaErrorHandler(L);
|
||||||
reportError(popString(), funcName);
|
reportError(popString(), funcName);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::collectGarbage()
|
void ScriptContext::collectGarbage()
|
||||||
{
|
{
|
||||||
for(int i=0;i<2;i++)
|
for(int i=0;i<2;i++)
|
||||||
lua_gc(L, LUA_GCCOLLECT, 0);
|
lua_gc(L, LUA_GCCOLLECT, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaScript::getStackSize()
|
int ScriptContext::getStackSize()
|
||||||
{
|
{
|
||||||
return lua_gettop(L);
|
return lua_gettop(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::insert(int index)
|
void ScriptContext::insert(int index)
|
||||||
{
|
{
|
||||||
if(index != -1)
|
if(index != -1)
|
||||||
lua_insert(L, index);
|
lua_insert(L, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::swap(int index)
|
void ScriptContext::swap(int index)
|
||||||
{
|
{
|
||||||
insert(index);
|
insert(index);
|
||||||
pushValue(index+1);
|
pushValue(index+1);
|
||||||
remove(index);
|
remove(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::remove(int index)
|
void ScriptContext::remove(int index)
|
||||||
{
|
{
|
||||||
lua_remove(L, index);
|
lua_remove(L, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaScript::next(int index)
|
bool ScriptContext::next(int index)
|
||||||
{
|
{
|
||||||
return lua_next(L, index);
|
return lua_next(L, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::releaseRef(int ref)
|
void ScriptContext::releaseRef(int ref)
|
||||||
{
|
{
|
||||||
luaL_unref(L, LUA_REGISTRYINDEX, ref);
|
luaL_unref(L, LUA_REGISTRYINDEX, ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::newTable()
|
void ScriptContext::newTable()
|
||||||
{
|
{
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::setTable(int index)
|
void ScriptContext::setTable(int index)
|
||||||
{
|
{
|
||||||
lua_settable(L, index);
|
lua_settable(L, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void *LuaScript::newUserdata(int size)
|
void *ScriptContext::newUserdata(int size)
|
||||||
{
|
{
|
||||||
return lua_newuserdata(L, size);
|
return lua_newuserdata(L, size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::newMetatable(const std::string& name)
|
void ScriptContext::newMetatable(const std::string& name)
|
||||||
{
|
{
|
||||||
luaL_newmetatable(L, name.c_str());
|
luaL_newmetatable(L, name.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::setMetatable(const std::string& name, int index)
|
void ScriptContext::setMetatable(const std::string& name, int index)
|
||||||
{
|
{
|
||||||
luaL_getmetatable(L, name.c_str());
|
luaL_getmetatable(L, name.c_str());
|
||||||
if(isNil())
|
if(isNil())
|
||||||
|
@ -183,57 +159,57 @@ void LuaScript::setMetatable(const std::string& name, int index)
|
||||||
lua_setmetatable(L, index < 0 ? index-1 : index);
|
lua_setmetatable(L, index < 0 ? index-1 : index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::rawGet(const std::string& key)
|
void ScriptContext::rawGet(const std::string& key)
|
||||||
{
|
{
|
||||||
pushString(key);
|
pushString(key);
|
||||||
lua_rawget(L, -2);
|
lua_rawget(L, -2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::rawSet(const std::string& key)
|
void ScriptContext::rawSet(const std::string& key)
|
||||||
{
|
{
|
||||||
pushString(key);
|
pushString(key);
|
||||||
insert(-2);
|
insert(-2);
|
||||||
lua_rawset(L, -3);
|
lua_rawset(L, -3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::getField(const std::string& key)
|
void ScriptContext::getField(const std::string& key)
|
||||||
{
|
{
|
||||||
lua_getfield(L, -1, key.c_str());
|
lua_getfield(L, -1, key.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::setField(const std::string& key)
|
void ScriptContext::setField(const std::string& key)
|
||||||
{
|
{
|
||||||
lua_setfield(L, -2, key.c_str());
|
lua_setfield(L, -2, key.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::getScriptableField(const ScriptablePtr& scriptable, const std::string& field)
|
void ScriptContext::getScriptObjectField(const ScriptObjectPtr& scriptobject, const std::string& field)
|
||||||
{
|
{
|
||||||
if(scriptable) {
|
if(scriptobject) {
|
||||||
pushRef(scriptable->getLuaTableRef());
|
pushRef(scriptobject->getScriptTable());
|
||||||
getField(field);
|
getField(field);
|
||||||
remove(-2);
|
remove(-2);
|
||||||
} else
|
} else
|
||||||
pushNil();
|
pushNil();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::setScriptableField(const ScriptablePtr& scriptable, const std::string& field)
|
void ScriptContext::setScriptObjectField(const ScriptObjectPtr& scriptobject, const std::string& field)
|
||||||
{
|
{
|
||||||
if(scriptable) {
|
if(scriptobject) {
|
||||||
pushRef(scriptable->getLuaTableRef());
|
pushRef(scriptobject->getScriptTable());
|
||||||
insert(-2);
|
insert(-2);
|
||||||
setField(field);
|
setField(field);
|
||||||
}
|
}
|
||||||
pop();
|
pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::rawGetGlobalTableField(const std::string& globalTable, const std::string& key)
|
void ScriptContext::rawGetGlobalTableField(const std::string& globalTable, const std::string& key)
|
||||||
{
|
{
|
||||||
getGlobal(globalTable);
|
getGlobal(globalTable);
|
||||||
rawGet(key);
|
rawGet(key);
|
||||||
remove(-2);
|
remove(-2);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::rawSetGlobalTableField(const std::string& globalTable, const std::string& key)
|
void ScriptContext::rawSetGlobalTableField(const std::string& globalTable, const std::string& key)
|
||||||
{
|
{
|
||||||
getGlobal(globalTable);
|
getGlobal(globalTable);
|
||||||
insert(-2);
|
insert(-2);
|
||||||
|
@ -241,81 +217,81 @@ void LuaScript::rawSetGlobalTableField(const std::string& globalTable, const std
|
||||||
pop();
|
pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::getGlobal(const std::string& key)
|
void ScriptContext::getGlobal(const std::string& key)
|
||||||
{
|
{
|
||||||
lua_getfield(L, LUA_GLOBALSINDEX, key.c_str());
|
lua_getfield(L, LUA_GLOBALSINDEX, key.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::setGlobal(const std::string& key)
|
void ScriptContext::setGlobal(const std::string& key)
|
||||||
{
|
{
|
||||||
lua_setfield(L, LUA_GLOBALSINDEX, key.c_str());
|
lua_setfield(L, LUA_GLOBALSINDEX, key.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaScript::isNil(int index)
|
bool ScriptContext::isNil(int index)
|
||||||
{
|
{
|
||||||
return lua_isnil(L, index);
|
return lua_isnil(L, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaScript::isBoolean(int index)
|
bool ScriptContext::isBoolean(int index)
|
||||||
{
|
{
|
||||||
return lua_isboolean(L, index);
|
return lua_isboolean(L, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaScript::isNumber(int index)
|
bool ScriptContext::isNumber(int index)
|
||||||
{
|
{
|
||||||
return lua_isnumber(L, index);
|
return lua_isnumber(L, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaScript::isString(int index)
|
bool ScriptContext::isString(int index)
|
||||||
{
|
{
|
||||||
return lua_isstring(L, index);
|
return lua_isstring(L, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaScript::isTable(int index)
|
bool ScriptContext::isTable(int index)
|
||||||
{
|
{
|
||||||
return lua_istable(L, index);
|
return lua_istable(L, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaScript::isUserdata(int index)
|
bool ScriptContext::isUserdata(int index)
|
||||||
{
|
{
|
||||||
return lua_isuserdata(L, index);
|
return lua_isuserdata(L, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaScript::isFunction(int index)
|
bool ScriptContext::isFunction(int index)
|
||||||
{
|
{
|
||||||
return lua_isfunction(L, index);
|
return lua_isfunction(L, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaScript::isCFunction(int index)
|
bool ScriptContext::isCFunction(int index)
|
||||||
{
|
{
|
||||||
return lua_iscfunction(L, index);
|
return lua_iscfunction(L, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaScript::isLuaFunction(int index)
|
bool ScriptContext::isLuaFunction(int index)
|
||||||
{
|
{
|
||||||
return isFunction(index) && !isCFunction(index);
|
return isFunction(index) && !isCFunction(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::pop(int n)
|
void ScriptContext::pop(int n)
|
||||||
{
|
{
|
||||||
lua_pop(L, n);
|
lua_pop(L, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaScript::popBoolean()
|
bool ScriptContext::popBoolean()
|
||||||
{
|
{
|
||||||
bool b = (lua_toboolean(L, -1) != 0);
|
bool b = (lua_toboolean(L, -1) != 0);
|
||||||
pop();
|
pop();
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaScript::popInteger()
|
int ScriptContext::popInteger()
|
||||||
{
|
{
|
||||||
double d = lua_tonumber(L, -1);
|
double d = lua_tonumber(L, -1);
|
||||||
pop();
|
pop();
|
||||||
return (int)d;
|
return (int)d;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string LuaScript::popString()
|
std::string ScriptContext::popString()
|
||||||
{
|
{
|
||||||
std::string str;
|
std::string str;
|
||||||
if(lua_isstring(L, -1))
|
if(lua_isstring(L, -1))
|
||||||
|
@ -324,64 +300,64 @@ std::string LuaScript::popString()
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptablePtr LuaScript::popClassInstance()
|
ScriptObjectPtr ScriptContext::popClassInstance()
|
||||||
{
|
{
|
||||||
ScriptablePtr object;
|
ScriptObjectPtr object;
|
||||||
if(isUserdata()) { // instances are store as userdata
|
if(isUserdata()) { // instances are store as userdata
|
||||||
object = *((ScriptablePtr *)lua_touserdata(L, -1));
|
object = *((ScriptObjectPtr *)lua_touserdata(L, -1));
|
||||||
if(!object)
|
if(!object)
|
||||||
reportErrorWithTraceback("attempt to retrive class instance from a object that is already expired");
|
reportErrorWithTraceback("attempt to retrive class instance from a object that is already expired");
|
||||||
} else if(!isNil()) // we accept nil values
|
} else if(!isNil()) // we accept nil values
|
||||||
reportErrorWithTraceback("couldn't retrive class instance, the value is not a scriptable type");
|
reportErrorWithTraceback("couldn't retrive class instance, the value is not a scriptobject type");
|
||||||
pop();
|
pop();
|
||||||
return object;
|
return object;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaScript::popRef()
|
int ScriptContext::popRef()
|
||||||
{
|
{
|
||||||
return luaL_ref(L, LUA_REGISTRYINDEX);
|
return luaL_ref(L, LUA_REGISTRYINDEX);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::pushNil()
|
void ScriptContext::pushNil()
|
||||||
{
|
{
|
||||||
lua_pushnil(L);
|
lua_pushnil(L);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::pushBoolean(bool b)
|
void ScriptContext::pushBoolean(bool b)
|
||||||
{
|
{
|
||||||
lua_pushboolean(L, b);
|
lua_pushboolean(L, b);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::pushInteger(int32_t i)
|
void ScriptContext::pushInteger(int32_t i)
|
||||||
{
|
{
|
||||||
lua_pushnumber(L, i);
|
lua_pushnumber(L, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::pushString(const std::string& str)
|
void ScriptContext::pushString(const std::string& str)
|
||||||
{
|
{
|
||||||
lua_pushstring(L, str.c_str());
|
lua_pushstring(L, str.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::pushClassInstance(const ScriptablePtr& object)
|
void ScriptContext::pushClassInstance(const ScriptObjectPtr& object)
|
||||||
{
|
{
|
||||||
if(object) {
|
if(object) {
|
||||||
new(newUserdata(sizeof(ScriptablePtr))) ScriptablePtr(object);
|
new(newUserdata(sizeof(ScriptObjectPtr))) ScriptObjectPtr(object);
|
||||||
setMetatable(std::string(object->getScriptableName()) + "_mt");
|
setMetatable(std::string(object->getScriptObjectType()) + "_mt");
|
||||||
} else
|
} else
|
||||||
pushNil();
|
pushNil();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::pushValue(int index)
|
void ScriptContext::pushValue(int index)
|
||||||
{
|
{
|
||||||
lua_pushvalue(L, index);
|
lua_pushvalue(L, index);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::pushRef(int ref)
|
void ScriptContext::pushRef(int ref)
|
||||||
{
|
{
|
||||||
lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
|
lua_rawgeti(L, LUA_REGISTRYINDEX, ref);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string LuaScript::getFunctionSourcePath(bool functionIsOnStack, int level)
|
std::string ScriptContext::getFunctionSourcePath(bool functionIsOnStack, int level)
|
||||||
{
|
{
|
||||||
std::string path;
|
std::string path;
|
||||||
|
|
||||||
|
@ -415,14 +391,14 @@ std::string LuaScript::getFunctionSourcePath(bool functionIsOnStack, int level)
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LuaScript::callFunction(int numArgs, int numRets)
|
bool ScriptContext::callFunction(int numArgs, int numRets)
|
||||||
{
|
{
|
||||||
pushValue(-numArgs - 1);
|
pushValue(-numArgs - 1);
|
||||||
g_resources.pushCurrentPath(getFunctionSourcePath(true));
|
g_resources.pushCurrentPath(getFunctionSourcePath(true));
|
||||||
|
|
||||||
int size = getStackSize();
|
int size = getStackSize();
|
||||||
int errorIndex = -numArgs - 2;
|
int errorIndex = -numArgs - 2;
|
||||||
lua_pushcfunction(L, &LuaScript::luaErrorHandler);
|
lua_pushcfunction(L, &ScriptContext::luaErrorHandler);
|
||||||
insert(errorIndex);
|
insert(errorIndex);
|
||||||
|
|
||||||
int ret = lua_pcall(L, numArgs, numRets, errorIndex);
|
int ret = lua_pcall(L, numArgs, numRets, errorIndex);
|
||||||
|
@ -443,13 +419,13 @@ bool LuaScript::callFunction(int numArgs, int numRets)
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::callModuleField(const std::string& module, const std::string& field)
|
void ScriptContext::callModuleField(const std::string& module, const std::string& field)
|
||||||
{
|
{
|
||||||
g_lua.rawGetGlobalTableField(module, field);
|
g_lua.rawGetGlobalTableField(module, field);
|
||||||
g_lua.callFunction();
|
g_lua.callFunction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::setupPackageLoader()
|
void ScriptContext::setupPackageLoader()
|
||||||
{
|
{
|
||||||
lua_getfield(L, LUA_GLOBALSINDEX, "package"); // package
|
lua_getfield(L, LUA_GLOBALSINDEX, "package"); // package
|
||||||
lua_getfield(L, -1, "loaders"); // package.loaders, package
|
lua_getfield(L, -1, "loaders"); // package.loaders, package
|
||||||
|
@ -462,12 +438,12 @@ void LuaScript::setupPackageLoader()
|
||||||
numLoaders++;
|
numLoaders++;
|
||||||
}
|
}
|
||||||
lua_pushinteger(L, numLoaders + 1); // at, package.loaders
|
lua_pushinteger(L, numLoaders + 1); // at, package.loaders
|
||||||
lua_pushcfunction(L, &LuaScript::luaPackageLoader); // luaPackageLoader, at, package.loaders
|
lua_pushcfunction(L, &ScriptContext::luaPackageLoader); // luaPackageLoader, at, package.loaders
|
||||||
lua_rawset(L, -3); // package.loaders
|
lua_rawset(L, -3); // package.loaders
|
||||||
lua_pop(L, 1); // (empty)
|
lua_pop(L, 1); // (empty)
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::registerClass(const std::string& klass, const std::string& baseClass)
|
void ScriptContext::registerClass(const std::string& klass, const std::string& baseClass)
|
||||||
{
|
{
|
||||||
// mt = {}
|
// mt = {}
|
||||||
lua_newtable(L);
|
lua_newtable(L);
|
||||||
|
@ -475,19 +451,19 @@ void LuaScript::registerClass(const std::string& klass, const std::string& baseC
|
||||||
lua_setfield(L, LUA_REGISTRYINDEX, (klass + "_mt").c_str());
|
lua_setfield(L, LUA_REGISTRYINDEX, (klass + "_mt").c_str());
|
||||||
|
|
||||||
// set __index metamethod
|
// set __index metamethod
|
||||||
lua_pushcfunction(L, &LuaScript::luaIndexMetaMethod);
|
lua_pushcfunction(L, &ScriptContext::luaIndexMetaMethod);
|
||||||
lua_setfield(L, -2, "__index");
|
lua_setfield(L, -2, "__index");
|
||||||
|
|
||||||
// set __newindex metamethod
|
// set __newindex metamethod
|
||||||
lua_pushcfunction(L, &LuaScript::luaNewIndexMetaMethod);
|
lua_pushcfunction(L, &ScriptContext::luaNewIndexMetaMethod);
|
||||||
lua_setfield(L, -2, "__newindex");
|
lua_setfield(L, -2, "__newindex");
|
||||||
|
|
||||||
// set __eq metamethod
|
// set __eq metamethod
|
||||||
lua_pushcfunction(L, &LuaScript::luaEqualMetaMethod);
|
lua_pushcfunction(L, &ScriptContext::luaEqualMetaMethod);
|
||||||
lua_setfield(L, -2, "__eq");
|
lua_setfield(L, -2, "__eq");
|
||||||
|
|
||||||
// set __gc metamethod, which collects userdata
|
// set __gc metamethod, which collects userdata
|
||||||
lua_pushcfunction(L, &LuaScript::luaGarbageCollectMetaMethod);
|
lua_pushcfunction(L, &ScriptContext::luaGarbageCollectMetaMethod);
|
||||||
lua_setfield(L, -2, "__gc");
|
lua_setfield(L, -2, "__gc");
|
||||||
|
|
||||||
// klass = { }
|
// klass = { }
|
||||||
|
@ -536,7 +512,7 @@ void LuaScript::registerClass(const std::string& klass, const std::string& baseC
|
||||||
m_currentClass = klass;
|
m_currentClass = klass;
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::registerMemberField(const std::string& field, LuaScript::LuaCFunction getFunction, LuaScript::LuaCFunction setFunction)
|
void ScriptContext::registerMemberField(const std::string& field, ScriptContext::LuaCFunction getFunction, ScriptContext::LuaCFunction setFunction)
|
||||||
{
|
{
|
||||||
if(getFunction) {
|
if(getFunction) {
|
||||||
int functionId = m_functions.size();
|
int functionId = m_functions.size();
|
||||||
|
@ -547,7 +523,7 @@ void LuaScript::registerMemberField(const std::string& field, LuaScript::LuaCFun
|
||||||
// push the function id
|
// push the function id
|
||||||
lua_pushnumber(L, functionId);
|
lua_pushnumber(L, functionId);
|
||||||
// store id in the closure
|
// store id in the closure
|
||||||
lua_pushcclosure(L, &LuaScript::luaFunctionCallback, 1);
|
lua_pushcclosure(L, &ScriptContext::luaFunctionCallback, 1);
|
||||||
// store the function at the class field functionName
|
// store the function at the class field functionName
|
||||||
lua_setfield(L, -2, ("get_" + field).c_str());
|
lua_setfield(L, -2, ("get_" + field).c_str());
|
||||||
// pop the table
|
// pop the table
|
||||||
|
@ -563,7 +539,7 @@ void LuaScript::registerMemberField(const std::string& field, LuaScript::LuaCFun
|
||||||
// push the function id
|
// push the function id
|
||||||
lua_pushnumber(L, functionId);
|
lua_pushnumber(L, functionId);
|
||||||
// store id in the closure
|
// store id in the closure
|
||||||
lua_pushcclosure(L, &LuaScript::luaFunctionCallback, 1);
|
lua_pushcclosure(L, &ScriptContext::luaFunctionCallback, 1);
|
||||||
// store the function at the class field functionName
|
// store the function at the class field functionName
|
||||||
lua_setfield(L, -2, ("set_" + field).c_str());
|
lua_setfield(L, -2, ("set_" + field).c_str());
|
||||||
// pop the table
|
// pop the table
|
||||||
|
@ -571,7 +547,7 @@ void LuaScript::registerMemberField(const std::string& field, LuaScript::LuaCFun
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::registerMemberFunction(const std::string& functionName, LuaCFunction function)
|
void ScriptContext::registerMemberFunction(const std::string& functionName, LuaCFunction function)
|
||||||
{
|
{
|
||||||
int functionId = m_functions.size();
|
int functionId = m_functions.size();
|
||||||
m_functions.push_back(function);
|
m_functions.push_back(function);
|
||||||
|
@ -581,14 +557,14 @@ void LuaScript::registerMemberFunction(const std::string& functionName, LuaCFunc
|
||||||
// push the function id
|
// push the function id
|
||||||
lua_pushnumber(L, functionId);
|
lua_pushnumber(L, functionId);
|
||||||
// store id in the closure
|
// store id in the closure
|
||||||
lua_pushcclosure(L, &LuaScript::luaFunctionCallback, 1);
|
lua_pushcclosure(L, &ScriptContext::luaFunctionCallback, 1);
|
||||||
// store the function at the class field functionName
|
// store the function at the class field functionName
|
||||||
lua_setfield(L, -2, functionName.c_str());
|
lua_setfield(L, -2, functionName.c_str());
|
||||||
// pop the table
|
// pop the table
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::registerGlobalFunction(const std::string& functionName, LuaCFunction function)
|
void ScriptContext::registerGlobalFunction(const std::string& functionName, LuaCFunction function)
|
||||||
{
|
{
|
||||||
int functionId = m_functions.size();
|
int functionId = m_functions.size();
|
||||||
m_functions.push_back(function);
|
m_functions.push_back(function);
|
||||||
|
@ -596,12 +572,12 @@ void LuaScript::registerGlobalFunction(const std::string& functionName, LuaCFunc
|
||||||
// push the function id
|
// push the function id
|
||||||
lua_pushnumber(L, functionId);
|
lua_pushnumber(L, functionId);
|
||||||
// store id in the closure
|
// store id in the closure
|
||||||
lua_pushcclosure(L, &LuaScript::luaFunctionCallback, 1);
|
lua_pushcclosure(L, &ScriptContext::luaFunctionCallback, 1);
|
||||||
// store the function in the global lua table
|
// store the function in the global lua table
|
||||||
lua_setfield(L, LUA_GLOBALSINDEX, functionName.c_str());
|
lua_setfield(L, LUA_GLOBALSINDEX, functionName.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
void LuaScript::registerModule(const std::string& module)
|
void ScriptContext::registerModule(const std::string& module)
|
||||||
{
|
{
|
||||||
registerClass(module);
|
registerClass(module);
|
||||||
lua_getfield(L, LUA_GLOBALSINDEX, module.c_str());
|
lua_getfield(L, LUA_GLOBALSINDEX, module.c_str());
|
||||||
|
@ -610,7 +586,7 @@ void LuaScript::registerModule(const std::string& module)
|
||||||
lua_pop(L, -1);
|
lua_pop(L, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaScript::luaPackageLoader(lua_State* L)
|
int ScriptContext::luaPackageLoader(lua_State* L)
|
||||||
{
|
{
|
||||||
std::string fileName = lua_tostring(L, -1);
|
std::string fileName = lua_tostring(L, -1);
|
||||||
fileName += ".lua";
|
fileName += ".lua";
|
||||||
|
@ -624,7 +600,7 @@ int LuaScript::luaPackageLoader(lua_State* L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaScript::luaIndexMetaMethod(lua_State* L)
|
int ScriptContext::luaIndexMetaMethod(lua_State* L)
|
||||||
{
|
{
|
||||||
// stack: key, obj
|
// stack: key, obj
|
||||||
std::string key = lua_tostring(L, -1); // key, obj
|
std::string key = lua_tostring(L, -1); // key, obj
|
||||||
|
@ -658,7 +634,7 @@ int LuaScript::luaIndexMetaMethod(lua_State* L)
|
||||||
g_lua.rawGet(key);
|
g_lua.rawGet(key);
|
||||||
g_lua.remove(-2);
|
g_lua.remove(-2);
|
||||||
} else if(g_lua.isUserdata()) {
|
} else if(g_lua.isUserdata()) {
|
||||||
g_lua.getScriptableField(g_lua.popClassInstance(), key);
|
g_lua.getScriptObjectField(g_lua.popClassInstance(), key);
|
||||||
} else {
|
} else {
|
||||||
g_lua.pop();
|
g_lua.pop();
|
||||||
g_lua.pushNil();
|
g_lua.pushNil();
|
||||||
|
@ -668,7 +644,7 @@ int LuaScript::luaIndexMetaMethod(lua_State* L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaScript::luaNewIndexMetaMethod(lua_State* L)
|
int ScriptContext::luaNewIndexMetaMethod(lua_State* L)
|
||||||
{
|
{
|
||||||
// stack: value, key, obj
|
// stack: value, key, obj
|
||||||
lua_insert(L, -2); // key, value, obj
|
lua_insert(L, -2); // key, value, obj
|
||||||
|
@ -693,7 +669,7 @@ int LuaScript::luaNewIndexMetaMethod(lua_State* L)
|
||||||
g_lua.rawSet(key);
|
g_lua.rawSet(key);
|
||||||
g_lua.pop();
|
g_lua.pop();
|
||||||
} else if(g_lua.isUserdata()) {
|
} else if(g_lua.isUserdata()) {
|
||||||
g_lua.setScriptableField(g_lua.popClassInstance(), key);
|
g_lua.setScriptObjectField(g_lua.popClassInstance(), key);
|
||||||
} else {
|
} else {
|
||||||
g_lua.pop(2);
|
g_lua.pop(2);
|
||||||
g_lua.reportErrorWithTraceback("unknown type in index metamethod");
|
g_lua.reportErrorWithTraceback("unknown type in index metamethod");
|
||||||
|
@ -702,14 +678,14 @@ int LuaScript::luaNewIndexMetaMethod(lua_State* L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaScript::luaEqualMetaMethod(lua_State* L)
|
int ScriptContext::luaEqualMetaMethod(lua_State* L)
|
||||||
{
|
{
|
||||||
if(!lua_isuserdata(L, -1) || !lua_isuserdata(L, -2)) {
|
if(!lua_isuserdata(L, -1) || !lua_isuserdata(L, -2)) {
|
||||||
lua_pop(L, 2);
|
lua_pop(L, 2);
|
||||||
lua_pushboolean(L, 0);
|
lua_pushboolean(L, 0);
|
||||||
} else {
|
} else {
|
||||||
ScriptablePtr *objectRef1 = (ScriptablePtr *)lua_touserdata(L, -1);
|
ScriptObjectPtr *objectRef1 = (ScriptObjectPtr *)lua_touserdata(L, -1);
|
||||||
ScriptablePtr *objectRef2 = (ScriptablePtr *)lua_touserdata(L, -2);
|
ScriptObjectPtr *objectRef2 = (ScriptObjectPtr *)lua_touserdata(L, -2);
|
||||||
lua_pop(L, 2);
|
lua_pop(L, 2);
|
||||||
if(objectRef1 == objectRef2)
|
if(objectRef1 == objectRef2)
|
||||||
lua_pushboolean(L, 1);
|
lua_pushboolean(L, 1);
|
||||||
|
@ -719,17 +695,17 @@ int LuaScript::luaEqualMetaMethod(lua_State* L)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaScript::luaGarbageCollectMetaMethod(lua_State* L)
|
int ScriptContext::luaGarbageCollectMetaMethod(lua_State* L)
|
||||||
{
|
{
|
||||||
if(lua_isuserdata(L, -1)) {
|
if(lua_isuserdata(L, -1)) {
|
||||||
ScriptablePtr *objectRef = (ScriptablePtr *)lua_touserdata(L, -1);
|
ScriptObjectPtr *objectRef = (ScriptObjectPtr *)lua_touserdata(L, -1);
|
||||||
objectRef->reset();
|
objectRef->reset();
|
||||||
}
|
}
|
||||||
lua_pop(L, 1);
|
lua_pop(L, 1);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaScript::luaFunctionCallback(lua_State* L)
|
int ScriptContext::luaFunctionCallback(lua_State* L)
|
||||||
{
|
{
|
||||||
// look for function id
|
// look for function id
|
||||||
int id = lua_tonumber(L, lua_upvalueindex(1));
|
int id = lua_tonumber(L, lua_upvalueindex(1));
|
||||||
|
@ -743,7 +719,7 @@ int LuaScript::luaFunctionCallback(lua_State* L)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
int LuaScript::luaErrorHandler(lua_State *L)
|
int ScriptContext::luaErrorHandler(lua_State *L)
|
||||||
{
|
{
|
||||||
// push debug
|
// push debug
|
||||||
lua_getfield(L, LUA_GLOBALSINDEX, "debug");
|
lua_getfield(L, LUA_GLOBALSINDEX, "debug");
|
|
@ -1,42 +1,18 @@
|
||||||
/* The MIT License
|
#ifndef SCRIPTCONTEXT_H
|
||||||
*
|
#define SCRIPTCONTEXT_H
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef LUASCRIPT_H
|
|
||||||
#define LUASCRIPT_H
|
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <script/scriptable.h>
|
#include "scriptobject.h"
|
||||||
|
|
||||||
#define reportFuncError(a) reportError(a, __FUNCTION__)
|
#define reportFuncError(a) reportError(a, __FUNCTION__)
|
||||||
#define reportFuncErrorWithTraceback(a) reportErrorWithTraceback(a, __FUNCTION__)
|
#define reportFuncErrorWithTraceback(a) reportErrorWithTraceback(a, __FUNCTION__)
|
||||||
|
|
||||||
struct lua_State;
|
struct lua_State;
|
||||||
|
|
||||||
class LuaScript
|
class ScriptContext
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
LuaScript() : L(NULL) { }
|
ScriptContext() : L(NULL) { }
|
||||||
|
|
||||||
void init();
|
void init();
|
||||||
void terminate();
|
void terminate();
|
||||||
|
@ -70,8 +46,8 @@ public:
|
||||||
void getField(const std::string& key);
|
void getField(const std::string& key);
|
||||||
void setField(const std::string& key);
|
void setField(const std::string& key);
|
||||||
|
|
||||||
void getScriptableField(const ScriptablePtr& scriptable, const std::string& field);
|
void getScriptObjectField(const ScriptObjectPtr& scriptobject, const std::string& field);
|
||||||
void setScriptableField(const ScriptablePtr& scriptable, const std::string& field);
|
void setScriptObjectField(const ScriptObjectPtr& scriptobject, const std::string& field);
|
||||||
|
|
||||||
void rawGetGlobalTableField(const std::string& globalTable, const std::string& key);
|
void rawGetGlobalTableField(const std::string& globalTable, const std::string& key);
|
||||||
void rawSetGlobalTableField(const std::string& globalTable, const std::string& key);
|
void rawSetGlobalTableField(const std::string& globalTable, const std::string& key);
|
||||||
|
@ -93,14 +69,14 @@ public:
|
||||||
bool popBoolean();
|
bool popBoolean();
|
||||||
int popInteger();
|
int popInteger();
|
||||||
std::string popString();
|
std::string popString();
|
||||||
ScriptablePtr popClassInstance();
|
ScriptObjectPtr popClassInstance();
|
||||||
int popRef();
|
int popRef();
|
||||||
|
|
||||||
void pushNil();
|
void pushNil();
|
||||||
void pushBoolean(bool b);
|
void pushBoolean(bool b);
|
||||||
void pushInteger(int i);
|
void pushInteger(int i);
|
||||||
void pushString(const std::string& str);
|
void pushString(const std::string& str);
|
||||||
void pushClassInstance(const ScriptablePtr& object);
|
void pushClassInstance(const ScriptObjectPtr& object);
|
||||||
void pushValue(int index = -1);
|
void pushValue(int index = -1);
|
||||||
void pushRef(int ref);
|
void pushRef(int ref);
|
||||||
|
|
||||||
|
@ -134,6 +110,6 @@ private:
|
||||||
lua_State *L;
|
lua_State *L;
|
||||||
};
|
};
|
||||||
|
|
||||||
extern LuaScript g_lua;
|
extern ScriptContext g_lua;
|
||||||
|
|
||||||
#endif // LUASCRIPT_H
|
#endif // SCRIPTCONTEXT_H
|
|
@ -1,37 +1,13 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <script/luafunctions.h>
|
#include <script/scriptfunctions.h>
|
||||||
#include <script/luascript.h>
|
#include <script/scriptcontext.h>
|
||||||
#include <core/engine.h>
|
#include <core/engine.h>
|
||||||
#include <core/resources.h>
|
#include <core/resources.h>
|
||||||
#include <ui/ui.h>
|
#include <ui/ui.h>
|
||||||
#include <core/dispatcher.h>
|
#include <core/dispatcher.h>
|
||||||
#include "../../protocollogin.h"
|
#include "../../protocollogin.h"
|
||||||
|
|
||||||
void registerLuaFunctions()
|
void registerScriptFunctions()
|
||||||
{
|
{
|
||||||
// App
|
// App
|
||||||
g_lua.registerModule("App");
|
g_lua.registerModule("App");
|
||||||
|
@ -240,7 +216,7 @@ int lua_UIElement_destroy()
|
||||||
{
|
{
|
||||||
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
if(UIElementPtr element = boost::dynamic_pointer_cast<UIElement>(g_lua.popClassInstance()))
|
||||||
element->destroyLater();
|
element->destroyLater();
|
||||||
g_dispatcher.addTask(boost::bind(&LuaScript::collectGarbage, &g_lua));
|
g_dispatcher.addTask(boost::bind(&ScriptContext::collectGarbage, &g_lua));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,52 @@
|
||||||
|
|
||||||
|
#ifndef SCRIPTFUNCTIONS_H
|
||||||
|
#define SCRIPTFUNCTIONS_H
|
||||||
|
|
||||||
|
#include <global.h>
|
||||||
|
#include "scriptobject.h"
|
||||||
|
|
||||||
|
void registerScriptFunctions();
|
||||||
|
|
||||||
|
// App
|
||||||
|
int lua_App_exit();
|
||||||
|
|
||||||
|
// UI
|
||||||
|
int lua_UI_load();
|
||||||
|
int lua_UI_getRootContainer();
|
||||||
|
|
||||||
|
// UIElement
|
||||||
|
int lua_UIElement_getId();
|
||||||
|
int lua_UIElement_setId();
|
||||||
|
int lua_UIElement_isEnabled();
|
||||||
|
int lua_UIElement_setEnabled();
|
||||||
|
int lua_UIElement_isVisible();
|
||||||
|
int lua_UIElement_setVisible();
|
||||||
|
int lua_UIElement_isFocused();
|
||||||
|
int lua_UIElement_setFocused();
|
||||||
|
int lua_UIElement_getParent();
|
||||||
|
int lua_UIElement_setParent();
|
||||||
|
int lua_UIElement_setLocked();
|
||||||
|
int lua_UIElement_destroy();
|
||||||
|
void lua_UIElement_onLoad();
|
||||||
|
void lua_UIElement_onDestroy();
|
||||||
|
|
||||||
|
// UIContainer
|
||||||
|
int lua_UIContainer_getChild();
|
||||||
|
int lua_UIContainer_getChildren();
|
||||||
|
|
||||||
|
// UILabel
|
||||||
|
int lua_UILabel_setText();
|
||||||
|
int lua_UILabel_getText();
|
||||||
|
|
||||||
|
// UITextEdit
|
||||||
|
int lua_UITextEdit_setText();
|
||||||
|
int lua_UITextEdit_getText();
|
||||||
|
|
||||||
|
// UIButton
|
||||||
|
void lua_UIButton_onClick();
|
||||||
|
|
||||||
|
// UIWindow
|
||||||
|
int lua_UIWindow_setTitle();
|
||||||
|
int lua_UIWindow_getTitle();
|
||||||
|
|
||||||
|
#endif // SCRIPTFUNCTIONS_H
|
|
@ -0,0 +1,54 @@
|
||||||
|
#include "scriptobject.h"
|
||||||
|
#include "scriptcontext.h"
|
||||||
|
|
||||||
|
#include <core/dispatcher.h>
|
||||||
|
|
||||||
|
void ScriptObject::releaseScriptObject()
|
||||||
|
{
|
||||||
|
if(m_scriptTableRef != -1) {
|
||||||
|
g_lua.releaseRef(m_scriptTableRef);
|
||||||
|
m_scriptTableRef = -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int ScriptObject::getScriptTable()
|
||||||
|
{
|
||||||
|
if(m_scriptTableRef == -1) {
|
||||||
|
g_lua.newTable();
|
||||||
|
m_scriptTableRef = g_lua.popRef();
|
||||||
|
}
|
||||||
|
return m_scriptTableRef;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptObject::callScriptTableField(const std::string& field, int numArgs)
|
||||||
|
{
|
||||||
|
// set self
|
||||||
|
g_lua.pushClassInstance(shared_from_this());
|
||||||
|
g_lua.setGlobal("self");
|
||||||
|
|
||||||
|
// push field
|
||||||
|
g_lua.getScriptObjectField(shared_from_this(), field);
|
||||||
|
|
||||||
|
// call it if its a function
|
||||||
|
if(g_lua.isFunction()) {
|
||||||
|
g_lua.insert(-numArgs-1);
|
||||||
|
g_lua.callFunction(numArgs);
|
||||||
|
// if its an array call each element
|
||||||
|
} else if(g_lua.isTable()) {
|
||||||
|
//TODO: call here with arguments
|
||||||
|
g_lua.pushNil();
|
||||||
|
while(g_lua.next()) {
|
||||||
|
// call it if its a function
|
||||||
|
if(g_lua.isFunction())
|
||||||
|
g_lua.callFunction();
|
||||||
|
g_lua.pop();
|
||||||
|
}
|
||||||
|
} else if(!g_lua.isNil()) {
|
||||||
|
g_lua.reportError(make_string("field '", field, "' for '", getScriptObjectType(), "' is not a valid function or array of functions"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// release self
|
||||||
|
g_lua.pushNil();
|
||||||
|
g_lua.setGlobal("self");
|
||||||
|
}
|
||||||
|
|
|
@ -0,0 +1,26 @@
|
||||||
|
#ifndef SCRIPTOBJECT_H
|
||||||
|
#define SCRIPTOBJECT_H
|
||||||
|
|
||||||
|
#include <global.h>
|
||||||
|
|
||||||
|
class ScriptObject : public boost::enable_shared_from_this<ScriptObject>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ScriptObject() : m_scriptTableRef(-1) { }
|
||||||
|
virtual ~ScriptObject() { releaseScriptObject(); }
|
||||||
|
|
||||||
|
void releaseScriptObject();
|
||||||
|
|
||||||
|
//TODO: global destroy
|
||||||
|
virtual const char *getScriptObjectType() const { return NULL; }
|
||||||
|
|
||||||
|
int getScriptTable();
|
||||||
|
void callScriptTableField(const std::string& field, int numArgs = 0);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int m_scriptTableRef;
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef boost::shared_ptr<ScriptObject> ScriptObjectPtr;
|
||||||
|
|
||||||
|
#endif // SCRIPTOBJECT_H
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <ui/uianchorlayout.h>
|
#include <ui/uianchorlayout.h>
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UIANCHORLAYOUT_H
|
#ifndef UIANCHORLAYOUT_H
|
||||||
#define UIANCHORLAYOUT_H
|
#define UIANCHORLAYOUT_H
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <core/dispatcher.h>
|
#include <core/dispatcher.h>
|
||||||
#include <ui/uibutton.h>
|
#include <ui/uibutton.h>
|
||||||
|
@ -34,7 +10,7 @@ void UIButton::onInputEvent(const InputEvent& event)
|
||||||
} else if(event.type == EV_MOUSE_LUP && m_state == ButtonDown) {
|
} else if(event.type == EV_MOUSE_LUP && m_state == ButtonDown) {
|
||||||
m_state = ButtonUp;
|
m_state = ButtonUp;
|
||||||
if(getRect().contains(event.mousePos)) {
|
if(getRect().contains(event.mousePos)) {
|
||||||
g_dispatcher.addTask(boost::bind(&Scriptable::callLuaTableField, shared_from_this(), "onClick", 0));
|
g_dispatcher.addTask(boost::bind(&ScriptObject::callScriptTableField, shared_from_this(), "onClick", 0));
|
||||||
}
|
}
|
||||||
} else if(event.type == EV_MOUSE_MOVE && m_state != ButtonDown) {
|
} else if(event.type == EV_MOUSE_MOVE && m_state != ButtonDown) {
|
||||||
if(isMouseOver())
|
if(isMouseOver())
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UIBUTTON_H
|
#ifndef UIBUTTON_H
|
||||||
#define UIBUTTON_H
|
#define UIBUTTON_H
|
||||||
|
|
||||||
|
@ -37,7 +13,7 @@ class UIButton : public UIElement
|
||||||
public:
|
public:
|
||||||
enum ButtonState
|
enum ButtonState
|
||||||
{
|
{
|
||||||
ButtonUp,
|
ButtonUp = 0,
|
||||||
ButtonDown,
|
ButtonDown,
|
||||||
ButtonMouseOver
|
ButtonMouseOver
|
||||||
};
|
};
|
||||||
|
@ -53,7 +29,7 @@ public:
|
||||||
|
|
||||||
ButtonState getState() { return m_state; }
|
ButtonState getState() { return m_state; }
|
||||||
|
|
||||||
virtual const char *getScriptableName() const { return "UIButton"; }
|
virtual const char *getScriptObjectType() const { return "UIButton"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_text;
|
std::string m_text;
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <graphics/fonts.h>
|
#include <graphics/fonts.h>
|
||||||
#include <ui/uibuttonskin.h>
|
#include <ui/uibuttonskin.h>
|
||||||
|
@ -31,40 +7,35 @@ void UIButtonSkin::load(OTMLNode* node)
|
||||||
{
|
{
|
||||||
UIElementSkin::load(node);
|
UIElementSkin::load(node);
|
||||||
|
|
||||||
m_buttonDownTextColor = getFontColor();
|
UIButtonStateSkinPtr defaultStateSkin = loadStateSkin(node);
|
||||||
m_buttonHoverTextColor = getFontColor();
|
m_statesSkin[UIButton::ButtonUp] = defaultStateSkin;
|
||||||
|
m_statesSkin[UIButton::ButtonDown] = defaultStateSkin;
|
||||||
|
m_statesSkin[UIButton::ButtonMouseOver] = defaultStateSkin;
|
||||||
|
|
||||||
if(OTMLNode* cnode = node->at("down state")) {
|
if(OTMLNode* cnode = node->at("down state"))
|
||||||
m_buttonDownImage = loadImage(cnode);
|
m_statesSkin[UIButton::ButtonDown] = loadStateSkin(cnode);
|
||||||
m_buttonDownTranslate = cnode->readAt("text translate", Point());
|
|
||||||
m_buttonDownTextColor = cnode->readAt("font color", getFontColor());
|
if(OTMLNode* cnode = node->at("hover state"))
|
||||||
|
m_statesSkin[UIButton::ButtonMouseOver] = loadStateSkin(cnode);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(OTMLNode* cnode = node->at("hover state")) {
|
UIButtonStateSkinPtr UIButtonSkin::loadStateSkin(OTMLNode* node)
|
||||||
m_buttonHoverImage = loadImage(cnode);
|
{
|
||||||
m_buttonHoverTextColor = cnode->readAt("font color", getFontColor());
|
UIButtonStateSkinPtr stateSkin = UIButtonStateSkinPtr(new UIButtonStateSkin);
|
||||||
}
|
stateSkin->image = loadImage(node);
|
||||||
|
stateSkin->textTranslate = node->readAt("text translate", Point());
|
||||||
|
stateSkin->textColor = node->readAt("font color", getFontColor());
|
||||||
|
return stateSkin;
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIButtonSkin::draw(UIElement *element)
|
void UIButtonSkin::draw(UIElement *element)
|
||||||
{
|
{
|
||||||
UIButton *button = static_cast<UIButton*>(element);
|
UIButton *button = static_cast<UIButton*>(element);
|
||||||
|
UIButtonStateSkinPtr stateSkin = m_statesSkin[button->getState()];
|
||||||
Rect textRect = button->getRect();
|
Rect textRect = button->getRect();
|
||||||
|
|
||||||
if(button->getState() == UIButton::ButtonDown && m_buttonDownImage) {
|
stateSkin->image->draw(element->getRect());
|
||||||
m_buttonDownImage->draw(element->getRect());
|
textRect.translate(stateSkin->textTranslate);
|
||||||
textRect.translate(m_buttonDownTranslate);
|
|
||||||
} else if(button->getState() == UIButton::ButtonMouseOver && m_buttonHoverImage) {
|
|
||||||
m_buttonHoverImage->draw(element->getRect());
|
|
||||||
} else {
|
|
||||||
UIElementSkin::draw(element);
|
|
||||||
}
|
|
||||||
|
|
||||||
Color textColor = getFontColor();
|
getFont()->renderText(button->getText(), textRect, AlignCenter, stateSkin->textColor);
|
||||||
if(button->getState() == UIButton::ButtonDown)
|
|
||||||
textColor = m_buttonDownTextColor;
|
|
||||||
else if(button->getState() == UIButton::ButtonMouseOver)
|
|
||||||
textColor = m_buttonHoverTextColor;
|
|
||||||
getFont()->renderText(button->getText(), textRect, AlignCenter, textColor);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UIBUTTONSKIN_H
|
#ifndef UIBUTTONSKIN_H
|
||||||
#define UIBUTTONSKIN_H
|
#define UIBUTTONSKIN_H
|
||||||
|
|
||||||
|
@ -31,6 +7,13 @@
|
||||||
|
|
||||||
class Font;
|
class Font;
|
||||||
|
|
||||||
|
struct UIButtonStateSkin {
|
||||||
|
ImagePtr image;
|
||||||
|
Point textTranslate;
|
||||||
|
Color textColor;
|
||||||
|
};
|
||||||
|
typedef boost::shared_ptr<UIButtonStateSkin> UIButtonStateSkinPtr;
|
||||||
|
|
||||||
class UIButtonSkin : public UIElementSkin
|
class UIButtonSkin : public UIElementSkin
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@ -38,14 +21,12 @@ public:
|
||||||
UIElementSkin(name, UI::Button) { }
|
UIElementSkin(name, UI::Button) { }
|
||||||
|
|
||||||
void load(OTMLNode* node);
|
void load(OTMLNode* node);
|
||||||
|
UIButtonStateSkinPtr loadStateSkin(OTMLNode* node);
|
||||||
|
|
||||||
void draw(UIElement *element);
|
void draw(UIElement *element);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ImagePtr m_buttonDownImage;
|
UIButtonStateSkinPtr m_statesSkin[3];
|
||||||
ImagePtr m_buttonHoverImage;
|
|
||||||
Point m_buttonDownTranslate;
|
|
||||||
Color m_buttonDownTextColor;
|
|
||||||
Color m_buttonHoverTextColor;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // UIBUTTONSKIN_H
|
#endif // UIBUTTONSKIN_H
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <ui/uicheckbox.h>
|
#include <ui/uicheckbox.h>
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UICHECKBOX_H
|
#ifndef UICHECKBOX_H
|
||||||
#define UICHECKBOX_H
|
#define UICHECKBOX_H
|
||||||
|
|
||||||
|
@ -33,7 +9,7 @@ class UICheckBox : public UIElement
|
||||||
public:
|
public:
|
||||||
UICheckBox(UI::ElementType type = UI::Element);
|
UICheckBox(UI::ElementType type = UI::Element);
|
||||||
|
|
||||||
virtual const char *getScriptableName() const { return "UICheckBox"; }
|
virtual const char *getScriptObjectType() const { return "UICheckBox"; }
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // UICHECKBOX_H
|
#endif // UICHECKBOX_H
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <ui/uicheckboxskin.h>
|
#include <ui/uicheckboxskin.h>
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UICHECKBOXSKIN_H
|
#ifndef UICHECKBOXSKIN_H
|
||||||
#define UICHECKBOXSKIN_H
|
#define UICHECKBOXSKIN_H
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UICONSTANTS_H
|
#ifndef UICONSTANTS_H
|
||||||
#define UICONSTANTS_H
|
#define UICONSTANTS_H
|
||||||
|
|
||||||
|
@ -39,13 +15,13 @@ namespace UI {
|
||||||
};
|
};
|
||||||
|
|
||||||
enum AnchorPoint {
|
enum AnchorPoint {
|
||||||
AnchorLeft = 0,
|
AnchorNone = 0,
|
||||||
AnchorHorizontalCenter,
|
|
||||||
AnchorRight,
|
|
||||||
AnchorTop,
|
AnchorTop,
|
||||||
AnchorVerticalCenter,
|
|
||||||
AnchorBottom,
|
AnchorBottom,
|
||||||
AnchorNone
|
AnchorLeft,
|
||||||
|
AnchorRight,
|
||||||
|
AnchorVerticalCenter,
|
||||||
|
AnchorHorizontalCenter,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <core/resources.h>
|
#include <core/resources.h>
|
||||||
#include <ui/uicontainer.h>
|
#include <ui/uicontainer.h>
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UICONTAINER_H
|
#ifndef UICONTAINER_H
|
||||||
#define UICONTAINER_H
|
#define UICONTAINER_H
|
||||||
|
|
||||||
|
@ -76,7 +52,7 @@ public:
|
||||||
virtual UI::ElementType getElementType() const { return UI::Container; }
|
virtual UI::ElementType getElementType() const { return UI::Container; }
|
||||||
UIContainerPtr asUIContainer() { return boost::static_pointer_cast<UIContainer>(shared_from_this()); }
|
UIContainerPtr asUIContainer() { return boost::static_pointer_cast<UIContainer>(shared_from_this()); }
|
||||||
|
|
||||||
virtual const char *getScriptableName() const { return "UIContainer"; }
|
virtual const char *getScriptObjectType() const { return "UIContainer"; }
|
||||||
|
|
||||||
/// Get root container (the container that contains everything)
|
/// Get root container (the container that contains everything)
|
||||||
static UIContainerPtr& getRoot();
|
static UIContainerPtr& getRoot();
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <core/dispatcher.h>
|
#include <core/dispatcher.h>
|
||||||
#include <graphics/graphics.h>
|
#include <graphics/graphics.h>
|
||||||
|
@ -31,7 +7,7 @@
|
||||||
#include <ui/uicontainer.h>
|
#include <ui/uicontainer.h>
|
||||||
|
|
||||||
UIElement::UIElement(UI::ElementType type) :
|
UIElement::UIElement(UI::ElementType type) :
|
||||||
Scriptable(),
|
ScriptObject(),
|
||||||
m_type(type),
|
m_type(type),
|
||||||
m_visible(true),
|
m_visible(true),
|
||||||
m_enabled(true),
|
m_enabled(true),
|
||||||
|
@ -60,14 +36,14 @@ void UIElement::destroy()
|
||||||
//logTraceDebug(getId());
|
//logTraceDebug(getId());
|
||||||
|
|
||||||
UIElementPtr me = asUIElement();
|
UIElementPtr me = asUIElement();
|
||||||
callLuaTableField("onDestroy");
|
callScriptTableField("onDestroy");
|
||||||
|
|
||||||
// remove from parent
|
// remove from parent
|
||||||
if(getParent())
|
if(getParent())
|
||||||
getParent()->removeChild(me);
|
getParent()->removeChild(me);
|
||||||
|
|
||||||
// free script stuff
|
// free script stuff
|
||||||
releaseLuaTableRef();
|
releaseScriptObject();
|
||||||
|
|
||||||
g_dispatcher.addTask(boost::bind(&UIElement::destroyCheck, me));
|
g_dispatcher.addTask(boost::bind(&UIElement::destroyCheck, me));
|
||||||
}
|
}
|
||||||
|
@ -115,7 +91,7 @@ void UIElement::setSkin(const UIElementSkinPtr& skin)
|
||||||
|
|
||||||
void UIElement::onLoad()
|
void UIElement::onLoad()
|
||||||
{
|
{
|
||||||
g_dispatcher.addTask(boost::bind(&Scriptable::callLuaTableField, shared_from_this(), "onLoad", 0));
|
g_dispatcher.addTask(boost::bind(&ScriptObject::callScriptTableField, shared_from_this(), "onLoad", 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIElement::render()
|
void UIElement::render()
|
||||||
|
|
|
@ -1,33 +1,9 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UIELEMENT_H
|
#ifndef UIELEMENT_H
|
||||||
#define UIELEMENT_H
|
#define UIELEMENT_H
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <core/input.h>
|
#include <core/input.h>
|
||||||
#include <script/scriptable.h>
|
#include <script/scriptobject.h>
|
||||||
#include <ui/uiconstants.h>
|
#include <ui/uiconstants.h>
|
||||||
#include <ui/uielementskin.h>
|
#include <ui/uielementskin.h>
|
||||||
#include <ui/uilayout.h>
|
#include <ui/uilayout.h>
|
||||||
|
@ -42,7 +18,7 @@ class UIElement;
|
||||||
typedef boost::shared_ptr<UIElement> UIElementPtr;
|
typedef boost::shared_ptr<UIElement> UIElementPtr;
|
||||||
typedef boost::weak_ptr<UIElement> UIElementWeakPtr;
|
typedef boost::weak_ptr<UIElement> UIElementWeakPtr;
|
||||||
|
|
||||||
class UIElement : public Scriptable
|
class UIElement : public ScriptObject
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UIElement(UI::ElementType type = UI::Element);
|
UIElement(UI::ElementType type = UI::Element);
|
||||||
|
@ -94,7 +70,7 @@ public:
|
||||||
|
|
||||||
UIElementPtr asUIElement() { return boost::static_pointer_cast<UIElement>(shared_from_this()); }
|
UIElementPtr asUIElement() { return boost::static_pointer_cast<UIElement>(shared_from_this()); }
|
||||||
virtual UIContainerPtr asUIContainer() { return UIContainerPtr(); }
|
virtual UIContainerPtr asUIContainer() { return UIContainerPtr(); }
|
||||||
virtual const char *getScriptableName() const { return "UIElement"; }
|
virtual const char *getScriptObjectType() const { return "UIElement"; }
|
||||||
|
|
||||||
void setSize(const Size& size);
|
void setSize(const Size& size);
|
||||||
Size getSize() { return m_rect.size(); }
|
Size getSize() { return m_rect.size(); }
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <ui/uiskins.h>
|
#include <ui/uiskins.h>
|
||||||
#include <ui/uielement.h>
|
#include <ui/uielement.h>
|
||||||
|
@ -56,35 +32,7 @@ ImagePtr UIElementSkin::loadImage(OTMLNode* node)
|
||||||
TexturePtr texture;
|
TexturePtr texture;
|
||||||
|
|
||||||
if(OTMLNode* cnode = node->at("bordered image")) {
|
if(OTMLNode* cnode = node->at("bordered image")) {
|
||||||
Rect left = cnode->readAt("left border", Rect());
|
image = BorderedImage::loadFromOTMLNode(cnode, g_uiSkins.getDefaultTexture());
|
||||||
Rect right = cnode->readAt("right border", Rect());
|
|
||||||
Rect top = cnode->readAt("top border", Rect());
|
|
||||||
Rect bottom = cnode->readAt("bottom border", Rect());
|
|
||||||
Rect topLeft = cnode->readAt("top left corner", Rect());
|
|
||||||
Rect topRight = cnode->readAt("top right corner", Rect());
|
|
||||||
Rect bottomLeft = cnode->readAt("bottom left corner", Rect());
|
|
||||||
Rect bottomRight = cnode->readAt("bottom right corner", Rect());
|
|
||||||
Rect center = cnode->readAt("center", Rect());
|
|
||||||
std::string textureName = cnode->readAt("source", std::string());
|
|
||||||
|
|
||||||
if(!textureName.empty())
|
|
||||||
texture = g_textures.get(textureName);
|
|
||||||
else
|
|
||||||
texture = g_uiSkins.getDefaultTexture();
|
|
||||||
|
|
||||||
if(texture) {
|
|
||||||
image = ImagePtr(new BorderedImage(texture,
|
|
||||||
left,
|
|
||||||
right,
|
|
||||||
top,
|
|
||||||
bottom,
|
|
||||||
topLeft,
|
|
||||||
topRight,
|
|
||||||
bottomLeft,
|
|
||||||
bottomRight,
|
|
||||||
center));
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!image)
|
if(!image)
|
||||||
error(node->generateErrorMessage("failed to load bordered image"));
|
error(node->generateErrorMessage("failed to load bordered image"));
|
||||||
} else if(OTMLNode* cnode = node->at("image")) {
|
} else if(OTMLNode* cnode = node->at("image")) {
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UIELEMENTSKIN_H
|
#ifndef UIELEMENTSKIN_H
|
||||||
#define UIELEMENTSKIN_H
|
#define UIELEMENTSKIN_H
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <ui/uilabel.h>
|
#include <ui/uilabel.h>
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UILABEL_H
|
#ifndef UILABEL_H
|
||||||
#define UILABEL_H
|
#define UILABEL_H
|
||||||
|
|
||||||
|
@ -42,7 +18,7 @@ public:
|
||||||
void setAlign(AlignmentFlag align) { m_align = align; }
|
void setAlign(AlignmentFlag align) { m_align = align; }
|
||||||
AlignmentFlag getAlign() const { return m_align; }
|
AlignmentFlag getAlign() const { return m_align; }
|
||||||
|
|
||||||
virtual const char *getScriptableName() const { return "UILabel"; }
|
virtual const char *getScriptObjectType() const { return "UILabel"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::string m_text;
|
std::string m_text;
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <graphics/fonts.h>
|
#include <graphics/fonts.h>
|
||||||
#include <ui/uilabelskin.h>
|
#include <ui/uilabelskin.h>
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UILABELSKIN_H
|
#ifndef UILABELSKIN_H
|
||||||
#define UILABELSKIN_H
|
#define UILABELSKIN_H
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UILAYOUT_H
|
#ifndef UILAYOUT_H
|
||||||
#define UILAYOUT_H
|
#define UILAYOUT_H
|
||||||
|
|
||||||
|
|
|
@ -1,33 +1,9 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#include <global.h>
|
#include <global.h>
|
||||||
#include <core/resources.h>
|
#include <core/resources.h>
|
||||||
#include <ui/ui.h>
|
#include <ui/ui.h>
|
||||||
#include <ui/uiloader.h>
|
#include <ui/uiloader.h>
|
||||||
#include <script/luascript.h>
|
#include <script/scriptcontext.h>
|
||||||
#include <script/luafunctions.h>
|
#include <script/scriptfunctions.h>
|
||||||
#include <otml/otml.h>
|
#include <otml/otml.h>
|
||||||
#include <ui/uianchorlayout.h>
|
#include <ui/uianchorlayout.h>
|
||||||
#include <util/translator.h>
|
#include <util/translator.h>
|
||||||
|
@ -42,8 +18,9 @@ UIElementPtr UILoader::createElementFromId(const std::string& id)
|
||||||
|
|
||||||
std::vector<std::string> split;
|
std::vector<std::string> split;
|
||||||
boost::split(split, id, boost::is_any_of(std::string("#")));
|
boost::split(split, id, boost::is_any_of(std::string("#")));
|
||||||
if(split.size() != 2)
|
if(split.size() != 2) {
|
||||||
return element;
|
return element;
|
||||||
|
}
|
||||||
|
|
||||||
std::string elementType = split[0].substr(1);
|
std::string elementType = split[0].substr(1);
|
||||||
std::string elementId = split[1];
|
std::string elementId = split[1];
|
||||||
|
@ -164,7 +141,7 @@ void UILoader::loadElement(const UIElementPtr& element, OTMLNode* node)
|
||||||
element->setSkin(g_uiSkins.getElementSkin(element->getElementType(), "default"));
|
element->setSkin(g_uiSkins.getElementSkin(element->getElementType(), "default"));
|
||||||
|
|
||||||
// load elements common proprieties
|
// load elements common proprieties
|
||||||
if(node->hasNode("size"))
|
if(node->hasChild("size"))
|
||||||
element->setSize(node->readAt<Size>("size"));
|
element->setSize(node->readAt<Size>("size"));
|
||||||
|
|
||||||
// load margins
|
// load margins
|
||||||
|
@ -247,7 +224,7 @@ void UILoader::loadElementScriptFunction(const UIElementPtr& element, OTMLNode*
|
||||||
functionDesc += "[" + node->tag() + "]";
|
functionDesc += "[" + node->tag() + "]";
|
||||||
|
|
||||||
if(g_lua.loadBufferAsFunction(node->value(), functionDesc))
|
if(g_lua.loadBufferAsFunction(node->value(), functionDesc))
|
||||||
g_lua.setScriptableField(element, node->tag());
|
g_lua.setScriptObjectField(element, node->tag());
|
||||||
else
|
else
|
||||||
error(node->generateErrorMessage("failed to parse inline lua script"));
|
error(node->generateErrorMessage("failed to parse inline lua script"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,7 +41,7 @@ void UISkins::load(const std::string& skinName)
|
||||||
g_resources.pushCurrentPath("skins");
|
g_resources.pushCurrentPath("skins");
|
||||||
|
|
||||||
std::stringstream fin;
|
std::stringstream fin;
|
||||||
if(!g_resources.loadFile(skinName + ".yml", fin))
|
if(!g_resources.loadFile(skinName + ".otml", fin))
|
||||||
fatal("FATAL ERROR: Could not load skin '",skinName,"'");
|
fatal("FATAL ERROR: Could not load skin '",skinName,"'");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -46,7 +46,7 @@ public:
|
||||||
|
|
||||||
bool isFocusable() const { return true; }
|
bool isFocusable() const { return true; }
|
||||||
|
|
||||||
virtual const char *getScriptableName() const { return "UITextEdit"; }
|
virtual const char *getScriptObjectType() const { return "UITextEdit"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
TextArea m_textArea;
|
TextArea m_textArea;
|
||||||
|
|
|
@ -40,7 +40,7 @@ public:
|
||||||
void setTitle(const std::string& title) { m_title = title; }
|
void setTitle(const std::string& title) { m_title = title; }
|
||||||
std::string getTitle() const { return m_title; }
|
std::string getTitle() const { return m_title; }
|
||||||
|
|
||||||
virtual const char *getScriptableName() const { return "UIWindow"; }
|
virtual const char *getScriptObjectType() const { return "UIWindow"; }
|
||||||
|
|
||||||
virtual bool isFocusable() const { return true; }
|
virtual bool isFocusable() const { return true; }
|
||||||
|
|
||||||
|
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef _DEBUG_MEMORY
|
#ifdef _DEBUG_MEMORY
|
||||||
|
|
||||||
#include "allocator.h"
|
#include "allocator.h"
|
|
@ -1,27 +1,3 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef __ALLOCATOR_H__
|
#ifndef __ALLOCATOR_H__
|
||||||
#define __ALLOCATOR_H__
|
#define __ALLOCATOR_H__
|
||||||
|
|
|
@ -3,34 +3,17 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
|
||||||
void log(LogLevel level, const std::string& message, const char *trace)
|
void log(LogLevel level, const std::string& message, std::string prettyFunction)
|
||||||
{
|
{
|
||||||
std::string strace;
|
if(!prettyFunction.empty()) {
|
||||||
if(trace) {
|
prettyFunction = prettyFunction.substr(0, prettyFunction.find_first_of('('));
|
||||||
strace = trace;
|
if(prettyFunction.find_last_of(' ') != std::string::npos)
|
||||||
strace = strace.substr(0, strace.find_first_of('('));
|
prettyFunction = prettyFunction.substr(prettyFunction.find_last_of(' ') + 1);
|
||||||
if(strace.find_last_of(' ') != std::string::npos)
|
if(!prettyFunction.empty())
|
||||||
strace = strace.substr(strace.find_last_of(' ') + 1);
|
std::cout << "[" << prettyFunction << "] ";
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef linux
|
std::cout << message << std::endl;
|
||||||
static char const *colors[] = { "\033[01;31m ", "\033[01;31m", "\033[01;33m", "\033[0;32m", "\033[01;34m" };
|
|
||||||
static bool colored = getenv("COLORED_OUTPUT");
|
|
||||||
if(colored)
|
|
||||||
std::cout << colors[level];
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if(!strace.empty())
|
|
||||||
std::cout << "[" << strace << "] ";
|
|
||||||
|
|
||||||
std::cout << message;
|
|
||||||
|
|
||||||
#ifdef linux
|
|
||||||
if(colored)
|
|
||||||
std::cout << "\033[0m";
|
|
||||||
#endif
|
|
||||||
|
|
||||||
std::cout << std::endl;
|
|
||||||
|
|
||||||
if(level == LogFatal)
|
if(level == LogFatal)
|
||||||
exit(-1);
|
exit(-1);
|
||||||
|
|
|
@ -10,7 +10,7 @@ enum LogLevel {
|
||||||
LogError,
|
LogError,
|
||||||
LogFatal
|
LogFatal
|
||||||
};
|
};
|
||||||
void log(LogLevel level, const std::string& message, const char *trace = NULL);
|
void log(LogLevel level, const std::string& message, std::string prettyFunction = "");
|
||||||
|
|
||||||
// specialized logging
|
// specialized logging
|
||||||
template<class... T>
|
template<class... T>
|
||||||
|
@ -24,7 +24,7 @@ void error(const T&... args) { log(LogError, make_string(args...)); }
|
||||||
template<class... T>
|
template<class... T>
|
||||||
void fatal(const T&... args) { log(LogFatal, make_string(args...)); }
|
void fatal(const T&... args) { log(LogFatal, make_string(args...)); }
|
||||||
|
|
||||||
#define trace() debug(LogDebug, "", __PRETTY_FUNCTION__)
|
#define trace() log(LogDebug, "", __PRETTY_FUNCTION__)
|
||||||
|
|
||||||
// dump utility
|
// dump utility
|
||||||
struct Dump {
|
struct Dump {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
#include "translator.h"
|
#include "translator.h"
|
||||||
|
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
|
|
||||||
AlignmentFlag parseAlignment(std::string aligment)
|
AlignmentFlag parseAlignment(std::string aligment)
|
||||||
|
|
|
@ -2,7 +2,6 @@
|
||||||
#define TRANSLATOR_H
|
#define TRANSLATOR_H
|
||||||
|
|
||||||
#include <const.h>
|
#include <const.h>
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
AlignmentFlag parseAlignment(std::string aligment);
|
AlignmentFlag parseAlignment(std::string aligment);
|
||||||
|
|
|
@ -1,52 +0,0 @@
|
||||||
/* The MIT License
|
|
||||||
*
|
|
||||||
* Copyright (c) 2010 OTClient, https://github.com/edubart/otclient
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in
|
|
||||||
* all copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
||||||
* THE SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef UTIL_H
|
|
||||||
#define UTIL_H
|
|
||||||
|
|
||||||
#include <util/logger.h>
|
|
||||||
#include <boost/lexical_cast.hpp>
|
|
||||||
#include <boost/format.hpp>
|
|
||||||
#include <constants.h>
|
|
||||||
|
|
||||||
// Easy/fast writing formater
|
|
||||||
#define fmt(a, b) (boost::format(a) % b).str()
|
|
||||||
|
|
||||||
/// Convert any data type through boost::lexical_cast
|
|
||||||
template<class R, class T>
|
|
||||||
R convert_cast(T t)
|
|
||||||
{
|
|
||||||
R ret = R();
|
|
||||||
try {
|
|
||||||
ret = boost::lexical_cast<R>(t);
|
|
||||||
} catch(boost::bad_lexical_cast bad) {
|
|
||||||
flogError("Error converting value: %s", bad.what());
|
|
||||||
}
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
AlignmentFlag parseAlignment(std::string aligment);
|
|
||||||
|
|
||||||
|
|
||||||
#endif // UTIL_H
|
|
|
@ -29,7 +29,7 @@
|
||||||
#include <core/platform.h>
|
#include <core/platform.h>
|
||||||
#include <core/dispatcher.h>
|
#include <core/dispatcher.h>
|
||||||
#include <ui/uiskins.h>
|
#include <ui/uiskins.h>
|
||||||
#include <script/luascript.h>
|
#include <script/scriptcontext.h>
|
||||||
#include <ui/uicontainer.h>
|
#include <ui/uicontainer.h>
|
||||||
|
|
||||||
#include <csignal>
|
#include <csignal>
|
||||||
|
@ -59,6 +59,7 @@ void loadDefaultConfigs()
|
||||||
g_configs.set("window width", defWidth);
|
g_configs.set("window width", defWidth);
|
||||||
g_configs.set("window height", defHeight);
|
g_configs.set("window height", defHeight);
|
||||||
g_configs.set("window maximized", false);
|
g_configs.set("window maximized", false);
|
||||||
|
g_configs.set("skin", "tibia");
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveConfigs()
|
void saveConfigs()
|
||||||
|
@ -99,7 +100,7 @@ int main(int argc, const char *argv[])
|
||||||
|
|
||||||
// load configurations
|
// load configurations
|
||||||
loadDefaultConfigs();
|
loadDefaultConfigs();
|
||||||
if(!g_configs.load("config.yml"))
|
if(!g_configs.load("config.otml"))
|
||||||
info("Could not read configuration file, default configurations will be used.");
|
info("Could not read configuration file, default configurations will be used.");
|
||||||
|
|
||||||
// create the window
|
// create the window
|
||||||
|
@ -115,7 +116,7 @@ int main(int argc, const char *argv[])
|
||||||
g_engine.enableFpsCounter();
|
g_engine.enableFpsCounter();
|
||||||
|
|
||||||
// load ui skins
|
// load ui skins
|
||||||
g_uiSkins.load("lightness");
|
g_uiSkins.load("tibia");
|
||||||
|
|
||||||
// load script modules
|
// load script modules
|
||||||
g_lua.loadAllModules();
|
g_lua.loadAllModules();
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
#include "protocollogin.h"
|
#include "protocollogin.h"
|
||||||
#include <net/outputmessage.h>
|
#include <net/outputmessage.h>
|
||||||
#include <net/rsa.h>
|
#include <net/rsa.h>
|
||||||
#include <script/luascript.h>
|
#include <script/scriptcontext.h>
|
||||||
#include <boost/bind.hpp>
|
#include <boost/bind.hpp>
|
||||||
|
|
||||||
ProtocolLogin::ProtocolLogin()
|
ProtocolLogin::ProtocolLogin()
|
||||||
|
@ -134,14 +134,14 @@ void ProtocolLogin::parseError(InputMessage *inputMessage)
|
||||||
{
|
{
|
||||||
std::string error = inputMessage->getString();
|
std::string error = inputMessage->getString();
|
||||||
g_lua.pushString(error);
|
g_lua.pushString(error);
|
||||||
callLuaTableField("onError", 1);
|
callScriptTableField("onError", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolLogin::parseMOTD(InputMessage *inputMessage)
|
void ProtocolLogin::parseMOTD(InputMessage *inputMessage)
|
||||||
{
|
{
|
||||||
std::string motd = inputMessage->getString();
|
std::string motd = inputMessage->getString();
|
||||||
g_lua.pushString(motd);
|
g_lua.pushString(motd);
|
||||||
callLuaTableField("onMotd", 1);
|
callScriptTableField("onMotd", 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolLogin::parseCharacterList(InputMessage *inputMessage)
|
void ProtocolLogin::parseCharacterList(InputMessage *inputMessage)
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
void sendPacket();
|
void sendPacket();
|
||||||
void onRecv(InputMessage *inputMessage);
|
void onRecv(InputMessage *inputMessage);
|
||||||
|
|
||||||
const char *getScriptableName() const { return "ProtocolLogin"; }
|
const char *getScriptObjectType() const { return "ProtocolLogin"; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void parseError(InputMessage *inputMessage);
|
void parseError(InputMessage *inputMessage);
|
||||||
|
|
Loading…
Reference in New Issue