Buttons for client options

This commit is contained in:
Eduardo Bart 2013-02-06 17:35:59 -02:00
parent cf77df05ca
commit 7ece0ed8c7
11 changed files with 63 additions and 12 deletions

View File

@ -284,3 +284,7 @@ end
function addTab(name, panel, icon)
optionsTabBar:addTab(name, panel, icon)
end
function addButton(name, func, icon)
optionsTabBar:addButton(name, func, icon)
end

View File

@ -60,6 +60,18 @@ function UITabBar:addTab(text, panel, icon)
return tab
end
function UITabBar:addButton(text, func, icon)
local button = g_ui.createWidget(self:getStyleName() .. 'Button', self.buttonsPanel)
button:setText(text)
local style = {}
style['icon-source'] = icon
button:mergeStyle(style)
button.onClick = func
return button
end
function UITabBar:removeTab(tab)
local index = table.find(self.tabs, tab)
if index == nil then return end

View File

@ -40,7 +40,7 @@ function onGameEditText(id, itemId, maxLength, text, writter, time)
textEdit:setText(text)
textEdit:setEditable(writeable)
textEdit:setCursorVisible(writeable)
local desc = ''
if #writter > 0 then
desc = tr('You read the following, written by \n%s\n', writter)
@ -71,6 +71,10 @@ function onGameEditText(id, itemId, maxLength, text, writter, time)
textWindow:setText(tr('Edit Text'))
end
if description:getHeight() < 64 then
description:setHeight(64)
end
local function destroy()
textWindow:destroy()
table.removevalue(windows, textWindow)
@ -109,20 +113,22 @@ function onGameEditList(id, doorId, text)
description:setText(tr('Enter one name per line.'))
textWindow:setText(tr('Edit List'))
if description:getHeight() < 64 then
description:setHeight(64)
end
local function destroy()
textWindow:destroy()
table.removevalue(windows, textWindow)
end
doneFunc = function()
local doneFunc = function()
g_game.editList(id, doorId, textEdit:getText())
destroy()
end
okButton.onClick = doneFunc
cancelButton.onClick = destroy
textWindow.onEnter = doneFunc
textWindow.onEscape = destroy
table.insert(windows, textWindow)

View File

@ -166,7 +166,7 @@ public:
return Otc::InvalidDirection;
}
bool isMapPosition() const { return (x < 65535 && y < 65535 && z <= Otc::MAX_Z); }
bool isMapPosition() const { return (x >=0 && y >= 0 && z >= 0 && x < 65535 && y < 65535 && z <= Otc::MAX_Z); }
bool isValid() const { return !(x == 65535 && y == 65535 && z == 255); }
float distance(const Position& pos) const { return sqrt(pow((pos.x - x), 2) + pow((pos.y - y), 2)); }
int manhattanDistance(const Position& pos) const { return std::abs(pos.x - x) + std::abs(pos.y - y); }
@ -226,9 +226,9 @@ public:
return false;
}
uint16 x;
uint16 y;
uint8 z;
int x;
int y;
short z;
};
struct PositionHasher : std::unary_function<Position, std::size_t> {

View File

@ -136,9 +136,11 @@ option(LUAJIT "Use lua jit" OFF)
if(NOT APPLE)
option(CRASH_HANDLER "Generate crash reports" ON)
option(USE_STATIC_LIBS "Don't use shared libraries (dlls)" ON)
option(USE_LIBCPP "Use the new libc++ library instead of stdc++" OFF)
else()
set(CRASH_HANDLER OFF)
set(USE_STATIC_LIBS OFF)
set(USE_LIBCPP ON)
endif()
set(BUILD_COMMIT "devel" CACHE "Git commit string (intended for releases)" STRING)
set(BUILD_REVISION "0" CACHE "Git revision string (intended for releases)" STRING)
@ -242,6 +244,10 @@ else()
message(STATUS "Crash handler: OFF")
endif()
if(USE_LIBCPP)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -Wno-deprecated-declarations")
endif()
if(WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mthreads")
set(framework_DEFINITIONS ${framework_DEFINITIONS} -D_WIN32_WINNT=0x0501)
@ -249,7 +255,6 @@ if(WIN32)
set(SYSTEM_LIBRARIES "")
else()
if(APPLE)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -stdlib=libc++ -Wno-deprecated-declarations")
set(framework_DEFINITIONS ${framework_DEFINITIONS} -D_REENTRANT) # enable thread safe code
set(SYSTEM_LIBRARIES "")
else()

View File

@ -479,6 +479,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("setIconSize", &UIWidget::setIconSize);
g_lua.bindClassMemberFunction<UIWidget>("setIconRect", &UIWidget::setIconRect);
g_lua.bindClassMemberFunction<UIWidget>("setIconClip", &UIWidget::setIconClip);
g_lua.bindClassMemberFunction<UIWidget>("setIconAlign", &UIWidget::setIconAlign);
g_lua.bindClassMemberFunction<UIWidget>("setBorderWidth", &UIWidget::setBorderWidth);
g_lua.bindClassMemberFunction<UIWidget>("setBorderWidthTop", &UIWidget::setBorderWidthTop);
g_lua.bindClassMemberFunction<UIWidget>("setBorderWidthRight", &UIWidget::setBorderWidthRight);
@ -530,6 +531,7 @@ void Application::registerLuaFunctions()
g_lua.bindClassMemberFunction<UIWidget>("getIconSize", &UIWidget::getIconSize);
g_lua.bindClassMemberFunction<UIWidget>("getIconRect", &UIWidget::getIconRect);
g_lua.bindClassMemberFunction<UIWidget>("getIconClip", &UIWidget::getIconClip);
g_lua.bindClassMemberFunction<UIWidget>("getIconAlign", &UIWidget::getIconAlign);
g_lua.bindClassMemberFunction<UIWidget>("getBorderTopColor", &UIWidget::getBorderTopColor);
g_lua.bindClassMemberFunction<UIWidget>("getBorderRightColor", &UIWidget::getBorderRightColor);
g_lua.bindClassMemberFunction<UIWidget>("getBorderBottomColor", &UIWidget::getBorderBottomColor);

View File

@ -374,6 +374,7 @@ public:
Size getIconSize() { return m_iconRect.size(); }
Rect getIconRect() { return m_iconRect; }
Rect getIconClip() { return m_iconClipRect; }
Fw::AlignmentFlag getIconAlign() { return m_iconAlign; }
Color getBorderTopColor() { return m_borderColor.top; }
Color getBorderRightColor() { return m_borderColor.right; }
Color getBorderBottomColor() { return m_borderColor.bottom; }

View File

@ -401,7 +401,10 @@ void UIWidget::drawIcon(const Rect& screenCoords)
void UIWidget::setIcon(const std::string& iconFile)
{
m_icon = g_textures.getTexture(iconFile);
if(iconFile.empty())
m_icon = nullptr;
else
m_icon = g_textures.getTexture(iconFile);
if(m_icon && !m_iconClipRect.isValid())
m_iconClipRect = Rect(0, 0, m_icon->getSize());
}

View File

@ -176,7 +176,10 @@ void UIWidget::drawImage(const Rect& screenCoords)
void UIWidget::setImageSource(const std::string& source)
{
m_imageTexture = g_textures.getTexture(source);
if(source.empty())
m_imageTexture = nullptr;
else
m_imageTexture = g_textures.getTexture(source);
m_imageMustRecache = true;
}

View File

@ -23,7 +23,7 @@
#include "color.h"
// NOTE: AABBGGRR order
const Color Color::alpha = 0x00000000;
const Color Color::alpha = 0x00000000U;
const Color Color::white = 0xffffffff;
const Color Color::black = 0xff000000;
const Color Color::red = 0xff0000ff;
@ -42,3 +42,9 @@ const Color Color::gray = 0xffa0a0a0;
const Color Color::darkGray = 0xff808080;
const Color Color::lightGray = 0xffc0c0c0;
const Color Color::orange = 0xffff8c00;
Color::Color(const std::string& coltext)
{
std::stringstream ss(coltext);
ss >> *this;
}

View File

@ -37,6 +37,7 @@ public:
Color(uint8 r, uint8 g, uint8 b, uint8 a = 0xFF) : m_r(r/255.0f), m_g(g/255.0f), m_b(b/255.0f), m_a(a/255.0f) { }
Color(int r, int g, int b, int a = 0xFF) : m_r(r/255.0f), m_g(g/255.0f), m_b(b/255.0f), m_a(a/255.0f) { }
Color(float r, float g, float b, float a = 1.0f) : m_r(r), m_g(g), m_b(b), m_a(a) { }
Color(const std::string& coltext);
uint8 a() const { return m_a*255.0f; }
uint8 b() const { return m_b*255.0f; }
@ -76,6 +77,14 @@ public:
bool operator==(const Color& other) const { return other.rgba() == rgba(); }
bool operator!=(const Color& other) const { return other.rgba() != rgba(); }
static uint8 to8bit(const Color& color) {
uint8 c = 0;
c += (color.r() / 51) * 36;
c += (color.g() / 51) * 6;
c += (color.b() / 51);
return c;
};
static Color from8bit(int color) {
if(color >= 216 || color <= 0)
return Color(0, 0, 0);