separator fix, fix draw outside map
This commit is contained in:
parent
4620f71444
commit
1b83126ed5
|
@ -22,10 +22,9 @@ function Game.createThingMenu(menuPosition, lookThing, useThing, creatureThing)
|
||||||
if useThing:isRotateable() then
|
if useThing:isRotateable() then
|
||||||
menu:addOption('Rotate', function() Game.rotate(useThing) end)
|
menu:addOption('Rotate', function() Game.rotate(useThing) end)
|
||||||
end
|
end
|
||||||
|
|
||||||
menu:addSeparator()
|
|
||||||
|
|
||||||
if not useThing:isNotMoveable() and useThing:isPickupable() then
|
if not useThing:isNotMoveable() and useThing:isPickupable() then
|
||||||
|
menu:addSeparator()
|
||||||
menu:addOption('Trade with ...', function() print('trade with') end)
|
menu:addOption('Trade with ...', function() print('trade with') end)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -159,6 +159,12 @@ public:
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool contains(const TRect<T> &r, bool insideOnly = false) const {
|
||||||
|
if(contains(r.topLeft(), insideOnly) && contains(r.bottomRight(), insideOnly))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool intersects(const TRect<T> &r) const {
|
bool intersects(const TRect<T> &r) const {
|
||||||
if(isNull() || r.isNull())
|
if(isNull() || r.isNull())
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -43,10 +43,13 @@ void AnimatedText::start()
|
||||||
}, DURATION);
|
}, DURATION);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimatedText::draw(const Point& p)
|
void AnimatedText::draw(const Point& p, const Rect& visibleRect)
|
||||||
{
|
{
|
||||||
if(m_font)
|
if(m_font) {
|
||||||
m_font->renderText(m_text, Rect(p + Point(20 - m_textSize.width() / 2, -20.0 * g_clock.timeElapsed(m_startTime) / (DURATION / 1000)), m_textSize), Fw::AlignLeft, m_color);
|
Rect rect = Rect(p + Point(20 - m_textSize.width() / 2, -20.0 * g_clock.timeElapsed(m_startTime) / (DURATION / 1000)), m_textSize);
|
||||||
|
if(visibleRect.contains(rect))
|
||||||
|
m_font->renderText(m_text, rect, Fw::AlignLeft, m_color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void AnimatedText::setColor(int color)
|
void AnimatedText::setColor(int color)
|
||||||
|
|
|
@ -36,7 +36,7 @@ public:
|
||||||
AnimatedText();
|
AnimatedText();
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
void draw(const Point& p);
|
void draw(const Point& p, const Rect& visibleRect);
|
||||||
|
|
||||||
void setColor(int color);
|
void setColor(int color);
|
||||||
void setText(const std::string& text);
|
void setText(const std::string& text);
|
||||||
|
|
|
@ -57,7 +57,7 @@ int LEGS_COLOR_UNIFORM = 12;
|
||||||
int FEET_COLOR_UNIFORM = 13;
|
int FEET_COLOR_UNIFORM = 13;
|
||||||
int MASK_TEXTURE_UNIFORM = 14;
|
int MASK_TEXTURE_UNIFORM = 14;
|
||||||
|
|
||||||
void Creature::draw(const Point& p)
|
void Creature::draw(const Point& p, const Rect&)
|
||||||
{
|
{
|
||||||
if(m_showVolatileSquare) {
|
if(m_showVolatileSquare) {
|
||||||
g_painter.setColor(m_volatileSquareColor);
|
g_painter.setColor(m_volatileSquareColor);
|
||||||
|
@ -125,7 +125,7 @@ void Creature::draw(const Point& p)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Creature::drawInformation(int x, int y, bool useGray, const Rect& rect)
|
void Creature::drawInformation(int x, int y, bool useGray, const Rect& visibleRect)
|
||||||
{
|
{
|
||||||
Color fillColor = Color(96, 96, 96);
|
Color fillColor = Color(96, 96, 96);
|
||||||
|
|
||||||
|
@ -134,15 +134,15 @@ void Creature::drawInformation(int x, int y, bool useGray, const Rect& rect)
|
||||||
|
|
||||||
// calculate main rects
|
// calculate main rects
|
||||||
Rect backgroundRect = Rect(x-(13.5), y, 27, 4);
|
Rect backgroundRect = Rect(x-(13.5), y, 27, 4);
|
||||||
backgroundRect.bound(rect);
|
backgroundRect.bound(visibleRect);
|
||||||
|
|
||||||
Rect textRect = Rect(x - m_nameSize.width() / 2.0, y-12, m_nameSize);
|
Rect textRect = Rect(x - m_nameSize.width() / 2.0, y-12, m_nameSize);
|
||||||
textRect.bound(rect);
|
textRect.bound(visibleRect);
|
||||||
|
|
||||||
// distance them
|
// distance them
|
||||||
if(textRect.top() == rect.top())
|
if(textRect.top() == visibleRect.top())
|
||||||
backgroundRect.moveTop(textRect.top() + 12);
|
backgroundRect.moveTop(textRect.top() + 12);
|
||||||
if(backgroundRect.bottom() == rect.bottom())
|
if(backgroundRect.bottom() == visibleRect.bottom())
|
||||||
textRect.moveTop(backgroundRect.top() - 12);
|
textRect.moveTop(backgroundRect.top() - 12);
|
||||||
|
|
||||||
// health rect is based on background rect, so no worries
|
// health rect is based on background rect, so no worries
|
||||||
|
|
|
@ -37,8 +37,8 @@ public:
|
||||||
Creature();
|
Creature();
|
||||||
virtual ~Creature() { }
|
virtual ~Creature() { }
|
||||||
|
|
||||||
virtual void draw(const Point& p);
|
virtual void draw(const Point& p, const Rect&);
|
||||||
void drawInformation(int x, int y, bool useGray, const Rect& rect);
|
void drawInformation(int x, int y, bool useGray, const Rect& visibleRect);
|
||||||
|
|
||||||
void setName(const std::string& name);
|
void setName(const std::string& name);
|
||||||
void setHealthPercent(uint8 healthPercent);
|
void setHealthPercent(uint8 healthPercent);
|
||||||
|
|
|
@ -51,7 +51,7 @@ void Effect::start()
|
||||||
}, TICKS_PER_FRAME * getAnimationPhases());
|
}, TICKS_PER_FRAME * getAnimationPhases());
|
||||||
}
|
}
|
||||||
|
|
||||||
void Effect::draw(const Point& p)
|
void Effect::draw(const Point& p, const Rect&)
|
||||||
{
|
{
|
||||||
internalDraw(p, 0);
|
internalDraw(p, 0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,7 @@ class Effect : public Thing
|
||||||
public:
|
public:
|
||||||
Effect();
|
Effect();
|
||||||
|
|
||||||
void draw(const Point& p);
|
void draw(const Point& p, const Rect&);
|
||||||
|
|
||||||
void start();
|
void start();
|
||||||
void updateAnimation();
|
void updateAnimation();
|
||||||
|
|
|
@ -32,7 +32,7 @@ Item::Item() : Thing()
|
||||||
m_data = 0;
|
m_data = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Item::draw(const Point& p)
|
void Item::draw(const Point& p, const Rect&)
|
||||||
{
|
{
|
||||||
if(m_type->dimensions[ThingType::AnimationPhases] > 1)
|
if(m_type->dimensions[ThingType::AnimationPhases] > 1)
|
||||||
m_animation = (g_clock.ticks() % (TICKS_PER_FRAME * m_type->dimensions[ThingType::AnimationPhases])) / TICKS_PER_FRAME;
|
m_animation = (g_clock.ticks() % (TICKS_PER_FRAME * m_type->dimensions[ThingType::AnimationPhases])) / TICKS_PER_FRAME;
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
TICKS_PER_FRAME = 500
|
TICKS_PER_FRAME = 500
|
||||||
};
|
};
|
||||||
|
|
||||||
void draw(const Point& p);
|
void draw(const Point& p, const Rect&);
|
||||||
|
|
||||||
void setPos(const Position &position);
|
void setPos(const Position &position);
|
||||||
void setData(int data);
|
void setData(int data);
|
||||||
|
|
|
@ -81,7 +81,7 @@ void Map::draw(const Rect& rect)
|
||||||
// skip tiles that are behind another tile
|
// skip tiles that are behind another tile
|
||||||
//if(isCompletlyCovered(tilePos, firstFloor))
|
//if(isCompletlyCovered(tilePos, firstFloor))
|
||||||
// continue;
|
// continue;
|
||||||
tile->draw(positionTo2D(tilePos) - m_drawOffset);
|
tile->draw(positionTo2D(tilePos) - m_drawOffset, rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,7 +89,7 @@ void Map::draw(const Rect& rect)
|
||||||
// after drawing all tiles, draw shots
|
// after drawing all tiles, draw shots
|
||||||
for(const MissilePtr& shot : m_missilesAtFloor[iz]) {
|
for(const MissilePtr& shot : m_missilesAtFloor[iz]) {
|
||||||
Position missilePos = shot->getPos();
|
Position missilePos = shot->getPos();
|
||||||
shot->draw(positionTo2D(missilePos) - m_drawOffset);
|
shot->draw(positionTo2D(missilePos) - m_drawOffset, rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ void Map::draw(const Rect& rect)
|
||||||
Point pos = positionTo2D((*it)->getPos()) - m_drawOffset;
|
Point pos = positionTo2D((*it)->getPos()) - m_drawOffset;
|
||||||
pos.x *= horizontalStretchFactor;
|
pos.x *= horizontalStretchFactor;
|
||||||
pos.y *= verticalStretchFactor;
|
pos.y *= verticalStretchFactor;
|
||||||
(*it)->draw(rect.topLeft() + pos);
|
(*it)->draw(rect.topLeft() + pos, rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
// draw static text
|
// draw static text
|
||||||
|
@ -143,7 +143,7 @@ void Map::draw(const Rect& rect)
|
||||||
Point pos = positionTo2D((*it)->getPos()) - m_drawOffset;
|
Point pos = positionTo2D((*it)->getPos()) - m_drawOffset;
|
||||||
pos.x *= horizontalStretchFactor;
|
pos.x *= horizontalStretchFactor;
|
||||||
pos.y *= verticalStretchFactor;
|
pos.y *= verticalStretchFactor;
|
||||||
(*it)->draw(rect.topLeft() + pos);
|
(*it)->draw(rect.topLeft() + pos, rect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,7 @@ Missile::Missile() : Thing()
|
||||||
m_startTicks = 0;
|
m_startTicks = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Missile::draw(const Point& p)
|
void Missile::draw(const Point& p, const Rect&)
|
||||||
{
|
{
|
||||||
float time = (g_clock.ticks() - m_startTicks) / m_duration;
|
float time = (g_clock.ticks() - m_startTicks) / m_duration;
|
||||||
internalDraw(p + Point(m_positionDelta.x * time, m_positionDelta.y * time), 0);
|
internalDraw(p + Point(m_positionDelta.x * time, m_positionDelta.y * time), 0);
|
||||||
|
|
|
@ -35,7 +35,7 @@ class Missile : public Thing
|
||||||
public:
|
public:
|
||||||
Missile();
|
Missile();
|
||||||
|
|
||||||
void draw(const Point& p);
|
void draw(const Point& p, const Rect&);
|
||||||
|
|
||||||
void updateAnimation();
|
void updateAnimation();
|
||||||
|
|
||||||
|
|
|
@ -31,10 +31,13 @@ StaticText::StaticText()
|
||||||
m_font = g_fonts.getFont("verdana-11px-rounded");
|
m_font = g_fonts.getFont("verdana-11px-rounded");
|
||||||
}
|
}
|
||||||
|
|
||||||
void StaticText::draw(const Point& p)
|
void StaticText::draw(const Point& p, const Rect& visibleRect)
|
||||||
{
|
{
|
||||||
if(m_font)
|
if(m_font) {
|
||||||
m_font->renderText(m_text, Rect(p - Point(m_textSize.width() / 2, m_textSize.height()) + Point(20, 5), m_textSize), Fw::AlignCenter, m_color);
|
Rect rect = Rect(p - Point(m_textSize.width() / 2, m_textSize.height()) + Point(20, 5), m_textSize);
|
||||||
|
if(visibleRect.contains(rect))
|
||||||
|
m_font->renderText(m_text, rect, Fw::AlignCenter, m_color);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool StaticText::addMessage(const std::string& name, int type, const std::string& message)
|
bool StaticText::addMessage(const std::string& name, int type, const std::string& message)
|
||||||
|
|
|
@ -35,7 +35,7 @@ public:
|
||||||
|
|
||||||
StaticText();
|
StaticText();
|
||||||
|
|
||||||
void draw(const Point& p);
|
void draw(const Point& p, const Rect& visibleRect);
|
||||||
|
|
||||||
std::string getName() { return m_name; }
|
std::string getName() { return m_name; }
|
||||||
int getMessageType() { return m_type; }
|
int getMessageType() { return m_type; }
|
||||||
|
|
|
@ -41,7 +41,7 @@ public:
|
||||||
|
|
||||||
virtual void start() {}
|
virtual void start() {}
|
||||||
|
|
||||||
virtual void draw(const Point& p) = 0;
|
virtual void draw(const Point& p, const Rect&) = 0;
|
||||||
|
|
||||||
void setId(int id);
|
void setId(int id);
|
||||||
virtual void setPos(const Position& position) { m_position = position; }
|
virtual void setPos(const Position& position) { m_position = position; }
|
||||||
|
|
|
@ -36,7 +36,7 @@ Tile::Tile(const Position& position)
|
||||||
m_position = position;
|
m_position = position;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tile::draw(const Point& p)
|
void Tile::draw(const Point& p, const Rect& visibleRect)
|
||||||
{
|
{
|
||||||
m_drawElevation = 0;
|
m_drawElevation = 0;
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ void Tile::draw(const Point& p)
|
||||||
ThingType *type = thing->getType();
|
ThingType *type = thing->getType();
|
||||||
if(!type->properties[ThingType::IsGround] && !type->properties[ThingType::IsGroundBorder] && !type->properties[ThingType::IsOnBottom])
|
if(!type->properties[ThingType::IsGround] && !type->properties[ThingType::IsGroundBorder] && !type->properties[ThingType::IsOnBottom])
|
||||||
break;
|
break;
|
||||||
thing->draw(p - m_drawElevation);
|
thing->draw(p - m_drawElevation, visibleRect);
|
||||||
m_drawElevation += type->parameters[ThingType::Elevation];
|
m_drawElevation += type->parameters[ThingType::Elevation];
|
||||||
if(m_drawElevation > MAX_DRAW_ELEVATION)
|
if(m_drawElevation > MAX_DRAW_ELEVATION)
|
||||||
m_drawElevation = MAX_DRAW_ELEVATION;
|
m_drawElevation = MAX_DRAW_ELEVATION;
|
||||||
|
@ -57,7 +57,7 @@ void Tile::draw(const Point& p)
|
||||||
ThingType *type = thing->getType();
|
ThingType *type = thing->getType();
|
||||||
if(thing->asCreature() || type->properties[ThingType::IsOnTop] || type->properties[ThingType::IsOnBottom] || type->properties[ThingType::IsGroundBorder] || type->properties[ThingType::IsGround])
|
if(thing->asCreature() || type->properties[ThingType::IsOnTop] || type->properties[ThingType::IsOnBottom] || type->properties[ThingType::IsGroundBorder] || type->properties[ThingType::IsGround])
|
||||||
break;
|
break;
|
||||||
thing->draw(p - m_drawElevation);
|
thing->draw(p - m_drawElevation, visibleRect);
|
||||||
m_drawElevation += type->parameters[ThingType::Elevation];
|
m_drawElevation += type->parameters[ThingType::Elevation];
|
||||||
if(m_drawElevation > MAX_DRAW_ELEVATION)
|
if(m_drawElevation > MAX_DRAW_ELEVATION)
|
||||||
m_drawElevation = MAX_DRAW_ELEVATION;
|
m_drawElevation = MAX_DRAW_ELEVATION;
|
||||||
|
@ -74,7 +74,7 @@ void Tile::draw(const Point& p)
|
||||||
|
|
||||||
// only render creatures where bottom right is inside our rect
|
// only render creatures where bottom right is inside our rect
|
||||||
if(thisTileRect.contains(creatureRect.bottomRight())) {
|
if(thisTileRect.contains(creatureRect.bottomRight())) {
|
||||||
creature->draw(Point(p.x + xi*32 - m_drawElevation, p.y + yi*32 - m_drawElevation));
|
creature->draw(Point(p.x + xi*32 - m_drawElevation, p.y + yi*32 - m_drawElevation), visibleRect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -82,13 +82,13 @@ void Tile::draw(const Point& p)
|
||||||
|
|
||||||
// effects
|
// effects
|
||||||
for(const EffectPtr& effect : m_effects)
|
for(const EffectPtr& effect : m_effects)
|
||||||
effect->draw(p - m_drawElevation);
|
effect->draw(p - m_drawElevation, visibleRect);
|
||||||
|
|
||||||
// top items
|
// top items
|
||||||
for(const ThingPtr& thing : m_things) {
|
for(const ThingPtr& thing : m_things) {
|
||||||
ThingType *type = thing->getType();
|
ThingType *type = thing->getType();
|
||||||
if(type->properties[ThingType::IsOnTop])
|
if(type->properties[ThingType::IsOnTop])
|
||||||
thing->draw(p);
|
thing->draw(p, visibleRect);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ class Tile : public LuaObject
|
||||||
public:
|
public:
|
||||||
Tile(const Position& position);
|
Tile(const Position& position);
|
||||||
|
|
||||||
void draw(const Point& p);
|
void draw(const Point& p, const Rect& visibleRect);
|
||||||
void clean();
|
void clean();
|
||||||
|
|
||||||
ThingPtr addThing(const ThingPtr& thing, int stackPos = -1);
|
ThingPtr addThing(const ThingPtr& thing, int stackPos = -1);
|
||||||
|
|
|
@ -35,7 +35,7 @@ void UICreature::render()
|
||||||
|
|
||||||
if(m_creature) {
|
if(m_creature) {
|
||||||
g_painter.setColor(Fw::white);
|
g_painter.setColor(Fw::white);
|
||||||
m_creature->draw(m_rect.bottomRight() - Point(32, 32) + m_creatureMargin);
|
m_creature->draw(m_rect.bottomRight() - Point(32, 32) + m_creatureMargin, m_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderChildren();
|
renderChildren();
|
||||||
|
|
|
@ -35,7 +35,7 @@ void UIItem::render()
|
||||||
|
|
||||||
if(m_item) {
|
if(m_item) {
|
||||||
g_painter.setColor(Fw::white);
|
g_painter.setColor(Fw::white);
|
||||||
m_item->draw(m_rect.bottomRight() - Point(32, 32) + m_itemMargin);
|
m_item->draw(m_rect.bottomRight() - Point(32, 32) + m_itemMargin, m_rect);
|
||||||
}
|
}
|
||||||
|
|
||||||
renderChildren();
|
renderChildren();
|
||||||
|
|
Loading…
Reference in New Issue