Skip to content

Commit 83d3660

Browse files
fix: alignment on unit stats and make drawing OOP (#982)
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
1 parent 8546127 commit 83d3660

File tree

4 files changed

+431
-396
lines changed

4 files changed

+431
-396
lines changed

objects/obj_controller/Create_0.gml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ serialize = function(){
12201220

12211221
}
12221222
var excluded_from_save = ["temp", "serialize", "deserialize", "build_chaos_gods", "company_data","menu_buttons",
1223-
"location_viewer", "production_research_pathways", "specialist_point_handler", "spec_train_data"]
1223+
"location_viewer", "production_research_pathways", "specialist_point_handler", "spec_train_data", "tooltips", "last_unit", "unit_manage_constants"],
12241224
var excluded_from_save_start = ["restart_"];
12251225

12261226
copy_serializable_fields(object_controller, save_data, excluded_from_save, excluded_from_save_start);

objects/obj_controller/Step_0.gml

Lines changed: 2 additions & 248 deletions
Original file line numberDiff line numberDiff line change
@@ -438,260 +438,14 @@ try {
438438
yy += 77;
439439
}
440440
if (is_struct(unit_focus)) {
441-
var ach = 0,
442-
damage_res = 1,
443-
armour_value = 0;
441+
444442
// Checks if the marine is not hidden
445443
var unit = unit_focus;
446444
if (!is_array(last_unit)) {
447445
last_unit = [0, 0];
448446
}
449447
if ((unit.base_group != "none") && (last_unit[1] != unit.marine_number || last_unit[0] != unit.company)) {
450-
last_unit = [unit.company, unit.marine_number];
451-
marine_armour[0] = unit.armour();
452-
fix_right = 0;
453-
equip_data = unit.unit_equipment_data();
454-
temp[100] = "1";
455-
if (unit.race() != 1) {
456-
temp[100] = unit.race();
457-
}
458-
459-
damage_res = unit.damage_resistance();
460-
461-
if (is_struct(equip_data.armour_data)) {
462-
temp[103] = equip_data.armour_data.item_tooltip_desc_gen();
463-
} else {
464-
temp[103] = "";
465-
}
466-
// Sets up the description for the equipement of current marine
467-
//temp[103]="";
468-
// Gear
469-
temp[104] = unit.gear();
470-
if (is_struct(equip_data.gear_data)) {
471-
temp[105] = equip_data.gear_data.item_tooltip_desc_gen();
472-
} else {
473-
temp[105] = "";
474-
}
475-
//if (string_count("&",temp[104])>0) then temp[104]=clean_tags(temp[104]);
476-
// Mobility Item
477-
temp[106] = unit.mobility_item();
478-
if (is_struct(equip_data.mobility_data)) {
479-
temp[107] = equip_data.mobility_data.item_tooltip_desc_gen();
480-
} else {
481-
temp[107] = "";
482-
}
483-
temp[108] = unit.weapon_one();
484-
if (is_struct(equip_data.weapon_one_data)) {
485-
temp[109] = equip_data.weapon_one_data.item_tooltip_desc_gen();
486-
} else {
487-
temp[109] = "";
488-
}
489-
temp[110] = unit.weapon_two();
490-
if (is_struct(equip_data.weapon_two_data)) {
491-
temp[111] = equip_data.weapon_two_data.item_tooltip_desc_gen();
492-
} else {
493-
temp[111] = "";
494-
}
495-
//if (string_count("&",temp[106])>0) then temp[106]=clean_tags(temp[106]);
496-
// Experience
497-
temp[113] = string(floor(unit.experience));
498-
// Psyker things
499-
temp[119] = "";
500-
temp[123] = "";
501-
var _psy_powers_known = unit.powers_known;
502-
var _psy_powers_count = array_length(_psy_powers_known);
503-
if (_psy_powers_count > 0) {
504-
var _psy_discipline = unit.psy_discipline();
505-
var _psy_discipline_name = get_discipline_data(_psy_discipline, "name");
506-
temp[119] = $"{unit.psionic}/{_psy_powers_count}";
507-
508-
var _tooltip = "";
509-
_tooltip += $"Psychic Rating: {unit.psionic}";
510-
511-
var _equipment_psychic_amplification = unit.gear_special_value("psychic_amplification");
512-
var _character_psychic_amplification = unit.psychic_amplification() * 100;
513-
var _equipment_psychic_focus = unit.gear_special_value("psychic_focus");
514-
var _character_psychic_focus = unit.psychic_focus();
515-
var _perils_chance = unit.perils_threshold() / 10;
516-
_tooltip += $"\nAmplification from Equipment: {_equipment_psychic_amplification}%";
517-
_tooltip += $"\nAmplification from Attributes (Psy Rating and EXP): {_character_psychic_amplification}%";
518-
519-
_tooltip += $"\n\nFocus Success Chance: {100 - unit.psychic_focus_difficulty()}%";
520-
_tooltip += $"\nFocus from Equipment: {_equipment_psychic_focus}%";
521-
_tooltip += $"\nFocus from Attributes (WIS and EXP): {_character_psychic_focus}%";
522-
523-
_tooltip += $"\n\nPerils of the Warp Chance: {_perils_chance}%";
524-
525-
_tooltip += $"\n\nMain Discipline: {_psy_discipline_name}";
526-
_tooltip += $"\nKnown Powers: ";
527-
for (var i = 0; i < _psy_powers_count; i++) {
528-
_tooltip += get_power_data(_psy_powers_known[i], "name");
529-
_tooltip += smart_delimeter_sign(_psy_powers_count, i, false);
530-
}
531-
temp[123] = _tooltip;
532-
}
533-
// Corruption
534-
if ((obj_controller.chaos_rating > 0) && (temp[119] != "")) {
535-
temp[119] += "#" + string(max(0, unit.corruption())) + "% Corruption.";
536-
}
537-
if ((obj_controller.chaos_rating > 0) && (temp[119] == "")) {
538-
temp[119] = string(max(0, unit.corruption())) + "% Corruption.";
539-
}
540-
// Melee Attack
541-
temp[116] = unit.melee_attack();
542-
// Ranged Attack
543-
temp[117] = unit.ranged_attack();
544-
// Damage Resistance
545-
temp[118] = string(damage_res) + "%";
546-
temp[130] = "Health damage taken by the marine is reduced by this percentage. This happens after the flat reduction from armor.\n\nContributing factors:\n";
547-
var equipment_types = ["armour", "weapon_one", "weapon_two", "mobility", "gear"];
548-
for (var i = 0; i < array_length(equipment_types); i++) {
549-
var equipment_type = equipment_types[i];
550-
var dr = 0;
551-
var name = "";
552-
switch (equipment_type) {
553-
case "armour":
554-
dr = unit.get_armour_data("damage_resistance_mod");
555-
name = unit.get_armour_data("name");
556-
break;
557-
case "weapon_one":
558-
dr = unit.get_weapon_one_data("damage_resistance_mod");
559-
name = unit.get_weapon_one_data("name");
560-
break;
561-
case "weapon_two":
562-
dr = unit.get_weapon_two_data("damage_resistance_mod");
563-
name = unit.get_weapon_two_data("name");
564-
break;
565-
case "mobility":
566-
dr = unit.get_mobility_data("damage_resistance_mod");
567-
name = unit.get_mobility_data("name");
568-
break;
569-
case "gear":
570-
dr = unit.get_gear_data("damage_resistance_mod");
571-
name = unit.get_gear_data("name");
572-
break;
573-
}
574-
if (dr != 0) {
575-
temp[130] += $"{name}: {dr}%\n";
576-
}
577-
}
578-
temp[130] += string("CON: {0}%\nEXP: {1}%", round(unit.constitution / 2), round(unit.experience / 10));
579-
if (is_struct(temp[121])) {
580-
try {
581-
temp[121].destroy_image();
582-
}
583-
delete temp[121];
584-
}
585-
temp[124] = $"{round(unit.hp())}/{round(unit.max_health())}"; // Health Tracker
586-
temp[125] = $"A measure how much punishment the creature can take. Marines can go into the negatives and still survive, but they'll require a bionic to become fighting fit once more.\n\nContributing factors:\nCON: {round(100 * (1 + ((unit.constitution - 40) * 0.025)))}\n";
587-
for (var i = 0; i < array_length(equipment_types); i++) {
588-
var equipment_type = equipment_types[i];
589-
var hp_mod = 0;
590-
var name = "";
591-
switch (equipment_type) {
592-
case "armour":
593-
hp_mod = unit.get_armour_data("hp_mod");
594-
name = unit.get_armour_data("name");
595-
break;
596-
case "weapon_one":
597-
hp_mod = unit.get_weapon_one_data("hp_mod");
598-
name = unit.get_weapon_one_data("name");
599-
break;
600-
case "weapon_two":
601-
hp_mod = unit.get_weapon_two_data("hp_mod");
602-
name = unit.get_weapon_two_data("name");
603-
break;
604-
case "mobility":
605-
hp_mod = unit.get_mobility_data("hp_mod");
606-
name = unit.get_mobility_data("name");
607-
break;
608-
case "gear":
609-
hp_mod = unit.get_gear_data("hp_mod");
610-
name = unit.get_gear_data("name");
611-
break;
612-
}
613-
if (hp_mod != 0) {
614-
temp[125] += $"{name}: {format_number_with_sign(hp_mod)}%\n";
615-
}
616-
}
617-
temp[126] = $"{unit.armour_calc()}"; // Armour Rating
618-
temp[127] = "Reduces incoming damage at a flat rate. Certain enemies may attack in ways that may bypass your armor entirely, for example power weapons and some warp sorceries.\n\nContributing factors:\n";
619-
for (var i = 0; i < array_length(equipment_types); i++) {
620-
var equipment_type = equipment_types[i];
621-
var ac = 0;
622-
var name = "";
623-
switch (equipment_type) {
624-
case "armour":
625-
ac = unit.get_armour_data("armour_value");
626-
name = unit.get_armour_data("name");
627-
break;
628-
case "weapon_one":
629-
ac = unit.get_weapon_one_data("armour_value");
630-
name = unit.get_weapon_one_data("name");
631-
break;
632-
case "weapon_two":
633-
ac = unit.get_weapon_two_data("armour_value");
634-
name = unit.get_weapon_two_data("name");
635-
break;
636-
case "mobility":
637-
ac = unit.get_mobility_data("armour_value");
638-
name = unit.get_mobility_data("name");
639-
break;
640-
case "gear":
641-
ac = unit.get_gear_data("armour_value");
642-
name = unit.get_gear_data("name");
643-
break;
644-
}
645-
if (ac != 0) {
646-
temp[127] += $"{name}: {ac}\n";
647-
}
648-
}
649-
if (obj_controller.stc_bonus[1] == 5 || obj_controller.stc_bonus[2] == 3) {
650-
temp[127] += $"STC Bonus: x1.05\n";
651-
}
652-
temp[128] = $"{unit.bionics}";
653-
var _body_parts = ARR_body_parts;
654-
var _body_parts_display = ARR_body_parts_display;
655-
temp[129] = "Bionic Augmentation is something a unit can do to both enhance their capabilities, but also replace a missing limb to get back into the fight.";
656-
temp[129] += "\nThere is a limit of 10 Bionic augmentations. After that the damage is so extensive that a marine requires a dreadnought to keep going.";
657-
temp[129] += "\nFor everyone else? It's time for the emperor's mercy.";
658-
temp[129] += "\n\nCurrent Bionic Augmentations:\n";
659-
for (var part = 0; part < array_length(_body_parts); part++) {
660-
if (struct_exists(unit.body[$ _body_parts[part]], "bionic")) {
661-
var part_display = _body_parts_display[part];
662-
temp[129] += $"Bionic {part_display}";
663-
switch (part_display) {
664-
case "Left Leg":
665-
case "Right Leg":
666-
temp[129] += $" (CON: +2 STR: +1 DEX: -2)\n";
667-
break;
668-
case "Left Eye":
669-
case "Right Eye":
670-
temp[129] += $" (CON: +1 WIS: +1 DEX: +1)\n";
671-
break;
672-
case "Left Arm":
673-
case "Right Arm":
674-
temp[129] += $" (CON: +2 STR: +2 WS: -1)\n";
675-
break;
676-
case "Torso":
677-
temp[129] += $" (CON: +4 STR: +1 DEX: -1)\n";
678-
break;
679-
case "Throat":
680-
temp[129] += $" (CHA: -1)\n";
681-
break;
682-
case "Jaw":
683-
case "Head":
684-
temp[129] += $" (CON: +1)\n";
685-
break;
686-
}
687-
}
688-
}
689-
temp[121] = unit.draw_unit_image();
690-
691-
temp[122] = unit.handle_stat_growth();
692-
/*if (man[sel]="vehicle"){
693-
// TODO
694-
}*/
448+
reset_manage_unit_constants(unit);
695449
}
696450
}
697451
}

scripts/scr_buttons/scr_buttons.gml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,68 @@ function pop_draw_return_values(){
2424
array_delete(global.draw_return_stack, _index, 1);
2525
}
2626
}
27+
//position, icon, text, text_max_width, tooltip, text_position, font = fnt_40k_14, colour = CM_GREEN_COLOR
28+
function LabeledIcon(icon, text,x1=0,y1=0,data = false) constructor{
29+
30+
self.x1 = x1;
31+
self.y1 = y1;
32+
x2 = 0;
33+
y2 = 0;
34+
35+
self.text = text;
36+
text_max_width = -1;
37+
font = fnt_40k_14;
38+
colour = CM_GREEN_COLOR;
39+
text_position = "right";
40+
tooltip = "";
41+
self.icon = sprite_exists(icon) ? icon : spr_none;
42+
icon_width = sprite_get_width(self.icon);
43+
icon_height = sprite_get_height(self.icon);
44+
w = icon_width;
45+
h = icon_height;
46+
47+
move_data_to_current_scope(data);
48+
49+
static update = function(data = {}){
50+
move_data_to_current_scope(data);
51+
add_draw_return_values();
52+
draw_set_font(font);
53+
if (text_position == "right"){
54+
w = x1 + icon_width + 2 + string_width(text);;
55+
x2 = w;
56+
h = icon_height;
57+
y2 = y1 + icon_height;
58+
}
59+
pop_draw_return_values();
60+
}
61+
62+
update();
63+
64+
static hit = function(){
65+
return scr_hit(x1,y1,x2,y2);
66+
}
67+
68+
69+
static draw = function(){
70+
add_draw_return_values();
71+
draw_set_font(font);
72+
draw_set_halign(fa_left);
73+
draw_set_valign(fa_top);
74+
draw_set_color(colour);
75+
draw_sprite_stretched(icon, 0, x1,y1, icon_width, icon_height);
76+
if (text_position == "right"){
77+
var _string_x = x1 + icon_width + 2;
78+
draw_text_outline(_string_x, y1 + 4, text);
79+
if (tooltip!=""){
80+
if (hit()){
81+
tooltip_draw(tooltip);
82+
}
83+
}
84+
};
85+
pop_draw_return_values()
86+
};
87+
88+
}
2789

2890
function draw_sprite_as_button(position, choice_sprite, scale = [1,1], hover_sprite = -1){
2991
var _pos = [position[0],position[1], position[0]+(sprite_get_width(choice_sprite)*scale[0]), position[1] + (sprite_get_height(choice_sprite)*scale[1])];

0 commit comments

Comments
 (0)