Merge branch 'master' into tracerestrict

This commit is contained in:
Jonathan G Rennison
2015-07-29 19:01:24 +01:00
4 changed files with 68 additions and 44 deletions

View File

@@ -20,7 +20,6 @@ void UpdateCompanyHQ(TileIndex tile, uint score);
void BuildObject(ObjectType type, TileIndex tile, CompanyID owner = OWNER_NONE, struct Town *town = NULL, uint8 view = 0); void BuildObject(ObjectType type, TileIndex tile, CompanyID owner = OWNER_NONE, struct Town *town = NULL, uint8 view = 0);
void PlaceProc_Object(TileIndex tile); void ShowBuildObjectPicker();
void ShowBuildObjectPicker(struct Window *w);
#endif /* OBJECT_H */ #endif /* OBJECT_H */

View File

@@ -16,6 +16,7 @@
#include "newgrf_text.h" #include "newgrf_text.h"
#include "strings_func.h" #include "strings_func.h"
#include "viewport_func.h" #include "viewport_func.h"
#include "tilehighlight_func.h"
#include "window_gui.h" #include "window_gui.h"
#include "window_func.h" #include "window_func.h"
#include "zoom_func.h" #include "zoom_func.h"
@@ -31,7 +32,7 @@ static int _selected_object_index; ///< the index of the selected obje
static uint8 _selected_object_view; ///< the view of the selected object static uint8 _selected_object_view; ///< the view of the selected object
/** The window used for building objects. */ /** The window used for building objects. */
class BuildObjectWindow : public PickerWindowBase { class BuildObjectWindow : public Window {
static const int OBJECT_MARGIN = 4; ///< The margin (in pixels) around an object. static const int OBJECT_MARGIN = 4; ///< The margin (in pixels) around an object.
int line_height; ///< The height of a single line. int line_height; ///< The height of a single line.
int info_height; ///< The height of the info box. int info_height; ///< The height of the info box.
@@ -73,11 +74,13 @@ class BuildObjectWindow : public PickerWindowBase {
} }
public: public:
BuildObjectWindow(WindowDesc *desc, Window *w) : PickerWindowBase(desc, w), info_height(1) BuildObjectWindow(WindowDesc *desc, WindowNumber number) : Window(desc), info_height(1)
{ {
this->CreateNestedTree(); this->CreateNestedTree();
this->vscroll = this->GetScrollbar(WID_BO_SCROLLBAR); this->vscroll = this->GetScrollbar(WID_BO_SCROLLBAR);
this->FinishInitNested(0); this->FinishInitNested(number);
ResetObjectToPlace();
this->vscroll->SetPosition(0); this->vscroll->SetPosition(0);
this->vscroll->SetCount(ObjectClass::GetUIClassCount()); this->vscroll->SetCount(ObjectClass::GetUIClassCount());
@@ -337,10 +340,11 @@ public:
_selected_object_view = 0; _selected_object_view = 0;
} }
this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->SetClicked(_selected_object_view); if (_selected_object_index != -1) {
this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetClicked(_selected_object_index != -1 ? ObjectClass::Get(_selected_object_class)->GetUIFromIndex(_selected_object_index) : -1); SetObjectToPlaceWnd(SPR_CURSOR_TRANSMITTER, PAL_NONE, HT_RECT, this);
this->UpdateSelectSize(); }
this->SetDirty();
this->UpdateButtons(_selected_object_class, _selected_object_index, _selected_object_view);
} }
void UpdateSelectSize() void UpdateSelectSize()
@@ -355,6 +359,29 @@ public:
} }
} }
/**
* Update buttons to show the selection to the user.
* @param sel_class The class of the selected object.
* @param sel_index Index of the object to select, or \c -1 .
* @param sel_view View of the object to select.
*/
void UpdateButtons(ObjectClassID sel_class, int sel_index, uint sel_view)
{
int view_number, object_number;
if (sel_index == -1) {
view_number = -1; // If no object selected, also hide the selected view.
object_number = -1;
} else {
view_number = sel_view;
object_number = ObjectClass::Get(sel_class)->GetUIFromIndex(sel_index);
}
this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->SetClicked(view_number);
this->GetWidget<NWidgetMatrix>(WID_BO_SELECT_MATRIX)->SetClicked(object_number);
this->UpdateSelectSize();
this->SetDirty();
}
virtual void OnResize() virtual void OnResize()
{ {
this->vscroll->SetCapacityFromWidget(this, WID_BO_CLASS_LIST); this->vscroll->SetCapacityFromWidget(this, WID_BO_CLASS_LIST);
@@ -382,14 +409,23 @@ public:
case WID_BO_OBJECT_SPRITE: case WID_BO_OBJECT_SPRITE:
if (_selected_object_index != -1) { if (_selected_object_index != -1) {
_selected_object_view = GB(widget, 16, 16); _selected_object_view = GB(widget, 16, 16);
this->GetWidget<NWidgetMatrix>(WID_BO_OBJECT_MATRIX)->SetClicked(_selected_object_view); this->SelectOtherObject(_selected_object_index); // Re-select the object for a different view.
this->UpdateSelectSize();
this->SetDirty();
} }
break; break;
} }
} }
virtual void OnPlaceObject(Point pt, TileIndex tile)
{
DoCommandP(tile, ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index)->Index(),
_selected_object_view, CMD_BUILD_OBJECT | CMD_MSG(STR_ERROR_CAN_T_BUILD_OBJECT), CcTerraform);
}
virtual void OnPlaceObjectAbort()
{
this->UpdateButtons(_selected_object_class, -1, _selected_object_view);
}
/** /**
* Select the first available object. * Select the first available object.
* @param change_class If true, change the class if no object in the current * @param change_class If true, change the class if no object in the current
@@ -488,9 +524,9 @@ static WindowDesc _build_object_desc(
* Show our object picker. * Show our object picker.
* @param w The toolbar window we're associated with. * @param w The toolbar window we're associated with.
*/ */
void ShowBuildObjectPicker(Window *w) void ShowBuildObjectPicker()
{ {
new BuildObjectWindow(&_build_object_desc, w); AllocateWindowDescFront<BuildObjectWindow>(&_build_object_desc, 0);
} }
/** Reset all data of the object GUI. */ /** Reset all data of the object GUI. */
@@ -498,13 +534,3 @@ void InitializeObjectGui()
{ {
_selected_object_class = (ObjectClassID)0; _selected_object_class = (ObjectClassID)0;
} }
/**
* PlaceProc function, called when someone pressed the button if the
* object-tool is selected
* @param tile on which to place the object
*/
void PlaceProc_Object(TileIndex tile)
{
DoCommandP(tile, ObjectClass::Get(_selected_object_class)->GetSpec(_selected_object_index)->Index(), _selected_object_view, CMD_BUILD_OBJECT | CMD_MSG(STR_ERROR_CAN_T_BUILD_OBJECT), CcTerraform);
}

View File

@@ -210,12 +210,7 @@ struct TerraformToolbarWindow : Window {
break; break;
case WID_TT_PLACE_OBJECT: // Place object button case WID_TT_PLACE_OBJECT: // Place object button
/* Don't show the place object button when there are no objects to place. */ ShowBuildObjectPicker();
if (ObjectClass::GetUIClassCount() == 0) return;
if (HandlePlacePushButton(this, WID_TT_PLACE_OBJECT, SPR_CURSOR_TRANSMITTER, HT_RECT)) {
ShowBuildObjectPicker(this);
this->last_user_action = widget;
}
break; break;
default: NOT_REACHED(); default: NOT_REACHED();
@@ -249,10 +244,6 @@ struct TerraformToolbarWindow : Window {
PlaceProc_Sign(tile); PlaceProc_Sign(tile);
break; break;
case WID_TT_PLACE_OBJECT: // Place object button
PlaceProc_Object(tile);
break;
default: NOT_REACHED(); default: NOT_REACHED();
} }
} }
@@ -286,7 +277,6 @@ struct TerraformToolbarWindow : Window {
virtual void OnPlaceObjectAbort() virtual void OnPlaceObjectAbort()
{ {
DeleteWindowById(WC_BUILD_OBJECT, 0);
this->RaiseButtons(); this->RaiseButtons();
} }
@@ -344,7 +334,7 @@ static const NWidgetPart _nested_terraform_widgets[] = {
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_PLACE_SIGN), SetMinimalSize(22, 22), NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_PLACE_SIGN), SetMinimalSize(22, 22),
SetFill(0, 1), SetDataTip(SPR_IMG_SIGN, STR_SCENEDIT_TOOLBAR_PLACE_SIGN), SetFill(0, 1), SetDataTip(SPR_IMG_SIGN, STR_SCENEDIT_TOOLBAR_PLACE_SIGN),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_TT_SHOW_PLACE_OBJECT), NWidget(NWID_SELECTION, INVALID_COLOUR, WID_TT_SHOW_PLACE_OBJECT),
NWidget(WWT_IMGBTN, COLOUR_DARK_GREEN, WID_TT_PLACE_OBJECT), SetMinimalSize(22, 22), NWidget(WWT_PUSHIMGBTN, COLOUR_DARK_GREEN, WID_TT_PLACE_OBJECT), SetMinimalSize(22, 22),
SetFill(0, 1), SetDataTip(SPR_IMG_TRANSMITTER, STR_SCENEDIT_TOOLBAR_PLACE_OBJECT), SetFill(0, 1), SetDataTip(SPR_IMG_TRANSMITTER, STR_SCENEDIT_TOOLBAR_PLACE_OBJECT),
EndContainer(), EndContainer(),
EndContainer(), EndContainer(),
@@ -616,10 +606,7 @@ struct ScenarioEditorLandscapeGenerationWindow : Window {
break; break;
case WID_ETT_PLACE_OBJECT: // Place transmitter button case WID_ETT_PLACE_OBJECT: // Place transmitter button
if (HandlePlacePushButton(this, WID_ETT_PLACE_OBJECT, SPR_CURSOR_TRANSMITTER, HT_RECT)) { ShowBuildObjectPicker();
ShowBuildObjectPicker(this);
this->last_user_action = widget;
}
break; break;
case WID_ETT_INCREASE_SIZE: case WID_ETT_INCREASE_SIZE:
@@ -687,10 +674,6 @@ struct ScenarioEditorLandscapeGenerationWindow : Window {
VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_DESERT); VpStartPlaceSizing(tile, VPM_X_AND_Y, DDSP_CREATE_DESERT);
break; break;
case WID_ETT_PLACE_OBJECT: // Place transmitter button
PlaceProc_Object(tile);
break;
default: NOT_REACHED(); default: NOT_REACHED();
} }
} }

View File

@@ -3141,6 +3141,13 @@ EventState VpHandlePlaceSizingDrag()
return ES_HANDLED; return ES_HANDLED;
} }
/**
* Change the cursor and mouse click/drag handling to a mode for performing special operations like tile area selection, object placement, etc.
* @param icon New shape of the mouse cursor.
* @param pal Palette to use.
* @param mode Mode to perform.
* @param w %Window requesting the mode change.
*/
void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Window *w) void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Window *w)
{ {
SetObjectToPlace(icon, pal, mode, w->window_class, w->window_number); SetObjectToPlace(icon, pal, mode, w->window_class, w->window_number);
@@ -3148,6 +3155,14 @@ void SetObjectToPlaceWnd(CursorID icon, PaletteID pal, HighLightStyle mode, Wind
#include "table/animcursors.h" #include "table/animcursors.h"
/**
* Change the cursor and mouse click/drag handling to a mode for performing special operations like tile area selection, object placement, etc.
* @param icon New shape of the mouse cursor.
* @param pal Palette to use.
* @param mode Mode to perform.
* @param window_class %Window class of the window requesting the mode change.
* @param window_num Number of the window in its class requesting the mode change.
*/
void SetObjectToPlace(CursorID icon, PaletteID pal, HighLightStyle mode, WindowClass window_class, WindowNumber window_num) void SetObjectToPlace(CursorID icon, PaletteID pal, HighLightStyle mode, WindowClass window_class, WindowNumber window_num)
{ {
if (_thd.window_class != WC_INVALID) { if (_thd.window_class != WC_INVALID) {
@@ -3192,6 +3207,7 @@ void SetObjectToPlace(CursorID icon, PaletteID pal, HighLightStyle mode, WindowC
} }
/** Reset the cursor and mouse mode handling back to default (normal cursor, only clicking in windows). */
void ResetObjectToPlace() void ResetObjectToPlace()
{ {
SetObjectToPlace(SPR_CURSOR_MOUSE, PAL_NONE, HT_NONE, WC_MAIN_WINDOW, 0); SetObjectToPlace(SPR_CURSOR_MOUSE, PAL_NONE, HT_NONE, WC_MAIN_WINDOW, 0);