mirror of
https://github.com/Relintai/mourne_rcpp_fw.git
synced 2024-12-23 21:16:50 +01:00
Ported the building editor's ui (at least what I could for now).
This commit is contained in:
parent
3042f4e37b
commit
c85911b12a
2
HEADS
2
HEADS
@ -1 +1 @@
|
||||
{"engine": {"master": "b8b2d5a3a6ce3556ee465290260ce0a902e1a40a"}}
|
||||
{"engine": {"master": "fd7bcb43cbf925731fee5c1b96166bf207dcbdd7"}}
|
@ -3,12 +3,15 @@
|
||||
#include "core/html/form_validator.h"
|
||||
#include "core/html/html_builder.h"
|
||||
#include "core/http/cookie.h"
|
||||
#include "core/http/http_enums.h"
|
||||
#include "core/http/http_session.h"
|
||||
#include "core/http/request.h"
|
||||
#include "core/http/session_manager.h"
|
||||
|
||||
#include "building_model.h"
|
||||
|
||||
#include "../html_macros.h"
|
||||
|
||||
void BuildingController::handle_request_default(Request *request) {
|
||||
}
|
||||
|
||||
@ -20,11 +23,31 @@ void BuildingController::admin_handle_request_main(Request *request) {
|
||||
return;
|
||||
} else if (seg == "new") {
|
||||
request->push_path();
|
||||
admin_render_building(request, Ref<Building>());
|
||||
Ref<Building> b;
|
||||
b.instance();
|
||||
|
||||
admin_render_building(request, b);
|
||||
return;
|
||||
} else if (seg == "edit") {
|
||||
request->push_path();
|
||||
admin_render_building(request, Ref<Building>());
|
||||
|
||||
String seg_building_id = request->get_current_path_segment();
|
||||
|
||||
if (!seg_building_id.is_int()) {
|
||||
request->send_error(HTTP_STATUS_CODE_404_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
|
||||
int bid = seg_building_id.to_int();
|
||||
|
||||
Ref<Building> b = BuildingModel::get_singleton()->get_building(bid);
|
||||
|
||||
if (!b.is_valid()) {
|
||||
request->send_error(HTTP_STATUS_CODE_404_NOT_FOUND);
|
||||
return;
|
||||
}
|
||||
|
||||
admin_render_building(request, b);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -83,6 +106,12 @@ void BuildingController::admin_render_building_list(Request *request) {
|
||||
}
|
||||
|
||||
void BuildingController::admin_render_building(Request *request, Ref<Building> building) {
|
||||
if (!building.is_valid()) {
|
||||
RLOG_ERR("admin_render_building: !building.is_valid()\n");
|
||||
request->send_error(HTTP_STATUS_CODE_500_INTERNAL_SERVER_ERROR);
|
||||
return;
|
||||
}
|
||||
|
||||
Vector<Ref<Building> > buildings = BuildingModel::get_singleton()->get_all();
|
||||
|
||||
HTMLBuilder b;
|
||||
@ -92,6 +121,156 @@ void BuildingController::admin_render_building(Request *request, Ref<Building> b
|
||||
b.fdiv("Building Editor", "top_menu");
|
||||
b.br();
|
||||
|
||||
b.form_post(request->get_url_root());
|
||||
|
||||
bool show_post = false; //request->get_method() == HTTP_METHOD_POST && validation errors;
|
||||
|
||||
ADMIN_EDIT_INPUT_TEXT("Name:", "name", show_post, building->name, request->get_parameter("name"));
|
||||
ADMIN_EDIT_INPUT_TEXTAREA("Description:", "description", show_post, building->description, request->get_parameter("description"));
|
||||
|
||||
b.div("row_edit");
|
||||
b.fdiv("Icon:", "edit_name");
|
||||
//todo I'm not sure yet how this worked originally
|
||||
//b.div("edit_input")->f()->input_image("icon", building->icon)->f()->cdiv();
|
||||
b.div("edit_input")->f()->w("TODO")->cdiv();
|
||||
b.cdiv();
|
||||
|
||||
ADMIN_EDIT_INPUT_TEXT("Rank:", "rank", show_post, String::num(building->rank), request->get_parameter("rank"));
|
||||
|
||||
Vector<Ref<Building> > nrbs = BuildingModel::get_singleton()->get_all();
|
||||
b.div("row_edit");
|
||||
b.fdiv("Next Rank:", "edit_name");
|
||||
b.div("edit_input");
|
||||
{
|
||||
b.select("next_rank", "drop");
|
||||
{
|
||||
int current_id = building->id;
|
||||
int current_nr = building->next_rank;
|
||||
|
||||
b.foption(String::num(0), "- None -", current_nr == 0);
|
||||
|
||||
for (int i = 0; i < nrbs.size(); ++i) {
|
||||
Ref<Building> build = nrbs[i];
|
||||
|
||||
int id = build->id;
|
||||
|
||||
if (id == current_id) {
|
||||
continue;
|
||||
}
|
||||
|
||||
b.foption(String::num(id), build->name + " R" + String::num(build->rank), current_nr == id);
|
||||
}
|
||||
}
|
||||
b.cselect();
|
||||
}
|
||||
b.cdiv();
|
||||
b.cdiv();
|
||||
|
||||
ADMIN_EDIT_INPUT_TEXT("Time to Build:", "time_to_build", show_post, String::num(building->time_to_build), request->get_parameter("time_to_build"));
|
||||
|
||||
ADMIN_EDIT_LINE_SPACER();
|
||||
|
||||
ADMIN_EDIT_INPUT_TEXT("Score:", "score", show_post, String::num(building->score), request->get_parameter("score"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Defense:", "defense", show_post, String::num(building->defense), request->get_parameter("defense"));
|
||||
|
||||
//TODO
|
||||
/*
|
||||
int ability;
|
||||
|
||||
<div class="row_edit">
|
||||
<div class="edit_name">
|
||||
Ability:
|
||||
</div>
|
||||
<div class="edit_input">
|
||||
<?=form_dropdown('ability', $opt_ability, $sability, $attr_drop); ?>
|
||||
</div>
|
||||
</div>
|
||||
*/
|
||||
|
||||
b.div("row_edit");
|
||||
b.fdiv("Ability:", "edit_name");
|
||||
b.div("edit_input")->f()->w("TODO")->cdiv();
|
||||
b.cdiv();
|
||||
|
||||
ADMIN_EDIT_LINE_SPACER();
|
||||
|
||||
ADMIN_EDIT_INPUT_TEXT("Cost Food:", "cost_food", show_post, String::num(building->cost_food), request->get_parameter("cost_food"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Cost Wood:", "cost_wood", show_post, String::num(building->cost_wood), request->get_parameter("cost_wood"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Cost Stone:", "cost_stone", show_post, String::num(building->cost_stone), request->get_parameter("cost_stone"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Cost Iron:", "cost_iron", show_post, String::num(building->cost_iron), request->get_parameter("cost_iron"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Cost Mana:", "cost_mana", show_post, String::num(building->cost_food), request->get_parameter("cost_mana"));
|
||||
|
||||
ADMIN_EDIT_LINE_SPACER();
|
||||
|
||||
/*
|
||||
int creates;
|
||||
int num_creates;
|
||||
|
||||
<div class="row_edit">
|
||||
<div class="edit_name">
|
||||
Creates:
|
||||
</div>
|
||||
<div class="edit_input">
|
||||
<?=form_dropdown($name_creates, $optcre, $screate, $attr_creates); ?>
|
||||
X (max) <?=form_input($attr_num_creates); ?>
|
||||
</div>
|
||||
</div>
|
||||
*/
|
||||
|
||||
b.div("row_edit");
|
||||
b.fdiv("Creates:", "edit_name");
|
||||
b.div("edit_input")->f()->w("TODO")->cdiv();
|
||||
b.cdiv();
|
||||
|
||||
ADMIN_EDIT_LINE_SPACER();
|
||||
|
||||
ADMIN_EDIT_INPUT_TEXT("Mod Max Food:", "mod_max_food", show_post, String::num(building->mod_max_food), request->get_parameter("mod_max_food"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Mod Max Wood:", "mod_max_wood", show_post, String::num(building->mod_max_wood), request->get_parameter("mod_max_wood"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Mod Max Stone:", "mod_max_stone", show_post, String::num(building->mod_max_stone), request->get_parameter("mod_max_stone"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Mod Max Iron:", "mod_max_iron", show_post, String::num(building->mod_max_iron), request->get_parameter("mod_max_iron"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Mod Max Mana:", "mod_max_mana", show_post, String::num(building->mod_max_mana), request->get_parameter("mod_max_mana"));
|
||||
|
||||
ADMIN_EDIT_LINE_SPACER();
|
||||
|
||||
ADMIN_EDIT_INPUT_TEXT("Mod Rate Food:", "mod_rate_food", show_post, String::num(building->mod_rate_food), request->get_parameter("mod_rate_food"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Mod Rate Wood:", "mod_rate_wood", show_post, String::num(building->mod_rate_wood), request->get_parameter("mod_rate_wood"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Mod Rate Stone:", "mod_rate_stone", show_post, String::num(building->mod_rate_stone), request->get_parameter("mod_rate_stone"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Mod Rate Iron:", "mod_rate_iron", show_post, String::num(building->mod_rate_iron), request->get_parameter("mod_rate_iron"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Mod Rate Mana:", "mod_rate_mana", show_post, String::num(building->mod_rate_mana), request->get_parameter("mod_rate_mana"));
|
||||
|
||||
ADMIN_EDIT_LINE_SPACER();
|
||||
|
||||
ADMIN_EDIT_INPUT_TEXT("Mod Percent Food:", "mod_percent_food", show_post, String::num(building->mod_percent_food), request->get_parameter("mod_percent_food"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Mod Percent Wood:", "mod_percent_wood", show_post, String::num(building->mod_percent_wood), request->get_parameter("mod_percent_wood"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Mod Percent Stone:", "mod_percent_stone", show_post, String::num(building->mod_percent_stone), request->get_parameter("mod_percent_stone"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Mod Percent Iron:", "mod_percent_iron", show_post, String::num(building->mod_percent_iron), request->get_parameter("mod_percent_iron"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Mod Percent Mana:", "mod_percent_mana", show_post, String::num(building->mod_percent_mana), request->get_parameter("mod_percent_mana"));
|
||||
|
||||
ADMIN_EDIT_LINE_SPACER();
|
||||
|
||||
//TODO <?=form_dropdown($name_assign1, $optass, $assign1, $attr_assign); ?>
|
||||
|
||||
ADMIN_EDIT_INPUT_TEXT("Assignment 1:", "assignment1", show_post, String::num(building->assignment1), request->get_parameter("assignment1"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Assignment 2:", "assignment2", show_post, String::num(building->assignment2), request->get_parameter("assignment2"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Assignment 3:", "assignment3", show_post, String::num(building->assignment3), request->get_parameter("assignment3"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Assignment 4:", "assignment4", show_post, String::num(building->assignment4), request->get_parameter("assignment4"));
|
||||
ADMIN_EDIT_INPUT_TEXT("Assignment 5:", "assignment5", show_post, String::num(building->assignment5), request->get_parameter("assignment5"));
|
||||
|
||||
ADMIN_EDIT_LINE_SPACER();
|
||||
|
||||
//TODO <?=form_dropdown($name_req_tech, $optreqtech, $selreqtech, $attr_req_tech); ?>
|
||||
ADMIN_EDIT_INPUT_TEXT("Required Technology:", "req_tech", show_post, String::num(building->req_tech), request->get_parameter("req_tech"));
|
||||
ADMIN_EDIT_LINE_SPACER();
|
||||
//TODO <?=form_dropdown($name_tech_group, $opttechgroup, $seltechgroup, $attr_assign);?>
|
||||
ADMIN_EDIT_INPUT_TEXT("Technology Group:", "tech_group", show_post, String::num(building->tech_group), request->get_parameter("tech_group"));
|
||||
ADMIN_EDIT_LINE_SPACER();
|
||||
//TODO <?=form_dropdown($name_tech_secondary_group, $opttechgroup, $seltechsecgroup, $attr_tech_secondary_group); ?>
|
||||
ADMIN_EDIT_INPUT_TEXT("Secondary Technology Group:", "tech_secondary_group", show_post, String::num(building->tech_secondary_group), request->get_parameter("tech_secondary_group"));
|
||||
|
||||
b.div("edit_submit")->f()->input_submit("Save", "submit")->f()->cdiv();
|
||||
|
||||
b.cform();
|
||||
|
||||
request->body += b.result;
|
||||
}
|
||||
|
||||
|
@ -17,7 +17,7 @@ public:
|
||||
virtual Ref<Building> get_building(const int id);
|
||||
virtual Vector<Ref<Building> > get_all();
|
||||
virtual void save_building(Ref<Building> &building);
|
||||
|
||||
|
||||
virtual void parse_row(Ref<QueryResult> &result, Ref<Building> &building);
|
||||
|
||||
virtual void create_table();
|
||||
|
19
app/html_macros.h
Normal file
19
app/html_macros.h
Normal file
@ -0,0 +1,19 @@
|
||||
#ifndef HTML_MACROS_H
|
||||
#define HTML_MACROS_H
|
||||
|
||||
#define ADMIN_EDIT_INPUT_TEXT(p_edit_name, p_var_name, p_show_post, p_var, p_request_var) \
|
||||
b.div("row_edit"); \
|
||||
b.fdiv(p_edit_name, "edit_name"); \
|
||||
b.div("edit_input")->f()->input_text(p_var_name, p_show_post ? p_request_var : p_var, "", "input")->f()->cdiv(); \
|
||||
b.cdiv();
|
||||
|
||||
#define ADMIN_EDIT_INPUT_TEXTAREA(p_edit_name, p_var_name, p_show_post, p_var, p_request_var) \
|
||||
b.div("row_edit_textbox"); \
|
||||
b.fdiv(p_edit_name, "edit_name"); \
|
||||
b.div("edit_input")->f()->ftextarea(p_var_name, p_show_post ? p_request_var : p_var, "textarea")->cdiv(); \
|
||||
b.cdiv();
|
||||
|
||||
#define ADMIN_EDIT_LINE_SPACER() \
|
||||
b.fdiv("", "edit_spacer");
|
||||
|
||||
#endif
|
1181
www/css/base.css
1181
www/css/base.css
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user