ULTIMA8: Refactor gump pattern of setting dims from shape

This commit is contained in:
Matthew Duggan 2020-03-29 12:59:06 +09:00
parent 241d4e761d
commit f5712907d1
13 changed files with 24 additions and 64 deletions

View File

@ -73,12 +73,7 @@ void BookGump::InitGump(Gump *newparent, bool take_focus) {
Shape *shapeP = GameData::get_instance()->getGumps()->getShape(6);
SetShape(shapeP, 0);
const ShapeFrame *sf = shapeP->getFrame(0);
assert(sf);
_dims.w = sf->_width;
_dims.h = sf->_height;
UpdateDimsFromShape();
}
void BookGump::NextText() {

View File

@ -66,11 +66,7 @@ ContainerGump::~ContainerGump() {
}
void ContainerGump::InitGump(Gump *newparent, bool take_focus) {
const ShapeFrame *sf = _shape->getFrame(_frameNum);
assert(sf);
_dims.w = sf->_width;
_dims.h = sf->_height;
UpdateDimsFromShape();
// Wait with ItemRelativeGump initialization until we calculated our size.
ItemRelativeGump::InitGump(newparent, take_focus);

View File

@ -82,12 +82,16 @@ void Gump::SetShape(FrameID frame, bool adjustsize) {
_frameNum = frame._frameNum;
if (adjustsize && _shape) {
const ShapeFrame *sf = _shape->getFrame(_frameNum);
_dims.w = sf->_width;
_dims.h = sf->_height;
UpdateDimsFromShape();
}
}
void Gump::UpdateDimsFromShape() {
const ShapeFrame *sf = _shape->getFrame(_frameNum);
assert(sf);
_dims.w = sf->_width;
_dims.h = sf->_height;
}
void Gump::CreateNotifier() {
assert(_notifier == 0);

View File

@ -94,6 +94,9 @@ public:
void SetShape(FrameID frame, bool adjustsize = false);
//! Update the width/height to match the gump's current shape frame
void UpdateDimsFromShape();
//! Set the Gump's frame
inline void Set_frameNum(uint32 frameNum) {
_frameNum = frameNum;

View File

@ -108,15 +108,11 @@ void MenuGump::InitGump(Gump *newparent, bool take_focus) {
ModalGump::InitGump(newparent, take_focus);
_shape = GameData::get_instance()->getGumps()->getShape(gumpShape);
const ShapeFrame *sf = _shape->getFrame(0);
assert(sf);
_dims.w = sf->_width;
_dims.h = sf->_height;
UpdateDimsFromShape();
Shape *logoShape;
logoShape = GameData::get_instance()->getGumps()->getShape(paganShape);
sf = logoShape->getFrame(0);
const ShapeFrame *sf = logoShape->getFrame(0);
assert(sf);
Gump *logo = new Gump(42, 10, sf->_width, sf->_height);

View File

@ -66,11 +66,7 @@ void MiniStatsGump::InitGump(Gump *newparent, bool take_focus) {
Gump::InitGump(newparent, take_focus);
_shape = GameData::get_instance()->getGumps()->getShape(gumpshape);
const ShapeFrame *sf = _shape->getFrame(0);
assert(sf);
_dims.w = sf->_width;
_dims.h = sf->_height;
UpdateDimsFromShape();
}
void MiniStatsGump::PaintThis(RenderSurface *surf, int32 lerp_factor, bool scaled) {

View File

@ -60,11 +60,7 @@ void PagedGump::InitGump(Gump *newparent, bool take_focus) {
ModalGump::InitGump(newparent, take_focus);
_shape = GameData::get_instance()->getGumps()->getShape(_gumpShape);
const ShapeFrame *sf = _shape->getFrame(0);
assert(sf);
_dims.w = sf->_width;
_dims.h = sf->_height;
UpdateDimsFromShape();
FrameID buttonleft(GameData::GUMPS, pageOverShape, 0);
FrameID buttonright(GameData::GUMPS, pageOverShape, 1);

View File

@ -57,17 +57,13 @@ void QuitGump::InitGump(Gump *newparent, bool take_focus) {
ModalGump::InitGump(newparent, take_focus);
_shape = GameData::get_instance()->getGumps()->getShape(gumpShape);
const ShapeFrame *sf = _shape->getFrame(0);
assert(sf);
_dims.w = sf->_width;
_dims.h = sf->_height;
UpdateDimsFromShape();
FrameID askshape(GameData::GUMPS, askShapeId, 0);
askshape = _TL_SHP_(askshape);
Shape *askShape = GameData::get_instance()->getShape(askshape);
sf = askShape->getFrame(askshape._frameNum);
const ShapeFrame *sf = askShape->getFrame(askshape._frameNum);
assert(sf);
Gump *ask = new Gump(0, 0, sf->_width, sf->_height);

View File

@ -63,11 +63,7 @@ void ReadableGump::InitGump(Gump *newparent, bool take_focus) {
SetShape(shape_, 0);
const ShapeFrame *sf = shape_->getFrame(0);
assert(sf);
_dims.w = sf->_width;
_dims.h = sf->_height;
UpdateDimsFromShape();
if (CoreApp::get_instance()->getGameInfo()->_language ==
GameInfo::GAMELANG_JAPANESE) {

View File

@ -66,12 +66,7 @@ void ScrollGump::InitGump(Gump *newparent, bool take_focus) {
Shape *shape_ = GameData::get_instance()->getGumps()->getShape(19);
SetShape(shape_, 0);
const ShapeFrame *sf = shape_->getFrame(0);
assert(sf);
_dims.w = sf->_width;
_dims.h = sf->_height;
UpdateDimsFromShape();
}
void ScrollGump::NextText() {

View File

@ -125,11 +125,7 @@ void SliderGump::InitGump(Gump *newparent, bool take_focus) {
ModalGump::InitGump(newparent, take_focus);
_shape = GameData::get_instance()->getGumps()->getShape(gumpshape);
const ShapeFrame *sf = _shape->getFrame(0);
assert(sf);
_dims.w = sf->_width;
_dims.h = sf->_height;
UpdateDimsFromShape();
Shape *childshape = GameData::get_instance()->
getGumps()->getShape(slidershape);

View File

@ -79,13 +79,8 @@ void ButtonWidget::InitGump(Gump *newparent, bool take_focus) {
assert(_shapeUp != nullptr);
assert(_shapeDown != nullptr);
_shape = _shapeUp;
_frameNum = _frameNumUp;
const ShapeFrame *sf = _shape->getFrame(_frameNum);
assert(sf);
_dims.w = sf->_width;
_dims.h = sf->_height;
SetShape(_shapeUp, _frameNumUp);
UpdateDimsFromShape();
}
}

View File

@ -49,11 +49,7 @@ SlidingWidget::~SlidingWidget() {
void SlidingWidget::InitGump(Gump *newparent, bool take_focus) {
Gump::InitGump(newparent, take_focus);
const ShapeFrame *sf = _shape->getFrame(_frameNum);
assert(sf);
_dims.w = sf->_width;
_dims.h = sf->_height;
UpdateDimsFromShape();
}
uint16 SlidingWidget::TraceObjId(int32 mx, int32 my) {